From 4be51c1bd86e6abb3ac2108766632169c68968b3 Mon Sep 17 00:00:00 2001 From: Steve Sloka Date: Mon, 30 Jul 2018 11:01:00 -0400 Subject: [PATCH 1/2] Update dep versions in Gopkg.toml Signed-off-by: Steve Sloka --- discovery/Gopkg.toml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/discovery/Gopkg.toml b/discovery/Gopkg.toml index e3910c56..5385ec1f 100644 --- a/discovery/Gopkg.toml +++ b/discovery/Gopkg.toml @@ -33,26 +33,26 @@ required = [ [[constraint]] name = "github.com/sirupsen/logrus" - version = "1.0.4" + version = "1.0.5" [[constraint]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/api" [[constraint]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/apimachinery" [[constraint]] name = "k8s.io/client-go" - version="~6.0" + version="v7.0.0" [[constraint]] name = "k8s.io/kubernetes" - version = "~1.9" + version = "~1.10" [[constraint]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/code-generator" [[constraint]] @@ -60,5 +60,9 @@ required = [ name = "k8s.io/gengo" [[constraint]] - branch = "master" + revision = "f8826f28e31a2f66e771939532bcae910ed2420f" name = "github.com/gophercloud/gophercloud" + +[[override]] + name = "github.com/json-iterator/go" + revision = "f2b4162afba35581b6d4a50d3b8f34e33c144682" \ No newline at end of file From bacbad6738d856950b830124facb6d5cb2853d7b Mon Sep 17 00:00:00 2001 From: Steve Sloka Date: Mon, 30 Jul 2018 11:02:05 -0400 Subject: [PATCH 2/2] Update vendor deps Signed-off-by: Steve Sloka --- discovery/Gopkg.lock | 145 +- .../github.com/PuerkitoBio/purell/.gitignore | 5 - .../github.com/PuerkitoBio/purell/LICENSE | 12 - .../github.com/PuerkitoBio/purell/README.md | 187 - .../PuerkitoBio/purell/benchmarks/v0.1.0 | 9 - .../github.com/PuerkitoBio/purell/purell.go | 379 - .../github.com/PuerkitoBio/urlesc/LICENSE | 27 - .../github.com/PuerkitoBio/urlesc/README.md | 16 - .../github.com/PuerkitoBio/urlesc/urlesc.go | 180 - .../beorn7/perks/histogram/bench_test.go | 26 + .../beorn7/perks/histogram/histogram_test.go | 38 + .../beorn7/perks/quantile/bench_test.go | 63 + .../beorn7/perks/quantile/example_test.go | 121 + .../beorn7/perks/quantile/stream_test.go | 215 + .../github.com/beorn7/perks/topk/topk_test.go | 57 + .../github.com/davecgh/go-spew/.travis.yml | 14 + .../davecgh/go-spew/spew/common_test.go | 298 + .../davecgh/go-spew/spew/dump_test.go | 1042 + .../davecgh/go-spew/spew/dumpcgo_test.go | 99 + .../davecgh/go-spew/spew/dumpnocgo_test.go | 26 + .../davecgh/go-spew/spew/example_test.go | 226 + .../davecgh/go-spew/spew/format_test.go | 1558 ++ .../davecgh/go-spew/spew/internal_test.go | 87 + .../go-spew/spew/internalunsafe_test.go | 102 + .../davecgh/go-spew/spew/spew_test.go | 320 + .../github.com/emicklei/go-restful/.gitignore | 70 - .../github.com/emicklei/go-restful/CHANGES.md | 226 - .../github.com/emicklei/go-restful/LICENSE | 22 - .../github.com/emicklei/go-restful/Makefile | 7 - .../github.com/emicklei/go-restful/README.md | 75 - .../github.com/emicklei/go-restful/Srcfile | 1 - .../emicklei/go-restful/bench_test.sh | 10 - .../emicklei/go-restful/compress.go | 123 - .../emicklei/go-restful/compressor_cache.go | 103 - .../emicklei/go-restful/compressor_pools.go | 91 - .../emicklei/go-restful/compressors.go | 54 - .../emicklei/go-restful/constants.go | 30 - .../emicklei/go-restful/container.go | 366 - .../emicklei/go-restful/cors_filter.go | 202 - .../emicklei/go-restful/coverage.sh | 2 - .../github.com/emicklei/go-restful/curly.go | 164 - .../emicklei/go-restful/curly_route.go | 52 - .../github.com/emicklei/go-restful/doc.go | 185 - .../emicklei/go-restful/entity_accessors.go | 163 - .../emicklei/go-restful/examples/.goconvey | 1 - .../examples/google_app_engine/.goconvey | 1 - .../examples/google_app_engine/app.yaml | 20 - .../google_app_engine/datastore/.goconvey | 1 - .../google_app_engine/datastore/app.yaml | 18 - .../google_app_engine/datastore/main.go | 267 - .../restful-appstats-integration.go | 12 - .../google_app_engine/restful-user-service.go | 162 - .../emicklei/go-restful/examples/home.html | 7 - .../examples/msgpack/msgpack_entity.go | 34 - .../examples/restful-CORS-filter.go | 68 - .../examples/restful-NCSA-logging.go | 54 - .../examples/restful-basic-authentication.go | 35 - .../examples/restful-cpuprofiler-service.go | 65 - .../examples/restful-curly-router.go | 107 - .../examples/restful-encoding-filter.go | 61 - .../go-restful/examples/restful-filters.go | 114 - .../examples/restful-form-handling.go | 63 - .../examples/restful-hello-world.go | 23 - .../examples/restful-html-template.go | 35 - .../examples/restful-multi-containers.go | 43 - .../examples/restful-no-cache-filter.go | 25 - .../examples/restful-options-filter.go | 51 - .../go-restful/examples/restful-path-tail.go | 27 - .../examples/restful-pre-post-filters.go | 98 - .../examples/restful-resource-functions.go | 63 - .../examples/restful-serve-static.go | 47 - .../go-restful/examples/restful-swagger.go | 61 - .../examples/restful-user-resource.go | 170 - .../github.com/emicklei/go-restful/filter.go | 35 - .../github.com/emicklei/go-restful/jsr311.go | 268 - .../github.com/emicklei/go-restful/log/log.go | 34 - .../github.com/emicklei/go-restful/logger.go | 32 - .../github.com/emicklei/go-restful/mime.go | 45 - .../emicklei/go-restful/options_filter.go | 34 - .../emicklei/go-restful/parameter.go | 114 - .../emicklei/go-restful/path_expression.go | 69 - .../github.com/emicklei/go-restful/request.go | 113 - .../emicklei/go-restful/response.go | 250 - .../github.com/emicklei/go-restful/route.go | 192 - .../emicklei/go-restful/route_builder.go | 310 - .../github.com/emicklei/go-restful/router.go | 18 - .../emicklei/go-restful/service_error.go | 23 - .../emicklei/go-restful/web_service.go | 290 - .../go-restful/web_service_container.go | 39 - .../vendor/github.com/ghodss/yaml/.travis.yml | 7 + .../github.com/ghodss/yaml/yaml_test.go | 287 + .../go-openapi/jsonpointer/.editorconfig | 26 - .../jsonpointer/.github/CONTRIBUTING.md | 117 - .../go-openapi/jsonpointer/.gitignore | 1 - .../go-openapi/jsonpointer/CODE_OF_CONDUCT.md | 74 - .../github.com/go-openapi/jsonpointer/LICENSE | 202 - .../go-openapi/jsonpointer/README.md | 15 - .../go-openapi/jsonpointer/pointer.go | 390 - .../jsonreference/.github/CONTRIBUTING.md | 117 - .../go-openapi/jsonreference/.gitignore | 1 - .../jsonreference/CODE_OF_CONDUCT.md | 74 - .../go-openapi/jsonreference/LICENSE | 202 - .../go-openapi/jsonreference/README.md | 15 - .../go-openapi/jsonreference/reference.go | 156 - .../github.com/go-openapi/spec/.editorconfig | 26 - .../go-openapi/spec/.github/CONTRIBUTING.md | 117 - .../github.com/go-openapi/spec/.gitignore | 2 - .../go-openapi/spec/CODE_OF_CONDUCT.md | 74 - .../vendor/github.com/go-openapi/spec/LICENSE | 202 - .../github.com/go-openapi/spec/README.md | 5 - .../github.com/go-openapi/spec/bindata.go | 260 - .../go-openapi/spec/contact_info.go | 24 - .../github.com/go-openapi/spec/expander.go | 894 - .../go-openapi/spec/external_docs.go | 24 - .../fixtures/expansion/all-the-things.json | 254 - .../spec/fixtures/expansion/circularRefs.json | 54 - .../spec/fixtures/expansion/circularSpec.json | 1 - .../spec/fixtures/expansion/circularSpec.yaml | 67 - .../spec/fixtures/expansion/clickmeter.json | 1 - .../spec/fixtures/expansion/clickmeter.yaml | 6461 ------ .../spec/fixtures/expansion/invalid-refs.json | 85 - .../fixtures/expansion/missingItemRef.json | 31 - .../spec/fixtures/expansion/missingRef.json | 165 - .../spec/fixtures/expansion/overflow.json | 124 - .../spec/fixtures/expansion/params.json | 25 - .../spec/fixtures/expansion/schemas1.json | 127 - .../spec/fixtures/expansion/schemas2.json | 161 - .../spec/fixtures/local_expansion/item.json | 18 - .../spec/fixtures/local_expansion/spec.json | 46 - .../spec/fixtures/specs/deeper/arrayProp.json | 6 - .../fixtures/specs/deeper/stringProp.json | 3 - .../go-openapi/spec/fixtures/specs/refed.json | 224 - .../spec/fixtures/specs/resolution.json | 14 - .../spec/fixtures/specs/resolution2.json | 9 - .../github.com/go-openapi/spec/header.go | 195 - .../vendor/github.com/go-openapi/spec/info.go | 168 - .../github.com/go-openapi/spec/items.go | 229 - .../github.com/go-openapi/spec/license.go | 23 - .../github.com/go-openapi/spec/operation.go | 258 - .../github.com/go-openapi/spec/parameter.go | 301 - .../github.com/go-openapi/spec/path_item.go | 90 - .../github.com/go-openapi/spec/paths.go | 97 - .../vendor/github.com/go-openapi/spec/ref.go | 164 - .../github.com/go-openapi/spec/response.go | 134 - .../github.com/go-openapi/spec/responses.go | 122 - .../github.com/go-openapi/spec/schema.go | 628 - .../spec/schemas/jsonschema-draft-04.json | 150 - .../go-openapi/spec/schemas/v2/README.md | 5 - .../go-openapi/spec/schemas/v2/schema.json | 1607 -- .../go-openapi/spec/security_scheme.go | 142 - .../vendor/github.com/go-openapi/spec/spec.go | 86 - .../github.com/go-openapi/spec/swagger.go | 317 - .../vendor/github.com/go-openapi/spec/tag.go | 73 - .../github.com/go-openapi/spec/xml_object.go | 68 - .../github.com/go-openapi/swag/.editorconfig | 26 - .../go-openapi/swag/.github/CONTRIBUTING.md | 117 - .../github.com/go-openapi/swag/.gitignore | 3 - .../go-openapi/swag/CODE_OF_CONDUCT.md | 74 - .../vendor/github.com/go-openapi/swag/LICENSE | 202 - .../github.com/go-openapi/swag/README.md | 12 - .../github.com/go-openapi/swag/convert.go | 188 - .../go-openapi/swag/convert_types.go | 595 - .../vendor/github.com/go-openapi/swag/json.go | 295 - .../github.com/go-openapi/swag/loading.go | 74 - .../vendor/github.com/go-openapi/swag/net.go | 24 - .../vendor/github.com/go-openapi/swag/path.go | 59 - .../vendor/github.com/go-openapi/swag/util.go | 374 - .../vendor/github.com/go-openapi/swag/yaml.go | 215 - .../github.com/gogo/protobuf/.travis.yml | 20 + .../gogo/protobuf/codec/codec_test.go | 54 + .../github.com/gogo/protobuf/io/io_test.go | 221 + .../gogo/protobuf/io/uint32_test.go | 38 + .../gogo/protobuf/jsonpb/jsonpb_test.go | 783 + .../gogo/protobuf/proto/all_test.go | 2278 ++ .../gogo/protobuf/proto/any_test.go | 300 + .../gogo/protobuf/proto/clone_test.go | 300 + .../gogo/protobuf/proto/decode_test.go | 262 + .../gogo/protobuf/proto/encode_test.go | 84 + .../gogo/protobuf/proto/equal_test.go | 224 + .../gogo/protobuf/proto/extensions_test.go | 538 + .../gogo/protobuf/proto/map_test.go | 46 + .../gogo/protobuf/proto/message_set_test.go | 66 + .../gogo/protobuf/proto/proto3_test.go | 135 + .../gogo/protobuf/proto/size2_test.go | 63 + .../gogo/protobuf/proto/size_test.go | 164 + .../protobuf/proto/testdata/golden_test.go | 86 + .../gogo/protobuf/proto/text_parser_test.go | 673 + .../gogo/protobuf/proto/text_test.go | 474 + .../descriptor/descriptor_test.go | 31 + .../protoc-gen-gogo/generator/name_test.go | 85 + .../testdata/extension_test.go | 210 + .../protoc-gen-gogo/testdata/main_test.go | 46 + .../test/asymetric-issue125/asym_test.go | 40 + .../test/asymetric-issue125/asympb_test.go | 185 + .../github.com/gogo/protobuf/test/bug_test.go | 252 + .../casttype/combos/both/casttypepb_test.go | 512 + .../combos/marshaler/casttypepb_test.go | 512 + .../combos/neither/casttypepb_test.go | 456 + .../combos/unmarshaler/casttypepb_test.go | 456 + .../test/castvalue/castvaluepb_test.go | 456 + .../castvalue/combos/both/castvaluepb_test.go | 512 + .../combos/marshaler/castvaluepb_test.go | 512 + .../combos/unmarshaler/castvaluepb_test.go | 456 + .../protobuf/test/combos/both/bug_test.go | 252 + .../test/combos/both/thetestpb_test.go | 17950 ++++++++++++++++ .../test/combos/marshaler/bug_test.go | 252 + .../test/combos/marshaler/thetestpb_test.go | 17950 ++++++++++++++++ .../test/combos/unmarshaler/bug_test.go | 252 + .../test/combos/unmarshaler/thetestpb_test.go | 16046 ++++++++++++++ .../gogo/protobuf/test/custom/custom_test.go | 43 + .../custombytesnonstruct_test.go | 34 + .../protobuf/test/dashfilename/df_test.go | 48 + .../gogo/protobuf/test/data/datapb_test.go | 262 + .../protobuf/test/defaultconflict/nc_test.go | 68 + .../protobuf/test/embedconflict/ec_test.go | 119 + .../protobuf/test/empty-issue70/empty_test.go | 37 + .../protobuf/test/enumdecl/enumdeclpb_test.go | 238 + .../test/enumdecl_all/enumdeclallpb_test.go | 238 + .../test/enumstringer/enumstringerpb_test.go | 450 + .../protobuf/test/example/example_test.go | 35 + .../protobuf/test/example/examplepb_test.go | 1671 ++ .../gogo/protobuf/test/extension_test.go | 164 + .../test/filedotname/file.dotpb_test.go | 245 + .../gogo/protobuf/test/fuzztests/fuzz_test.go | 136 + .../gogo/protobuf/test/group/grouppb_test.go | 540 + .../test/importdedup/importdedup_test.go | 34 + .../indeximport-issue72/index/indexpb_test.go | 154 + .../indeximport-issue72/indeximportpb_test.go | 155 + .../test/int64support/object_js_test.go | 47 + .../test/int64support/objectpb_test.go | 262 + .../protobuf/test/issue260/issue260pb_test.go | 657 + .../test/issue312/events/eventspb_test.go | 123 + .../protobuf/test/issue322/issue322pb_test.go | 168 + .../protobuf/test/issue330/issue330pb_test.go | 208 + .../protobuf/test/issue34/issue34_test.go | 82 + .../protobuf/test/issue42order/order_test.go | 56 + .../gogo/protobuf/test/issue8/protopb_test.go | 107 + .../test/jsonpb-gogo/jsonpb_gogo_test.go | 36 + .../test/mapdefaults/combos/both/map_test.go | 180 + .../mapdefaults/combos/both/mappb_test.go | 565 + .../mapdefaults/combos/marshaler/map_test.go | 180 + .../combos/marshaler/mappb_test.go | 565 + .../mapdefaults/combos/neither/map_test.go | 180 + .../mapdefaults/combos/neither/mappb_test.go | 481 + .../combos/unmarshaler/map_test.go | 180 + .../combos/unmarshaler/mappb_test.go | 481 + .../mapsproto2/combos/both/mapsproto2_test.go | 104 + .../combos/both/mapsproto2pb_test.go | 990 + .../combos/marshaler/mapsproto2_test.go | 104 + .../combos/marshaler/mapsproto2pb_test.go | 990 + .../combos/neither/mapsproto2_test.go | 104 + .../combos/neither/mapsproto2pb_test.go | 878 + .../combos/unmarshaler/mapsproto2_test.go | 104 + .../combos/unmarshaler/mapsproto2pb_test.go | 878 + .../protobuf/test/moredefaults/md_test.go | 61 + .../protobuf/test/moredefaults/mdpb_test.go | 186 + .../protobuf/test/nopackage/nopackage_test.go | 38 + .../test/oneof/combos/both/onepb_test.go | 742 + .../test/oneof/combos/marshaler/onepb_test.go | 742 + .../test/oneof/combos/neither/onepb_test.go | 630 + .../oneof/combos/unmarshaler/onepb_test.go | 630 + .../test/oneof3/combos/both/onepb_test.go | 388 + .../oneof3/combos/marshaler/onepb_test.go | 388 + .../test/oneof3/combos/neither/onepb_test.go | 332 + .../oneof3/combos/unmarshaler/onepb_test.go | 332 + .../test/oneofembed/oneofembedpb_test.go | 185 + .../gogo/protobuf/test/packed/packed_test.go | 328 + .../protobuf/test/protosize/protosize_test.go | 37 + .../test/protosize/protosizepb_test.go | 154 + .../test/required/requiredexamplepb_test.go | 181 + .../test/sizerconflict/sizerconflict_test.go | 48 + .../sizeunderscore/sizeunderscorepb_test.go | 154 + .../test/stdtypes/concurrency_test.go | 31 + .../protobuf/test/stdtypes/stdtypespb_test.go | 808 + .../gogo/protobuf/test/tags/tags_test.go | 119 + .../test/theproto3/combos/both/proto3_test.go | 159 + .../theproto3/combos/both/theproto3pb_test.go | 2424 +++ .../theproto3/combos/marshaler/proto3_test.go | 159 + .../combos/marshaler/theproto3pb_test.go | 2424 +++ .../theproto3/combos/neither/proto3_test.go | 159 + .../combos/neither/theproto3pb_test.go | 2144 ++ .../combos/unmarshaler/proto3_test.go | 159 + .../combos/unmarshaler/theproto3pb_test.go | 2144 ++ .../gogo/protobuf/test/thetestpb_test.go | 16046 ++++++++++++++ .../protobuf/test/typedecl/typedeclpb_test.go | 656 + .../test/typedecl_all/typedeclallpb_test.go | 656 + .../typedeclimport/typedeclimport_test.go | 7 + .../test/types/combos/both/types_test.go | 242 + .../test/types/combos/both/typespb_test.go | 1985 ++ .../test/types/combos/marshaler/types_test.go | 242 + .../types/combos/marshaler/typespb_test.go | 1985 ++ .../test/types/combos/neither/types_test.go | 242 + .../test/types/combos/neither/typespb_test.go | 1733 ++ .../types/combos/unmarshaler/types_test.go | 242 + .../types/combos/unmarshaler/typespb_test.go | 1733 ++ .../unmarshalmerge/unmarshalmerge_test.go | 99 + .../unmarshalmerge/unmarshalmergepb_test.go | 704 + .../protobuf/test/unrecognized/oldnew_test.go | 200 + .../test/unrecognized/unrecognizedpb_test.go | 1881 ++ .../test/unrecognizedgroup/oldnew_test.go | 128 + .../unrecognizedgrouppb_test.go | 767 + .../gogo/protobuf/test/uuid_test.go | 51 + .../gogo/protobuf/types/any_test.go | 112 + .../gogo/protobuf/types/duration_test.go | 120 + .../gogo/protobuf/types/timestamp_test.go | 152 + .../gogo/protobuf/vanity/test/vanity_test.go | 93 + .../github.com/golang/glog/glog_test.go | 415 + .../github.com/golang/protobuf/.travis.yml | 18 + .../protobuf/descriptor/descriptor_test.go | 32 + .../golang/protobuf/jsonpb/jsonpb_test.go | 897 + .../golang/protobuf/proto/all_test.go | 2278 ++ .../golang/protobuf/proto/any_test.go | 300 + .../golang/protobuf/proto/clone_test.go | 300 + .../golang/protobuf/proto/decode_test.go | 258 + .../golang/protobuf/proto/encode_test.go | 85 + .../golang/protobuf/proto/equal_test.go | 224 + .../golang/protobuf/proto/extensions_test.go | 536 + .../golang/protobuf/proto/map_test.go | 46 + .../golang/protobuf/proto/message_set_test.go | 66 + .../golang/protobuf/proto/proto3_test.go | 135 + .../golang/protobuf/proto/size2_test.go | 63 + .../golang/protobuf/proto/size_test.go | 164 + .../protobuf/proto/testdata/golden_test.go | 86 + .../golang/protobuf/proto/text_parser_test.go | 673 + .../golang/protobuf/proto/text_test.go | 474 + .../protoc-gen-go/generator/name_test.go | 114 + .../protoc-gen-go/testdata/extension_test.go | 210 + .../protoc-gen-go/testdata/main_test.go | 46 + .../golang/protobuf/ptypes/any_test.go | 113 + .../golang/protobuf/ptypes/duration_test.go | 121 + .../golang/protobuf/ptypes/timestamp_test.go | 153 + .../vendor/github.com/google/btree/LICENSE | 202 - .../vendor/github.com/google/btree/README.md | 12 - .../vendor/github.com/google/btree/btree.go | 821 - .../github.com/google/btree/btree_mem.go | 76 - .../github.com/google/gofuzz/.travis.yml | 13 + .../github.com/google/gofuzz/example_test.go | 225 + .../github.com/google/gofuzz/fuzz_test.go | 472 + .../github.com/googleapis/gnostic/.travis.yml | 46 + .../generate-extension_test.go | 52 + .../googleapis/gnostic/gnostic_test.go | 453 + .../examples/v2.0/bookstore/bookstore_test.go | 239 + .../examples/v3.0/bookstore/bookstore_test.go | 239 + .../gophercloud/.github/CONTRIBUTING.md | 26 +- .../gophercloud/.github/ISSUE_TEMPLATE | 2 +- .../gophercloud/.github/PULL_REQUEST_TEMPLATE | 3 + .../gophercloud/gophercloud/.gitignore | 1 + .../gophercloud/gophercloud/.travis.yml | 21 + .../gophercloud/gophercloud/.zuul.yaml | 74 + .../gophercloud-acceptance-test/run.yaml | 26 + .../playbooks/gophercloud-unittest/run.yaml | 16 + .../gophercloud/gophercloud/README.md | 6 +- .../gophercloud/acceptance/clients/clients.go | 187 +- .../acceptance/clients/conditions.go | 68 + .../gophercloud/acceptance/clients/http.go | 168 + .../extensions/schedulerstats_test.go | 36 + .../blockstorage/extensions/services_test.go | 32 + .../extensions/volumeactions_test.go | 170 + .../blockstorage/noauth/snapshots_test.go | 58 + .../blockstorage/noauth/volumes_test.go | 52 + .../blockstorage/v1/snapshots_test.go | 58 + .../openstack/blockstorage/v1/volumes_test.go | 52 + .../blockstorage/v1/volumetypes_test.go | 47 + .../openstack/blockstorage/v2/blockstorage.go | 94 +- .../blockstorage/v2/snapshots_test.go | 46 + .../openstack/blockstorage/v2/volumes_test.go | 61 + .../openstack/blockstorage/v3/blockstorage.go | 118 +- .../blockstorage/v3/quotaset_test.go | 145 + .../blockstorage/v3/snapshots_test.go | 58 + .../openstack/blockstorage/v3/volumes_test.go | 50 + .../blockstorage/v3/volumetypes_test.go | 52 + .../acceptance/openstack/client_test.go | 86 + .../openstack/clustering/v1/actions_test.go | 31 + .../openstack/clustering/v1/clustering.go | 433 + .../openstack/clustering/v1/clusters_test.go | 267 + .../openstack/clustering/v1/nodes_test.go | 69 + .../acceptance/openstack/clustering/v1/pkg.go | 2 + .../openstack/clustering/v1/policies_test.go | 69 + .../clustering/v1/policytypes_test.go | 64 + .../openstack/clustering/v1/profiles_test.go | 49 + .../clustering/v1/profiletypes_test.go | 47 + .../openstack/clustering/v1/receivers_test.go | 59 + .../clustering/v1/webhooktrigger_test.go | 65 + .../openstack/compute/v2/aggregates_test.go | 146 + .../compute/v2/attachinterfaces_test.go | 51 + .../compute/v2/availabilityzones_test.go | 58 + .../compute/v2/bootfromvolume_test.go | 304 + .../openstack/compute/v2/compute.go | 288 +- .../openstack/compute/v2/defsecrules_test.go | 61 + .../openstack/compute/v2/extension_test.go | 46 + .../openstack/compute/v2/flavors_test.go | 202 + .../openstack/compute/v2/floatingip_test.go | 123 + .../openstack/compute/v2/hypervisors_test.go | 95 + .../openstack/compute/v2/images_test.go | 52 + .../openstack/compute/v2/keypairs_test.go | 102 + .../openstack/compute/v2/limits_test.go | 50 + .../openstack/compute/v2/migrate_test.go | 56 + .../openstack/compute/v2/network_test.go | 55 + .../openstack/compute/v2/quotaset_test.go | 147 + .../openstack/compute/v2/secgroup_test.go | 140 + .../openstack/compute/v2/servergroup_test.go | 71 + .../openstack/compute/v2/servers_test.go | 482 + .../openstack/compute/v2/services_test.go | 36 + .../compute/v2/tenantnetworks_test.go | 53 + .../openstack/compute/v2/usage_test.go | 91 + .../openstack/compute/v2/volumeattach_test.go | 38 + .../openstack/container/v1/capsules.go | 31 + .../openstack/container/v1/capsules_test.go | 88 + .../containerinfra/v1/certificates_test.go | 22 + .../v1/clustertemplates_test.go | 67 + .../containerinfra/v1/containerinfra.go | 83 + .../openstack/containerinfra/v1/pkg.go | 1 + .../openstack/db/v1/configurations_test.go | 50 + .../openstack/db/v1/databases_test.go | 55 + .../openstack/db/v1/flavors_test.go | 58 + .../openstack/db/v1/instances_test.go | 71 + .../acceptance/openstack/db/v1/users_test.go | 54 + .../acceptance/openstack/dns/v2/dns.go | 15 +- .../openstack/dns/v2/recordsets_test.go | 86 + .../acceptance/openstack/dns/v2/zones_test.go | 54 + .../openstack/identity/v2/extension_test.go | 49 + .../openstack/identity/v2/identity.go | 8 +- .../openstack/identity/v2/role_test.go | 76 + .../openstack/identity/v2/tenant_test.go | 65 + .../openstack/identity/v2/token_test.go | 60 + .../openstack/identity/v2/user_test.go | 59 + .../openstack/identity/v3/domains_test.go | 89 + .../openstack/identity/v3/endpoint_test.go | 78 + .../openstack/identity/v3/groups_test.go | 126 + .../openstack/identity/v3/identity.go | 15 + .../openstack/identity/v3/policies_test.go | 143 + .../openstack/identity/v3/projects_test.go | 192 + .../openstack/identity/v3/regions_test.go | 96 + .../openstack/identity/v3/roles_test.go | 633 + .../openstack/identity/v3/service_test.go | 78 + .../openstack/identity/v3/token_test.go | 49 + .../openstack/identity/v3/users_test.go | 334 + .../openstack/imageservice/v2/images_test.go | 140 + .../openstack/imageservice/v2/imageservice.go | 46 +- .../openstack/imageservice/v2/tasks_test.go | 63 + .../openstack/keymanager/v1/acls_test.go | 103 + .../keymanager/v1/containers_test.go | 188 + .../openstack/keymanager/v1/keymanager.go | 713 + .../openstack/keymanager/v1/orders_test.go | 84 + .../openstack/keymanager/v1/secrets_test.go | 242 + .../loadbalancer/v2/l7policies_test.go | 32 + .../loadbalancer/v2/listeners_test.go | 32 + .../openstack/loadbalancer/v2/loadbalancer.go | 397 + .../loadbalancer/v2/loadbalancers_test.go | 394 + .../loadbalancer/v2/monitors_test.go | 32 + .../openstack/loadbalancer/v2/pkg.go | 1 + .../openstack/loadbalancer/v2/pools_test.go | 32 + .../openstack/messaging/v2/claims_test.go | 63 + .../openstack/messaging/v2/message_test.go | 301 + .../openstack/messaging/v2/messaging.go | 173 + .../openstack/messaging/v2/queue_test.go | 154 + .../networking/v2/apiversion_test.go | 53 + .../openstack/networking/v2/extension_test.go | 46 + .../v2/extensions/fwaas/firewall_test.go | 212 + .../v2/extensions/fwaas/policy_test.go | 71 + .../v2/extensions/fwaas/rule_test.go | 64 + .../v2/extensions/layer3/floatingips_test.go | 147 + .../v2/extensions/layer3/routers_test.go | 119 + .../v2/extensions/lbaas/members_test.go | 83 + .../v2/extensions/lbaas/monitors_test.go | 63 + .../v2/extensions/lbaas/pools_test.go | 118 + .../v2/extensions/lbaas/vips_test.go | 83 + .../v2/extensions/lbaas_v2/listeners_test.go | 32 + .../extensions/lbaas_v2/loadbalancers_test.go | 178 + .../v2/extensions/lbaas_v2/monitors_test.go | 32 + .../v2/extensions/lbaas_v2/pools_test.go | 32 + .../networkipavailabilities_test.go | 32 + .../extensions/networkipavailabilities/pkg.go | 1 + .../portsbinding/portsbinding_test.go | 57 + .../networking/v2/extensions/provider_test.go | 34 + .../qos/ruletypes/ruletypes_test.go | 31 + .../v2/extensions/rbacpolicies/pkg.go | 1 + .../extensions/rbacpolicies/rbacpolicies.go | 43 + .../rbacpolicies/rbacpolicies_test.go | 113 + .../networking/v2/extensions/security_test.go | 105 + .../subnetpools/subnetpools_test.go | 65 + .../v2/extensions/vpnaas/group_test.go | 65 + .../v2/extensions/vpnaas/ikepolicy_test.go | 69 + .../v2/extensions/vpnaas/ipsecpolicy_test.go | 63 + .../v2/extensions/vpnaas/service_test.go | 60 + .../extensions/vpnaas/siteconnection_test.go | 125 + .../networking/v2/extensions/vpnaas/vpnaas.go | 258 + .../openstack/networking/v2/networking.go | 167 + .../openstack/networking/v2/networks_test.go | 179 + .../openstack/networking/v2/ports_test.go | 466 + .../openstack/networking/v2/subnets_test.go | 227 + .../objectstorage/v1/accounts_test.go | 55 + .../objectstorage/v1/containers_test.go | 150 + .../objectstorage/v1/objects_test.go | 263 + .../orchestration/v1/buildinfo_test.go | 20 + .../orchestration/v1/stackevents_test.go | 68 + .../orchestration/v1/stackresources_test.go | 62 + .../openstack/orchestration/v1/stacks_test.go | 153 + .../orchestration/v1/stacktemplates_test.go | 75 + .../v2/availabilityzones_test.go | 29 + .../v2/securityservices_test.go | 142 + .../v2/sharenetworks_test.go | 223 + .../openstack/sharedfilesystems/v2/shares.go | 45 + .../sharedfilesystems/v2/shares_test.go | 110 + .../sharedfilesystems/v2/sharetypes_test.go | 162 + .../gophercloud/gophercloud/auth_options.go | 75 +- .../gophercloud/gophercloud/{ => docs}/FAQ.md | 0 .../gophercloud/{ => docs}/MIGRATING.md | 2 +- .../gophercloud/{ => docs}/STYLEGUIDE.md | 0 .../gophercloud/{ => docs}/assets/openlab.png | Bin .../{ => docs}/assets/vexxhost.png | Bin .../contributor-tutorial/.template/doc.go | 13 + .../.template/requests.go | 105 + .../contributor-tutorial/.template/results.go | 83 + .../.template/testing/fixtures.go | 118 + .../.template/testing/requests_test.go | 89 + .../contributor-tutorial/.template/urls.go | 23 + .../docs/contributor-tutorial/README.md | 12 + .../step-01-introduction.md | 16 + .../contributor-tutorial/step-02-issues.md | 124 + .../step-03-code-hunting.md | 104 + .../step-04-acceptance-testing.md | 27 + .../step-05-pull-requests.md | 189 + .../step-06-code-review.md | 93 + .../step-07-congratulations.md | 9 + .../gophercloud/gophercloud/errors.go | 56 +- .../gophercloud/internal/testing/util_test.go | 42 + .../gophercloud/openstack/auth_env.go | 12 +- .../blockstorage/extensions/quotasets/doc.go | 42 + .../extensions/quotasets/requests.go | 94 + .../extensions/quotasets/results.go | 165 + .../extensions/quotasets/testing/doc.go | 2 + .../extensions/quotasets/testing/fixtures.go | 162 + .../quotasets/testing/requests_test.go | 80 + .../blockstorage/extensions/quotasets/urls.go | 21 + .../extensions/schedulerstats/results.go | 2 +- .../schedulerstats/testing/requests_test.go | 38 + .../services/testing/requests_test.go | 41 + .../volumeactions/testing/requests_test.go | 166 + .../noauth/testing/requests_test.go | 38 + .../v1/apiversions/testing/requests_test.go | 64 + .../blockstorage/v1/snapshots/requests.go | 7 +- .../v1/snapshots/testing/requests_test.go | 116 + .../blockstorage/v1/volumes/requests.go | 7 +- .../v1/volumes/testing/requests_test.go | 152 + .../v1/volumetypes/testing/requests_test.go | 119 + .../blockstorage/v2/snapshots/requests.go | 7 +- .../v2/snapshots/testing/requests_test.go | 116 + .../blockstorage/v2/volumes/requests.go | 22 +- .../blockstorage/v2/volumes/results.go | 15 +- .../v2/volumes/testing/requests_test.go | 257 + .../blockstorage/v3/snapshots/requests.go | 7 +- .../v3/snapshots/testing/requests_test.go | 116 + .../blockstorage/v3/volumes/requests.go | 7 +- .../v3/volumes/testing/requests_test.go | 257 + .../v3/volumetypes/testing/requests_test.go | 118 + .../cdn/v1/base/testing/requests_test.go | 46 + .../cdn/v1/flavors/testing/requests_test.go | 90 + .../v1/serviceassets/testing/requests_test.go | 19 + .../cdn/v1/services/testing/requests_test.go | 359 + .../gophercloud/openstack/client.go | 60 +- .../openstack/clustering/v1/actions/doc.go | 33 + .../clustering/v1/actions/requests.go | 51 + .../clustering/v1/actions/results.go | 106 + .../clustering/v1/actions/testing/doc.go | 2 + .../clustering/v1/actions/testing/fixtures.go | 166 + .../v1/actions/testing/requests_test.go | 44 + .../openstack/clustering/v1/actions/urls.go | 22 + .../openstack/clustering/v1/clusters/doc.go | 227 + .../clustering/v1/clusters/requests.go | 525 + .../clustering/v1/clusters/results.go | 201 + .../clustering/v1/clusters/testing/doc.go | 2 + .../v1/clusters/testing/fixtures.go | 624 + .../v1/clusters/testing/requests_test.go | 428 + .../openstack/clustering/v1/clusters/urls.go | 46 + .../openstack/clustering/v1/nodes/doc.go | 74 + .../openstack/clustering/v1/nodes/requests.go | 146 + .../openstack/clustering/v1/nodes/results.go | 129 + .../clustering/v1/nodes/testing/doc.go | 2 + .../clustering/v1/nodes/testing/fixtures.go | 316 + .../v1/nodes/testing/requests_test.go | 105 + .../openstack/clustering/v1/nodes/urls.go | 34 + .../openstack/clustering/v1/policies/doc.go | 96 + .../clustering/v1/policies/requests.go | 193 + .../clustering/v1/policies/results.go | 183 + .../clustering/v1/policies/testing/doc.go | 2 + .../v1/policies/testing/fixtures.go | 513 + .../v1/policies/testing/requests_test.go | 147 + .../openstack/clustering/v1/policies/urls.go | 32 + .../clustering/v1/policytypes/doc.go | 31 + .../clustering/v1/policytypes/requests.go | 26 + .../clustering/v1/policytypes/results.go | 68 + .../clustering/v1/policytypes/testing/doc.go | 2 + .../v1/policytypes/testing/fixtures.go | 235 + .../v1/policytypes/testing/requests_test.go | 49 + .../clustering/v1/policytypes/urls.go | 16 + .../openstack/clustering/v1/profiles/doc.go | 85 + .../clustering/v1/profiles/requests.go | 139 + .../clustering/v1/profiles/results.go | 148 + .../clustering/v1/profiles/testing/doc.go | 2 + .../v1/profiles/testing/fixtures.go | 395 + .../v1/profiles/testing/requests_test.go | 109 + .../openstack/clustering/v1/profiles/urls.go | 34 + .../clustering/v1/profiletypes/doc.go | 47 + .../clustering/v1/profiletypes/requests.go | 28 + .../clustering/v1/profiletypes/results.go | 67 + .../clustering/v1/profiletypes/testing/doc.go | 2 + .../v1/profiletypes/testing/fixtures.go | 296 + .../v1/profiletypes/testing/requests_test.go | 74 + .../clustering/v1/profiletypes/urls.go | 28 + .../openstack/clustering/v1/receivers/doc.go | 72 + .../clustering/v1/receivers/requests.go | 145 + .../clustering/v1/receivers/results.go | 114 + .../clustering/v1/receivers/testing/doc.go | 2 + .../v1/receivers/testing/fixtures.go | 229 + .../v1/receivers/testing/requests_test.go | 94 + .../openstack/clustering/v1/receivers/urls.go | 34 + .../openstack/clustering/v1/webhooks/doc.go | 15 + .../clustering/v1/webhooks/requests.go | 53 + .../clustering/v1/webhooks/results.go | 22 + .../clustering/v1/webhooks/testing/doc.go | 2 + .../v1/webhooks/testing/requests_test.go | 136 + .../openstack/clustering/v1/webhooks/urls.go | 7 + .../extensions/testing/requests_test.go | 39 + .../compute/v2/extensions/aggregates/doc.go | 17 +- .../v2/extensions/aggregates/requests.go | 23 + .../extensions/aggregates/testing/fixtures.go | 44 + .../aggregates/testing/requests_test.go | 149 + .../compute/v2/extensions/aggregates/urls.go | 4 + .../extensions/attachinterfaces/requests.go | 2 +- .../v2/extensions/attachinterfaces/results.go | 4 +- .../attachinterfaces/testing/requests_test.go | 89 + .../testing/requests_test.go | 41 + .../v2/extensions/bootfromvolume/requests.go | 8 + .../bootfromvolume/testing/fixtures.go | 275 + .../bootfromvolume/testing/requests_test.go | 44 + .../defsecrules/testing/requests_test.go | 127 + .../diskconfig/testing/requests_test.go | 88 + .../evacuate/testing/requests_test.go | 60 + .../floatingips/testing/requests_test.go | 111 + .../hypervisors/testing/requests_test.go | 89 + .../compute/v2/extensions/keypairs/doc.go | 2 +- .../keypairs/testing/requests_test.go | 72 + .../limits/testing/requests_test.go | 23 + .../lockunlock/testing/request_test.go | 31 + .../migrate/testing/requests_test.go | 41 + .../networks/testing/requests_test.go | 38 + .../pauseunpause/testing/requests_test.go | 31 + .../v2/extensions/quotasets/requests.go | 26 +- .../extensions/quotasets/testing/fixtures.go | 2 +- .../quotasets/testing/requests_test.go | 73 + .../resetstate/testing/requests_test.go | 21 + .../schedulerhints/testing/requests_test.go | 131 + .../v2/extensions/secgroups/requests.go | 4 +- .../extensions/secgroups/testing/fixtures.go | 2 - .../secgroups/testing/requests_test.go | 302 + .../servergroups/testing/requests_test.go | 60 + .../services/testing/requests_test.go | 42 + .../startstop/testing/requests_test.go | 31 + .../suspendresume/testing/requests_test.go | 31 + .../tenantnetworks/testing/requests_test.go | 38 + .../v2/extensions/testing/delegate_test.go | 56 + .../compute/v2/extensions/usage/doc.go | 58 +- .../compute/v2/extensions/usage/requests.go | 70 +- .../compute/v2/extensions/usage/results.go | 56 +- .../v2/extensions/usage/testing/fixtures.go | 177 + .../extensions/usage/testing/requests_test.go | 52 + .../compute/v2/extensions/usage/urls.go | 2 +- .../volumeattach/testing/requests_test.go | 102 + .../openstack/compute/v2/flavors/requests.go | 38 +- .../v2/flavors/testing/requests_test.go | 402 + .../v2/images/testing/requests_test.go | 225 + .../openstack/compute/v2/servers/requests.go | 40 +- .../openstack/compute/v2/servers/results.go | 15 + .../compute/v2/servers/testing/fixtures.go | 19 + .../v2/servers/testing/requests_test.go | 566 + .../v2/servers/testing/results_test.go | 110 + .../openstack/container/v1/capsules/doc.go | 4 + .../openstack/container/v1/capsules/errors.go | 15 + .../container/v1/capsules/requests.go | 102 + .../container/v1/capsules/results.go | 323 + .../container/v1/capsules/template.go | 27 + .../container/v1/capsules/testing/doc.go | 1 + .../container/v1/capsules/testing/fixtures.go | 570 + .../v1/capsules/testing/requests_test.go | 119 + .../v1/capsules/testing/template_test.go | 29 + .../openstack/container/v1/capsules/urls.go | 21 + .../containerinfra/v1/certificates/doc.go | 15 + .../v1/certificates/requests.go | 16 + .../containerinfra/v1/certificates/results.go | 29 + .../v1/certificates/testing/doc.go | 1 + .../v1/certificates/testing/fixtures.go | 55 + .../v1/certificates/testing/requests_test.go | 23 + .../containerinfra/v1/certificates/urls.go | 15 + .../containerinfra/v1/clustertemplates/doc.go | 42 + .../v1/clustertemplates/requests.go | 66 + .../v1/clustertemplates/results.go | 60 + .../v1/clustertemplates/testing/doc.go | 1 + .../v1/clustertemplates/testing/fixtures.go | 114 + .../clustertemplates/testing/requests_test.go | 59 + .../v1/clustertemplates/urls.go | 15 + .../configurations/testing/requests_test.go | 237 + .../db/v1/databases/testing/requests_test.go | 67 + .../db/v1/datastores/testing/requests_test.go | 79 + .../db/v1/flavors/testing/requests_test.go | 107 + .../openstack/db/v1/instances/results.go | 33 + .../db/v1/instances/testing/fixtures.go | 86 +- .../db/v1/instances/testing/requests_test.go | 182 + .../db/v1/users/testing/requests_test.go | 85 + .../v2/recordsets/testing/requests_test.go | 145 + .../dns/v2/zones/testing/requests_test.go | 105 + .../openstack/endpoint_location.go | 2 +- .../admin/roles/testing/requests_test.go | 65 + .../v2/extensions/testing/delegate_test.go | 39 + .../v2/tenants/testing/requests_test.go | 113 + .../v2/tokens/testing/requests_test.go | 104 + .../v2/users/testing/requests_test.go | 161 + .../v3/domains/testing/requests_test.go | 89 + .../identity/v3/endpoints/requests.go | 7 +- .../v3/endpoints/testing/requests_test.go | 214 + .../trusts/testing/requests_test.go | 74 + .../openstack/identity/v3/groups/errors.go | 17 + .../openstack/identity/v3/groups/requests.go | 22 + .../v3/groups/testing/requests_test.go | 133 + .../openstack/identity/v3/policies/doc.go | 77 + .../openstack/identity/v3/policies/errors.go | 31 + .../identity/v3/policies/requests.go | 195 + .../openstack/identity/v3/policies/results.go | 131 + .../identity/v3/policies/testing/doc.go | 2 + .../identity/v3/policies/testing/fixtures.go | 229 + .../v3/policies/testing/requests_test.go | 229 + .../openstack/identity/v3/policies/urls.go | 25 + .../openstack/identity/v3/projects/errors.go | 17 + .../identity/v3/projects/requests.go | 22 + .../v3/projects/testing/requests_test.go | 111 + .../v3/regions/testing/requests_test.go | 105 + .../openstack/identity/v3/roles/doc.go | 23 + .../openstack/identity/v3/roles/errors.go | 17 + .../openstack/identity/v3/roles/requests.go | 78 + .../identity/v3/roles/testing/fixtures.go | 95 + .../v3/roles/testing/requests_test.go | 296 + .../openstack/identity/v3/roles/urls.go | 4 + .../v3/services/testing/requests_test.go | 107 + .../openstack/identity/v3/tokens/requests.go | 73 +- .../openstack/identity/v3/tokens/results.go | 1 + .../identity/v3/tokens/testing/fixtures.go | 6 + .../v3/tokens/testing/requests_test.go | 551 + .../v3/tokens/testing/results_test.go | 52 + .../openstack/identity/v3/users/doc.go | 49 + .../openstack/identity/v3/users/errors.go | 17 + .../openstack/identity/v3/users/requests.go | 96 + .../openstack/identity/v3/users/results.go | 30 + .../identity/v3/users/testing/fixtures.go | 57 +- .../v3/users/testing/requests_test.go | 248 + .../openstack/identity/v3/users/urls.go | 16 + .../v2/imagedata/testing/requests_test.go | 87 + .../imageservice/v2/images/requests.go | 62 +- .../imageservice/v2/images/results.go | 5 +- .../v2/images/testing/fixtures.go | 43 + .../v2/images/testing/requests_test.go | 390 + .../openstack/imageservice/v2/images/types.go | 25 + .../openstack/imageservice/v2/images/urls.go | 22 +- .../v2/members/testing/requests_test.go | 172 + .../openstack/imageservice/v2/tasks/doc.go | 55 + .../imageservice/v2/tasks/requests.go | 128 + .../imageservice/v2/tasks/results.go | 114 + .../imageservice/v2/tasks/testing/doc.go | 2 + .../imageservice/v2/tasks/testing/fixtures.go | 124 + .../v2/tasks/testing/requests_test.go | 138 + .../openstack/imageservice/v2/tasks/urls.go | 55 + .../openstack/keymanager/v1/acls/doc.go | 54 + .../openstack/keymanager/v1/acls/requests.go | 112 + .../openstack/keymanager/v1/acls/results.go | 85 + .../keymanager/v1/acls/testing/fixtures.go | 168 + .../v1/acls/testing/requests_test.go | 115 + .../openstack/keymanager/v1/acls/urls.go | 11 + .../openstack/keymanager/v1/containers/doc.go | 86 + .../keymanager/v1/containers/requests.go | 212 + .../keymanager/v1/containers/results.go | 232 + .../v1/containers/testing/fixtures.go | 321 + .../v1/containers/testing/requests_test.go | 144 + .../keymanager/v1/containers/urls.go | 31 + .../openstack/keymanager/v1/orders/doc.go | 45 + .../keymanager/v1/orders/requests.go | 129 + .../openstack/keymanager/v1/orders/results.go | 170 + .../keymanager/v1/orders/testing/fixtures.go | 186 + .../v1/orders/testing/requests_test.go | 81 + .../openstack/keymanager/v1/orders/urls.go | 19 + .../openstack/keymanager/v1/secrets/doc.go | 142 + .../keymanager/v1/secrets/requests.go | 412 + .../keymanager/v1/secrets/results.go | 227 + .../keymanager/v1/secrets/testing/fixtures.go | 355 + .../v1/secrets/testing/requests_test.go | 179 + .../openstack/keymanager/v1/secrets/urls.go | 35 + .../openstack/loadbalancer/v2/doc.go | 3 + .../loadbalancer/v2/l7policies/doc.go | 123 + .../loadbalancer/v2/l7policies/requests.go | 328 + .../loadbalancer/v2/l7policies/results.go | 223 + .../loadbalancer/v2/l7policies/testing/doc.go | 2 + .../v2/l7policies/testing/fixtures.go | 375 + .../v2/l7policies/testing/requests_test.go | 292 + .../loadbalancer/v2/l7policies/urls.go | 25 + .../loadbalancer/v2/listeners/doc.go | 63 + .../loadbalancer/v2/listeners/requests.go | 194 + .../loadbalancer/v2/listeners/results.go | 135 + .../loadbalancer/v2/listeners/testing/doc.go | 2 + .../v2/listeners/testing/fixtures.go | 213 + .../v2/listeners/testing/requests_test.go | 137 + .../loadbalancer/v2/listeners/urls.go | 16 + .../loadbalancer/v2/loadbalancers/doc.go | 76 + .../loadbalancer/v2/loadbalancers/requests.go | 205 + .../loadbalancer/v2/loadbalancers/results.go | 149 + .../v2/loadbalancers/testing/doc.go | 2 + .../v2/loadbalancers/testing/fixtures.go | 292 + .../v2/loadbalancers/testing/requests_test.go | 162 + .../loadbalancer/v2/loadbalancers/urls.go | 21 + .../openstack/loadbalancer/v2/monitors/doc.go | 69 + .../loadbalancer/v2/monitors/requests.go | 257 + .../loadbalancer/v2/monitors/results.go | 153 + .../loadbalancer/v2/monitors/testing/doc.go | 2 + .../v2/monitors/testing/fixtures.go | 215 + .../v2/monitors/testing/requests_test.go | 154 + .../loadbalancer/v2/monitors/urls.go | 16 + .../openstack/loadbalancer/v2/pools/doc.go | 124 + .../loadbalancer/v2/pools/requests.go | 346 + .../loadbalancer/v2/pools/results.go | 281 + .../loadbalancer/v2/pools/testing/doc.go | 2 + .../loadbalancer/v2/pools/testing/fixtures.go | 388 + .../v2/pools/testing/requests_test.go | 262 + .../openstack/loadbalancer/v2/pools/urls.go | 25 + .../loadbalancer/v2/testhelper/client.go | 14 + .../openstack/messaging/v2/claims/doc.go | 53 + .../openstack/messaging/v2/claims/requests.go | 120 + .../openstack/messaging/v2/claims/results.go | 52 + .../messaging/v2/claims/testing/doc.go | 2 + .../messaging/v2/claims/testing/fixtures.go | 133 + .../v2/claims/testing/requests_test.go | 58 + .../openstack/messaging/v2/claims/urls.go | 24 + .../openstack/messaging/v2/messages/doc.go | 121 + .../messaging/v2/messages/requests.go | 253 + .../messaging/v2/messages/results.go | 132 + .../messaging/v2/messages/testing/doc.go | 2 + .../messaging/v2/messages/testing/fixtures.go | 316 + .../v2/messages/testing/requests_test.go | 126 + .../openstack/messaging/v2/messages/urls.go | 49 + .../openstack/messaging/v2/queues/doc.go | 111 + .../openstack/messaging/v2/queues/requests.go | 292 + .../openstack/messaging/v2/queues/results.go | 201 + .../messaging/v2/queues/testing/doc.go | 2 + .../messaging/v2/queues/testing/fixtures.go | 315 + .../v2/queues/testing/requests_test.go | 133 + .../openstack/messaging/v2/queues/urls.go | 61 + .../v2/apiversions/testing/requests_test.go | 183 + .../networking/v2/extensions/external/doc.go | 9 +- .../v2/extensions/external/requests.go | 28 + .../extensions/external/testing/fixtures.go | 2 + .../external/testing/requests_test.go | 26 + .../external/testing/results_test.go | 138 + .../v2/extensions/extradhcpopts/doc.go | 80 + .../v2/extensions/extradhcpopts/requests.go | 102 + .../v2/extensions/extradhcpopts/results.go | 20 + .../v2/extensions/fwaas/firewalls/requests.go | 2 + .../v2/extensions/fwaas/firewalls/results.go | 1 + .../fwaas/firewalls/testing/requests_test.go | 341 + .../v2/extensions/fwaas/policies/requests.go | 2 + .../v2/extensions/fwaas/policies/results.go | 1 + .../fwaas/policies/testing/requests_test.go | 274 + .../routerinsertion/testing/requests_test.go | 235 + .../v2/extensions/fwaas/rules/requests.go | 2 + .../v2/extensions/fwaas/rules/results.go | 1 + .../fwaas/rules/testing/requests_test.go | 381 + .../extensions/layer3/floatingips/requests.go | 2 + .../extensions/layer3/floatingips/results.go | 7 +- .../floatingips/testing/requests_test.go | 415 + .../v2/extensions/layer3/routers/requests.go | 2 + .../v2/extensions/layer3/routers/results.go | 7 +- .../layer3/routers/testing/requests_test.go | 471 + .../lbaas/members/testing/requests_test.go | 238 + .../lbaas/monitors/testing/requests_test.go | 310 + .../lbaas/pools/testing/requests_test.go | 316 + .../lbaas/vips/testing/requests_test.go | 330 + .../extensions/lbaas_v2/listeners/requests.go | 7 +- .../extensions/lbaas_v2/listeners/results.go | 4 + .../listeners/testing/requests_test.go | 137 + .../lbaas_v2/loadbalancers/requests.go | 27 +- .../lbaas_v2/loadbalancers/results.go | 4 +- .../loadbalancers/testing/fixtures.go | 32 +- .../loadbalancers/testing/requests_test.go | 161 + .../extensions/lbaas_v2/monitors/requests.go | 9 +- .../extensions/lbaas_v2/monitors/results.go | 4 + .../monitors/testing/requests_test.go | 154 + .../v2/extensions/lbaas_v2/pools/requests.go | 17 +- .../v2/extensions/lbaas_v2/pools/results.go | 8 + .../lbaas_v2/pools/testing/requests_test.go | 262 + .../extensions/networkipavailabilities/doc.go | 30 + .../networkipavailabilities/requests.go | 61 + .../networkipavailabilities/results.go | 96 + .../networkipavailabilities/testing/doc.go | 2 + .../testing/fixtures.go | 130 + .../testing/requests_test.go | 87 + .../networkipavailabilities/urls.go | 21 + .../portsbinding/testing/requests_test.go | 183 + .../v2/extensions/portsecurity/doc.go | 103 +- .../v2/extensions/portsecurity/requests.go | 104 + .../provider/testing/results_test.go | 222 + .../v2/extensions/qos/ruletypes/doc.go | 19 + .../v2/extensions/qos/ruletypes/requests.go | 13 + .../v2/extensions/qos/ruletypes/results.go | 26 + .../extensions/qos/ruletypes/testing/doc.go | 2 + .../qos/ruletypes/testing/fixtures.go | 19 + .../qos/ruletypes/testing/requests_test.go | 41 + .../v2/extensions/qos/ruletypes/urls.go | 7 + .../v2/extensions/rbacpolicies/doc.go | 79 + .../v2/extensions/rbacpolicies/requests.go | 142 + .../v2/extensions/rbacpolicies/results.go | 98 + .../v2/extensions/rbacpolicies/testing/doc.go | 2 + .../rbacpolicies/testing/fixtures.go | 112 + .../rbacpolicies/testing/requests_test.go | 169 + .../v2/extensions/rbacpolicies/urls.go | 31 + .../v2/extensions/security/groups/requests.go | 30 +- .../v2/extensions/security/groups/results.go | 5 +- .../security/groups/testing/requests_test.go | 134 + .../v2/extensions/security/rules/requests.go | 7 +- .../v2/extensions/security/rules/results.go | 5 +- .../security/rules/testing/requests_test.go | 236 + .../v2/extensions/subnetpools/requests.go | 39 +- .../v2/extensions/subnetpools/results.go | 5 +- .../subnetpools/testing/fixtures.go | 18 +- .../subnetpools/testing/requests_test.go | 192 + .../v2/extensions/testing/delegate_test.go | 106 + .../extensions/vpnaas/endpointgroups/doc.go | 58 + .../vpnaas/endpointgroups/requests.go | 144 + .../vpnaas/endpointgroups/results.go | 104 + .../endpointgroups/testing/requests_test.go | 265 + .../extensions/vpnaas/endpointgroups/urls.go | 16 + .../v2/extensions/vpnaas/ikepolicies/doc.go | 64 + .../extensions/vpnaas/ikepolicies/requests.go | 209 + .../extensions/vpnaas/ikepolicies/results.go | 125 + .../ikepolicies/testing/requests_test.go | 304 + .../v2/extensions/vpnaas/ikepolicies/urls.go | 16 + .../v2/extensions/vpnaas/ipsecpolicies/doc.go | 56 + .../vpnaas/ipsecpolicies/requests.go | 211 + .../vpnaas/ipsecpolicies/results.go | 126 + .../ipsecpolicies/testing/requests_test.go | 321 + .../extensions/vpnaas/ipsecpolicies/urls.go | 16 + .../v2/extensions/vpnaas/services/doc.go | 68 + .../v2/extensions/vpnaas/services/requests.go | 150 + .../v2/extensions/vpnaas/services/results.go | 121 + .../vpnaas/services/testing/requests_test.go | 267 + .../v2/extensions/vpnaas/services/urls.go | 16 + .../extensions/vpnaas/siteconnections/doc.go | 68 + .../vpnaas/siteconnections/requests.go | 243 + .../vpnaas/siteconnections/results.go | 163 + .../siteconnections/testing/requests_test.go | 413 + .../extensions/vpnaas/siteconnections/urls.go | 16 + .../networking/v2/networks/requests.go | 9 +- .../networking/v2/networks/results.go | 5 +- .../v2/networks/testing/fixtures.go | 50 + .../v2/networks/testing/requests_test.go | 297 + .../openstack/networking/v2/ports/requests.go | 9 +- .../openstack/networking/v2/ports/results.go | 5 +- .../networking/v2/ports/testing/fixtures.go | 244 + .../v2/ports/testing/requests_test.go | 779 + .../networking/v2/subnets/requests.go | 24 +- .../networking/v2/subnets/results.go | 8 +- .../networking/v2/subnets/testing/fixtures.go | 133 +- .../v2/subnets/testing/requests_test.go | 561 + .../v2/subnets/testing/results_test.go | 59 + .../objectstorage/v1/accounts/requests.go | 2 +- .../objectstorage/v1/accounts/results.go | 13 + .../v1/accounts/testing/fixtures.go | 18 + .../v1/accounts/testing/requests_test.go | 82 + .../objectstorage/v1/containers/doc.go | 4 + .../objectstorage/v1/containers/requests.go | 36 +- .../v1/containers/testing/requests_test.go | 148 + .../openstack/objectstorage/v1/objects/doc.go | 4 + .../objectstorage/v1/objects/requests.go | 66 +- .../objectstorage/v1/objects/results.go | 40 +- .../v1/objects/testing/fixtures.go | 2 + .../v1/objects/testing/requests_test.go | 312 + .../v1/swauth/testing/requests_test.go | 35 + .../v1/apiversions/testing/requests_test.go | 90 + .../v1/buildinfo/testing/requests_test.go | 21 + .../v1/stackevents/testing/requests_test.go | 72 + .../stackresources/testing/requests_test.go | 112 + .../openstack/orchestration/v1/stacks/doc.go | 121 +- .../v1/stacks/environment_test.go | 192 + .../orchestration/v1/stacks/errors.go | 8 + .../orchestration/v1/stacks/requests.go | 72 +- .../orchestration/v1/stacks/template_test.go | 148 + .../v1/stacks/testing/fixtures.go | 13 + .../v1/stacks/testing/requests_test.go | 224 + .../orchestration/v1/stacks/utils_test.go | 94 + .../stacktemplates/testing/requests_test.go | 58 + .../apiversions/testing/requests_test.go | 56 + .../testing/requests_test.go | 34 + .../securityservices/testing/requests_test.go | 208 + .../v2/sharenetworks/testing/requests_test.go | 280 + .../sharedfilesystems/v2/shares/requests.go | 148 +- .../sharedfilesystems/v2/shares/results.go | 128 + .../v2/shares/testing/fixtures.go | 118 + .../v2/shares/testing/request_test.go | 235 + .../sharedfilesystems/v2/shares/urls.go | 12 + .../v2/sharetypes/testing/requests_test.go | 217 + .../openstack/testing/client_test.go | 315 + .../testing/endpoint_location_test.go | 274 + .../openstack/utils/base_endpoint.go | 28 + .../utils/testing/base_endpoint_test.go | 88 + .../utils/testing/choose_version_test.go | 119 + .../gophercloud/pagination/pager.go | 32 +- .../pagination/testing/linked_test.go | 112 + .../pagination/testing/marker_test.go | 127 + .../pagination/testing/pagination_test.go | 13 + .../pagination/testing/single_test.go | 79 + .../gophercloud/gophercloud/params.go | 12 +- .../gophercloud/provider_client.go | 53 +- .../gophercloud/gophercloud/results.go | 68 +- .../gophercloud/script/acceptancetest | 57 +- .../gophercloud/gophercloud/script/format | 26 +- .../gophercloud/gophercloud/script/stackenv | 25 + .../gophercloud/gophercloud/service_client.go | 26 + .../testing/endpoint_search_test.go | 20 + .../gophercloud/testing/params_test.go | 276 + .../testing/provider_client_test.go | 124 + .../gophercloud/testing/results_test.go | 208 + .../testing/service_client_test.go | 34 + .../gophercloud/testing/util_test.go | 122 + .../gregjones/httpcache/LICENSE.txt | 7 - .../github.com/gregjones/httpcache/README.md | 25 - .../httpcache/diskcache/diskcache.go | 61 - .../gregjones/httpcache/httpcache.go | 551 - .../httpcache/leveldbcache/leveldbcache.go | 51 - .../gregjones/httpcache/memcache/appengine.go | 61 - .../gregjones/httpcache/memcache/memcache.go | 60 - .../gregjones/httpcache/redis/redis.go | 43 - .../hashicorp/golang-lru/2q_test.go | 306 + .../hashicorp/golang-lru/arc_test.go | 377 + .../hashicorp/golang-lru/lru_test.go | 221 + .../golang-lru/simplelru/lru_test.go | 167 + .../github.com/howeyc/gopass/.travis.yml | 11 + .../github.com/howeyc/gopass/pass_test.go | 225 + .../github.com/imdario/mergo/.travis.yml | 2 + .../github.com/imdario/mergo/issue17_test.go | 25 + .../github.com/imdario/mergo/issue23_test.go | 27 + .../github.com/imdario/mergo/issue38_test.go | 59 + .../github.com/imdario/mergo/mergo_test.go | 662 + .../github.com/json-iterator/go/.gitignore | 6 +- .../github.com/json-iterator/go/.travis.yml | 14 + .../github.com/json-iterator/go/Gopkg.lock | 27 + .../github.com/json-iterator/go/Gopkg.toml | 26 + .../github.com/json-iterator/go/README.md | 5 + .../github.com/json-iterator/go/adapter.go | 148 + .../vendor/github.com/json-iterator/go/any.go | 321 + .../go/{feature_any_array.go => any_array.go} | 0 .../go/{feature_any_bool.go => any_bool.go} | 0 .../go/{feature_any_float.go => any_float.go} | 0 .../go/{feature_any_int32.go => any_int32.go} | 0 .../go/{feature_any_int64.go => any_int64.go} | 0 ...{feature_any_invalid.go => any_invalid.go} | 0 .../go/{feature_any_nil.go => any_nil.go} | 0 .../github.com/json-iterator/go/any_number.go | 123 + .../{feature_any_object.go => any_object.go} | 0 .../github.com/json-iterator/go/any_str.go | 166 + .../go/any_tests/jsoniter_any_array_test.go | 123 + .../go/any_tests/jsoniter_any_bool_test.go | 65 + .../go/any_tests/jsoniter_any_float_test.go | 103 + .../go/any_tests/jsoniter_any_int_test.go | 198 + .../go/any_tests/jsoniter_any_map_test.go | 28 + .../go/any_tests/jsoniter_any_null_test.go | 16 + .../go/any_tests/jsoniter_any_object_test.go | 123 + .../go/any_tests/jsoniter_any_string_test.go | 58 + .../any_tests/jsoniter_must_be_valid_test.go | 72 + .../go/any_tests/jsoniter_wrap_test.go | 119 + .../{feature_any_uint32.go => any_uint32.go} | 0 .../{feature_any_uint64.go => any_uint64.go} | 0 .../json-iterator/go/api_tests/config_test.go | 174 + .../go/api_tests/decoder_test.go | 64 + .../go/api_tests/encoder_18_test.go | 46 + .../go/api_tests/encoder_test.go | 20 + .../go/api_tests/marshal_indent_test.go | 36 + .../go/benchmarks/encode_string_test.go | 25 + .../go/benchmarks/jsoniter_large_file_test.go | 158 + .../github.com/json-iterator/go/build.sh | 12 + .../github.com/json-iterator/go/config.go | 372 + .../json-iterator/go/example_test.go | 121 + .../go/extension_tests/decoder_test.go | 100 + .../go/extension_tests/extension_test.go | 120 + .../go/extra/binary_as_string_codec.go | 238 + .../go/extra/binary_as_string_codec_test.go | 32 + .../json-iterator/go/extra/fuzzy_decoder.go | 20 +- .../go/extra/fuzzy_decoder_test.go | 393 + .../json-iterator/go/extra/naming_strategy.go | 4 +- .../go/extra/naming_strategy_test.go | 23 + .../json-iterator/go/extra/privat_fields.go | 36 +- .../go/extra/private_fields_test.go | 18 + .../go/extra/time_as_int64_codec.go | 3 - .../go/extra/time_as_int64_codec_test.go | 31 + .../json-iterator/go/feature_adapter.go | 133 - .../json-iterator/go/feature_any.go | 245 - .../json-iterator/go/feature_any_number.go | 104 - .../json-iterator/go/feature_any_string.go | 166 - .../json-iterator/go/feature_config.go | 347 - .../json-iterator/go/feature_iter_float.go | 341 - .../json-iterator/go/feature_iter_int.go | 268 - .../json-iterator/go/feature_iter_object.go | 267 - .../json-iterator/go/feature_json_number.go | 31 - .../json-iterator/go/feature_pool.go | 59 - .../json-iterator/go/feature_reflect.go | 721 - .../json-iterator/go/feature_reflect_array.go | 99 - .../go/feature_reflect_extension.go | 414 - .../json-iterator/go/feature_reflect_map.go | 244 - .../go/feature_reflect_native.go | 764 - .../go/feature_reflect_object.go | 196 - .../json-iterator/go/feature_reflect_slice.go | 147 - .../go/feature_reflect_struct_decoder.go | 934 - .../json-iterator/go/feature_stream.go | 308 - .../json-iterator/go/feature_stream_float.go | 96 - .../json-iterator/go/feature_stream_int.go | 320 - .../json-iterator/go/feature_stream_string.go | 396 - .../go/{feature_iter.go => iter.go} | 0 .../{feature_iter_array.go => iter_array.go} | 0 .../github.com/json-iterator/go/iter_float.go | 347 + .../github.com/json-iterator/go/iter_int.go | 345 + .../json-iterator/go/iter_object.go | 252 + .../go/{feature_iter_skip.go => iter_skip.go} | 0 ...ter_skip_sloppy.go => iter_skip_sloppy.go} | 0 .../json-iterator/go/iter_skip_sloppy_test.go | 162 + ...ter_skip_strict.go => iter_skip_strict.go} | 0 .../{feature_iter_string.go => iter_str.go} | 0 .../go/misc_tests/jsoniter_array_test.go | 226 + .../go/misc_tests/jsoniter_bool_test.go | 47 + .../go/misc_tests/jsoniter_float_test.go | 95 + .../go/misc_tests/jsoniter_int_test.go | 101 + .../go/misc_tests/jsoniter_interface_test.go | 178 + .../go/misc_tests/jsoniter_iterator_test.go | 67 + .../go/misc_tests/jsoniter_map_test.go | 44 + .../go/misc_tests/jsoniter_nested_test.go | 89 + .../go/misc_tests/jsoniter_null_test.go | 81 + .../go/misc_tests/jsoniter_object_test.go | 149 + .../misc_tests/jsoniter_raw_message_test.go | 68 + .../go/output_tests/array/array/bool/types.go | 3 - .../go/output_tests/array/array/byte/types.go | 3 - .../output_tests/array/array/float64/types.go | 3 - .../output_tests/array/array/int32/types.go | 3 - .../array/array/ptr_string/types.go | 3 - .../output_tests/array/array/string/types.go | 3 - .../output_tests/array/array/uint8/types.go | 3 - .../go/output_tests/array/bool/types.go | 3 - .../go/output_tests/array/byte/types.go | 3 - .../go/output_tests/array/float64/types.go | 3 - .../go/output_tests/array/int32/types.go | 3 - .../array/map/int32_string/types.go | 3 - .../array/map/string_string/types.go | 3 - .../go/output_tests/array/ptr_bool/types.go | 3 - .../output_tests/array/ptr_float64/types.go | 3 - .../go/output_tests/array/ptr_int32/types.go | 3 - .../array/ptr_map/int32_string/types.go | 3 - .../array/ptr_map/string_string/types.go | 3 - .../array/ptr_slice/bool/types.go | 3 - .../array/ptr_slice/byte/types.go | 3 - .../array/ptr_slice/float64/types.go | 3 - .../array/ptr_slice/int32/types.go | 3 - .../array/ptr_slice/ptr_string/types.go | 3 - .../array/ptr_slice/string/types.go | 3 - .../array/ptr_slice/uint8/types.go | 3 - .../go/output_tests/array/ptr_string/types.go | 3 - .../array/ptr_struct_various/types.go | 12 - .../go/output_tests/array/ptr_uint8/types.go | 3 - .../go/output_tests/array/slice/bool/types.go | 3 - .../go/output_tests/array/slice/byte/types.go | 3 - .../output_tests/array/slice/float64/types.go | 3 - .../output_tests/array/slice/int32/types.go | 3 - .../array/slice/ptr_string/types.go | 3 - .../output_tests/array/slice/string/types.go | 3 - .../output_tests/array/slice/uint8/types.go | 3 - .../go/output_tests/array/string/types.go | 3 - .../output_tests/array/struct_empty/types.go | 3 - .../array/struct_empty_alias/types.go | 5 - .../array/struct_ptr_string/types.go | 5 - .../array/struct_various/types.go | 12 - .../go/output_tests/array/uint8/types.go | 3 - .../go/output_tests/builtins/bool/types.go | 3 - .../output_tests/builtins/bool_alias/types.go | 3 - .../go/output_tests/builtins/byte/types.go | 3 - .../output_tests/builtins/byte_alias/types.go | 3 - .../go/output_tests/builtins/float32/types.go | 3 - .../builtins/float32_alias/types.go | 3 - .../go/output_tests/builtins/float64/types.go | 3 - .../builtins/float64_alias/types.go | 3 - .../go/output_tests/builtins/int16/types.go | 3 - .../builtins/int16_alias/types.go | 3 - .../go/output_tests/builtins/int32/types.go | 3 - .../builtins/int32_alias/types.go | 3 - .../go/output_tests/builtins/int64/types.go | 3 - .../go/output_tests/builtins/int8/types.go | 3 - .../output_tests/builtins/int8_alias/types.go | 3 - .../go/output_tests/builtins/string/types.go | 3 - .../builtins/string_alias/types.go | 3 - .../go/output_tests/builtins/uint16/types.go | 3 - .../builtins/uint16_alias/types.go | 3 - .../go/output_tests/builtins/uint32/types.go | 3 - .../builtins/uint32_alias/types.go | 3 - .../go/output_tests/builtins/uint8/types.go | 3 - .../builtins/uint8_alias/types.go | 3 - .../go/output_tests/builtins/uintptr/types.go | 3 - .../output_tests/caseless_unmarshal/types.go | 9 - .../json_marshal/string_alias/types.go | 50 - .../output_tests/json_marshal/struct/types.go | 52 - .../json_marshal/struct_alias/types.go | 54 - .../json_marshal/struct_field/types.go | 56 - .../json_marshal/struct_field_alias/types.go | 58 - .../go/output_tests/map/int16/string/types.go | 3 - .../go/output_tests/map/int32/string/types.go | 3 - .../go/output_tests/map/int64/string/types.go | 3 - .../go/output_tests/map/int8/string/types.go | 3 - .../map/string/array_string/types.go | 3 - .../go/output_tests/map/string/bool/types.go | 3 - .../go/output_tests/map/string/byte/types.go | 3 - .../output_tests/map/string/float64/types.go | 3 - .../go/output_tests/map/string/int32/types.go | 3 - .../map/string/map_string_string/types.go | 3 - .../map/string/ptr_array_string/types.go | 3 - .../output_tests/map/string/ptr_bool/types.go | 3 - .../map/string/ptr_float64/types.go | 3 - .../map/string/ptr_int32/types.go | 3 - .../map/string/ptr_map_string_string/types.go | 3 - .../map/string/ptr_slice_string/types.go | 3 - .../map/string/ptr_string/types.go | 3 - .../map/string/ptr_struct_various/types.go | 14 - .../map/string/ptr_uint8/types.go | 3 - .../map/string/slice_string/types.go | 3 - .../output_tests/map/string/string/types.go | 3 - .../map/string/string_alias/types.go | 5 - .../map/string/struct_empty/types.go | 3 - .../map/string/struct_empty_alias/types.go | 5 - .../map/string/struct_ptr_string/types.go | 5 - .../map/string/struct_various/types.go | 12 - .../go/output_tests/map/string/uint8/types.go | 3 - .../map/string_alias/string/types.go | 5 - .../map/string_alias/string_alias/types.go | 5 - .../output_tests/map/uint16/string/types.go | 3 - .../output_tests/map/uint32/string/types.go | 3 - .../go/output_tests/map/uint8/string/types.go | 3 - .../string_alias/types.go | 22 - .../map_key_text_marshal/struct/types.go | 24 - .../go/output_tests/marshal_fail_case.go | 23 - .../output_tests/partial_unmarshal/types.go | 11 - .../go/output_tests/slice/array/bool/types.go | 3 - .../go/output_tests/slice/array/byte/types.go | 3 - .../output_tests/slice/array/float64/types.go | 3 - .../output_tests/slice/array/int32/types.go | 3 - .../slice/array/ptr_string/types.go | 3 - .../output_tests/slice/array/string/types.go | 3 - .../output_tests/slice/array/uint8/types.go | 3 - .../go/output_tests/slice/bool/types.go | 3 - .../go/output_tests/slice/byte/types.go | 3 - .../go/output_tests/slice/float64/types.go | 3 - .../go/output_tests/slice/int32/types.go | 3 - .../go/output_tests/slice/int64/types.go | 3 - .../slice/map/int32_string/types.go | 3 - .../slice/map/string_string/types.go | 3 - .../slice/ptr_array/bool/types.go | 3 - .../slice/ptr_array/byte/types.go | 3 - .../slice/ptr_array/float64/types.go | 3 - .../slice/ptr_array/int32/types.go | 3 - .../slice/ptr_array/ptr_string/types.go | 3 - .../slice/ptr_array/string/types.go | 3 - .../slice/ptr_array/uint8/types.go | 3 - .../go/output_tests/slice/ptr_bool/types.go | 3 - .../output_tests/slice/ptr_float64/types.go | 3 - .../go/output_tests/slice/ptr_int32/types.go | 3 - .../slice/ptr_map/int32_string/types.go | 3 - .../slice/ptr_map/string_string/types.go | 3 - .../slice/ptr_slice/bool/types.go | 3 - .../slice/ptr_slice/byte/types.go | 3 - .../slice/ptr_slice/float64/types.go | 3 - .../slice/ptr_slice/int32/types.go | 3 - .../slice/ptr_slice/ptr_string/types.go | 3 - .../slice/ptr_slice/string/types.go | 3 - .../slice/ptr_slice/uint8/types.go | 3 - .../go/output_tests/slice/ptr_string/types.go | 3 - .../slice/ptr_struct_various/types.go | 12 - .../go/output_tests/slice/ptr_uint8/types.go | 3 - .../go/output_tests/slice/slice/bool/types.go | 3 - .../go/output_tests/slice/slice/byte/types.go | 3 - .../output_tests/slice/slice/float64/types.go | 3 - .../output_tests/slice/slice/int32/types.go | 3 - .../slice/slice/ptr_string/types.go | 3 - .../output_tests/slice/slice/string/types.go | 3 - .../output_tests/slice/slice/uint8/types.go | 3 - .../go/output_tests/slice/string/types.go | 3 - .../output_tests/slice/struct_empty/types.go | 3 - .../slice/struct_empty_alias/types.go | 5 - .../slice/struct_ptr_string/types.go | 5 - .../slice/struct_various/types.go | 12 - .../go/output_tests/slice/uint8/types.go | 3 - .../go/output_tests/struct/alias/types.go | 20 - .../anonymous/no_overlap/float64/types.go | 8 - .../anonymous/no_overlap/int32/types.go | 8 - .../no_overlap/json_marshal/types.go | 57 - .../no_overlap/map_string_string/types.go | 8 - .../anonymous/no_overlap/ptr_float64/types.go | 8 - .../anonymous/no_overlap/ptr_int32/types.go | 8 - .../no_overlap/ptr_map_string_string/types.go | 8 - .../no_overlap/ptr_slice_string/types.go | 8 - .../anonymous/no_overlap/ptr_string/types.go | 8 - .../no_overlap/ptr_struct_various/types.go | 17 - .../no_overlap/slice_string/types.go | 8 - .../anonymous/no_overlap/string/types.go | 8 - .../no_overlap/string_with_tag/types.go | 8 - .../no_overlap/struct_various/types.go | 17 - .../no_overlap/text_marshal/types.go | 57 - .../overlap/different_levels/types.go | 17 - .../overlap/ignore_deeper_level/types.go | 23 - .../overlap/same_level_1_both_tagged/types.go | 16 - .../overlap/same_level_1_no_tags/types.go | 16 - .../overlap/same_level_1_tagged/types.go | 16 - .../overlap/same_level_2_both_tagged/types.go | 26 - .../overlap/same_level_2_no_tags/types.go | 26 - .../overlap/same_level_2_tagged/types.go | 26 - .../struct/array/ptr_string/types.go | 5 - .../output_tests/struct/array/string/types.go | 5 - .../struct/array/string_alias/types.go | 9 - .../struct/array/strings/types.go | 7 - .../struct/array/struct_strings/types.go | 9 - .../go/output_tests/struct/empty/types.go | 3 - .../output_tests/struct/empty_alias/types.go | 5 - .../output_tests/struct/everything/types.go | 20 - .../go/output_tests/struct/float64/types.go | 5 - .../struct/float64_alias/types.go | 7 - .../go/output_tests/struct/float64s/types.go | 7 - .../struct/float64s_alias/types.go | 9 - .../go/output_tests/struct/int32/types.go | 5 - .../output_tests/struct/int32_alias/types.go | 7 - .../go/output_tests/struct/int32s/types.go | 7 - .../output_tests/struct/int32s_alias/types.go | 9 - .../go/output_tests/struct/int64/types.go | 5 - .../struct/map/int32_ptr_string/types.go | 5 - .../struct/map/int32_string/types.go | 5 - .../struct/map/int32_struct_strings/types.go | 9 - .../struct/map/string_ptr_string/types.go | 5 - .../struct/map/string_string/types.go | 5 - .../struct/map/string_struct_strings/types.go | 9 - .../output_tests/struct/ptr_float64/types.go | 5 - .../struct/ptr_float64_alias/types.go | 10 - .../go/output_tests/struct/ptr_int32/types.go | 5 - .../struct/ptr_int32_alias/types.go | 11 - .../struct/ptr_ptr_struct_empty/types.go | 5 - .../struct/ptr_ptr_struct_strings/types.go | 9 - .../output_tests/struct/ptr_string/types.go | 5 - .../struct/ptr_string_alias/types.go | 10 - .../struct/ptr_struct_empty/types.go | 5 - .../struct/ptr_struct_strings/types.go | 9 - .../output_tests/struct/ptrs_float64/types.go | 7 - .../output_tests/struct/ptrs_int32/types.go | 7 - .../output_tests/struct/ptrs_string/types.go | 7 - .../struct/slice/ptr_string/types.go | 5 - .../output_tests/struct/slice/string/types.go | 5 - .../struct/slice/string_alias/types.go | 9 - .../struct/slice/strings/types.go | 7 - .../struct/slice/struct_strings/types.go | 9 - .../go/output_tests/struct/string/types.go | 5 - .../output_tests/struct/string_alias/types.go | 7 - .../go/output_tests/struct/strings/types.go | 7 - .../struct/strings_alias/types.go | 9 - .../struct/struct/empties/types.go | 7 - .../output_tests/struct/struct/empty/types.go | 5 - .../struct/struct/empty_alias/types.go | 7 - .../struct/struct/float32s/types.go | 9 - .../struct/struct/float64/types.go | 7 - .../struct/struct/float64_alias/types.go | 9 - .../struct/struct/int32s/types.go | 9 - .../struct/struct/strings/types.go | 9 - .../struct/struct/strings_alias/types.go | 13 - .../struct_tags/fieldname/embedded/types.go | 40 - .../struct_tags/fieldname/string/types.go | 16 - .../struct_tags/fieldname/struct/types.go | 40 - .../struct_tags/omitempty/bool/types.go | 6 - .../struct_tags/omitempty/embedded/types.go | 10 - .../struct_tags/omitempty/float32/types.go | 6 - .../struct_tags/omitempty/int32/types.go | 6 - .../omitempty/map_string_string/types.go | 6 - .../struct_tags/omitempty/ptr_bool/types.go | 6 - .../omitempty/ptr_float32/types.go | 6 - .../struct_tags/omitempty/ptr_int32/types.go | 6 - .../omitempty/ptr_map_string_string/types.go | 6 - .../omitempty/ptr_slice_string/types.go | 6 - .../omitempty/ptr_string/string/types.go | 6 - .../struct_tags/omitempty/ptr_string/types.go | 6 - .../ptr_string_json_marshal/types.go | 15 - .../ptr_string_text_marshal/types.go | 15 - .../ptr_struct_json_marshal/types.go | 15 - .../ptr_struct_text_marshal/types.go | 15 - .../struct_tags/omitempty/ptr_uint32/types.go | 6 - .../omitempty/slice_string/types.go | 6 - .../struct_tags/omitempty/string/types.go | 6 - .../omitempty/string_json_marshal/types.go | 15 - .../omitempty/string_text_marshal/types.go | 15 - .../struct_tags/omitempty/struct/types.go | 5 - .../omitempty/struct_json_marshal/types.go | 15 - .../omitempty/struct_text_marshal/types.go | 15 - .../struct_tags/omitempty/uint32/types.go | 6 - .../struct_tags/string/bool/types.go | 6 - .../struct_tags/string/byte/types.go | 6 - .../struct_tags/string/float32/types.go | 6 - .../struct_tags/string/float64/types.go | 6 - .../struct_tags/string/int16/types.go | 6 - .../struct_tags/string/int32/types.go | 6 - .../struct_tags/string/int8/types.go | 6 - .../struct_tags/string/string/types.go | 6 - .../struct_tags/string/uint16/types.go | 6 - .../struct_tags/string/uint32/types.go | 6 - .../struct_tags/string/uint8/types.go | 6 - .../text_marshal/string_alias/types.go | 50 - .../output_tests/text_marshal/struct/types.go | 52 - .../text_marshal/struct_alias/types.go | 54 - .../text_marshal/struct_field/types.go | 56 - .../text_marshal/struct_field_alias/types.go | 58 - .../github.com/json-iterator/go/pool.go | 42 + .../github.com/json-iterator/go/reflect.go | 330 + .../json-iterator/go/reflect_array.go | 104 + .../json-iterator/go/reflect_dynamic.go | 70 + .../json-iterator/go/reflect_extension.go | 471 + .../json-iterator/go/reflect_json_number.go | 112 + .../go/reflect_json_raw_message.go | 60 + .../json-iterator/go/reflect_map.go | 318 + .../json-iterator/go/reflect_marshaler.go | 218 + .../json-iterator/go/reflect_native.go | 451 + .../json-iterator/go/reflect_optional.go | 133 + .../json-iterator/go/reflect_slice.go | 99 + .../go/reflect_struct_decoder.go | 1048 + .../go/reflect_struct_encoder.go | 210 + .../go/skip_tests/array/inputs.go | 12 - .../json-iterator/go/skip_tests/array_test.go | 15 + .../go/skip_tests/float64_test.go | 20 + .../go/skip_tests/jsoniter_skip_test.go | 185 + .../go/skip_tests/number/inputs.go | 17 - .../go/skip_tests/object/inputs.go | 16 - .../json-iterator/go/skip_tests/skip_test.go | 45 + .../go/skip_tests/string/inputs.go | 14 - .../go/skip_tests/string_test.go | 17 + .../go/skip_tests/struct_test.go | 19 + .../github.com/json-iterator/go/stream.go | 211 + .../json-iterator/go/stream_float.go | 94 + .../github.com/json-iterator/go/stream_int.go | 190 + .../github.com/json-iterator/go/stream_str.go | 372 + .../json-iterator/go/stream_test.go | 69 + .../github.com/json-iterator/go/test.sh | 2 +- .../json-iterator/go/type_tests/array_test.go | 63 + .../go/type_tests/builtin_test.go | 69 + .../go/type_tests/map_key_test.go | 43 + .../json-iterator/go/type_tests/map_test.go | 60 + .../go/type_tests/marshaler_string_test.go | 52 + .../go/type_tests/marshaler_struct_test.go | 69 + .../json-iterator/go/type_tests/slice_test.go | 125 + .../go/type_tests/struct_embedded_test.go | 233 + .../go/type_tests/struct_field_case_test.go | 30 + .../go/type_tests/struct_tags_test.go | 282 + .../go/type_tests/struct_test.go | 404 + .../type_tests/text_marshaler_string_test.go | 57 + .../type_tests/text_marshaler_struct_test.go | 69 + .../json-iterator/go/type_tests/type_test.go | 162 + .../go/value_tests/array_test.go | 20 + .../json-iterator/go/value_tests/bool_test.go | 10 + .../go/value_tests/eface_test.go | 78 + .../go/value_tests/error_test.go | 36 + .../go/value_tests/float_test.go | 129 + .../go/value_tests/iface_test.go | 45 + .../json-iterator/go/value_tests/int_test.go | 419 + .../go/value_tests/invalid_test.go | 226 + .../json-iterator/go/value_tests/map_test.go | 51 + .../go/value_tests/marshaler_test.go | 84 + .../go/value_tests/number_test.go | 17 + .../json-iterator/go/value_tests/ptr_test.go | 39 + .../go/value_tests/raw_message_test.go | 13 + .../go/value_tests/slice_test.go | 27 + .../go/value_tests/string_test.go | 88 + .../go/value_tests/struct_test.go | 230 + .../go/value_tests/value_test.go | 80 + .../vendor/github.com/juju/ratelimit/LICENSE | 191 - .../github.com/juju/ratelimit/README.md | 117 - .../github.com/juju/ratelimit/ratelimit.go | 344 - .../github.com/juju/ratelimit/reader.go | 51 - .../github.com/mailru/easyjson/.gitignore | 4 - .../vendor/github.com/mailru/easyjson/LICENSE | 7 - .../github.com/mailru/easyjson/Makefile | 56 - .../github.com/mailru/easyjson/README.md | 331 - .../mailru/easyjson/benchmark/data.go | 148 - .../mailru/easyjson/benchmark/data_codec.go | 6914 ------ .../mailru/easyjson/benchmark/data_ffjson.go | 6723 ------ .../mailru/easyjson/benchmark/data_var.go | 350 - .../mailru/easyjson/benchmark/example.json | 415 - .../mailru/easyjson/benchmark/ujson.sh | 7 - .../mailru/easyjson/bootstrap/bootstrap.go | 188 - .../github.com/mailru/easyjson/buffer/pool.go | 270 - .../mailru/easyjson/easyjson/main.go | 106 - .../github.com/mailru/easyjson/gen/decoder.go | 489 - .../github.com/mailru/easyjson/gen/encoder.go | 382 - .../mailru/easyjson/gen/generator.go | 523 - .../github.com/mailru/easyjson/helpers.go | 78 - .../mailru/easyjson/jlexer/bytestostr.go | 24 - .../easyjson/jlexer/bytestostr_nounsafe.go | 13 - .../mailru/easyjson/jlexer/error.go | 15 - .../mailru/easyjson/jlexer/lexer.go | 1141 - .../mailru/easyjson/jwriter/writer.go | 377 - .../mailru/easyjson/opt/gotemplate_Bool.go | 79 - .../mailru/easyjson/opt/gotemplate_Float32.go | 79 - .../mailru/easyjson/opt/gotemplate_Float64.go | 79 - .../mailru/easyjson/opt/gotemplate_Int.go | 79 - .../mailru/easyjson/opt/gotemplate_Int16.go | 79 - .../mailru/easyjson/opt/gotemplate_Int32.go | 79 - .../mailru/easyjson/opt/gotemplate_Int64.go | 79 - .../mailru/easyjson/opt/gotemplate_Int8.go | 79 - .../mailru/easyjson/opt/gotemplate_String.go | 79 - .../mailru/easyjson/opt/gotemplate_Uint.go | 79 - .../mailru/easyjson/opt/gotemplate_Uint16.go | 79 - .../mailru/easyjson/opt/gotemplate_Uint32.go | 79 - .../mailru/easyjson/opt/gotemplate_Uint64.go | 79 - .../mailru/easyjson/opt/gotemplate_Uint8.go | 79 - .../mailru/easyjson/opt/optional/opt.go | 80 - .../github.com/mailru/easyjson/opt/opts.go | 22 - .../mailru/easyjson/parser/parser.go | 97 - .../mailru/easyjson/parser/parser_unix.go | 42 - .../mailru/easyjson/parser/parser_windows.go | 49 - .../vendor/github.com/mailru/easyjson/raw.go | 45 - .../github.com/mailru/easyjson/tests/data.go | 759 - .../mailru/easyjson/tests/errors.go | 26 - .../mailru/easyjson/tests/named_type.go | 22 - .../mailru/easyjson/tests/nested_easy.go | 25 - .../mailru/easyjson/tests/nothing.go | 3 - .../mailru/easyjson/tests/omitempty.go | 12 - .../github.com/mailru/easyjson/tests/snake.go | 10 - .../golang_protobuf_extensions/.travis.yml | 2 + .../pbutil/all_test.go | 177 + .../pbutil/decode_test.go | 99 + .../pbutil/encode_test.go | 67 + .../pbutil/fixtures_test.go | 103 + .../modern-go/concurrent/.gitignore | 1 + .../modern-go/concurrent/.travis.yml | 14 + .../github.com/modern-go/concurrent/LICENSE | 201 + .../github.com/modern-go/concurrent/README.md | 49 + .../modern-go/concurrent/executor.go | 14 + .../modern-go/concurrent/go_above_19.go | 15 + .../modern-go/concurrent/go_below_19.go | 33 + .../github.com/modern-go/concurrent/log.go | 13 + .../modern-go/concurrent/map_test.go | 18 + .../github.com/modern-go/concurrent/test.sh | 12 + .../concurrent/unbounded_executor.go | 119 + .../concurrent/unbounded_executor_test.go | 54 + .../github.com/modern-go/reflect2/.gitignore | 2 + .../github.com/modern-go/reflect2/.travis.yml | 15 + .../github.com/modern-go/reflect2/Gopkg.lock | 15 + .../github.com/modern-go/reflect2/Gopkg.toml | 35 + .../github.com/modern-go/reflect2/LICENSE | 201 + .../github.com/modern-go/reflect2/README.md | 71 + .../modern-go/reflect2/go_above_17.go | 8 + .../modern-go/reflect2/go_above_19.go | 14 + .../modern-go/reflect2/go_below_17.go | 9 + .../modern-go/reflect2/go_below_19.go | 14 + .../github.com/modern-go/reflect2/reflect2.go | 298 + .../modern-go/reflect2/reflect2_amd64.s | 0 .../modern-go/reflect2/reflect2_kind.go | 30 + .../modern-go/reflect2/relfect2_386.s | 0 .../modern-go/reflect2/relfect2_amd64p32.s | 0 .../modern-go/reflect2/relfect2_arm.s | 0 .../modern-go/reflect2/relfect2_arm64.s | 0 .../modern-go/reflect2/relfect2_mips64x.s | 0 .../modern-go/reflect2/relfect2_mipsx.s | 0 .../modern-go/reflect2/relfect2_ppc64x.s | 0 .../modern-go/reflect2/relfect2_s390x.s | 0 .../modern-go/reflect2/safe_field.go | 58 + .../github.com/modern-go/reflect2/safe_map.go | 101 + .../modern-go/reflect2/safe_slice.go | 92 + .../modern-go/reflect2/safe_struct.go | 29 + .../modern-go/reflect2/safe_type.go | 78 + .../github.com/modern-go/reflect2/test.sh | 12 + .../github.com/modern-go/reflect2/type_map.go | 103 + .../modern-go/reflect2/unsafe_array.go | 65 + .../modern-go/reflect2/unsafe_eface.go | 59 + .../modern-go/reflect2/unsafe_field.go | 74 + .../modern-go/reflect2/unsafe_iface.go | 64 + .../modern-go/reflect2/unsafe_link.go | 70 + .../modern-go/reflect2/unsafe_map.go | 138 + .../modern-go/reflect2/unsafe_ptr.go | 46 + .../modern-go/reflect2/unsafe_slice.go | 177 + .../modern-go/reflect2/unsafe_struct.go | 59 + .../modern-go/reflect2/unsafe_type.go | 85 + .../vendor/github.com/petar/GoLLRB/.gitignore | 23 - .../vendor/github.com/petar/GoLLRB/AUTHORS | 4 - .../vendor/github.com/petar/GoLLRB/LICENSE | 27 - .../vendor/github.com/petar/GoLLRB/README.md | 66 - .../petar/GoLLRB/doc/Sedgewick-LLRB.pdf | Bin 819932 -> 0 bytes .../GoLLRB/doc/Sedgewick-RedBlackBST.java | 475 - .../GoLLRB/doc/Sedgewick-Talk-Penn2008.pdf | Bin 11636171 -> 0 bytes .../github.com/petar/GoLLRB/example/ex1.go | 26 - .../github.com/petar/GoLLRB/llrb/avgvar.go | 39 - .../github.com/petar/GoLLRB/llrb/iterator.go | 93 - .../petar/GoLLRB/llrb/llrb-stats.go | 46 - .../github.com/petar/GoLLRB/llrb/llrb.go | 456 - .../github.com/petar/GoLLRB/llrb/util.go | 17 - .../github.com/peterbourgon/diskv/LICENSE | 19 - .../github.com/peterbourgon/diskv/README.md | 141 - .../peterbourgon/diskv/compression.go | 64 - .../github.com/peterbourgon/diskv/diskv.go | 624 - .../examples/content-addressable-store/cas.go | 63 - .../super-simple-store/super-simple-store.go | 30 - .../github.com/peterbourgon/diskv/index.go | 115 - .../github.com/pmezard/go-difflib/.travis.yml | 5 + .../go-difflib/difflib/difflib_test.go | 426 + .../prometheus/client_golang/.travis.yml | 9 + .../client_golang/api/prometheus/api_test.go | 453 + .../prometheus/benchmark_test.go | 183 + .../client_golang/prometheus/counter_test.go | 58 + .../prometheus/example_clustermanager_test.go | 118 + .../client_golang/prometheus/examples_test.go | 751 + .../prometheus/expvar_collector_test.go | 97 + .../client_golang/prometheus/gauge_test.go | 182 + .../prometheus/go_collector_test.go | 123 + .../prometheus/histogram_test.go | 326 + .../client_golang/prometheus/http_test.go | 121 + .../client_golang/prometheus/metric_test.go | 35 + .../prometheus/process_collector_test.go | 58 + .../prometheus/promhttp/http_test.go | 137 + .../prometheus/push/examples_test.go | 56 + .../prometheus/push/push_test.go | 176 + .../client_golang/prometheus/registry_test.go | 545 + .../client_golang/prometheus/summary_test.go | 347 + .../client_golang/prometheus/vec_test.go | 312 + .../github.com/prometheus/common/.travis.yml | 6 + .../common/config/http_config_test.go | 157 + .../common/config/tls_config_test.go | 92 + .../prometheus/common/expfmt/bench_test.go | 167 + .../prometheus/common/expfmt/decode_test.go | 435 + .../common/expfmt/text_create_test.go | 443 + .../common/expfmt/text_parse_test.go | 593 + .../ww/goautoneg/autoneg_test.go | 33 + .../prometheus/common/log/log_test.go | 39 + .../common/log/syslog_formatter_test.go | 52 + .../prometheus/common/model/alert_test.go | 118 + .../prometheus/common/model/labels_test.go | 140 + .../prometheus/common/model/metric_test.go | 132 + .../prometheus/common/model/signature_test.go | 314 + .../prometheus/common/model/silence_test.go | 228 + .../prometheus/common/model/time_test.go | 132 + .../prometheus/common/model/value_test.go | 468 + .../prometheus/common/route/route_test.go | 76 + .../github.com/prometheus/procfs/.travis.yml | 15 + .../prometheus/procfs/bcache/get_test.go | 114 + .../prometheus/procfs/buddyinfo_test.go | 64 + .../github.com/prometheus/procfs/fs_test.go | 39 + .../github.com/prometheus/procfs/ipvs_test.go | 250 + .../prometheus/procfs/mdstat_test.go | 44 + .../prometheus/procfs/mountstats_test.go | 286 + .../prometheus/procfs/net_dev_test.go | 86 + .../prometheus/procfs/nfs/parse_nfs_test.go | 305 + .../prometheus/procfs/nfs/parse_nfsd_test.go | 196 + .../prometheus/procfs/proc_io_test.go | 46 + .../prometheus/procfs/proc_limits_test.go | 44 + .../prometheus/procfs/proc_ns_test.go | 44 + .../prometheus/procfs/proc_stat_test.go | 123 + .../github.com/prometheus/procfs/proc_test.go | 174 + .../github.com/prometheus/procfs/stat_test.go | 74 + .../prometheus/procfs/sysfs/fs_test.go | 108 + .../prometheus/procfs/sysfs/net_class_test.go | 67 + .../github.com/prometheus/procfs/xfrm_test.go | 66 + .../prometheus/procfs/xfs/parse_test.go | 442 + .../github.com/sirupsen/logrus/.travis.yml | 13 + .../github.com/sirupsen/logrus/CHANGELOG.md | 5 + .../github.com/sirupsen/logrus/README.md | 60 +- .../sirupsen/logrus/alt_exit_test.go | 83 + .../github.com/sirupsen/logrus/entry.go | 67 +- .../github.com/sirupsen/logrus/entry_test.go | 115 + .../sirupsen/logrus/example_basic_test.go | 69 + .../sirupsen/logrus/example_hook_test.go | 35 + .../github.com/sirupsen/logrus/exported.go | 20 +- .../github.com/sirupsen/logrus/formatter.go | 20 +- .../sirupsen/logrus/formatter_bench_test.go | 101 + .../github.com/sirupsen/logrus/hook_test.go | 144 + .../logrus/hooks/syslog/syslog_test.go | 27 + .../sirupsen/logrus/hooks/test/test.go | 15 +- .../sirupsen/logrus/hooks/test/test_test.go | 73 + .../sirupsen/logrus/json_formatter.go | 12 +- .../sirupsen/logrus/json_formatter_test.go | 296 + .../github.com/sirupsen/logrus/logger.go | 16 +- .../sirupsen/logrus/logger_bench_test.go | 61 + .../github.com/sirupsen/logrus/logrus_test.go | 446 + .../sirupsen/logrus/terminal_bsd.go | 2 +- .../logrus/terminal_check_appengine.go | 2 +- .../logrus/terminal_check_notappengine.go | 2 +- .../sirupsen/logrus/terminal_linux.go | 2 +- .../sirupsen/logrus/text_formatter.go | 31 +- .../sirupsen/logrus/text_formatter_test.go | 220 + .../vendor/github.com/spf13/pflag/.travis.yml | 21 + .../github.com/spf13/pflag/bool_slice_test.go | 215 + .../github.com/spf13/pflag/bool_test.go | 179 + .../github.com/spf13/pflag/count_test.go | 52 + .../github.com/spf13/pflag/example_test.go | 36 + .../github.com/spf13/pflag/export_test.go | 29 + .../github.com/spf13/pflag/flag_test.go | 1085 + .../github.com/spf13/pflag/golangflag_test.go | 39 + .../github.com/spf13/pflag/int_slice_test.go | 165 + .../github.com/spf13/pflag/ip_slice_test.go | 222 + .../vendor/github.com/spf13/pflag/ip_test.go | 63 + .../github.com/spf13/pflag/ipnet_test.go | 70 + .../spf13/pflag/string_array_test.go | 233 + .../spf13/pflag/string_slice_test.go | 253 + .../github.com/spf13/pflag/uint_slice_test.go | 161 + .../github.com/stretchr/testify/.travis.yml | 15 + .../testify/assert/assertions_test.go | 1581 ++ .../testify/assert/forward_assertions_test.go | 611 + .../testify/assert/http_assertions_test.go | 117 + .../stretchr/testify/mock/mock_test.go | 1352 ++ .../stretchr/testify/package_test.go | 12 + .../require/forward_requirements_test.go | 385 + .../testify/require/requirements_test.go | 369 + .../stretchr/testify/suite/suite_test.go | 294 + .../golang.org/x/crypto/acme/acme_test.go | 1352 ++ .../x/crypto/acme/autocert/autocert_test.go | 606 + .../x/crypto/acme/autocert/cache_test.go | 58 + .../x/crypto/acme/autocert/example_test.go | 35 + .../x/crypto/acme/autocert/renewal_test.go | 191 + .../golang.org/x/crypto/acme/jws_test.go | 319 + .../golang.org/x/crypto/acme/types_test.go | 63 + .../golang.org/x/crypto/bcrypt/bcrypt_test.go | 243 + .../x/crypto/blake2b/blake2b_test.go | 798 + .../x/crypto/blake2s/blake2s_test.go | 1002 + .../x/crypto/blowfish/blowfish_test.go | 274 + .../golang.org/x/crypto/bn256/bn256_test.go | 304 + .../golang.org/x/crypto/bn256/example_test.go | 43 + .../golang.org/x/crypto/cast5/cast5_test.go | 106 + .../chacha20poly1305/chacha20poly1305_test.go | 182 + .../chacha20poly1305_vectors_test.go | 332 + .../internal/chacha20/chacha_test.go | 33 + .../x/crypto/cryptobyte/asn1_test.go | 300 + .../x/crypto/cryptobyte/cryptobyte_test.go | 428 + .../x/crypto/cryptobyte/example_test.go | 154 + .../x/crypto/curve25519/curve25519_test.go | 39 + .../x/crypto/ed25519/ed25519_test.go | 183 + .../golang.org/x/crypto/hkdf/example_test.go | 61 + .../golang.org/x/crypto/hkdf/hkdf_test.go | 370 + .../golang.org/x/crypto/md4/example_test.go | 20 + .../golang.org/x/crypto/md4/md4_test.go | 71 + .../x/crypto/nacl/auth/auth_test.go | 172 + .../x/crypto/nacl/auth/example_test.go | 36 + .../golang.org/x/crypto/nacl/box/box_test.go | 78 + .../x/crypto/nacl/box/example_test.go | 95 + .../x/crypto/nacl/secretbox/example_test.go | 53 + .../x/crypto/nacl/secretbox/secretbox_test.go | 154 + .../golang.org/x/crypto/ocsp/ocsp_test.go | 875 + .../x/crypto/openpgp/armor/armor_test.go | 95 + .../x/crypto/openpgp/canonical_text_test.go | 52 + .../openpgp/clearsign/clearsign_test.go | 210 + .../x/crypto/openpgp/elgamal/elgamal_test.go | 49 + .../golang.org/x/crypto/openpgp/keys_test.go | 419 + .../crypto/openpgp/packet/compressed_test.go | 41 + .../openpgp/packet/encrypted_key_test.go | 146 + .../x/crypto/openpgp/packet/ocfb_test.go | 46 + .../x/crypto/openpgp/packet/opaque_test.go | 67 + .../x/crypto/openpgp/packet/packet_test.go | 255 + .../crypto/openpgp/packet/private_key_test.go | 270 + .../crypto/openpgp/packet/public_key_test.go | 202 + .../openpgp/packet/public_key_v3_test.go | 82 + .../x/crypto/openpgp/packet/signature_test.go | 78 + .../openpgp/packet/signature_v3_test.go | 92 + .../packet/symmetric_key_encrypted_test.go | 117 + .../packet/symmetrically_encrypted_test.go | 123 + .../openpgp/packet/userattribute_test.go | 109 + .../x/crypto/openpgp/packet/userid_test.go | 87 + .../golang.org/x/crypto/openpgp/read_test.go | 613 + .../x/crypto/openpgp/s2k/s2k_test.go | 137 + .../golang.org/x/crypto/openpgp/write_test.go | 273 + .../golang.org/x/crypto/otr/otr_test.go | 470 + .../golang.org/x/crypto/pbkdf2/pbkdf2_test.go | 157 + .../x/crypto/pkcs12/bmp-string_test.go | 63 + .../golang.org/x/crypto/pkcs12/crypto_test.go | 125 + .../crypto/pkcs12/internal/rc2/bench_test.go | 27 + .../x/crypto/pkcs12/internal/rc2/rc2_test.go | 92 + .../golang.org/x/crypto/pkcs12/mac_test.go | 42 + .../golang.org/x/crypto/pkcs12/pbkdf_test.go | 34 + .../golang.org/x/crypto/pkcs12/pkcs12_test.go | 138 + .../x/crypto/poly1305/poly1305_test.go | 159 + .../x/crypto/ripemd160/ripemd160_test.go | 64 + .../x/crypto/salsa20/salsa/salsa_test.go | 54 + .../x/crypto/salsa20/salsa20_test.go | 139 + .../x/crypto/scrypt/example_test.go | 26 + .../golang.org/x/crypto/scrypt/scrypt_test.go | 162 + .../golang.org/x/crypto/sha3/sha3_test.go | 311 + .../x/crypto/ssh/agent/client_test.go | 379 + .../x/crypto/ssh/agent/example_test.go | 41 + .../x/crypto/ssh/agent/keyring_test.go | 76 + .../x/crypto/ssh/agent/server_test.go | 259 + .../x/crypto/ssh/agent/testdata_test.go | 64 + .../golang.org/x/crypto/ssh/benchmark_test.go | 122 + .../golang.org/x/crypto/ssh/buffer_test.go | 87 + .../golang.org/x/crypto/ssh/certs_test.go | 222 + .../golang.org/x/crypto/ssh/cipher_test.go | 129 + .../x/crypto/ssh/client_auth_test.go | 628 + .../golang.org/x/crypto/ssh/client_test.go | 130 + .../golang.org/x/crypto/ssh/example_test.go | 320 + .../golang.org/x/crypto/ssh/handshake_test.go | 559 + .../golang.org/x/crypto/ssh/kex_test.go | 50 + .../golang.org/x/crypto/ssh/keys_test.go | 500 + .../crypto/ssh/knownhosts/knownhosts_test.go | 329 + .../golang.org/x/crypto/ssh/mempipe_test.go | 110 + .../golang.org/x/crypto/ssh/messages_test.go | 288 + .../golang.org/x/crypto/ssh/mux_test.go | 505 + .../golang.org/x/crypto/ssh/session_test.go | 774 + .../golang.org/x/crypto/ssh/tcpip_test.go | 20 + .../x/crypto/ssh/terminal/terminal_test.go | 350 + .../x/crypto/ssh/test/agent_unix_test.go | 59 + .../x/crypto/ssh/test/banner_test.go | 32 + .../golang.org/x/crypto/ssh/test/cert_test.go | 77 + .../x/crypto/ssh/test/dial_unix_test.go | 128 + .../x/crypto/ssh/test/forward_unix_test.go | 194 + .../x/crypto/ssh/test/session_test.go | 413 + .../x/crypto/ssh/test/test_unix_test.go | 298 + .../x/crypto/ssh/test/testdata_test.go | 64 + .../golang.org/x/crypto/ssh/testdata_test.go | 63 + .../golang.org/x/crypto/ssh/transport_test.go | 109 + .../golang.org/x/crypto/tea/tea_test.go | 93 + .../x/crypto/twofish/twofish_test.go | 129 + .../golang.org/x/crypto/xtea/xtea_test.go | 229 + .../golang.org/x/crypto/xts/xts_test.go | 105 + .../golang.org/x/net/bpf/instructions_test.go | 525 + .../golang.org/x/net/bpf/vm_aluop_test.go | 512 + .../golang.org/x/net/bpf/vm_bpf_test.go | 192 + .../golang.org/x/net/bpf/vm_extension_test.go | 49 + .../golang.org/x/net/bpf/vm_jump_test.go | 380 + .../golang.org/x/net/bpf/vm_load_test.go | 246 + .../golang.org/x/net/bpf/vm_ret_test.go | 115 + .../golang.org/x/net/bpf/vm_scratch_test.go | 247 + .../vendor/golang.org/x/net/bpf/vm_test.go | 144 + .../golang.org/x/net/context/context_test.go | 583 + .../x/net/context/ctxhttp/ctxhttp_17_test.go | 29 + .../net/context/ctxhttp/ctxhttp_pre17_test.go | 79 + .../x/net/context/ctxhttp/ctxhttp_test.go | 105 + .../x/net/context/withtimeout_test.go | 31 + .../x/net/dns/dnsmessage/example_test.go | 132 + .../x/net/dns/dnsmessage/message_test.go | 1141 + .../golang.org/x/net/html/atom/atom_test.go | 109 + .../golang.org/x/net/html/atom/table_test.go | 373 + .../x/net/html/charset/charset_test.go | 237 + .../golang.org/x/net/html/entity_test.go | 29 + .../golang.org/x/net/html/escape_test.go | 97 + .../golang.org/x/net/html/example_test.go | 40 + .../vendor/golang.org/x/net/html/node_test.go | 146 + .../golang.org/x/net/html/parse_test.go | 388 + .../golang.org/x/net/html/render_test.go | 156 + .../golang.org/x/net/html/token_test.go | 748 + .../x/net/http/httpproxy/export_test.go | 7 + .../x/net/http/httpproxy/go19_test.go | 13 + .../x/net/http/httpproxy/proxy_test.go | 301 + .../golang.org/x/net/http2/ciphers_test.go | 309 + .../golang.org/x/net/http2/databuffer_test.go | 157 + .../golang.org/x/net/http2/errors_test.go | 24 + .../golang.org/x/net/http2/flow_test.go | 53 + .../golang.org/x/net/http2/frame_test.go | 1191 + .../golang.org/x/net/http2/go18_test.go | 79 + .../golang.org/x/net/http2/go19_test.go | 59 + .../golang.org/x/net/http2/gotrack_test.go | 33 + .../x/net/http2/hpack/encode_test.go | 386 + .../x/net/http2/hpack/hpack_test.go | 722 + .../x/net/http2/hpack/tables_test.go | 214 + .../golang.org/x/net/http2/http2_test.go | 199 + .../golang.org/x/net/http2/pipe_test.go | 130 + .../x/net/http2/server_push_test.go | 521 + .../golang.org/x/net/http2/server_test.go | 3725 ++++ .../golang.org/x/net/http2/transport_test.go | 3847 ++++ .../x/net/http2/writesched_priority_test.go | 541 + .../x/net/http2/writesched_random_test.go | 44 + .../golang.org/x/net/http2/writesched_test.go | 125 + .../golang.org/x/net/http2/z_spec_test.go | 356 + .../golang.org/x/net/icmp/example_test.go | 63 + .../golang.org/x/net/icmp/extension_test.go | 259 + .../vendor/golang.org/x/net/icmp/ipv4_test.go | 83 + .../golang.org/x/net/icmp/message_test.go | 134 + .../golang.org/x/net/icmp/multipart_test.go | 442 + .../vendor/golang.org/x/net/icmp/ping_test.go | 200 + .../golang.org/x/net/idna/example_test.go | 70 + .../vendor/golang.org/x/net/idna/idna_test.go | 108 + .../golang.org/x/net/idna/punycode_test.go | 198 + .../net/internal/socket/socket_go1_9_test.go | 259 + .../x/net/internal/socket/socket_test.go | 46 + .../internal/timeseries/timeseries_test.go | 170 + .../vendor/golang.org/x/net/ipv4/bpf_test.go | 93 + .../golang.org/x/net/ipv4/control_test.go | 21 + .../golang.org/x/net/ipv4/example_test.go | 224 + .../golang.org/x/net/ipv4/header_test.go | 228 + .../vendor/golang.org/x/net/ipv4/icmp_test.go | 95 + .../golang.org/x/net/ipv4/multicast_test.go | 334 + .../x/net/ipv4/multicastlistener_test.go | 265 + .../x/net/ipv4/multicastsockopt_test.go | 195 + .../x/net/ipv4/readwrite_go1_8_test.go | 248 + .../x/net/ipv4/readwrite_go1_9_test.go | 388 + .../golang.org/x/net/ipv4/readwrite_test.go | 140 + .../golang.org/x/net/ipv4/unicast_test.go | 247 + .../x/net/ipv4/unicastsockopt_test.go | 148 + .../vendor/golang.org/x/net/ipv6/bpf_test.go | 96 + .../golang.org/x/net/ipv6/control_test.go | 21 + .../golang.org/x/net/ipv6/example_test.go | 216 + .../golang.org/x/net/ipv6/header_test.go | 55 + .../vendor/golang.org/x/net/ipv6/icmp_test.go | 96 + .../x/net/ipv6/mocktransponder_test.go | 32 + .../golang.org/x/net/ipv6/multicast_test.go | 264 + .../x/net/ipv6/multicastlistener_test.go | 261 + .../x/net/ipv6/multicastsockopt_test.go | 157 + .../x/net/ipv6/readwrite_go1_8_test.go | 242 + .../x/net/ipv6/readwrite_go1_9_test.go | 373 + .../golang.org/x/net/ipv6/readwrite_test.go | 148 + .../golang.org/x/net/ipv6/sockopt_test.go | 133 + .../golang.org/x/net/ipv6/unicast_test.go | 184 + .../x/net/ipv6/unicastsockopt_test.go | 120 + .../x/net/lex/httplex/httplex_test.go | 119 + .../golang.org/x/net/lif/address_test.go | 123 + .../vendor/golang.org/x/net/lif/link_test.go | 63 + .../golang.org/x/net/nettest/conntest_test.go | 76 + .../golang.org/x/net/netutil/listen_test.go | 101 + .../golang.org/x/net/proxy/per_host_test.go | 55 + .../golang.org/x/net/proxy/proxy_test.go | 215 + .../x/net/publicsuffix/list_test.go | 416 + .../x/net/publicsuffix/table_test.go | 16756 +++++++++++++++ .../x/net/route/address_darwin_test.go | 63 + .../golang.org/x/net/route/address_test.go | 103 + .../x/net/route/message_darwin_test.go | 34 + .../x/net/route/message_freebsd_test.go | 92 + .../golang.org/x/net/route/message_test.go | 239 + .../golang.org/x/net/route/route_test.go | 390 + .../golang.org/x/net/trace/histogram_test.go | 325 + .../golang.org/x/net/trace/trace_test.go | 178 + .../golang.org/x/net/webdav/file_test.go | 1184 + .../vendor/golang.org/x/net/webdav/if_test.go | 322 + .../x/net/webdav/internal/xml/atom_test.go | 56 + .../x/net/webdav/internal/xml/example_test.go | 151 + .../x/net/webdav/internal/xml/marshal_test.go | 1939 ++ .../x/net/webdav/internal/xml/read_test.go | 744 + .../x/net/webdav/internal/xml/xml_test.go | 752 + .../golang.org/x/net/webdav/lock_test.go | 731 + .../golang.org/x/net/webdav/prop_test.go | 613 + .../golang.org/x/net/webdav/webdav_test.go | 344 + .../golang.org/x/net/webdav/xml_test.go | 906 + .../golang.org/x/net/websocket/dial_test.go | 43 + .../x/net/websocket/exampledial_test.go | 31 + .../x/net/websocket/examplehandler_test.go | 26 + .../golang.org/x/net/websocket/hybi_test.go | 608 + .../x/net/websocket/websocket_test.go | 665 + .../golang.org/x/net/xsrftoken/xsrf_test.go | 83 + .../golang.org/x/sys/plan9/syscall_test.go | 33 + .../golang.org/x/sys/unix/creds_test.go | 152 + .../golang.org/x/sys/unix/dev_darwin_test.go | 51 + .../x/sys/unix/dev_dragonfly_test.go | 50 + .../golang.org/x/sys/unix/dev_linux_test.go | 53 + .../golang.org/x/sys/unix/dev_netbsd_test.go | 50 + .../golang.org/x/sys/unix/dev_openbsd_test.go | 54 + .../golang.org/x/sys/unix/dev_solaris_test.go | 51 + .../golang.org/x/sys/unix/export_test.go | 9 + .../golang.org/x/sys/unix/mmap_unix_test.go | 35 + .../golang.org/x/sys/unix/openbsd_test.go | 113 + .../golang.org/x/sys/unix/syscall_bsd_test.go | 70 + .../x/sys/unix/syscall_freebsd_test.go | 297 + .../x/sys/unix/syscall_linux_test.go | 257 + .../x/sys/unix/syscall_solaris_test.go | 34 + .../golang.org/x/sys/unix/syscall_test.go | 60 + .../x/sys/unix/syscall_unix_test.go | 452 + .../golang.org/x/sys/unix/timestruct_test.go | 54 + .../x/sys/windows/registry/export_test.go | 11 + .../x/sys/windows/registry/registry_test.go | 756 + .../x/sys/windows/svc/eventlog/log_test.go | 51 + .../x/sys/windows/svc/mgr/mgr_test.go | 169 + .../golang.org/x/sys/windows/svc/svc_test.go | 118 + .../golang.org/x/sys/windows/syscall_test.go | 53 + .../x/sys/windows/syscall_windows_test.go | 107 + .../golang.org/x/text/cases/context_test.go | 438 + .../golang.org/x/text/cases/example_test.go | 53 + .../golang.org/x/text/cases/fold_test.go | 51 + .../golang.org/x/text/cases/icu_test.go | 210 + .../golang.org/x/text/cases/map_test.go | 950 + .../x/text/cases/tables10.0.0_test.go | 1160 + .../x/text/cases/tables9.0.0_test.go | 1156 + .../x/text/collate/build/builder_test.go | 290 + .../x/text/collate/build/colelem_test.go | 215 + .../x/text/collate/build/contract_test.go | 266 + .../x/text/collate/build/order_test.go | 229 + .../x/text/collate/build/trie_test.go | 107 + .../golang.org/x/text/collate/collate_test.go | 482 + .../golang.org/x/text/collate/export_test.go | 51 + .../golang.org/x/text/collate/option_test.go | 209 + .../golang.org/x/text/collate/reg_test.go | 230 + .../golang.org/x/text/collate/sort_test.go | 55 + .../golang.org/x/text/collate/table_test.go | 291 + .../x/text/currency/currency_test.go | 171 + .../x/text/currency/example_test.go | 27 + .../golang.org/x/text/currency/format_test.go | 70 + .../golang.org/x/text/currency/query_test.go | 107 + .../golang.org/x/text/currency/tables_test.go | 93 + .../golang.org/x/text/date/data_test.go | 335 + .../vendor/golang.org/x/text/date/gen_test.go | 241 + .../x/text/encoding/charmap/charmap_test.go | 258 + .../x/text/encoding/encoding_test.go | 290 + .../x/text/encoding/example_test.go | 42 + .../text/encoding/htmlindex/htmlindex_test.go | 144 + .../x/text/encoding/ianaindex/example_test.go | 27 + .../text/encoding/ianaindex/ianaindex_test.go | 192 + .../x/text/encoding/japanese/all_test.go | 248 + .../x/text/encoding/korean/all_test.go | 94 + .../encoding/simplifiedchinese/all_test.go | 143 + .../encoding/traditionalchinese/all_test.go | 114 + .../x/text/encoding/unicode/unicode_test.go | 499 + .../text/encoding/unicode/utf32/utf32_test.go | 248 + .../x/text/feature/plural/data_test.go | 197 + .../x/text/feature/plural/example_test.go | 46 + .../x/text/feature/plural/message_test.go | 197 + .../x/text/feature/plural/plural_test.go | 216 + .../x/text/internal/catmsg/catmsg_test.go | 316 + .../x/text/internal/catmsg/varint_test.go | 123 + .../x/text/internal/cldrtree/cldrtree_test.go | 456 + .../x/text/internal/colltab/collate_test.go | 121 + .../x/text/internal/colltab/collelem_test.go | 183 + .../x/text/internal/colltab/colltab_test.go | 64 + .../x/text/internal/colltab/contract_test.go | 131 + .../x/text/internal/colltab/iter_test.go | 63 + .../x/text/internal/colltab/numeric_test.go | 159 + .../x/text/internal/colltab/trie_test.go | 106 + .../x/text/internal/colltab/weighter_test.go | 42 + .../text/internal/export/idna/common_test.go | 55 + .../text/internal/export/idna/example_test.go | 68 + .../internal/export/idna/gen10.0.0_test.go | 93 + .../internal/export/idna/gen9.0.0_test.go | 84 + .../internal/export/idna/idna10.0.0_test.go | 140 + .../internal/export/idna/idna9.0.0_test.go | 136 + .../x/text/internal/export/idna/idna_test.go | 178 + .../internal/export/idna/punycode_test.go | 198 + .../x/text/internal/format/parser_test.go | 32 + .../golang.org/x/text/internal/gen_test.go | 38 + .../x/text/internal/internal_test.go | 38 + .../golang.org/x/text/internal/match_test.go | 56 + .../x/text/internal/number/decimal_test.go | 329 + .../x/text/internal/number/format_test.go | 522 + .../x/text/internal/number/number_test.go | 104 + .../x/text/internal/number/pattern_test.go | 438 + .../x/text/internal/number/tables_test.go | 125 + .../x/text/internal/stringset/set_test.go | 53 + .../x/text/internal/tag/tag_test.go | 67 + .../x/text/internal/triegen/data_test.go | 875 + .../internal/triegen/example_compact_test.go | 71 + .../x/text/internal/triegen/example_test.go | 148 + .../x/text/internal/triegen/gen_test.go | 68 + .../x/text/internal/ucd/example_test.go | 81 + .../x/text/internal/ucd/ucd_test.go | 105 + .../x/text/language/coverage_test.go | 154 + .../x/text/language/display/dict_test.go | 39 + .../x/text/language/display/display_test.go | 714 + .../x/text/language/display/examples_test.go | 116 + .../x/text/language/examples_test.go | 413 + .../x/text/language/httpexample_test.go | 48 + .../x/text/language/language_test.go | 911 + .../golang.org/x/text/language/lookup_test.go | 457 + .../golang.org/x/text/language/match_test.go | 505 + .../golang.org/x/text/language/parse_test.go | 517 + .../x/text/message/catalog/catalog_test.go | 296 + .../golang.org/x/text/message/catalog_test.go | 43 + .../x/text/message/examples_test.go | 42 + .../golang.org/x/text/message/fmt_test.go | 1871 ++ .../golang.org/x/text/message/message_test.go | 181 + .../golang.org/x/text/number/examples_test.go | 28 + .../golang.org/x/text/number/format_test.go | 112 + .../golang.org/x/text/number/number_test.go | 190 + .../golang.org/x/text/runes/cond_test.go | 282 + .../golang.org/x/text/runes/example_test.go | 60 + .../golang.org/x/text/runes/runes_test.go | 664 + .../golang.org/x/text/search/pattern_test.go | 357 + .../x/text/secure/bidirule/bench_test.go | 54 + .../secure/bidirule/bidirule10.0.0_test.go | 694 + .../secure/bidirule/bidirule9.0.0_test.go | 668 + .../x/text/secure/bidirule/bidirule_test.go | 168 + .../x/text/secure/precis/benchmark_test.go | 82 + .../x/text/secure/precis/class_test.go | 50 + .../text/secure/precis/enforce10.0.0_test.go | 244 + .../x/text/secure/precis/enforce9.0.0_test.go | 244 + .../x/text/secure/precis/enforce_test.go | 162 + .../x/text/secure/precis/profile_test.go | 149 + .../x/text/secure/precis/tables_test.go | 69 + .../x/text/transform/examples_test.go | 37 + .../x/text/transform/transform_test.go | 1317 ++ .../x/text/unicode/bidi/core_test.go | 224 + .../x/text/unicode/bidi/ranges_test.go | 53 + .../x/text/unicode/bidi/tables_test.go | 82 + .../x/text/unicode/cldr/cldr_test.go | 27 + .../x/text/unicode/cldr/collate_test.go | 275 + .../x/text/unicode/cldr/data_test.go | 186 + .../x/text/unicode/cldr/examples_test.go | 21 + .../x/text/unicode/cldr/resolve_test.go | 368 + .../x/text/unicode/cldr/slice_test.go | 175 + .../x/text/unicode/norm/composition_test.go | 130 + .../x/text/unicode/norm/data10.0.0_test.go | 7424 +++++++ .../x/text/unicode/norm/data9.0.0_test.go | 7409 +++++++ .../x/text/unicode/norm/example_iter_test.go | 82 + .../x/text/unicode/norm/example_test.go | 27 + .../x/text/unicode/norm/forminfo_test.go | 54 + .../x/text/unicode/norm/iter_test.go | 98 + .../x/text/unicode/norm/normalize_test.go | 1287 ++ .../x/text/unicode/norm/readwriter_test.go | 56 + .../x/text/unicode/norm/transform_test.go | 101 + .../x/text/unicode/norm/ucd_test.go | 275 + .../x/text/unicode/rangetable/merge_test.go | 184 + .../unicode/rangetable/rangetable_test.go | 55 + .../x/text/unicode/runenames/example_test.go | 118 + .../text/unicode/runenames/runenames_test.go | 46 + .../golang.org/x/text/width/common_test.go | 92 + .../golang.org/x/text/width/example_test.go | 52 + .../golang.org/x/text/width/runes_test.go | 461 + .../golang.org/x/text/width/tables_test.go | 59 + .../golang.org/x/text/width/transform_test.go | 701 + discovery/vendor/golang.org/x/time/AUTHORS | 3 + .../vendor/golang.org/x/time/CONTRIBUTING.md | 26 + .../vendor/golang.org/x/time/CONTRIBUTORS | 3 + discovery/vendor/golang.org/x/time/LICENSE | 27 + discovery/vendor/golang.org/x/time/PATENTS | 22 + discovery/vendor/golang.org/x/time/README.md | 17 + .../vendor/golang.org/x/time/rate/rate.go | 384 + .../golang.org/x/time/rate/rate_go16.go | 21 + .../golang.org/x/time/rate/rate_go17.go | 21 + .../golang.org/x/time/rate/rate_test.go | 459 + .../x/tools/benchmark/parse/parse_test.go | 154 + .../x/tools/cmd/benchcmp/benchcmp_test.go | 59 + .../x/tools/cmd/benchcmp/compare_test.go | 133 + .../x/tools/cmd/bundle/main_test.go | 74 + .../x/tools/cmd/callgraph/main_test.go | 81 + .../callgraph/testdata/src/pkg/pkg_test.go | 7 + .../x/tools/cmd/cover/cover_test.go | 94 + .../x/tools/cmd/digraph/digraph_test.go | 121 + .../x/tools/cmd/fiximports/main_test.go | 243 + .../x/tools/cmd/getgo/download_test.go | 36 + .../golang.org/x/tools/cmd/getgo/main_test.go | 173 + .../golang.org/x/tools/cmd/getgo/path_test.go | 58 + .../tools/cmd/go-contrib-init/contrib_test.go | 35 + .../x/tools/cmd/godoc/godoc19_test.go | 9 + .../x/tools/cmd/godoc/godoc_test.go | 471 + .../x/tools/cmd/gorename/cgo_test.go | 11 + .../x/tools/cmd/gorename/gorename_test.go | 380 + .../golang.org/x/tools/cmd/guru/guru_test.go | 329 + .../guru/testdata/src/referrers/ext_test.go | 12 + .../guru/testdata/src/referrers/int_test.go | 8 + .../golang.org/x/tools/cmd/guru/unit_test.go | 105 + .../x/tools/cmd/stringer/endtoend_test.go | 111 + .../x/tools/cmd/stringer/golden_test.go | 284 + .../x/tools/cmd/stringer/util_test.go | 77 + .../golang.org/x/tools/cmd/tip/tip_test.go | 25 + .../x/tools/container/intsets/sparse_test.go | 710 + .../x/tools/container/intsets/util_test.go | 58 + .../x/tools/go/ast/astutil/enclosing_test.go | 195 + .../x/tools/go/ast/astutil/imports_test.go | 1818 ++ .../x/tools/go/ast/astutil/rewrite_test.go | 248 + .../x/tools/go/buildutil/allpackages_test.go | 78 + .../x/tools/go/buildutil/overlay_test.go | 70 + .../x/tools/go/buildutil/tags_test.go | 28 + .../x/tools/go/buildutil/util_test.go | 72 + .../x/tools/go/buildutil/util_windows_test.go | 48 + .../x/tools/go/callgraph/cha/cha_test.go | 110 + .../x/tools/go/callgraph/rta/rta_test.go | 139 + .../tools/go/callgraph/static/static_test.go | 88 + .../gccgoexportdata/gccgoexportdata_test.go | 67 + .../x/tools/go/gcexportdata/example_test.go | 121 + .../go/gcexportdata/gcexportdata_test.go | 41 + .../x/tools/go/gcimporter15/bexport19_test.go | 93 + .../x/tools/go/gcimporter15/bexport_test.go | 326 + .../tools/go/gcimporter15/gcimporter_test.go | 521 + .../gccgoimporter/gccgoinstallation_test.go | 195 + .../internal/gccgoimporter/importer19_test.go | 15 + .../internal/gccgoimporter/importer_test.go | 178 + .../go/internal/gccgoimporter/parser_test.go | 79 + .../go/internal/gccgoimporter/testenv_test.go | 40 + .../x/tools/go/loader/example_test.go | 179 + .../x/tools/go/loader/loader_test.go | 816 + .../x/tools/go/loader/stdlib_test.go | 201 + .../x/tools/go/pointer/example_test.go | 126 + .../x/tools/go/pointer/pointer_test.go | 601 + .../x/tools/go/pointer/query_test.go | 68 + .../x/tools/go/pointer/stdlib_test.go | 111 + .../x/tools/go/pointer/testdata/a_test.go | 42 + .../golang.org/x/tools/go/ssa/builder_test.go | 500 + .../golang.org/x/tools/go/ssa/example_test.go | 138 + .../x/tools/go/ssa/identical_test.go | 9 + .../x/tools/go/ssa/interp/interp_test.go | 313 + .../x/tools/go/ssa/interp/testdata/a_test.go | 17 + .../x/tools/go/ssa/interp/testdata/b_test.go | 11 + .../x/tools/go/ssa/interp/testdata/c_test.go | 17 + .../golang.org/x/tools/go/ssa/source_test.go | 397 + .../x/tools/go/ssa/ssautil/load_test.go | 64 + .../x/tools/go/ssa/ssautil/switch_test.go | 74 + .../golang.org/x/tools/go/ssa/stdlib_test.go | 151 + .../x/tools/go/ssa/testmain_test.go | 124 + .../x/tools/go/types/typeutil/example_test.go | 67 + .../x/tools/go/types/typeutil/imports_test.go | 80 + .../x/tools/go/types/typeutil/map_test.go | 174 + .../x/tools/go/types/typeutil/ui_test.go | 61 + .../golang.org/x/tools/go/vcs/vcs_test.go | 142 + .../golang.org/x/tools/godoc/cmdline_test.go | 294 + .../golang.org/x/tools/godoc/dl/dl_test.go | 137 + .../golang.org/x/tools/godoc/godoc17_test.go | 35 + .../golang.org/x/tools/godoc/godoc_test.go | 323 + .../golang.org/x/tools/godoc/index_test.go | 323 + .../x/tools/godoc/redirect/redirect_test.go | 104 + .../x/tools/godoc/vfs/emptyvfs_test.go | 58 + .../x/tools/godoc/vfs/mapfs/mapfs_test.go | 111 + .../x/tools/godoc/vfs/zipfs/zipfs_test.go | 189 + .../x/tools/imports/fastwalk_test.go | 171 + .../golang.org/x/tools/imports/fix_test.go | 1959 ++ .../x/tools/playground/socket/socket_test.go | 77 + .../golang.org/x/tools/present/code_test.go | 225 + .../golang.org/x/tools/present/link_test.go | 40 + .../golang.org/x/tools/present/style_test.go | 124 + .../golang.org/x/tools/refactor/eg/eg_test.go | 160 + .../tools/refactor/importgraph/graph_test.go | 99 + .../x/tools/refactor/rename/mvpkg_test.go | 444 + .../x/tools/refactor/rename/rename_test.go | 1334 ++ .../vendor/gopkg.in/inf.v0/benchmark_test.go | 210 + .../vendor/gopkg.in/inf.v0/dec_go1_2_test.go | 33 + .../gopkg.in/inf.v0/dec_internal_test.go | 40 + discovery/vendor/gopkg.in/inf.v0/dec_test.go | 379 + .../vendor/gopkg.in/inf.v0/example_test.go | 62 + .../gopkg.in/inf.v0/rounder_example_test.go | 72 + .../vendor/gopkg.in/inf.v0/rounder_test.go | 109 + discovery/vendor/gopkg.in/yaml.v2/.travis.yml | 9 + .../vendor/gopkg.in/yaml.v2/decode_test.go | 1032 + .../vendor/gopkg.in/yaml.v2/encode_test.go | 501 + .../gopkg.in/yaml.v2/example_embedded_test.go | 41 + .../vendor/gopkg.in/yaml.v2/suite_test.go | 12 + .../api/.github/PULL_REQUEST_TEMPLATE.md | 2 + discovery/vendor/k8s.io/api/CONTRIBUTING.md | 7 + .../vendor/k8s.io/api/Godeps/Godeps.json | 126 +- discovery/vendor/k8s.io/api/Godeps/OWNERS | 2 + discovery/vendor/k8s.io/api/OWNERS | 1 - .../v1beta1/zz_generated.deepcopy.go | 5 +- .../v1alpha1/zz_generated.deepcopy.go | 8 +- .../v1beta1/generated.proto | 4 + .../admissionregistration/v1beta1/types.go | 10 +- .../v1beta1/types_swagger_doc_generated.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 14 +- discovery/vendor/k8s.io/api/apps/OWNERS | 1 - .../vendor/k8s.io/api/apps/v1/generated.proto | 2 +- discovery/vendor/k8s.io/api/apps/v1/types.go | 2 +- .../apps/v1/types_swagger_doc_generated.go | 2 +- .../api/apps/v1/zz_generated.deepcopy.go | 32 +- .../api/apps/v1beta1/zz_generated.deepcopy.go | 26 +- .../api/apps/v1beta2/zz_generated.deepcopy.go | 35 +- .../vendor/k8s.io/api/authentication/OWNERS | 1 - .../api/authentication/v1/generated.pb.go | 962 +- .../api/authentication/v1/generated.proto | 61 + .../k8s.io/api/authentication/v1/register.go | 1 + .../k8s.io/api/authentication/v1/types.go | 61 + .../v1/types_swagger_doc_generated.go | 41 + .../v1/zz_generated.deepcopy.go | 133 +- .../v1beta1/zz_generated.deepcopy.go | 33 +- .../vendor/k8s.io/api/authorization/OWNERS | 1 - .../authorization/v1/zz_generated.deepcopy.go | 42 +- .../v1beta1/zz_generated.deepcopy.go | 42 +- .../vendor/k8s.io/api/autoscaling/OWNERS | 1 - .../k8s.io/api/autoscaling/v1/generated.pb.go | 1006 +- .../k8s.io/api/autoscaling/v1/generated.proto | 65 +- .../vendor/k8s.io/api/autoscaling/v1/types.go | 63 +- .../v1/types_swagger_doc_generated.go | 30 +- .../autoscaling/v1/zz_generated.deepcopy.go | 115 +- .../api/autoscaling/v2beta1/generated.pb.go | 995 +- .../api/autoscaling/v2beta1/generated.proto | 66 +- .../k8s.io/api/autoscaling/v2beta1/types.go | 64 +- .../v2beta1/types_swagger_doc_generated.go | 30 +- .../v2beta1/zz_generated.deepcopy.go | 112 +- discovery/vendor/k8s.io/api/batch/OWNERS | 1 - .../api/batch/v1/zz_generated.deepcopy.go | 14 +- .../batch/v1beta1/zz_generated.deepcopy.go | 15 +- .../batch/v2alpha1/zz_generated.deepcopy.go | 15 +- .../vendor/k8s.io/api/certificates/OWNERS | 1 - .../k8s.io/api/certificates/v1beta1/types.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 36 +- .../vendor/k8s.io/api/code-of-conduct.md | 3 + .../vendor/k8s.io/api/core/v1/generated.pb.go | 4641 ++-- .../vendor/k8s.io/api/core/v1/generated.proto | 158 +- .../vendor/k8s.io/api/core/v1/register.go | 2 - .../vendor/k8s.io/api/core/v1/taint_test.go | 122 + .../k8s.io/api/core/v1/toleration_test.go | 123 + discovery/vendor/k8s.io/api/core/v1/types.go | 175 +- .../core/v1/types_swagger_doc_generated.go | 69 +- .../api/core/v1/zz_generated.deepcopy.go | 328 +- .../k8s.io/api/events/v1beta1/generated.proto | 2 +- .../vendor/k8s.io/api/events/v1beta1/types.go | 2 +- .../v1beta1/types_swagger_doc_generated.go | 2 +- .../events/v1beta1/zz_generated.deepcopy.go | 8 +- discovery/vendor/k8s.io/api/extensions/OWNERS | 1 - .../v1beta1/zz_generated.deepcopy.go | 47 +- .../v1alpha1/zz_generated.deepcopy.go | 5 +- .../networking/v1/zz_generated.deepcopy.go | 8 +- discovery/vendor/k8s.io/api/policy/OWNERS | 4 + .../k8s.io/api/policy/v1beta1/generated.pb.go | 3526 ++- .../k8s.io/api/policy/v1beta1/generated.proto | 193 + .../k8s.io/api/policy/v1beta1/register.go | 2 + .../vendor/k8s.io/api/policy/v1beta1/types.go | 253 + .../v1beta1/types_swagger_doc_generated.go | 124 + .../policy/v1beta1/zz_generated.deepcopy.go | 295 +- discovery/vendor/k8s.io/api/rbac/OWNERS | 1 - .../api/rbac/v1/zz_generated.deepcopy.go | 26 +- .../rbac/v1alpha1/zz_generated.deepcopy.go | 26 +- .../api/rbac/v1beta1/zz_generated.deepcopy.go | 26 +- .../api/scheduling/v1alpha1/generated.proto | 7 +- .../k8s.io/api/scheduling/v1alpha1/types.go | 7 +- .../v1alpha1/types_swagger_doc_generated.go | 6 +- .../v1alpha1/zz_generated.deepcopy.go | 8 +- .../v1alpha1/zz_generated.deepcopy.go | 8 +- .../api/storage/v1/zz_generated.deepcopy.go | 8 +- .../storage/v1alpha1/zz_generated.deepcopy.go | 8 +- .../api/storage/v1beta1/generated.pb.go | 1579 +- .../api/storage/v1beta1/generated.proto | 97 + .../k8s.io/api/storage/v1beta1/register.go | 3 + .../k8s.io/api/storage/v1beta1/types.go | 107 + .../v1beta1/types_swagger_doc_generated.go | 63 + .../storage/v1beta1/zz_generated.deepcopy.go | 167 +- .../.github/PULL_REQUEST_TEMPLATE.md | 2 + .../k8s.io/apimachinery/CONTRIBUTING.md | 7 + .../k8s.io/apimachinery/Godeps/Godeps.json | 88 +- .../vendor/k8s.io/apimachinery/Godeps/OWNERS | 2 + .../vendor/k8s.io/apimachinery/README.md | 6 +- .../k8s.io/apimachinery/code-of-conduct.md | 3 + .../k8s.io/apimachinery/hack/godep-deps.sh | 66 - .../apimachinery/hack/sync-from-kubernetes.sh | 65 - .../k8s.io/apimachinery/pkg/api/errors/OWNERS | 1 - .../apimachinery/pkg/api/errors/errors.go | 21 + .../pkg/api/errors/errors_test.go | 222 + .../apimachinery/pkg/api/meta/errors.go | 20 +- .../k8s.io/apimachinery/pkg/api/meta/meta.go | 8 +- .../apimachinery/pkg/api/meta/meta_test.go | 51 + .../pkg/api/meta/multirestmapper.go | 4 +- .../pkg/api/meta/multirestmapper_test.go | 391 + .../apimachinery/pkg/api/meta/priority.go | 2 +- .../pkg/api/meta/priority_test.go | 346 + .../apimachinery/pkg/api/meta/restmapper.go | 4 +- .../pkg/api/meta/restmapper_test.go | 751 + .../apimachinery/pkg/api/meta/table/table.go | 71 + .../apimachinery/pkg/api/resource/OWNERS | 1 - .../pkg/api/resource/amount_test.go | 133 + .../pkg/api/resource/math_test.go | 211 + .../apimachinery/pkg/api/resource/quantity.go | 22 +- .../pkg/api/resource/quantity_example_test.go | 59 + .../pkg/api/resource/quantity_proto_test.go | 103 + .../pkg/api/resource/quantity_test.go | 1368 ++ .../pkg/api/resource/scale_int_test.go | 85 + .../pkg/api/resource/zz_generated.deepcopy.go | 2 +- .../pkg/api/testing/fuzzer/valuefuzz_test.go | 73 + .../pkg/api/testing/roundtrip/roundtrip.go | 6 - .../pkg/api/validation/objectmeta_test.go | 500 + .../pkg/api/validation/path/name_test.go | 168 + .../pkg/apimachinery/announced/announced.go | 2 +- .../apimachinery/announced/announced_test.go | 64 + .../registered/registered_test.go | 71 + .../pkg/apimachinery/types_test.go | 43 + .../pkg/apis/meta/fuzzer/fuzzer.go | 6 +- .../pkg/apis/meta/internalversion/doc.go | 1 + .../pkg/apis/meta/internalversion/register.go | 20 +- .../meta/internalversion/register_test.go | 89 + .../meta/internalversion/roundtrip_test.go | 28 + .../zz_generated.conversion.go | 13 +- .../internalversion/zz_generated.deepcopy.go | 8 +- .../apimachinery/pkg/apis/meta/v1/OWNERS | 1 - .../pkg/apis/meta/v1/controller_ref_test.go | 133 + .../pkg/apis/meta/v1/conversion.go | 18 + .../pkg/apis/meta/v1/conversion_test.go | 49 + .../pkg/apis/meta/v1/duration_test.go | 153 + .../pkg/apis/meta/v1/generated.proto | 1 + .../pkg/apis/meta/v1/group_version_test.go | 79 + .../pkg/apis/meta/v1/helpers_test.go | 154 + .../apimachinery/pkg/apis/meta/v1/labels.go | 28 +- .../pkg/apis/meta/v1/labels_test.go | 123 + .../pkg/apis/meta/v1/micro_time.go | 22 +- .../pkg/apis/meta/v1/micro_time_test.go | 139 + .../apimachinery/pkg/apis/meta/v1/time.go | 22 +- .../pkg/apis/meta/v1/time_test.go | 197 + .../apimachinery/pkg/apis/meta/v1/types.go | 13 + .../meta/v1/types_swagger_doc_generated.go | 2 +- .../pkg/apis/meta/v1/types_test.go | 135 + .../pkg/apis/meta/v1/unstructured/helpers.go | 218 +- .../apis/meta/v1/unstructured/helpers_test.go | 60 + .../apis/meta/v1/unstructured/unstructured.go | 22 +- .../v1/unstructured/unstructured_list_test.go | 86 + .../v1/unstructured/zz_generated.deepcopy.go | 8 +- .../meta/v1/validation/validation_test.go | 94 + .../pkg/apis/meta/v1/zz_generated.deepcopy.go | 58 +- .../pkg/apis/meta/v1/zz_generated.defaults.go | 2 +- .../pkg/apis/meta/v1alpha1/conversion.go | 27 - .../pkg/apis/meta/v1alpha1/doc.go | 22 - .../pkg/apis/meta/v1alpha1/register.go | 57 - .../pkg/apis/meta/v1alpha1/types.go | 161 - .../v1alpha1/types_swagger_doc_generated.go | 104 - .../meta/v1alpha1/zz_generated.deepcopy.go | 194 - .../meta/v1alpha1/zz_generated.defaults.go | 32 - .../pkg/apis/meta/v1beta1/conversion.go | 27 + .../meta/{v1alpha1 => v1beta1}/deepcopy.go | 2 +- .../apimachinery/pkg/apis/meta/v1beta1/doc.go | 22 + .../{v1alpha1 => v1beta1}/generated.pb.go | 68 +- .../{v1alpha1 => v1beta1}/generated.proto | 6 +- .../pkg/apis/meta/v1beta1/register.go | 57 + .../pkg/apis/meta/v1beta1/types.go | 161 + .../v1beta1/types_swagger_doc_generated.go | 104 + .../meta/v1beta1/zz_generated.deepcopy.go | 190 + .../meta/v1beta1/zz_generated.defaults.go | 32 + .../testapigroup/install/roundtrip_test.go | 28 + .../pkg/apis/testapigroup/v1/generated.pb.go | 138 +- .../pkg/apis/testapigroup/v1/generated.proto | 4 +- .../pkg/apis/testapigroup/v1/types.go | 2 +- .../v1/types_swagger_doc_generated.go | 17 - .../v1/zz_generated.conversion.go | 5 +- .../testapigroup/v1/zz_generated.deepcopy.go | 12 +- .../testapigroup/v1/zz_generated.defaults.go | 2 +- .../testapigroup/zz_generated.deepcopy.go | 12 +- .../pkg/conversion/converter_test.go | 826 + .../pkg/conversion/helper_test.go | 38 + .../conversion/queryparams/convert_test.go | 215 + .../apimachinery/pkg/fields/fields_test.go | 57 + .../apimachinery/pkg/fields/selector.go | 2 +- .../apimachinery/pkg/fields/selector_test.go | 397 + .../apimachinery/pkg/labels/labels_test.go | 231 + .../apimachinery/pkg/labels/selector_test.go | 575 + .../pkg/labels/zz_generated.deepcopy.go | 2 +- .../k8s.io/apimachinery/pkg/runtime/codec.go | 2 +- .../pkg/runtime/conversion_test.go | 115 + .../pkg/runtime/converter_test.go | 597 + .../apimachinery/pkg/runtime/embedded_test.go | 256 + .../pkg/runtime/extension_test.go | 113 + .../pkg/runtime/schema/group_version.go | 24 + .../pkg/runtime/schema/group_version_test.go | 136 + .../k8s.io/apimachinery/pkg/runtime/scheme.go | 1 + .../apimachinery/pkg/runtime/scheme_test.go | 1035 + .../pkg/runtime/serializer/codec_test.go | 339 + .../pkg/runtime/serializer/json/json.go | 72 +- .../pkg/runtime/serializer/json/json_test.go | 336 + .../pkg/runtime/serializer/json/meta_test.go | 45 + .../recognizer/testing/recognizer_test.go | 61 + .../serializer/streaming/streaming_test.go | 84 + .../testing/zz_generated.deepcopy.go | 17 +- .../serializer/versioning/versioning_test.go | 381 + .../pkg/runtime/swagger_doc_generator_test.go | 43 + .../apimachinery/pkg/runtime/testing/types.go | 3 + .../runtime/testing/zz_generated.deepcopy.go | 65 +- .../pkg/runtime/zz_generated.deepcopy.go | 8 +- .../pkg/test/api_meta_help_test.go | 331 + .../pkg/test/api_meta_meta_test.go | 429 + ...pis_meta_v1_unstructed_unstructure_test.go | 571 + .../pkg/test/runtime_helper_test.go | 49 + ...ntime_serializer_protobuf_protobuf_test.go | 360 + .../pkg/test/runtime_unversioned_test.go | 99 + .../pkg/test/zz_generated.deepcopy.go | 8 +- .../apimachinery/pkg/util/cache/cache_test.go | 90 + .../pkg/util/cache/lruexpirecache_test.go | 68 + .../apimachinery/pkg/util/clock/clock_test.go | 184 + .../apimachinery/pkg/util/diff/diff_test.go | 96 + .../pkg/util/duration/duration.go | 43 + .../apimachinery/pkg/util/errors/errors.go | 2 +- .../pkg/util/errors/errors_test.go | 368 + .../pkg/util/framer/framer_test.go | 176 + .../pkg/util/httpstream/httpstream_test.go | 125 + .../util/httpstream/spdy/connection_test.go | 164 + .../util/httpstream/spdy/roundtripper_test.go | 529 + .../pkg/util/httpstream/spdy/upgrade_test.go | 93 + .../apimachinery/pkg/util/intstr/intstr.go | 22 +- .../pkg/util/intstr/intstr_test.go | 176 + .../apimachinery/pkg/util/json/json_test.go | 319 + .../pkg/util/jsonmergepatch/patch_test.go | 663 + .../pkg/util/mergepatch/util_test.go | 138 + .../k8s.io/apimachinery/pkg/util/net/http.go | 3 + .../apimachinery/pkg/util/net/http_test.go | 282 + .../pkg/util/net/interface_test.go | 725 + .../pkg/util/net/port_range_test.go | 69 + .../pkg/util/net/port_split_test.go | 121 + .../apimachinery/pkg/util/net/util_test.go | 68 + .../apimachinery/pkg/util/proxy/dial_test.go | 176 + .../pkg/util/proxy/transport_test.go | 276 + .../pkg/util/proxy/upgradeaware_test.go | 818 + .../apimachinery/pkg/util/rand/rand_test.go | 114 + .../apimachinery/pkg/util/runtime/runtime.go | 2 +- .../pkg/util/runtime/runtime_test.go | 71 + .../apimachinery/pkg/util/sets/set_test.go | 270 + .../pkg/util/strategicpatch/patch.go | 28 +- .../pkg/util/strategicpatch/patch_test.go | 6763 ++++++ .../pkg/util/validation/field/errors_test.go | 175 + .../pkg/util/validation/field/path_test.go | 123 + .../pkg/util/validation/validation_test.go | 513 + .../apimachinery/pkg/util/wait/wait_test.go | 501 + .../pkg/util/waitgroup/waitgroup.go | 2 +- .../pkg/util/waitgroup/waitgroup_test.go | 60 + .../apimachinery/pkg/util/yaml/decoder.go | 6 +- .../pkg/util/yaml/decoder_test.go | 405 + .../apimachinery/pkg/watch/filter_test.go | 84 + .../k8s.io/apimachinery/pkg/watch/mux_test.go | 176 + .../pkg/watch/streamwatcher_test.go | 68 + .../apimachinery/pkg/watch/until_test.go | 172 + .../apimachinery/pkg/watch/watch_test.go | 137 + .../pkg/watch/zz_generated.deepcopy.go | 2 +- .../forked/golang/json/fields_test.go | 30 + .../forked/golang/reflect/deep_equal_test.go | 137 + .../.github/PULL_REQUEST_TEMPLATE.md | 6 +- discovery/vendor/k8s.io/client-go/.travis.yml | 8 + .../vendor/k8s.io/client-go/CHANGELOG.md | 105 + .../vendor/k8s.io/client-go/CONTRIBUTING.md | 7 + .../k8s.io/client-go/Godeps/Godeps.json | 328 +- .../vendor/k8s.io/client-go/Godeps/OWNERS | 2 + discovery/vendor/k8s.io/client-go/INSTALL.md | 6 +- discovery/vendor/k8s.io/client-go/README.md | 42 +- .../k8s.io/client-go/code-of-conduct.md | 3 + .../vendor/k8s.io/client-go/discovery/BUILD | 75 + .../k8s.io/client-go/discovery/cached/BUILD | 44 + .../discovery/cached/memcache_test.go | 132 + .../client-go/discovery/discovery_client.go | 34 +- .../discovery/discovery_client_test.go | 830 + .../k8s.io/client-go/discovery/fake/BUILD | 45 + .../discovery/fake/discovery_test.go | 46 + .../discovery/helper_blackbox_test.go | 184 + .../k8s.io/client-go/discovery/restmapper.go | 2 + .../client-go/discovery/restmapper_test.go | 384 + .../vendor/k8s.io/client-go/dynamic/BUILD | 68 + .../vendor/k8s.io/client-go/dynamic/client.go | 55 +- .../k8s.io/client-go/dynamic/client_test.go | 634 + .../client-go/dynamic/dynamic_util_test.go | 79 + .../k8s.io/client-go/dynamic/fake/BUILD | 40 + .../k8s.io/client-go/dynamic/fake/client.go | 2 +- .../create-update-delete-deployment/BUILD | 40 + .../create-update-delete-deployment/README.md | 2 +- .../in-cluster-client-configuration/BUILD | 37 + .../out-of-cluster-client-configuration/BUILD | 37 + .../main.go | 11 +- .../k8s.io/client-go/examples/workqueue/BUILD | 43 + .../vendor/k8s.io/client-go/informers/BUILD | 91 + .../informers/admissionregistration/BUILD | 34 + .../admissionregistration/interface.go | 4 +- .../admissionregistration/v1alpha1/BUILD | 35 + .../v1alpha1/initializerconfiguration.go | 7 +- .../v1alpha1/interface.go | 4 +- .../admissionregistration/v1beta1/BUILD | 36 + .../v1beta1/interface.go | 4 +- .../v1beta1/mutatingwebhookconfiguration.go | 7 +- .../v1beta1/validatingwebhookconfiguration.go | 7 +- .../k8s.io/client-go/informers/apps/BUILD | 36 + .../client-go/informers/apps/interface.go | 4 +- .../k8s.io/client-go/informers/apps/v1/BUILD | 39 + .../informers/apps/v1/controllerrevision.go | 7 +- .../client-go/informers/apps/v1/daemonset.go | 7 +- .../client-go/informers/apps/v1/deployment.go | 7 +- .../client-go/informers/apps/v1/interface.go | 4 +- .../client-go/informers/apps/v1/replicaset.go | 7 +- .../informers/apps/v1/statefulset.go | 7 +- .../client-go/informers/apps/v1beta1/BUILD | 40 + .../apps/v1beta1/controllerrevision.go | 7 +- .../informers/apps/v1beta1/deployment.go | 7 +- .../informers/apps/v1beta1/interface.go | 4 +- .../informers/apps/v1beta1/statefulset.go | 7 +- .../client-go/informers/apps/v1beta2/BUILD | 42 + .../apps/v1beta2/controllerrevision.go | 7 +- .../informers/apps/v1beta2/daemonset.go | 7 +- .../informers/apps/v1beta2/deployment.go | 7 +- .../informers/apps/v1beta2/interface.go | 4 +- .../informers/apps/v1beta2/replicaset.go | 7 +- .../informers/apps/v1beta2/statefulset.go | 7 +- .../client-go/informers/autoscaling/BUILD | 31 + .../informers/autoscaling/interface.go | 4 +- .../client-go/informers/autoscaling/v1/BUILD | 35 + .../autoscaling/v1/horizontalpodautoscaler.go | 7 +- .../informers/autoscaling/v1/interface.go | 4 +- .../informers/autoscaling/v2beta1/BUILD | 35 + .../v2beta1/horizontalpodautoscaler.go | 7 +- .../autoscaling/v2beta1/interface.go | 4 +- .../k8s.io/client-go/informers/batch/BUILD | 36 + .../client-go/informers/batch/interface.go | 4 +- .../k8s.io/client-go/informers/batch/v1/BUILD | 38 + .../client-go/informers/batch/v1/interface.go | 4 +- .../client-go/informers/batch/v1/job.go | 7 +- .../client-go/informers/batch/v1beta1/BUILD | 38 + .../informers/batch/v1beta1/cronjob.go | 7 +- .../informers/batch/v1beta1/interface.go | 4 +- .../client-go/informers/batch/v2alpha1/BUILD | 38 + .../informers/batch/v2alpha1/cronjob.go | 7 +- .../informers/batch/v2alpha1/interface.go | 4 +- .../client-go/informers/certificates/BUILD | 32 + .../informers/certificates/interface.go | 4 +- .../informers/certificates/v1beta1/BUILD | 38 + .../v1beta1/certificatesigningrequest.go | 7 +- .../certificates/v1beta1/interface.go | 4 +- .../k8s.io/client-go/informers/core/BUILD | 32 + .../client-go/informers/core/interface.go | 4 +- .../k8s.io/client-go/informers/core/v1/BUILD | 53 + .../informers/core/v1/componentstatus.go | 7 +- .../client-go/informers/core/v1/configmap.go | 7 +- .../client-go/informers/core/v1/endpoints.go | 7 +- .../client-go/informers/core/v1/event.go | 7 +- .../client-go/informers/core/v1/interface.go | 4 +- .../client-go/informers/core/v1/limitrange.go | 7 +- .../client-go/informers/core/v1/namespace.go | 7 +- .../client-go/informers/core/v1/node.go | 7 +- .../informers/core/v1/persistentvolume.go | 7 +- .../core/v1/persistentvolumeclaim.go | 7 +- .../k8s.io/client-go/informers/core/v1/pod.go | 7 +- .../informers/core/v1/podtemplate.go | 7 +- .../core/v1/replicationcontroller.go | 7 +- .../informers/core/v1/resourcequota.go | 7 +- .../client-go/informers/core/v1/secret.go | 7 +- .../client-go/informers/core/v1/service.go | 7 +- .../informers/core/v1/serviceaccount.go | 7 +- .../k8s.io/client-go/informers/events/BUILD | 29 + .../client-go/informers/events/interface.go | 4 +- .../client-go/informers/events/v1beta1/BUILD | 35 + .../informers/events/v1beta1/event.go | 7 +- .../informers/events/v1beta1/interface.go | 4 +- .../client-go/informers/extensions/BUILD | 32 + .../informers/extensions/interface.go | 4 +- .../informers/extensions/v1beta1/BUILD | 42 + .../informers/extensions/v1beta1/daemonset.go | 7 +- .../extensions/v1beta1/deployment.go | 7 +- .../informers/extensions/v1beta1/ingress.go | 7 +- .../informers/extensions/v1beta1/interface.go | 4 +- .../extensions/v1beta1/podsecuritypolicy.go | 7 +- .../extensions/v1beta1/replicaset.go | 7 +- .../k8s.io/client-go/informers/factory.go | 11 +- .../k8s.io/client-go/informers/generic.go | 9 +- .../informers/internalinterfaces/BUILD | 31 + .../internalinterfaces/factory_interfaces.go | 7 +- .../client-go/informers/networking/BUILD | 32 + .../informers/networking/interface.go | 4 +- .../client-go/informers/networking/v1/BUILD | 38 + .../informers/networking/v1/interface.go | 4 +- .../informers/networking/v1/networkpolicy.go | 7 +- .../k8s.io/client-go/informers/policy/BUILD | 32 + .../client-go/informers/policy/interface.go | 4 +- .../client-go/informers/policy/v1beta1/BUILD | 39 + .../informers/policy/v1beta1/interface.go | 11 +- .../policy/v1beta1/poddisruptionbudget.go | 7 +- .../policy/v1beta1/podsecuritypolicy.go | 88 + .../k8s.io/client-go/informers/rbac/BUILD | 36 + .../client-go/informers/rbac/interface.go | 4 +- .../k8s.io/client-go/informers/rbac/v1/BUILD | 41 + .../informers/rbac/v1/clusterrole.go | 7 +- .../informers/rbac/v1/clusterrolebinding.go | 7 +- .../client-go/informers/rbac/v1/interface.go | 4 +- .../client-go/informers/rbac/v1/role.go | 7 +- .../informers/rbac/v1/rolebinding.go | 7 +- .../client-go/informers/rbac/v1alpha1/BUILD | 41 + .../informers/rbac/v1alpha1/clusterrole.go | 7 +- .../rbac/v1alpha1/clusterrolebinding.go | 7 +- .../informers/rbac/v1alpha1/interface.go | 4 +- .../client-go/informers/rbac/v1alpha1/role.go | 7 +- .../informers/rbac/v1alpha1/rolebinding.go | 7 +- .../client-go/informers/rbac/v1beta1/BUILD | 41 + .../informers/rbac/v1beta1/clusterrole.go | 7 +- .../rbac/v1beta1/clusterrolebinding.go | 7 +- .../informers/rbac/v1beta1/interface.go | 4 +- .../client-go/informers/rbac/v1beta1/role.go | 7 +- .../informers/rbac/v1beta1/rolebinding.go | 7 +- .../client-go/informers/scheduling/BUILD | 32 + .../informers/scheduling/interface.go | 4 +- .../informers/scheduling/v1alpha1/BUILD | 38 + .../scheduling/v1alpha1/interface.go | 4 +- .../scheduling/v1alpha1/priorityclass.go | 7 +- .../k8s.io/client-go/informers/settings/BUILD | 32 + .../client-go/informers/settings/interface.go | 4 +- .../informers/settings/v1alpha1/BUILD | 38 + .../informers/settings/v1alpha1/interface.go | 4 +- .../informers/settings/v1alpha1/podpreset.go | 7 +- .../k8s.io/client-go/informers/storage/BUILD | 36 + .../client-go/informers/storage/interface.go | 4 +- .../client-go/informers/storage/v1/BUILD | 38 + .../informers/storage/v1/interface.go | 4 +- .../informers/storage/v1/storageclass.go | 7 +- .../informers/storage/v1alpha1/BUILD | 35 + .../informers/storage/v1alpha1/interface.go | 4 +- .../storage/v1alpha1/volumeattachment.go | 7 +- .../client-go/informers/storage/v1beta1/BUILD | 39 + .../informers/storage/v1beta1/interface.go | 11 +- .../informers/storage/v1beta1/storageclass.go | 7 +- .../storage/v1beta1/volumeattachment.go | 88 + .../vendor/k8s.io/client-go/kubernetes/BUILD | 95 + .../k8s.io/client-go/kubernetes/clientset.go | 4 +- .../vendor/k8s.io/client-go/kubernetes/doc.go | 4 +- .../k8s.io/client-go/kubernetes/fake/BUILD | 124 + .../kubernetes/fake/clientset_generated.go | 14 +- .../k8s.io/client-go/kubernetes/fake/doc.go | 4 +- .../client-go/kubernetes/fake/register.go | 7 +- .../k8s.io/client-go/kubernetes/scheme/BUILD | 62 + .../k8s.io/client-go/kubernetes/scheme/doc.go | 4 +- .../client-go/kubernetes/scheme/register.go | 7 +- .../admissionregistration/v1alpha1/BUILD | 39 + .../v1alpha1/admissionregistration_client.go | 4 +- .../admissionregistration/v1alpha1/doc.go | 4 +- .../admissionregistration/v1alpha1/fake/BUILD | 37 + .../v1alpha1/fake/doc.go | 4 +- .../fake/fake_admissionregistration_client.go | 4 +- .../fake/fake_initializerconfiguration.go | 4 +- .../v1alpha1/generated_expansion.go | 4 +- .../v1alpha1/initializerconfiguration.go | 4 +- .../typed/admissionregistration/v1beta1/BUILD | 40 + .../v1beta1/admissionregistration_client.go | 4 +- .../admissionregistration/v1beta1/doc.go | 4 +- .../admissionregistration/v1beta1/fake/BUILD | 38 + .../admissionregistration/v1beta1/fake/doc.go | 4 +- .../fake/fake_admissionregistration_client.go | 4 +- .../fake/fake_mutatingwebhookconfiguration.go | 4 +- .../fake_validatingwebhookconfiguration.go | 4 +- .../v1beta1/generated_expansion.go | 4 +- .../v1beta1/mutatingwebhookconfiguration.go | 4 +- .../v1beta1/validatingwebhookconfiguration.go | 4 +- .../client-go/kubernetes/typed/apps/v1/BUILD | 43 + .../kubernetes/typed/apps/v1/apps_client.go | 4 +- .../typed/apps/v1/controllerrevision.go | 4 +- .../kubernetes/typed/apps/v1/daemonset.go | 4 +- .../kubernetes/typed/apps/v1/deployment.go | 4 +- .../client-go/kubernetes/typed/apps/v1/doc.go | 4 +- .../kubernetes/typed/apps/v1/fake/BUILD | 41 + .../kubernetes/typed/apps/v1/fake/doc.go | 4 +- .../typed/apps/v1/fake/fake_apps_client.go | 4 +- .../apps/v1/fake/fake_controllerrevision.go | 4 +- .../typed/apps/v1/fake/fake_daemonset.go | 4 +- .../typed/apps/v1/fake/fake_deployment.go | 4 +- .../typed/apps/v1/fake/fake_replicaset.go | 4 +- .../typed/apps/v1/fake/fake_statefulset.go | 4 +- .../typed/apps/v1/generated_expansion.go | 4 +- .../kubernetes/typed/apps/v1/replicaset.go | 4 +- .../kubernetes/typed/apps/v1/statefulset.go | 4 +- .../kubernetes/typed/apps/v1beta1/BUILD | 45 + .../typed/apps/v1beta1/apps_client.go | 4 +- .../typed/apps/v1beta1/controllerrevision.go | 4 +- .../typed/apps/v1beta1/deployment.go | 4 +- .../kubernetes/typed/apps/v1beta1/doc.go | 4 +- .../kubernetes/typed/apps/v1beta1/fake/BUILD | 43 + .../kubernetes/typed/apps/v1beta1/fake/doc.go | 4 +- .../apps/v1beta1/fake/fake_apps_client.go | 4 +- .../v1beta1/fake/fake_controllerrevision.go | 4 +- .../apps/v1beta1/fake/fake_deployment.go | 4 +- .../typed/apps/v1beta1/fake/fake_scale.go | 4 +- .../apps/v1beta1/fake/fake_statefulset.go | 4 +- .../typed/apps/v1beta1/generated_expansion.go | 4 +- .../kubernetes/typed/apps/v1beta1/scale.go | 4 +- .../typed/apps/v1beta1/statefulset.go | 4 +- .../kubernetes/typed/apps/v1beta2/BUILD | 47 + .../typed/apps/v1beta2/apps_client.go | 4 +- .../typed/apps/v1beta2/controllerrevision.go | 4 +- .../typed/apps/v1beta2/daemonset.go | 4 +- .../typed/apps/v1beta2/deployment.go | 4 +- .../kubernetes/typed/apps/v1beta2/doc.go | 4 +- .../kubernetes/typed/apps/v1beta2/fake/BUILD | 45 + .../kubernetes/typed/apps/v1beta2/fake/doc.go | 4 +- .../apps/v1beta2/fake/fake_apps_client.go | 4 +- .../v1beta2/fake/fake_controllerrevision.go | 4 +- .../typed/apps/v1beta2/fake/fake_daemonset.go | 4 +- .../apps/v1beta2/fake/fake_deployment.go | 4 +- .../apps/v1beta2/fake/fake_replicaset.go | 4 +- .../typed/apps/v1beta2/fake/fake_scale.go | 4 +- .../apps/v1beta2/fake/fake_statefulset.go | 4 +- .../typed/apps/v1beta2/generated_expansion.go | 4 +- .../typed/apps/v1beta2/replicaset.go | 4 +- .../kubernetes/typed/apps/v1beta2/scale.go | 4 +- .../typed/apps/v1beta2/statefulset.go | 4 +- .../kubernetes/typed/authentication/v1/BUILD | 40 + .../v1/authentication_client.go | 4 +- .../kubernetes/typed/authentication/v1/doc.go | 4 +- .../typed/authentication/v1/fake/BUILD | 36 + .../typed/authentication/v1/fake/doc.go | 4 +- .../v1/fake/fake_authentication_client.go | 4 +- .../v1/fake/fake_tokenreview.go | 4 +- .../authentication/v1/generated_expansion.go | 4 +- .../typed/authentication/v1/tokenreview.go | 4 +- .../typed/authentication/v1beta1/BUILD | 40 + .../v1beta1/authentication_client.go | 4 +- .../typed/authentication/v1beta1/doc.go | 4 +- .../typed/authentication/v1beta1/fake/BUILD | 36 + .../typed/authentication/v1beta1/fake/doc.go | 4 +- .../fake/fake_authentication_client.go | 4 +- .../v1beta1/fake/fake_tokenreview.go | 4 +- .../v1beta1/generated_expansion.go | 4 +- .../authentication/v1beta1/tokenreview.go | 4 +- .../kubernetes/typed/authorization/v1/BUILD | 46 + .../authorization/v1/authorization_client.go | 4 +- .../kubernetes/typed/authorization/v1/doc.go | 4 +- .../typed/authorization/v1/fake/BUILD | 42 + .../typed/authorization/v1/fake/doc.go | 4 +- .../v1/fake/fake_authorization_client.go | 4 +- .../v1/fake/fake_localsubjectaccessreview.go | 4 +- .../v1/fake/fake_selfsubjectaccessreview.go | 4 +- .../v1/fake/fake_selfsubjectrulesreview.go | 4 +- .../v1/fake/fake_subjectaccessreview.go | 4 +- .../authorization/v1/generated_expansion.go | 4 +- .../v1/localsubjectaccessreview.go | 4 +- .../v1/selfsubjectaccessreview.go | 4 +- .../v1/selfsubjectrulesreview.go | 4 +- .../authorization/v1/subjectaccessreview.go | 4 +- .../typed/authorization/v1beta1/BUILD | 46 + .../v1beta1/authorization_client.go | 4 +- .../typed/authorization/v1beta1/doc.go | 4 +- .../typed/authorization/v1beta1/fake/BUILD | 43 + .../typed/authorization/v1beta1/fake/doc.go | 4 +- .../v1beta1/fake/fake_authorization_client.go | 4 +- .../fake/fake_localsubjectaccessreview.go | 4 +- .../fake/fake_selfsubjectaccessreview.go | 4 +- .../fake/fake_selfsubjectrulesreview.go | 4 +- .../v1beta1/fake/fake_subjectaccessreview.go | 4 +- .../v1beta1/generated_expansion.go | 4 +- .../v1beta1/localsubjectaccessreview.go | 4 +- .../v1beta1/selfsubjectaccessreview.go | 4 +- .../v1beta1/selfsubjectrulesreview.go | 4 +- .../v1beta1/subjectaccessreview.go | 4 +- .../kubernetes/typed/autoscaling/v1/BUILD | 42 + .../autoscaling/v1/autoscaling_client.go | 4 +- .../kubernetes/typed/autoscaling/v1/doc.go | 4 +- .../typed/autoscaling/v1/fake/BUILD | 40 + .../typed/autoscaling/v1/fake/doc.go | 4 +- .../v1/fake/fake_autoscaling_client.go | 4 +- .../v1/fake/fake_horizontalpodautoscaler.go | 4 +- .../autoscaling/v1/generated_expansion.go | 4 +- .../autoscaling/v1/horizontalpodautoscaler.go | 4 +- .../typed/autoscaling/v2beta1/BUILD | 39 + .../autoscaling/v2beta1/autoscaling_client.go | 4 +- .../typed/autoscaling/v2beta1/doc.go | 4 +- .../typed/autoscaling/v2beta1/fake/BUILD | 37 + .../typed/autoscaling/v2beta1/fake/doc.go | 4 +- .../v2beta1/fake/fake_autoscaling_client.go | 4 +- .../fake/fake_horizontalpodautoscaler.go | 4 +- .../v2beta1/generated_expansion.go | 4 +- .../v2beta1/horizontalpodautoscaler.go | 4 +- .../client-go/kubernetes/typed/batch/v1/BUILD | 42 + .../kubernetes/typed/batch/v1/batch_client.go | 4 +- .../kubernetes/typed/batch/v1/doc.go | 4 +- .../kubernetes/typed/batch/v1/fake/BUILD | 40 + .../kubernetes/typed/batch/v1/fake/doc.go | 4 +- .../typed/batch/v1/fake/fake_batch_client.go | 4 +- .../typed/batch/v1/fake/fake_job.go | 4 +- .../typed/batch/v1/generated_expansion.go | 4 +- .../kubernetes/typed/batch/v1/job.go | 4 +- .../kubernetes/typed/batch/v1beta1/BUILD | 42 + .../typed/batch/v1beta1/batch_client.go | 4 +- .../kubernetes/typed/batch/v1beta1/cronjob.go | 4 +- .../kubernetes/typed/batch/v1beta1/doc.go | 4 +- .../kubernetes/typed/batch/v1beta1/fake/BUILD | 40 + .../typed/batch/v1beta1/fake/doc.go | 4 +- .../batch/v1beta1/fake/fake_batch_client.go | 4 +- .../typed/batch/v1beta1/fake/fake_cronjob.go | 4 +- .../batch/v1beta1/generated_expansion.go | 4 +- .../kubernetes/typed/batch/v2alpha1/BUILD | 42 + .../typed/batch/v2alpha1/batch_client.go | 4 +- .../typed/batch/v2alpha1/cronjob.go | 4 +- .../kubernetes/typed/batch/v2alpha1/doc.go | 4 +- .../typed/batch/v2alpha1/fake/BUILD | 40 + .../typed/batch/v2alpha1/fake/doc.go | 4 +- .../batch/v2alpha1/fake/fake_batch_client.go | 4 +- .../typed/batch/v2alpha1/fake/fake_cronjob.go | 4 +- .../batch/v2alpha1/generated_expansion.go | 4 +- .../typed/certificates/v1beta1/BUILD | 43 + .../v1beta1/certificates_client.go | 4 +- .../v1beta1/certificatesigningrequest.go | 4 +- .../typed/certificates/v1beta1/doc.go | 4 +- .../typed/certificates/v1beta1/fake/BUILD | 41 + .../typed/certificates/v1beta1/fake/doc.go | 4 +- .../v1beta1/fake/fake_certificates_client.go | 4 +- .../fake/fake_certificatesigningrequest.go | 4 +- .../v1beta1/generated_expansion.go | 4 +- .../client-go/kubernetes/typed/core/v1/BUILD | 70 + .../typed/core/v1/componentstatus.go | 4 +- .../kubernetes/typed/core/v1/configmap.go | 4 +- .../kubernetes/typed/core/v1/core_client.go | 4 +- .../client-go/kubernetes/typed/core/v1/doc.go | 4 +- .../kubernetes/typed/core/v1/endpoints.go | 4 +- .../kubernetes/typed/core/v1/event.go | 4 +- .../kubernetes/typed/core/v1/fake/BUILD | 66 + .../kubernetes/typed/core/v1/fake/doc.go | 4 +- .../core/v1/fake/fake_componentstatus.go | 4 +- .../typed/core/v1/fake/fake_configmap.go | 4 +- .../typed/core/v1/fake/fake_core_client.go | 4 +- .../typed/core/v1/fake/fake_endpoints.go | 4 +- .../typed/core/v1/fake/fake_event.go | 4 +- .../typed/core/v1/fake/fake_limitrange.go | 4 +- .../typed/core/v1/fake/fake_namespace.go | 4 +- .../typed/core/v1/fake/fake_node.go | 4 +- .../core/v1/fake/fake_persistentvolume.go | 4 +- .../v1/fake/fake_persistentvolumeclaim.go | 4 +- .../kubernetes/typed/core/v1/fake/fake_pod.go | 4 +- .../typed/core/v1/fake/fake_podtemplate.go | 4 +- .../v1/fake/fake_replicationcontroller.go | 4 +- .../typed/core/v1/fake/fake_resourcequota.go | 4 +- .../typed/core/v1/fake/fake_secret.go | 4 +- .../typed/core/v1/fake/fake_service.go | 4 +- .../typed/core/v1/fake/fake_serviceaccount.go | 4 +- .../v1/fake/fake_serviceaccount_expansion.go | 31 + .../typed/core/v1/generated_expansion.go | 6 +- .../kubernetes/typed/core/v1/limitrange.go | 4 +- .../kubernetes/typed/core/v1/namespace.go | 4 +- .../kubernetes/typed/core/v1/node.go | 4 +- .../typed/core/v1/persistentvolume.go | 4 +- .../typed/core/v1/persistentvolumeclaim.go | 4 +- .../client-go/kubernetes/typed/core/v1/pod.go | 4 +- .../kubernetes/typed/core/v1/podtemplate.go | 4 +- .../typed/core/v1/replicationcontroller.go | 4 +- .../kubernetes/typed/core/v1/resourcequota.go | 4 +- .../kubernetes/typed/core/v1/secret.go | 4 +- .../kubernetes/typed/core/v1/service.go | 4 +- .../typed/core/v1/serviceaccount.go | 4 +- .../typed/core/v1/serviceaccount_expansion.go | 41 + .../kubernetes/typed/events/v1beta1/BUILD | 39 + .../kubernetes/typed/events/v1beta1/doc.go | 4 +- .../kubernetes/typed/events/v1beta1/event.go | 4 +- .../typed/events/v1beta1/events_client.go | 4 +- .../typed/events/v1beta1/fake/BUILD | 37 + .../typed/events/v1beta1/fake/doc.go | 4 +- .../typed/events/v1beta1/fake/fake_event.go | 4 +- .../events/v1beta1/fake/fake_events_client.go | 4 +- .../events/v1beta1/generated_expansion.go | 4 +- .../kubernetes/typed/extensions/v1beta1/BUILD | 51 + .../typed/extensions/v1beta1/daemonset.go | 4 +- .../typed/extensions/v1beta1/deployment.go | 4 +- .../typed/extensions/v1beta1/doc.go | 4 +- .../extensions/v1beta1/extensions_client.go | 4 +- .../typed/extensions/v1beta1/fake/BUILD | 47 + .../typed/extensions/v1beta1/fake/doc.go | 4 +- .../extensions/v1beta1/fake/fake_daemonset.go | 4 +- .../v1beta1/fake/fake_deployment.go | 4 +- .../v1beta1/fake/fake_extensions_client.go | 4 +- .../extensions/v1beta1/fake/fake_ingress.go | 4 +- .../v1beta1/fake/fake_podsecuritypolicy.go | 4 +- .../v1beta1/fake/fake_replicaset.go | 4 +- .../extensions/v1beta1/fake/fake_scale.go | 4 +- .../extensions/v1beta1/generated_expansion.go | 4 +- .../typed/extensions/v1beta1/ingress.go | 4 +- .../extensions/v1beta1/podsecuritypolicy.go | 4 +- .../typed/extensions/v1beta1/replicaset.go | 4 +- .../typed/extensions/v1beta1/scale.go | 4 +- .../kubernetes/typed/networking/v1/BUILD | 42 + .../kubernetes/typed/networking/v1/doc.go | 4 +- .../kubernetes/typed/networking/v1/fake/BUILD | 40 + .../typed/networking/v1/fake/doc.go | 4 +- .../v1/fake/fake_networking_client.go | 4 +- .../networking/v1/fake/fake_networkpolicy.go | 4 +- .../networking/v1/generated_expansion.go | 4 +- .../typed/networking/v1/networking_client.go | 4 +- .../typed/networking/v1/networkpolicy.go | 4 +- .../kubernetes/typed/policy/v1beta1/BUILD | 45 + .../kubernetes/typed/policy/v1beta1/doc.go | 4 +- .../typed/policy/v1beta1/eviction.go | 4 +- .../typed/policy/v1beta1/fake/BUILD | 43 + .../typed/policy/v1beta1/fake/doc.go | 4 +- .../policy/v1beta1/fake/fake_eviction.go | 4 +- .../v1beta1/fake/fake_poddisruptionbudget.go | 4 +- .../v1beta1/fake/fake_podsecuritypolicy.go | 120 + .../policy/v1beta1/fake/fake_policy_client.go | 8 +- .../policy/v1beta1/generated_expansion.go | 6 +- .../policy/v1beta1/poddisruptionbudget.go | 4 +- .../typed/policy/v1beta1/podsecuritypolicy.go | 147 + .../typed/policy/v1beta1/policy_client.go | 9 +- .../client-go/kubernetes/typed/rbac/v1/BUILD | 45 + .../kubernetes/typed/rbac/v1/clusterrole.go | 4 +- .../typed/rbac/v1/clusterrolebinding.go | 4 +- .../client-go/kubernetes/typed/rbac/v1/doc.go | 4 +- .../kubernetes/typed/rbac/v1/fake/BUILD | 43 + .../kubernetes/typed/rbac/v1/fake/doc.go | 4 +- .../typed/rbac/v1/fake/fake_clusterrole.go | 4 +- .../rbac/v1/fake/fake_clusterrolebinding.go | 4 +- .../typed/rbac/v1/fake/fake_rbac_client.go | 4 +- .../typed/rbac/v1/fake/fake_role.go | 4 +- .../typed/rbac/v1/fake/fake_rolebinding.go | 4 +- .../typed/rbac/v1/generated_expansion.go | 4 +- .../kubernetes/typed/rbac/v1/rbac_client.go | 4 +- .../kubernetes/typed/rbac/v1/role.go | 4 +- .../kubernetes/typed/rbac/v1/rolebinding.go | 4 +- .../kubernetes/typed/rbac/v1alpha1/BUILD | 45 + .../typed/rbac/v1alpha1/clusterrole.go | 4 +- .../typed/rbac/v1alpha1/clusterrolebinding.go | 4 +- .../kubernetes/typed/rbac/v1alpha1/doc.go | 4 +- .../kubernetes/typed/rbac/v1alpha1/fake/BUILD | 43 + .../typed/rbac/v1alpha1/fake/doc.go | 4 +- .../rbac/v1alpha1/fake/fake_clusterrole.go | 4 +- .../v1alpha1/fake/fake_clusterrolebinding.go | 4 +- .../rbac/v1alpha1/fake/fake_rbac_client.go | 4 +- .../typed/rbac/v1alpha1/fake/fake_role.go | 4 +- .../rbac/v1alpha1/fake/fake_rolebinding.go | 4 +- .../rbac/v1alpha1/generated_expansion.go | 4 +- .../typed/rbac/v1alpha1/rbac_client.go | 4 +- .../kubernetes/typed/rbac/v1alpha1/role.go | 4 +- .../typed/rbac/v1alpha1/rolebinding.go | 4 +- .../kubernetes/typed/rbac/v1beta1/BUILD | 45 + .../typed/rbac/v1beta1/clusterrole.go | 4 +- .../typed/rbac/v1beta1/clusterrolebinding.go | 4 +- .../kubernetes/typed/rbac/v1beta1/doc.go | 4 +- .../kubernetes/typed/rbac/v1beta1/fake/BUILD | 43 + .../kubernetes/typed/rbac/v1beta1/fake/doc.go | 4 +- .../rbac/v1beta1/fake/fake_clusterrole.go | 4 +- .../v1beta1/fake/fake_clusterrolebinding.go | 4 +- .../rbac/v1beta1/fake/fake_rbac_client.go | 4 +- .../typed/rbac/v1beta1/fake/fake_role.go | 4 +- .../rbac/v1beta1/fake/fake_rolebinding.go | 4 +- .../typed/rbac/v1beta1/generated_expansion.go | 4 +- .../typed/rbac/v1beta1/rbac_client.go | 4 +- .../kubernetes/typed/rbac/v1beta1/role.go | 4 +- .../typed/rbac/v1beta1/rolebinding.go | 4 +- .../typed/scheduling/v1alpha1/BUILD | 42 + .../typed/scheduling/v1alpha1/doc.go | 4 +- .../typed/scheduling/v1alpha1/fake/BUILD | 40 + .../typed/scheduling/v1alpha1/fake/doc.go | 4 +- .../v1alpha1/fake/fake_priorityclass.go | 4 +- .../v1alpha1/fake/fake_scheduling_client.go | 4 +- .../v1alpha1/generated_expansion.go | 4 +- .../scheduling/v1alpha1/priorityclass.go | 4 +- .../scheduling/v1alpha1/scheduling_client.go | 4 +- .../kubernetes/typed/settings/v1alpha1/BUILD | 42 + .../kubernetes/typed/settings/v1alpha1/doc.go | 4 +- .../typed/settings/v1alpha1/fake/BUILD | 40 + .../typed/settings/v1alpha1/fake/doc.go | 4 +- .../settings/v1alpha1/fake/fake_podpreset.go | 4 +- .../v1alpha1/fake/fake_settings_client.go | 4 +- .../settings/v1alpha1/generated_expansion.go | 4 +- .../typed/settings/v1alpha1/podpreset.go | 4 +- .../settings/v1alpha1/settings_client.go | 4 +- .../kubernetes/typed/storage/v1/BUILD | 42 + .../kubernetes/typed/storage/v1/doc.go | 4 +- .../kubernetes/typed/storage/v1/fake/BUILD | 40 + .../kubernetes/typed/storage/v1/fake/doc.go | 4 +- .../storage/v1/fake/fake_storage_client.go | 4 +- .../storage/v1/fake/fake_storageclass.go | 4 +- .../typed/storage/v1/generated_expansion.go | 4 +- .../typed/storage/v1/storage_client.go | 4 +- .../typed/storage/v1/storageclass.go | 4 +- .../kubernetes/typed/storage/v1alpha1/BUILD | 39 + .../kubernetes/typed/storage/v1alpha1/doc.go | 4 +- .../typed/storage/v1alpha1/fake/BUILD | 37 + .../typed/storage/v1alpha1/fake/doc.go | 4 +- .../v1alpha1/fake/fake_storage_client.go | 4 +- .../v1alpha1/fake/fake_volumeattachment.go | 4 +- .../storage/v1alpha1/generated_expansion.go | 4 +- .../typed/storage/v1alpha1/storage_client.go | 4 +- .../storage/v1alpha1/volumeattachment.go | 4 +- .../kubernetes/typed/storage/v1beta1/BUILD | 43 + .../kubernetes/typed/storage/v1beta1/doc.go | 4 +- .../typed/storage/v1beta1/fake/BUILD | 41 + .../typed/storage/v1beta1/fake/doc.go | 4 +- .../v1beta1/fake/fake_storage_client.go | 8 +- .../storage/v1beta1/fake/fake_storageclass.go | 4 +- .../v1beta1/fake/fake_volumeattachment.go | 131 + .../storage/v1beta1/generated_expansion.go | 6 +- .../typed/storage/v1beta1/storage_client.go | 9 +- .../typed/storage/v1beta1/storageclass.go | 4 +- .../typed/storage/v1beta1/volumeattachment.go | 163 + .../admissionregistration/v1alpha1/BUILD | 31 + .../v1alpha1/expansion_generated.go | 4 +- .../v1alpha1/initializerconfiguration.go | 4 +- .../admissionregistration/v1beta1/BUILD | 32 + .../v1beta1/expansion_generated.go | 4 +- .../v1beta1/mutatingwebhookconfiguration.go | 4 +- .../v1beta1/validatingwebhookconfiguration.go | 4 +- .../k8s.io/client-go/listers/apps/v1/BUILD | 41 + .../listers/apps/v1/controllerrevision.go | 4 +- .../client-go/listers/apps/v1/daemonset.go | 4 +- .../client-go/listers/apps/v1/deployment.go | 4 +- .../listers/apps/v1/expansion_generated.go | 4 +- .../client-go/listers/apps/v1/replicaset.go | 4 +- .../client-go/listers/apps/v1/statefulset.go | 4 +- .../client-go/listers/apps/v1beta1/BUILD | 40 + .../apps/v1beta1/controllerrevision.go | 4 +- .../listers/apps/v1beta1/deployment.go | 4 +- .../apps/v1beta1/expansion_generated.go | 4 +- .../client-go/listers/apps/v1beta1/scale.go | 4 +- .../listers/apps/v1beta1/statefulset.go | 4 +- .../client-go/listers/apps/v1beta2/BUILD | 45 + .../apps/v1beta2/controllerrevision.go | 4 +- .../listers/apps/v1beta2/daemonset.go | 4 +- .../listers/apps/v1beta2/deployment.go | 4 +- .../apps/v1beta2/expansion_generated.go | 4 +- .../listers/apps/v1beta2/replicaset.go | 4 +- .../client-go/listers/apps/v1beta2/scale.go | 4 +- .../listers/apps/v1beta2/statefulset.go | 4 +- .../client-go/listers/authentication/v1/BUILD | 34 + .../authentication/v1/expansion_generated.go | 4 +- .../listers/authentication/v1/tokenreview.go | 4 +- .../listers/authentication/v1beta1/BUILD | 34 + .../v1beta1/expansion_generated.go | 4 +- .../authentication/v1beta1/tokenreview.go | 4 +- .../client-go/listers/authorization/v1/BUILD | 37 + .../authorization/v1/expansion_generated.go | 4 +- .../v1/localsubjectaccessreview.go | 4 +- .../v1/selfsubjectaccessreview.go | 4 +- .../v1/selfsubjectrulesreview.go | 4 +- .../authorization/v1/subjectaccessreview.go | 4 +- .../listers/authorization/v1beta1/BUILD | 37 + .../v1beta1/expansion_generated.go | 4 +- .../v1beta1/localsubjectaccessreview.go | 4 +- .../v1beta1/selfsubjectaccessreview.go | 4 +- .../v1beta1/selfsubjectrulesreview.go | 4 +- .../v1beta1/subjectaccessreview.go | 4 +- .../client-go/listers/autoscaling/v1/BUILD | 31 + .../autoscaling/v1/expansion_generated.go | 4 +- .../autoscaling/v1/horizontalpodautoscaler.go | 4 +- .../listers/autoscaling/v2beta1/BUILD | 31 + .../v2beta1/expansion_generated.go | 4 +- .../v2beta1/horizontalpodautoscaler.go | 4 +- .../k8s.io/client-go/listers/batch/v1/BUILD | 37 + .../listers/batch/v1/expansion_generated.go | 4 +- .../k8s.io/client-go/listers/batch/v1/job.go | 4 +- .../client-go/listers/batch/v1beta1/BUILD | 34 + .../listers/batch/v1beta1/cronjob.go | 4 +- .../batch/v1beta1/expansion_generated.go | 4 +- .../client-go/listers/batch/v2alpha1/BUILD | 34 + .../listers/batch/v2alpha1/cronjob.go | 4 +- .../batch/v2alpha1/expansion_generated.go | 4 +- .../listers/certificates/v1beta1/BUILD | 34 + .../v1beta1/certificatesigningrequest.go | 4 +- .../v1beta1/expansion_generated.go | 4 +- .../k8s.io/client-go/listers/core/v1/BUILD | 52 + .../listers/core/v1/componentstatus.go | 4 +- .../client-go/listers/core/v1/configmap.go | 4 +- .../client-go/listers/core/v1/endpoints.go | 4 +- .../k8s.io/client-go/listers/core/v1/event.go | 4 +- .../listers/core/v1/expansion_generated.go | 4 +- .../client-go/listers/core/v1/limitrange.go | 4 +- .../client-go/listers/core/v1/namespace.go | 4 +- .../k8s.io/client-go/listers/core/v1/node.go | 4 +- .../listers/core/v1/persistentvolume.go | 4 +- .../listers/core/v1/persistentvolumeclaim.go | 4 +- .../k8s.io/client-go/listers/core/v1/pod.go | 4 +- .../client-go/listers/core/v1/podtemplate.go | 4 +- .../listers/core/v1/replicationcontroller.go | 4 +- .../listers/core/v1/resourcequota.go | 4 +- .../client-go/listers/core/v1/secret.go | 4 +- .../client-go/listers/core/v1/service.go | 4 +- .../listers/core/v1/serviceaccount.go | 4 +- .../client-go/listers/events/v1beta1/BUILD | 31 + .../client-go/listers/events/v1beta1/event.go | 4 +- .../events/v1beta1/expansion_generated.go | 4 +- .../listers/extensions/v1beta1/BUILD | 60 + .../listers/extensions/v1beta1/daemonset.go | 4 +- .../v1beta1/daemonset_expansion_test.go | 152 + .../listers/extensions/v1beta1/deployment.go | 4 +- .../extensions/v1beta1/expansion_generated.go | 4 +- .../listers/extensions/v1beta1/ingress.go | 4 +- .../extensions/v1beta1/podsecuritypolicy.go | 4 +- .../listers/extensions/v1beta1/replicaset.go | 4 +- .../listers/extensions/v1beta1/scale.go | 4 +- .../listers/imagepolicy/v1alpha1/BUILD | 34 + .../v1alpha1/expansion_generated.go | 4 +- .../imagepolicy/v1alpha1/imagereview.go | 4 +- .../client-go/listers/networking/v1/BUILD | 34 + .../networking/v1/expansion_generated.go | 4 +- .../listers/networking/v1/networkpolicy.go | 4 +- .../client-go/listers/policy/v1beta1/BUILD | 40 + .../listers/policy/v1beta1/eviction.go | 4 +- .../policy/v1beta1/expansion_generated.go | 8 +- .../policy/v1beta1/poddisruptionbudget.go | 4 +- .../policy/v1beta1/podsecuritypolicy.go | 65 + .../k8s.io/client-go/listers/rbac/v1/BUILD | 37 + .../client-go/listers/rbac/v1/clusterrole.go | 4 +- .../listers/rbac/v1/clusterrolebinding.go | 4 +- .../listers/rbac/v1/expansion_generated.go | 4 +- .../k8s.io/client-go/listers/rbac/v1/role.go | 4 +- .../client-go/listers/rbac/v1/rolebinding.go | 4 +- .../client-go/listers/rbac/v1alpha1/BUILD | 37 + .../listers/rbac/v1alpha1/clusterrole.go | 4 +- .../rbac/v1alpha1/clusterrolebinding.go | 4 +- .../rbac/v1alpha1/expansion_generated.go | 4 +- .../client-go/listers/rbac/v1alpha1/role.go | 4 +- .../listers/rbac/v1alpha1/rolebinding.go | 4 +- .../client-go/listers/rbac/v1beta1/BUILD | 37 + .../listers/rbac/v1beta1/clusterrole.go | 4 +- .../rbac/v1beta1/clusterrolebinding.go | 4 +- .../rbac/v1beta1/expansion_generated.go | 4 +- .../client-go/listers/rbac/v1beta1/role.go | 4 +- .../listers/rbac/v1beta1/rolebinding.go | 4 +- .../listers/scheduling/v1alpha1/BUILD | 34 + .../v1alpha1/expansion_generated.go | 4 +- .../scheduling/v1alpha1/priorityclass.go | 4 +- .../client-go/listers/settings/v1alpha1/BUILD | 34 + .../settings/v1alpha1/expansion_generated.go | 4 +- .../listers/settings/v1alpha1/podpreset.go | 4 +- .../k8s.io/client-go/listers/storage/v1/BUILD | 34 + .../listers/storage/v1/expansion_generated.go | 4 +- .../listers/storage/v1/storageclass.go | 4 +- .../client-go/listers/storage/v1alpha1/BUILD | 31 + .../storage/v1alpha1/expansion_generated.go | 4 +- .../storage/v1alpha1/volumeattachment.go | 4 +- .../client-go/listers/storage/v1beta1/BUILD | 35 + .../storage/v1beta1/expansion_generated.go | 8 +- .../listers/storage/v1beta1/storageclass.go | 4 +- .../storage/v1beta1/volumeattachment.go | 65 + .../pkg/apis/clientauthentication/BUILD | 36 + .../pkg/apis/clientauthentication/doc.go | 19 + .../apis/clientauthentication/install/BUILD | 32 + .../clientauthentication/install/install.go | 43 + .../pkg/apis/clientauthentication/register.go | 50 + .../pkg/apis/clientauthentication/types.go | 70 + .../apis/clientauthentication/v1alpha1/BUILD | 39 + .../apis/clientauthentication/v1alpha1/doc.go | 23 + .../clientauthentication/v1alpha1/register.go | 55 + .../clientauthentication/v1alpha1/types.go | 70 + .../v1alpha1/zz_generated.conversion.go | 141 + .../v1alpha1/zz_generated.deepcopy.go | 137 + .../v1alpha1/zz_generated.defaults.go | 32 + .../zz_generated.deepcopy.go | 137 + .../vendor/k8s.io/client-go/pkg/version/BUILD | 30 + .../k8s.io/client-go/pkg/version/def.bzl | 14 + .../token/oidc/testing/provider.go | 200 - .../client-go/plugin/pkg/client/auth/BUILD | 38 + .../plugin/pkg/client/auth/azure/BUILD | 41 + .../pkg/client/auth/azure/azure_test.go | 133 + .../plugin/pkg/client/auth/exec/BUILD | 44 + .../plugin/pkg/client/auth/exec/exec.go | 280 + .../plugin/pkg/client/auth/exec/exec_test.go | 413 + .../client/auth/exec/testdata/test-plugin.sh | 18 + .../plugin/pkg/client/auth/gcp/BUILD | 43 + .../plugin/pkg/client/auth/gcp/gcp.go | 75 +- .../plugin/pkg/client/auth/gcp/gcp_test.go | 497 + .../plugin/pkg/client/auth/oidc/BUILD | 38 + .../plugin/pkg/client/auth/oidc/oidc_test.go | 138 + .../plugin/pkg/client/auth/openstack/BUILD | 38 + .../client/auth/openstack/openstack_test.go | 116 + discovery/vendor/k8s.io/client-go/rest/BUILD | 99 + .../vendor/k8s.io/client-go/rest/client.go | 4 +- .../k8s.io/client-go/rest/client_test.go | 343 + .../vendor/k8s.io/client-go/rest/config.go | 14 +- .../k8s.io/client-go/rest/config_test.go | 376 + .../vendor/k8s.io/client-go/rest/fake/BUILD | 32 + .../vendor/k8s.io/client-go/rest/fake/fake.go | 2 +- .../k8s.io/client-go/rest/plugin_test.go | 311 + .../vendor/k8s.io/client-go/rest/request.go | 3 +- .../k8s.io/client-go/rest/request_test.go | 1789 ++ .../vendor/k8s.io/client-go/rest/transport.go | 16 +- .../k8s.io/client-go/rest/url_utils_test.go | 61 + .../k8s.io/client-go/rest/urlbackoff_test.go | 79 + .../vendor/k8s.io/client-go/rest/versions.go | 88 - .../vendor/k8s.io/client-go/rest/watch/BUILD | 56 + .../client-go/rest/watch/decoder_test.go | 123 + .../client-go/rest/watch/encoder_test.go | 84 + .../client-go/rest/zz_generated.deepcopy.go | 4 +- discovery/vendor/k8s.io/client-go/scale/BUILD | 76 + .../vendor/k8s.io/client-go/scale/client.go | 48 +- .../k8s.io/client-go/scale/client_test.go | 283 + .../vendor/k8s.io/client-go/scale/fake/BUILD | 28 + .../k8s.io/client-go/scale/roundtrip_test.go | 34 + .../k8s.io/client-go/scale/scheme/BUILD | 41 + .../client-go/scale/scheme/appsint/BUILD | 31 + .../client-go/scale/scheme/appsint/doc.go | 2 +- .../client-go/scale/scheme/appsv1beta1/BUILD | 35 + .../appsv1beta1/zz_generated.conversion.go | 4 +- .../client-go/scale/scheme/appsv1beta2/BUILD | 35 + .../appsv1beta2/zz_generated.conversion.go | 4 +- .../scale/scheme/autoscalingv1/BUILD | 35 + .../autoscalingv1/zz_generated.conversion.go | 4 +- .../scale/scheme/extensionsint/BUILD | 31 + .../scale/scheme/extensionsint/doc.go | 2 +- .../scale/scheme/extensionsv1beta1/BUILD | 35 + .../zz_generated.conversion.go | 4 +- .../scale/scheme/zz_generated.deepcopy.go | 7 +- .../vendor/k8s.io/client-go/scale/util.go | 19 + .../vendor/k8s.io/client-go/testing/BUILD | 60 + .../k8s.io/client-go/testing/fixture.go | 60 +- .../k8s.io/client-go/testing/fixture_test.go | 192 + .../third_party/forked/golang/template/BUILD | 28 + .../vendor/k8s.io/client-go/tools/auth/BUILD | 33 + .../k8s.io/client-go/tools/auth/clientauth.go | 2 +- .../client-go/tools/auth/clientauth_test.go | 69 + .../client-go/tools/bootstrap/token/api/BUILD | 26 + .../tools/bootstrap/token/api/OWNERS | 5 + .../tools/bootstrap/token/api/doc.go | 20 + .../tools/bootstrap/token/api/types.go | 100 + .../tools/bootstrap/token/util/BUILD | 32 + .../tools/bootstrap/token/util/helpers.go | 52 + .../bootstrap/token/util/helpers_test.go | 76 + .../vendor/k8s.io/client-go/tools/cache/BUILD | 103 + .../client-go/tools/cache/controller.go | 4 +- .../client-go/tools/cache/controller_test.go | 405 + .../client-go/tools/cache/delta_fifo.go | 84 +- .../client-go/tools/cache/delta_fifo_test.go | 492 + .../tools/cache/expiration_cache_test.go | 189 + .../k8s.io/client-go/tools/cache/fifo.go | 2 +- .../k8s.io/client-go/tools/cache/fifo_test.go | 280 + .../k8s.io/client-go/tools/cache/heap_test.go | 382 + .../client-go/tools/cache/index_test.go | 163 + .../k8s.io/client-go/tools/cache/listwatch.go | 14 +- .../tools/cache/mutation_detector_test.go | 81 + .../tools/cache/processor_listener_test.go | 58 + .../k8s.io/client-go/tools/cache/reflector.go | 10 +- .../client-go/tools/cache/reflector_test.go | 389 + .../client-go/tools/cache/shared_informer.go | 59 +- .../tools/cache/shared_informer_test.go | 265 + .../client-go/tools/cache/store_test.go | 156 + .../client-go/tools/cache/testing/BUILD | 45 + .../testing/fake_controller_source_test.go | 95 + .../tools/cache/undelta_store_test.go | 131 + .../k8s.io/client-go/tools/clientcmd/BUILD | 78 + .../client-go/tools/clientcmd/api/BUILD | 50 + .../tools/clientcmd/api/helpers_test.go | 301 + .../tools/clientcmd/api/latest/BUILD | 33 + .../client-go/tools/clientcmd/api/types.go | 32 + .../tools/clientcmd/api/types_test.go | 135 + .../client-go/tools/clientcmd/api/v1/BUILD | 37 + .../client-go/tools/clientcmd/api/v1/types.go | 32 + .../clientcmd/api/v1/zz_generated.deepcopy.go | 58 +- .../clientcmd/api/zz_generated.deepcopy.go | 58 +- .../tools/clientcmd/client_config.go | 12 +- .../tools/clientcmd/client_config_test.go | 528 + .../client-go/tools/clientcmd/loader.go | 11 +- .../client-go/tools/clientcmd/loader_test.go | 594 + .../clientcmd/merged_client_builder_test.go | 328 + .../tools/clientcmd/overrides_test.go | 50 + .../client-go/tools/clientcmd/validation.go | 23 + .../tools/clientcmd/validation_test.go | 574 + .../client-go/tools/leaderelection/BUILD | 53 + .../tools/leaderelection/leaderelection.go | 4 +- .../leaderelection/leaderelection_test.go | 292 + .../tools/leaderelection/resourcelock/BUILD | 35 + .../resourcelock/configmaplock.go | 12 +- .../k8s.io/client-go/tools/metrics/BUILD | 25 + .../vendor/k8s.io/client-go/tools/pager/BUILD | 49 + .../client-go/tools/pager/pager_test.go | 206 + .../k8s.io/client-go/tools/portforward/BUILD | 41 + .../tools/portforward/portforward.go | 4 +- .../tools/portforward/portforward_test.go | 188 + .../k8s.io/client-go/tools/record/BUILD | 68 + .../client-go/tools/record/event_test.go | 924 + .../tools/record/events_cache_test.go | 287 + .../k8s.io/client-go/tools/reference/BUILD | 31 + .../client-go/tools/remotecommand/BUILD | 60 + .../client-go/tools/remotecommand/v2_test.go | 228 + .../client-go/tools/remotecommand/v4_test.go | 71 + .../vendor/k8s.io/client-go/transport/BUILD | 48 + .../k8s.io/client-go/transport/cache.go | 33 +- .../k8s.io/client-go/transport/cache_test.go | 128 + .../k8s.io/client-go/transport/config.go | 4 - .../client-go/transport/round_trippers.go | 31 - .../transport/round_trippers_test.go | 218 + .../k8s.io/client-go/transport/spdy/BUILD | 30 + .../client-go/transport/transport_test.go | 204 + .../vendor/k8s.io/client-go/util/buffer/BUILD | 29 + .../util/buffer/ring_growing_test.go | 50 + .../vendor/k8s.io/client-go/util/cert/BUILD | 47 + .../vendor/k8s.io/client-go/util/cert/cert.go | 42 +- .../k8s.io/client-go/util/cert/csr_test.go | 75 + .../k8s.io/client-go/util/cert/pem_test.go | 197 + .../k8s.io/client-go/util/cert/triple/BUILD | 26 + .../k8s.io/client-go/util/certificate/BUILD | 66 + .../util/certificate/certificate_manager.go | 89 +- .../certificate/certificate_manager_test.go | 910 + .../certificate/certificate_store_test.go | 505 + .../client-go/util/certificate/csr/BUILD | 53 + .../util/certificate/csr/csr_test.go | 135 + .../vendor/k8s.io/client-go/util/exec/BUILD | 25 + .../k8s.io/client-go/util/flowcontrol/BUILD | 44 + .../util/flowcontrol/backoff_test.go | 195 + .../client-go/util/flowcontrol/throttle.go | 55 +- .../util/flowcontrol/throttle_test.go | 153 + .../k8s.io/client-go/util/homedir/BUILD | 25 + .../k8s.io/client-go/util/integer/BUILD | 32 + .../client-go/util/integer/integer_test.go | 244 + .../k8s.io/client-go/util/jsonpath/BUILD | 41 + .../client-go/util/jsonpath/jsonpath_test.go | 371 + .../client-go/util/jsonpath/parser_test.go | 152 + .../vendor/k8s.io/client-go/util/retry/BUILD | 41 + .../k8s.io/client-go/util/retry/util_test.go | 71 + .../k8s.io/client-go/util/testing/BUILD | 35 + .../util/testing/fake_handler_test.go | 180 + .../k8s.io/client-go/util/workqueue/BUILD | 59 + .../util/workqueue/default_rate_limiters.go | 8 +- .../workqueue/default_rate_limiters_test.go | 184 + .../util/workqueue/delaying_queue.go | 2 +- .../util/workqueue/delaying_queue_test.go | 255 + .../client-go/util/workqueue/queue_test.go | 161 + .../util/workqueue/rate_limitting_queue.go | 2 +- .../workqueue/rate_limitting_queue_test.go | 75 + .../.github/PULL_REQUEST_TEMPLATE.md | 2 + .../k8s.io/code-generator/CONTRIBUTING.md | 7 + .../k8s.io/code-generator/Godeps/Godeps.json | 40 +- .../k8s.io/code-generator/Godeps/OWNERS | 2 + .../example/v1/zz_generated.conversion.go | 5 +- .../example/v1/zz_generated.conversions.go | 113 - .../apis/example/v1/zz_generated.deepcopy.go | 8 +- .../apis/example/v1/zz_generated.defaults.go | 2 +- .../apis/example/zz_generated.deepcopy.go | 8 +- .../example2/v1/zz_generated.conversion.go | 5 +- .../apis/example2/v1/zz_generated.deepcopy.go | 8 +- .../apis/example2/v1/zz_generated.defaults.go | 2 +- .../apis/example2/zz_generated.deepcopy.go | 8 +- .../clientset/internalversion/clientset.go | 2 + .../clientset/internalversion/doc.go | 2 + .../fake/clientset_generated.go | 12 +- .../clientset/internalversion/fake/doc.go | 2 + .../internalversion/fake/register.go | 5 +- .../clientset/internalversion/scheme/doc.go | 2 + .../internalversion/scheme/register.go | 6 +- .../typed/example/internalversion/doc.go | 2 + .../example/internalversion/example_client.go | 2 + .../typed/example/internalversion/fake/doc.go | 2 + .../fake/fake_example_client.go | 2 + .../internalversion/fake/fake_testtype.go | 2 + .../internalversion/generated_expansion.go | 2 + .../typed/example/internalversion/testtype.go | 2 + .../typed/example2/internalversion/doc.go | 2 + .../internalversion/example2_client.go | 2 + .../example2/internalversion/fake/doc.go | 2 + .../fake/fake_example2_client.go | 2 + .../internalversion/fake/fake_testtype.go | 2 + .../internalversion/generated_expansion.go | 2 + .../example2/internalversion/testtype.go | 2 + .../clientset/versioned/clientset.go | 2 + .../apiserver/clientset/versioned/doc.go | 2 + .../versioned/fake/clientset_generated.go | 12 +- .../apiserver/clientset/versioned/fake/doc.go | 2 + .../clientset/versioned/fake/register.go | 5 +- .../clientset/versioned/scheme/doc.go | 2 + .../clientset/versioned/scheme/register.go | 5 +- .../versioned/typed/example/v1/doc.go | 2 + .../typed/example/v1/example_client.go | 2 + .../versioned/typed/example/v1/fake/doc.go | 2 + .../example/v1/fake/fake_example_client.go | 2 + .../typed/example/v1/fake/fake_testtype.go | 2 + .../typed/example/v1/generated_expansion.go | 2 + .../versioned/typed/example/v1/testtype.go | 2 + .../versioned/typed/example2/v1/doc.go | 2 + .../typed/example2/v1/example2_client.go | 2 + .../versioned/typed/example2/v1/fake/doc.go | 2 + .../example2/v1/fake/fake_example2_client.go | 2 + .../typed/example2/v1/fake/fake_testtype.go | 2 + .../typed/example2/v1/generated_expansion.go | 2 + .../versioned/typed/example2/v1/testtype.go | 2 + .../externalversions/example/interface.go | 2 +- .../externalversions/example/v1/interface.go | 2 +- .../externalversions/example/v1/testtype.go | 5 +- .../externalversions/example2/interface.go | 2 +- .../externalversions/example2/v1/interface.go | 2 +- .../externalversions/example2/v1/testtype.go | 5 +- .../informers/externalversions/factory.go | 9 +- .../informers/externalversions/generic.go | 3 +- .../internalinterfaces/factory_interfaces.go | 5 +- .../internalversion/example/interface.go | 2 +- .../example/internalversion/interface.go | 2 +- .../example/internalversion/testtype.go | 5 +- .../internalversion/example2/interface.go | 2 +- .../example2/internalversion/interface.go | 2 +- .../example2/internalversion/testtype.go | 5 +- .../informers/internalversion/factory.go | 9 +- .../informers/internalversion/generic.go | 3 +- .../internalinterfaces/factory_interfaces.go | 5 +- .../internalversion/expansion_generated.go | 2 +- .../example/internalversion/testtype.go | 2 +- .../listers/example/v1/expansion_generated.go | 2 +- .../apiserver/listers/example/v1/testtype.go | 2 +- .../internalversion/expansion_generated.go | 2 +- .../example2/internalversion/testtype.go | 2 +- .../example2/v1/expansion_generated.go | 2 +- .../apiserver/listers/example2/v1/testtype.go | 2 +- .../apis/example/v1/zz_generated.deepcopy.go | 8 +- .../apis/example2/v1/zz_generated.deepcopy.go | 8 +- .../crd/clientset/versioned/clientset.go | 2 + .../_examples/crd/clientset/versioned/doc.go | 2 + .../versioned/fake/clientset_generated.go | 12 +- .../crd/clientset/versioned/fake/doc.go | 2 + .../crd/clientset/versioned/fake/register.go | 5 +- .../crd/clientset/versioned/scheme/doc.go | 2 + .../clientset/versioned/scheme/register.go | 5 +- .../versioned/typed/example/v1/doc.go | 2 + .../typed/example/v1/example_client.go | 2 + .../versioned/typed/example/v1/fake/doc.go | 2 + .../example/v1/fake/fake_example_client.go | 2 + .../typed/example/v1/fake/fake_testtype.go | 2 + .../typed/example/v1/generated_expansion.go | 2 + .../versioned/typed/example/v1/testtype.go | 2 + .../versioned/typed/example2/v1/doc.go | 2 + .../typed/example2/v1/example2_client.go | 2 + .../versioned/typed/example2/v1/fake/doc.go | 2 + .../example2/v1/fake/fake_example2_client.go | 2 + .../typed/example2/v1/fake/fake_testtype.go | 2 + .../typed/example2/v1/generated_expansion.go | 2 + .../versioned/typed/example2/v1/testtype.go | 2 + .../externalversions/example/interface.go | 2 +- .../externalversions/example/v1/interface.go | 2 +- .../externalversions/example/v1/testtype.go | 5 +- .../externalversions/example2/interface.go | 2 +- .../externalversions/example2/v1/interface.go | 2 +- .../externalversions/example2/v1/testtype.go | 5 +- .../crd/informers/externalversions/factory.go | 9 +- .../crd/informers/externalversions/generic.go | 3 +- .../internalinterfaces/factory_interfaces.go | 5 +- .../listers/example/v1/expansion_generated.go | 2 +- .../crd/listers/example/v1/testtype.go | 2 +- .../example2/v1/expansion_generated.go | 2 +- .../crd/listers/example2/v1/testtype.go | 2 +- .../cmd/client-gen/args/args.go | 91 +- .../cmd/client-gen/args/gvpackages.go | 161 +- .../cmd/client-gen/args/gvpackages_test.go | 116 + .../client-gen/generators/client_generator.go | 32 +- .../generators/fake/fake_client_generator.go | 12 +- .../fake/generator_fake_for_clientset.go | 14 +- .../generators/generator_for_clientset.go | 4 +- .../generators/generator_for_group.go | 5 +- .../generators/scheme/generator_for_scheme.go | 30 +- .../client-gen/generators/util/tags_test.go | 148 + .../code-generator/cmd/client-gen/main.go | 44 +- .../cmd/client-gen/types/helpers.go | 20 +- .../cmd/client-gen/types/helpers_test.go | 32 + .../cmd/client-gen/types/types.go | 14 +- .../cmd/conversion-gen/args/args.go | 83 + .../conversion-gen/generators/conversion.go | 35 +- .../code-generator/cmd/conversion-gen/main.go | 40 +- .../cmd/deepcopy-gen/args/args.go | 54 + .../code-generator/cmd/deepcopy-gen/main.go | 31 +- .../cmd/defaulter-gen/args/args.go | 54 + .../code-generator/cmd/defaulter-gen/main.go | 33 +- .../code-generator/cmd/go-to-protobuf/main.go | 1 + .../cmd/go-to-protobuf/protobuf/cmd.go | 6 +- .../cmd/go-to-protobuf/protobuf/generator.go | 11 +- .../cmd/go-to-protobuf/protobuf/namer_test.go | 50 + .../code-generator/cmd/import-boss/main.go | 3 +- .../cmd/informer-gen/args/args.go | 77 + .../cmd/informer-gen/generators/customargs.go | 33 - .../cmd/informer-gen/generators/generic.go | 6 +- .../informer-gen/generators/groupinterface.go | 4 +- .../cmd/informer-gen/generators/packages.go | 34 +- .../code-generator/cmd/informer-gen/main.go | 39 +- .../cmd/lister-gen/args/args.go | 56 + .../cmd/lister-gen/generators/lister.go | 8 - .../code-generator/cmd/lister-gen/main.go | 25 +- .../cmd/openapi-gen/args/args.go | 53 + .../code-generator/cmd/openapi-gen/main.go | 24 +- .../k8s.io/code-generator/cmd/set-gen/main.go | 3 +- .../k8s.io/code-generator/code-of-conduct.md | 3 + .../k8s.io/code-generator/generate-groups.sh | 2 +- .../generate-internal-groups.sh | 4 +- .../code-generator/hack/boilerplate.go.txt | 16 + .../k8s.io/code-generator/pkg/util/build.go | 61 + discovery/vendor/k8s.io/gengo/.travis.yml | 17 + .../vendor/k8s.io/gengo/args/args_test.go | 35 + .../deepcopy-gen/generators/deepcopy_test.go | 398 + .../output_tests/wholepkg/deepcopy_test.go | 145 + .../go-to-protobuf/protobuf/namer_test.go | 50 + .../generators/import_restrict_test.go | 36 + .../gengo/examples/set-gen/sets/set_test.go | 270 + .../gengo/generator/snippet_writer_test.go | 88 + .../vendor/k8s.io/gengo/namer/namer_test.go | 100 + .../k8s.io/gengo/namer/plural_namer_test.go | 68 + .../k8s.io/gengo/parser/local_parse_test.go | 68 + .../vendor/k8s.io/gengo/parser/parse_test.go | 458 + .../k8s.io/gengo/types/comments_test.go | 86 + .../vendor/k8s.io/gengo/types/flatten_test.go | 68 + .../vendor/k8s.io/gengo/types/types_test.go | 210 + .../vendor/k8s.io/kube-openapi/.travis.yml | 4 + .../pkg/aggregator/aggregator_test.go | 1099 + .../kube-openapi/pkg/builder/openapi_test.go | 465 + .../pkg/generators/openapi_test.go | 375 + .../pkg/util/proto/openapi_suite_test.go | 49 + .../pkg/util/proto/openapi_test.go | 207 + 3543 files changed, 482212 insertions(+), 67066 deletions(-) delete mode 100644 discovery/vendor/github.com/PuerkitoBio/purell/.gitignore delete mode 100644 discovery/vendor/github.com/PuerkitoBio/purell/LICENSE delete mode 100644 discovery/vendor/github.com/PuerkitoBio/purell/README.md delete mode 100644 discovery/vendor/github.com/PuerkitoBio/purell/benchmarks/v0.1.0 delete mode 100644 discovery/vendor/github.com/PuerkitoBio/purell/purell.go delete mode 100644 discovery/vendor/github.com/PuerkitoBio/urlesc/LICENSE delete mode 100644 discovery/vendor/github.com/PuerkitoBio/urlesc/README.md delete mode 100644 discovery/vendor/github.com/PuerkitoBio/urlesc/urlesc.go create mode 100644 discovery/vendor/github.com/beorn7/perks/histogram/bench_test.go create mode 100644 discovery/vendor/github.com/beorn7/perks/histogram/histogram_test.go create mode 100644 discovery/vendor/github.com/beorn7/perks/quantile/bench_test.go create mode 100644 discovery/vendor/github.com/beorn7/perks/quantile/example_test.go create mode 100644 discovery/vendor/github.com/beorn7/perks/quantile/stream_test.go create mode 100644 discovery/vendor/github.com/beorn7/perks/topk/topk_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/.travis.yml create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/common_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/dump_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/example_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/format_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/internal_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go create mode 100644 discovery/vendor/github.com/davecgh/go-spew/spew/spew_test.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/.gitignore delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/CHANGES.md delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/LICENSE delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/Makefile delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/README.md delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/Srcfile delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/bench_test.sh delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/compress.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/compressor_cache.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/compressor_pools.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/compressors.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/constants.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/container.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/cors_filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/coverage.sh delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/curly.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/curly_route.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/doc.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/entity_accessors.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/.goconvey delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/.goconvey delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/app.yaml delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/.goconvey delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/app.yaml delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/main.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-appstats-integration.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-user-service.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/home.html delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/msgpack/msgpack_entity.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-CORS-filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-NCSA-logging.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-cpuprofiler-service.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-curly-router.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-encoding-filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-filters.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-form-handling.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-hello-world.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-html-template.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-multi-containers.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-no-cache-filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-options-filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-path-tail.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-pre-post-filters.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-resource-functions.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-serve-static.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-swagger.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/examples/restful-user-resource.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/jsr311.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/log/log.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/logger.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/mime.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/options_filter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/parameter.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/path_expression.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/request.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/response.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/route.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/route_builder.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/router.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/service_error.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/web_service.go delete mode 100644 discovery/vendor/github.com/emicklei/go-restful/web_service_container.go create mode 100644 discovery/vendor/github.com/ghodss/yaml/.travis.yml create mode 100644 discovery/vendor/github.com/ghodss/yaml/yaml_test.go delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/.editorconfig delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/.github/CONTRIBUTING.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/.gitignore delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/LICENSE delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/README.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonpointer/pointer.go delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/.github/CONTRIBUTING.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/.gitignore delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/LICENSE delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/README.md delete mode 100644 discovery/vendor/github.com/go-openapi/jsonreference/reference.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/.editorconfig delete mode 100644 discovery/vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md delete mode 100644 discovery/vendor/github.com/go-openapi/spec/.gitignore delete mode 100644 discovery/vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md delete mode 100644 discovery/vendor/github.com/go-openapi/spec/LICENSE delete mode 100644 discovery/vendor/github.com/go-openapi/spec/README.md delete mode 100644 discovery/vendor/github.com/go-openapi/spec/bindata.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/contact_info.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/expander.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/external_docs.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/params.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/specs/refed.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/header.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/info.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/items.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/license.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/operation.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/parameter.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/path_item.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/paths.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/ref.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/response.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/responses.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/schema.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/schemas/v2/README.md delete mode 100644 discovery/vendor/github.com/go-openapi/spec/schemas/v2/schema.json delete mode 100644 discovery/vendor/github.com/go-openapi/spec/security_scheme.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/spec.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/swagger.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/tag.go delete mode 100644 discovery/vendor/github.com/go-openapi/spec/xml_object.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/.editorconfig delete mode 100644 discovery/vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md delete mode 100644 discovery/vendor/github.com/go-openapi/swag/.gitignore delete mode 100644 discovery/vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md delete mode 100644 discovery/vendor/github.com/go-openapi/swag/LICENSE delete mode 100644 discovery/vendor/github.com/go-openapi/swag/README.md delete mode 100644 discovery/vendor/github.com/go-openapi/swag/convert.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/convert_types.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/json.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/loading.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/net.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/path.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/util.go delete mode 100644 discovery/vendor/github.com/go-openapi/swag/yaml.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/.travis.yml create mode 100644 discovery/vendor/github.com/gogo/protobuf/codec/codec_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/io/io_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/io/uint32_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/all_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/any_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/clone_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/decode_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/encode_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/equal_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/extensions_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/map_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/message_set_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/proto3_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/size2_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/size_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/text_parser_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/proto/text_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/bug_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/custom/custom_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/data/datapb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/example/example_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/extension_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/packed/packed_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/tags/tags_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/thetestpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/test/uuid_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/types/any_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/types/duration_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/types/timestamp_test.go create mode 100644 discovery/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go create mode 100644 discovery/vendor/github.com/golang/glog/glog_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/.travis.yml create mode 100644 discovery/vendor/github.com/golang/protobuf/descriptor/descriptor_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/all_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/any_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/clone_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/decode_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/encode_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/equal_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/extensions_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/map_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/message_set_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/proto3_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/size2_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/size_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/testdata/golden_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/text_parser_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/proto/text_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/main_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/ptypes/any_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/ptypes/duration_test.go create mode 100644 discovery/vendor/github.com/golang/protobuf/ptypes/timestamp_test.go delete mode 100644 discovery/vendor/github.com/google/btree/LICENSE delete mode 100644 discovery/vendor/github.com/google/btree/README.md delete mode 100644 discovery/vendor/github.com/google/btree/btree.go delete mode 100644 discovery/vendor/github.com/google/btree/btree_mem.go create mode 100644 discovery/vendor/github.com/google/gofuzz/.travis.yml create mode 100644 discovery/vendor/github.com/google/gofuzz/example_test.go create mode 100644 discovery/vendor/github.com/google/gofuzz/fuzz_test.go create mode 100644 discovery/vendor/github.com/googleapis/gnostic/.travis.yml create mode 100644 discovery/vendor/github.com/googleapis/gnostic/generate-gnostic/generate-extension_test.go create mode 100644 discovery/vendor/github.com/googleapis/gnostic/gnostic_test.go create mode 100644 discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/bookstore/bookstore_test.go create mode 100644 discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v3.0/bookstore/bookstore_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/.travis.yml create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-acceptance-test/run.yaml create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-unittest/run.yaml create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/conditions.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/http.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/schedulerstats_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/services_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/volumeactions_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/snapshots_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/volumes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/snapshots_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumetypes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/snapshots_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/volumes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/quotaset_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/snapshots_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumetypes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/client_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/actions_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clustering.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clusters_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/nodes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/pkg.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policies_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policytypes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiles_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiletypes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/receivers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/webhooktrigger_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/aggregates_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/attachinterfaces_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/availabilityzones_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/bootfromvolume_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/defsecrules_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/extension_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/flavors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/floatingip_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/hypervisors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/images_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/keypairs_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/limits_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/migrate_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/network_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/quotaset_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/secgroup_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servergroup_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/services_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/usage_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/volumeattach_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/certificates_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/clustertemplates_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/containerinfra.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/pkg.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/configurations_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/databases_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/flavors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/instances_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/users_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/recordsets_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/zones_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/extension_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/role_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/tenant_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/token_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/user_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/domains_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/endpoint_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/groups_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/policies_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/projects_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/regions_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/roles_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/service_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/token_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/users_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/images_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/tasks_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/acls_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/containers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/keymanager.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/orders_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/secrets_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/l7policies_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/listeners_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancer.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/monitors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pkg.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pools_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/claims_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/message_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/messaging.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/queue_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/apiversion_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extension_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/firewall_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/policy_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/rule_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/floatingips_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/routers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/members_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/monitors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/pools_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/vips_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/listeners_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/loadbalancers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/monitors_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/pools_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/networkipavailabilities_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/pkg.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/provider_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/qos/ruletypes/ruletypes_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/pkg.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/security_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/group_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ikepolicy_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ipsecpolicy_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/service_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/siteconnection_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/ports_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/subnets_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/accounts_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/containers_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/objects_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/buildinfo_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackevents_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackresources_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacks_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacktemplates_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/availabilityzones_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go rename discovery/vendor/github.com/gophercloud/gophercloud/{ => docs}/FAQ.md (100%) rename discovery/vendor/github.com/gophercloud/gophercloud/{ => docs}/MIGRATING.md (95%) rename discovery/vendor/github.com/gophercloud/gophercloud/{ => docs}/STYLEGUIDE.md (100%) rename discovery/vendor/github.com/gophercloud/gophercloud/{ => docs}/assets/openlab.png (100%) rename discovery/vendor/github.com/gophercloud/gophercloud/{ => docs}/assets/vexxhost.png (100%) create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/README.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-01-introduction.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-02-issues.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-03-code-hunting.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-04-acceptance-testing.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-05-pull-requests.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-06-code-review.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-07-congratulations.md create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/internal/testing/util_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/noauth/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/base/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/services/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/common/extensions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/evacuate/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock/testing/request_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/resetstate/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/testing/delegate_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/template.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/template_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/configurations/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/databases/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/datastores/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/flavors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/users/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/zones/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/testing/delegate_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/users/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/domains/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/regions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/services/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/errors.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/members/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper/client.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/fixtures.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/testing/delegate_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/doc.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/requests.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/results.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/urls.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/apiversions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/environment_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/template_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/utils_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/request_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/client_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/endpoint_location_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/base_endpoint.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/base_endpoint_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/choose_version_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/linked_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/marker_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/pagination_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/single_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/script/stackenv create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/endpoint_search_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/params_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/provider_client_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/results_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/service_client_test.go create mode 100644 discovery/vendor/github.com/gophercloud/gophercloud/testing/util_test.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/LICENSE.txt delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/README.md delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/httpcache.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/leveldbcache/leveldbcache.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/memcache/appengine.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/memcache/memcache.go delete mode 100644 discovery/vendor/github.com/gregjones/httpcache/redis/redis.go create mode 100644 discovery/vendor/github.com/hashicorp/golang-lru/2q_test.go create mode 100644 discovery/vendor/github.com/hashicorp/golang-lru/arc_test.go create mode 100644 discovery/vendor/github.com/hashicorp/golang-lru/lru_test.go create mode 100644 discovery/vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go create mode 100644 discovery/vendor/github.com/howeyc/gopass/.travis.yml create mode 100644 discovery/vendor/github.com/howeyc/gopass/pass_test.go create mode 100644 discovery/vendor/github.com/imdario/mergo/.travis.yml create mode 100644 discovery/vendor/github.com/imdario/mergo/issue17_test.go create mode 100644 discovery/vendor/github.com/imdario/mergo/issue23_test.go create mode 100644 discovery/vendor/github.com/imdario/mergo/issue38_test.go create mode 100644 discovery/vendor/github.com/imdario/mergo/mergo_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/.travis.yml create mode 100644 discovery/vendor/github.com/json-iterator/go/Gopkg.lock create mode 100644 discovery/vendor/github.com/json-iterator/go/Gopkg.toml create mode 100644 discovery/vendor/github.com/json-iterator/go/adapter.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any.go rename discovery/vendor/github.com/json-iterator/go/{feature_any_array.go => any_array.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_bool.go => any_bool.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_float.go => any_float.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_int32.go => any_int32.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_int64.go => any_int64.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_invalid.go => any_invalid.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_nil.go => any_nil.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/any_number.go rename discovery/vendor/github.com/json-iterator/go/{feature_any_object.go => any_object.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/any_str.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_array_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_bool_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_float_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_int_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_map_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_null_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_object_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_must_be_valid_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_wrap_test.go rename discovery/vendor/github.com/json-iterator/go/{feature_any_uint32.go => any_uint32.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_any_uint64.go => any_uint64.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/api_tests/config_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/api_tests/decoder_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/api_tests/encoder_18_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/api_tests/encoder_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/api_tests/marshal_indent_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/benchmarks/encode_string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/benchmarks/jsoniter_large_file_test.go create mode 100755 discovery/vendor/github.com/json-iterator/go/build.sh create mode 100644 discovery/vendor/github.com/json-iterator/go/config.go create mode 100644 discovery/vendor/github.com/json-iterator/go/example_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extension_tests/decoder_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extension_tests/extension_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/naming_strategy_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/private_fields_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec_test.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_adapter.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_any.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_any_number.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_any_string.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_config.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_iter_float.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_iter_int.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_iter_object.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_json_number.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_pool.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_array.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_extension.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_map.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_native.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_object.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_slice.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_reflect_struct_decoder.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_stream.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_stream_float.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_stream_int.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/feature_stream_string.go rename discovery/vendor/github.com/json-iterator/go/{feature_iter.go => iter.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_iter_array.go => iter_array.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/iter_float.go create mode 100644 discovery/vendor/github.com/json-iterator/go/iter_int.go create mode 100644 discovery/vendor/github.com/json-iterator/go/iter_object.go rename discovery/vendor/github.com/json-iterator/go/{feature_iter_skip.go => iter_skip.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_iter_skip_sloppy.go => iter_skip_sloppy.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/iter_skip_sloppy_test.go rename discovery/vendor/github.com/json-iterator/go/{feature_iter_skip_strict.go => iter_skip_strict.go} (100%) rename discovery/vendor/github.com/json-iterator/go/{feature_iter_string.go => iter_str.go} (100%) create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_array_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_bool_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_float_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_int_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_interface_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_iterator_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_map_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_nested_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_null_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_object_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/misc_tests/jsoniter_raw_message_test.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/array/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/map/int32_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/map/string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_map/int32_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_map/string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_slice/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/ptr_uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/slice/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/struct_empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/struct_empty_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/struct_ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/array/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/bool_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/byte_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/float32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/float32_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/float64_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int16/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int16_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int32_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/int8_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint16/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint16_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint32_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uint8_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/builtins/uintptr/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/caseless_unmarshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/json_marshal/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/json_marshal/struct/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/json_marshal/struct_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/json_marshal/struct_field/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/json_marshal/struct_field_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/int16/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/int32/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/int64/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/int8/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/array_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_array_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/ptr_uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/struct_empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/struct_empty_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/struct_ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string_alias/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/string_alias/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/uint16/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/uint32/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map/uint8/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map_key_text_marshal/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/map_key_text_marshal/struct/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/marshal_fail_case.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/partial_unmarshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/array/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/int64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/map/int32_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/map/string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_array/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_map/int32_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_map/string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_slice/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/ptr_uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/slice/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/struct_empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/struct_empty_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/struct_ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/slice/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/json_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/ptr_struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/string_with_tag/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/struct_various/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/no_overlap/text_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/different_levels/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/ignore_deeper_level/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_1_no_tags/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_1_tagged/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_2_no_tags/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/anonymous/overlap/same_level_2_tagged/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/array/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/array/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/array/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/array/strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/array/struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/empty_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/everything/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/float64_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/float64s/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/float64s_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/int32_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/int32s/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/int32s_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/int64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/int32_ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/int32_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/int32_struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/string_ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/map/string_struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_float64_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_int32_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_ptr_struct_empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_ptr_struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_struct_empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptr_struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptrs_float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptrs_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/ptrs_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/slice/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/slice/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/slice/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/slice/strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/slice/struct_strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/strings_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/empties/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/empty/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/empty_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/float32s/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/float64_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/int32s/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/strings/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct/struct/strings_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/fieldname/embedded/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/fieldname/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/fieldname/struct/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/embedded/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/float32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_float32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_map_string_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_string/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_string_json_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_string_text_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_struct_json_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_struct_text_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/ptr_uint32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/slice_string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/string_json_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/string_text_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/struct/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/struct_json_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/struct_text_marshal/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/omitempty/uint32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/bool/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/byte/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/float32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/float64/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/int16/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/int32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/int8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/string/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/uint16/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/uint32/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/struct_tags/string/uint8/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/text_marshal/string_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/text_marshal/struct/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/text_marshal/struct_alias/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/text_marshal/struct_field/types.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/output_tests/text_marshal/struct_field_alias/types.go create mode 100644 discovery/vendor/github.com/json-iterator/go/pool.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_array.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_dynamic.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_extension.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_json_number.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_json_raw_message.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_map.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_marshaler.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_native.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_optional.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_slice.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_struct_decoder.go create mode 100644 discovery/vendor/github.com/json-iterator/go/reflect_struct_encoder.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/array/inputs.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/array_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/float64_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/jsoniter_skip_test.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/number/inputs.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/object/inputs.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/skip_test.go delete mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/string/inputs.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/skip_tests/struct_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/stream.go create mode 100644 discovery/vendor/github.com/json-iterator/go/stream_float.go create mode 100644 discovery/vendor/github.com/json-iterator/go/stream_int.go create mode 100644 discovery/vendor/github.com/json-iterator/go/stream_str.go create mode 100644 discovery/vendor/github.com/json-iterator/go/stream_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/array_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/builtin_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/map_key_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/map_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/marshaler_string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/marshaler_struct_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/slice_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/struct_embedded_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/struct_field_case_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/struct_tags_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/struct_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/text_marshaler_string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/text_marshaler_struct_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/type_tests/type_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/array_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/bool_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/eface_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/error_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/float_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/iface_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/int_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/invalid_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/map_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/marshaler_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/number_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/ptr_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/raw_message_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/slice_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/string_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/struct_test.go create mode 100644 discovery/vendor/github.com/json-iterator/go/value_tests/value_test.go delete mode 100644 discovery/vendor/github.com/juju/ratelimit/LICENSE delete mode 100644 discovery/vendor/github.com/juju/ratelimit/README.md delete mode 100644 discovery/vendor/github.com/juju/ratelimit/ratelimit.go delete mode 100644 discovery/vendor/github.com/juju/ratelimit/reader.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/.gitignore delete mode 100644 discovery/vendor/github.com/mailru/easyjson/LICENSE delete mode 100644 discovery/vendor/github.com/mailru/easyjson/Makefile delete mode 100644 discovery/vendor/github.com/mailru/easyjson/README.md delete mode 100644 discovery/vendor/github.com/mailru/easyjson/benchmark/data.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/benchmark/data_codec.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/benchmark/data_ffjson.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/benchmark/data_var.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/benchmark/example.json delete mode 100755 discovery/vendor/github.com/mailru/easyjson/benchmark/ujson.sh delete mode 100644 discovery/vendor/github.com/mailru/easyjson/bootstrap/bootstrap.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/buffer/pool.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/easyjson/main.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/gen/decoder.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/gen/encoder.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/gen/generator.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/helpers.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/jlexer/bytestostr.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/jlexer/bytestostr_nounsafe.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/jlexer/error.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/jlexer/lexer.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/jwriter/writer.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Bool.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Float32.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Float64.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Int.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Int16.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Int64.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Int8.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_String.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Uint.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Uint16.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Uint32.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Uint64.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/gotemplate_Uint8.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/optional/opt.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/opt/opts.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/parser/parser.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/parser/parser_unix.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/parser/parser_windows.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/raw.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/data.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/errors.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/named_type.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/nested_easy.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/nothing.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/omitempty.go delete mode 100644 discovery/vendor/github.com/mailru/easyjson/tests/snake.go create mode 100644 discovery/vendor/github.com/matttproud/golang_protobuf_extensions/.travis.yml create mode 100644 discovery/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go create mode 100644 discovery/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode_test.go create mode 100644 discovery/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode_test.go create mode 100644 discovery/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/.gitignore create mode 100644 discovery/vendor/github.com/modern-go/concurrent/.travis.yml create mode 100644 discovery/vendor/github.com/modern-go/concurrent/LICENSE create mode 100644 discovery/vendor/github.com/modern-go/concurrent/README.md create mode 100644 discovery/vendor/github.com/modern-go/concurrent/executor.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/go_above_19.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/go_below_19.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/log.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/map_test.go create mode 100755 discovery/vendor/github.com/modern-go/concurrent/test.sh create mode 100644 discovery/vendor/github.com/modern-go/concurrent/unbounded_executor.go create mode 100644 discovery/vendor/github.com/modern-go/concurrent/unbounded_executor_test.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/.gitignore create mode 100644 discovery/vendor/github.com/modern-go/reflect2/.travis.yml create mode 100644 discovery/vendor/github.com/modern-go/reflect2/Gopkg.lock create mode 100644 discovery/vendor/github.com/modern-go/reflect2/Gopkg.toml create mode 100644 discovery/vendor/github.com/modern-go/reflect2/LICENSE create mode 100644 discovery/vendor/github.com/modern-go/reflect2/README.md create mode 100644 discovery/vendor/github.com/modern-go/reflect2/go_above_17.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/go_above_19.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/go_below_17.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/go_below_19.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/reflect2.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/reflect2_amd64.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/reflect2_kind.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_386.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_amd64p32.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_arm.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_arm64.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_mips64x.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_mipsx.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_ppc64x.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/relfect2_s390x.s create mode 100644 discovery/vendor/github.com/modern-go/reflect2/safe_field.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/safe_map.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/safe_slice.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/safe_struct.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/safe_type.go create mode 100755 discovery/vendor/github.com/modern-go/reflect2/test.sh create mode 100644 discovery/vendor/github.com/modern-go/reflect2/type_map.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_array.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_eface.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_field.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_iface.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_link.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_map.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_ptr.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_slice.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_struct.go create mode 100644 discovery/vendor/github.com/modern-go/reflect2/unsafe_type.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/.gitignore delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/AUTHORS delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/LICENSE delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/README.md delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/doc/Sedgewick-LLRB.pdf delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/doc/Sedgewick-RedBlackBST.java delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/doc/Sedgewick-Talk-Penn2008.pdf delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/example/ex1.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/llrb/avgvar.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/llrb/iterator.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/llrb/llrb-stats.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/llrb/llrb.go delete mode 100644 discovery/vendor/github.com/petar/GoLLRB/llrb/util.go delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/LICENSE delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/README.md delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/compression.go delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/diskv.go delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/examples/content-addressable-store/cas.go delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/examples/super-simple-store/super-simple-store.go delete mode 100644 discovery/vendor/github.com/peterbourgon/diskv/index.go create mode 100644 discovery/vendor/github.com/pmezard/go-difflib/.travis.yml create mode 100644 discovery/vendor/github.com/pmezard/go-difflib/difflib/difflib_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/.travis.yml create mode 100644 discovery/vendor/github.com/prometheus/client_golang/api/prometheus/api_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/benchmark_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/counter_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/example_clustermanager_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/examples_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/go_collector_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/histogram_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/http_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/metric_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/process_collector_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/push/examples_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/push/push_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/registry_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/summary_test.go create mode 100644 discovery/vendor/github.com/prometheus/client_golang/prometheus/vec_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/.travis.yml create mode 100644 discovery/vendor/github.com/prometheus/common/config/http_config_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/config/tls_config_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/expfmt/bench_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/expfmt/decode_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/expfmt/text_create_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/expfmt/text_parse_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/log/log_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/log/syslog_formatter_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/alert_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/labels_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/metric_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/signature_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/silence_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/time_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/model/value_test.go create mode 100644 discovery/vendor/github.com/prometheus/common/route/route_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/.travis.yml create mode 100644 discovery/vendor/github.com/prometheus/procfs/bcache/get_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/buddyinfo_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/fs_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/ipvs_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/mdstat_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/mountstats_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/net_dev_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/nfs/parse_nfs_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/nfs/parse_nfsd_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/proc_io_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/proc_limits_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/proc_ns_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/proc_stat_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/proc_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/stat_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/sysfs/fs_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/sysfs/net_class_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/xfrm_test.go create mode 100644 discovery/vendor/github.com/prometheus/procfs/xfs/parse_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/.travis.yml create mode 100644 discovery/vendor/github.com/sirupsen/logrus/alt_exit_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/entry_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/example_basic_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/example_hook_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/formatter_bench_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/hook_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/hooks/test/test_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/json_formatter_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/logger_bench_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/logrus_test.go create mode 100644 discovery/vendor/github.com/sirupsen/logrus/text_formatter_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/.travis.yml create mode 100644 discovery/vendor/github.com/spf13/pflag/bool_slice_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/bool_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/count_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/example_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/export_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/flag_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/golangflag_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/int_slice_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/ip_slice_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/ip_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/ipnet_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/string_array_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/string_slice_test.go create mode 100644 discovery/vendor/github.com/spf13/pflag/uint_slice_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/.travis.yml create mode 100644 discovery/vendor/github.com/stretchr/testify/assert/assertions_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/assert/forward_assertions_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/assert/http_assertions_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/mock/mock_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/package_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/require/forward_requirements_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/require/requirements_test.go create mode 100644 discovery/vendor/github.com/stretchr/testify/suite/suite_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/acme_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/autocert/autocert_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/autocert/cache_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/autocert/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/autocert/renewal_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/jws_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/acme/types_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/bcrypt/bcrypt_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/blake2b/blake2b_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/blake2s/blake2s_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/blowfish/blowfish_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/bn256/bn256_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/bn256/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/cast5/cast5_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_vectors_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/chacha20poly1305/internal/chacha20/chacha_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/cryptobyte/asn1_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/cryptobyte/cryptobyte_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/cryptobyte/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/curve25519/curve25519_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ed25519/ed25519_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/hkdf/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/hkdf/hkdf_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/md4/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/md4/md4_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/auth/auth_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/auth/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/box/box_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/box/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/secretbox/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/nacl/secretbox/secretbox_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ocsp/ocsp_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/armor/armor_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/canonical_text_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/clearsign/clearsign_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/elgamal/elgamal_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/keys_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/compressed_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/encrypted_key_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/ocfb_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/opaque_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/packet_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/private_key_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/public_key_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/public_key_v3_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/signature_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/signature_v3_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/symmetric_key_encrypted_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/symmetrically_encrypted_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/userattribute_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/packet/userid_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/read_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/s2k/s2k_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/openpgp/write_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/otr/otr_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pbkdf2/pbkdf2_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/bmp-string_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/crypto_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/mac_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/pbkdf_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/pkcs12/pkcs12_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/poly1305/poly1305_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ripemd160/ripemd160_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/salsa20/salsa/salsa_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/salsa20/salsa20_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/scrypt/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/scrypt/scrypt_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/sha3/sha3_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/agent/client_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/agent/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/agent/keyring_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/agent/server_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/agent/testdata_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/benchmark_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/buffer_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/certs_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/cipher_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/client_auth_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/client_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/example_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/handshake_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/kex_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/keys_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/mempipe_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/messages_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/mux_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/session_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/tcpip_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/terminal/terminal_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/agent_unix_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/banner_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/cert_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/dial_unix_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/forward_unix_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/session_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/test_unix_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/test/testdata_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/testdata_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/ssh/transport_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/tea/tea_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/twofish/twofish_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/xtea/xtea_test.go create mode 100644 discovery/vendor/golang.org/x/crypto/xts/xts_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/instructions_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_aluop_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_bpf_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_extension_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_jump_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_load_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_ret_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_scratch_test.go create mode 100644 discovery/vendor/golang.org/x/net/bpf/vm_test.go create mode 100644 discovery/vendor/golang.org/x/net/context/context_test.go create mode 100644 discovery/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go create mode 100644 discovery/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17_test.go create mode 100644 discovery/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_test.go create mode 100644 discovery/vendor/golang.org/x/net/context/withtimeout_test.go create mode 100644 discovery/vendor/golang.org/x/net/dns/dnsmessage/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/dns/dnsmessage/message_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/atom/atom_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/atom/table_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/charset/charset_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/entity_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/escape_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/node_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/parse_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/render_test.go create mode 100644 discovery/vendor/golang.org/x/net/html/token_test.go create mode 100644 discovery/vendor/golang.org/x/net/http/httpproxy/export_test.go create mode 100644 discovery/vendor/golang.org/x/net/http/httpproxy/go19_test.go create mode 100644 discovery/vendor/golang.org/x/net/http/httpproxy/proxy_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/ciphers_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/databuffer_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/errors_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/flow_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/frame_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/go18_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/go19_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/gotrack_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/hpack/encode_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/hpack/hpack_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/hpack/tables_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/http2_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/pipe_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/server_push_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/server_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/transport_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/writesched_priority_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/writesched_random_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/writesched_test.go create mode 100644 discovery/vendor/golang.org/x/net/http2/z_spec_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/extension_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/ipv4_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/message_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/multipart_test.go create mode 100644 discovery/vendor/golang.org/x/net/icmp/ping_test.go create mode 100644 discovery/vendor/golang.org/x/net/idna/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/idna/idna_test.go create mode 100644 discovery/vendor/golang.org/x/net/idna/punycode_test.go create mode 100644 discovery/vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go create mode 100644 discovery/vendor/golang.org/x/net/internal/socket/socket_test.go create mode 100644 discovery/vendor/golang.org/x/net/internal/timeseries/timeseries_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/bpf_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/control_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/header_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/icmp_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/multicast_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/multicastlistener_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/multicastsockopt_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/readwrite_go1_8_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/readwrite_go1_9_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/readwrite_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/unicast_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv4/unicastsockopt_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/bpf_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/control_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/header_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/icmp_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/mocktransponder_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/multicast_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/multicastlistener_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/multicastsockopt_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/readwrite_go1_8_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/readwrite_go1_9_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/readwrite_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/sockopt_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/unicast_test.go create mode 100644 discovery/vendor/golang.org/x/net/ipv6/unicastsockopt_test.go create mode 100644 discovery/vendor/golang.org/x/net/lex/httplex/httplex_test.go create mode 100644 discovery/vendor/golang.org/x/net/lif/address_test.go create mode 100644 discovery/vendor/golang.org/x/net/lif/link_test.go create mode 100644 discovery/vendor/golang.org/x/net/nettest/conntest_test.go create mode 100644 discovery/vendor/golang.org/x/net/netutil/listen_test.go create mode 100644 discovery/vendor/golang.org/x/net/proxy/per_host_test.go create mode 100644 discovery/vendor/golang.org/x/net/proxy/proxy_test.go create mode 100644 discovery/vendor/golang.org/x/net/publicsuffix/list_test.go create mode 100644 discovery/vendor/golang.org/x/net/publicsuffix/table_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/address_darwin_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/address_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/message_darwin_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/message_freebsd_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/message_test.go create mode 100644 discovery/vendor/golang.org/x/net/route/route_test.go create mode 100644 discovery/vendor/golang.org/x/net/trace/histogram_test.go create mode 100644 discovery/vendor/golang.org/x/net/trace/trace_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/file_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/if_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/internal/xml/atom_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/internal/xml/example_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/internal/xml/marshal_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/internal/xml/read_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/internal/xml/xml_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/lock_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/prop_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/webdav_test.go create mode 100644 discovery/vendor/golang.org/x/net/webdav/xml_test.go create mode 100644 discovery/vendor/golang.org/x/net/websocket/dial_test.go create mode 100644 discovery/vendor/golang.org/x/net/websocket/exampledial_test.go create mode 100644 discovery/vendor/golang.org/x/net/websocket/examplehandler_test.go create mode 100644 discovery/vendor/golang.org/x/net/websocket/hybi_test.go create mode 100644 discovery/vendor/golang.org/x/net/websocket/websocket_test.go create mode 100644 discovery/vendor/golang.org/x/net/xsrftoken/xsrf_test.go create mode 100644 discovery/vendor/golang.org/x/sys/plan9/syscall_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/creds_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_darwin_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_dragonfly_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_linux_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_netbsd_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_openbsd_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/dev_solaris_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/export_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/mmap_unix_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/openbsd_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_bsd_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_freebsd_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_linux_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_solaris_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/syscall_unix_test.go create mode 100644 discovery/vendor/golang.org/x/sys/unix/timestruct_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/registry/export_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/registry/registry_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/svc/eventlog/log_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/svc/svc_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/syscall_test.go create mode 100644 discovery/vendor/golang.org/x/sys/windows/syscall_windows_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/context_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/fold_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/icu_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/map_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/tables10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/cases/tables9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/build/builder_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/build/colelem_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/build/contract_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/build/order_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/build/trie_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/collate_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/export_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/option_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/reg_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/sort_test.go create mode 100644 discovery/vendor/golang.org/x/text/collate/table_test.go create mode 100644 discovery/vendor/golang.org/x/text/currency/currency_test.go create mode 100644 discovery/vendor/golang.org/x/text/currency/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/currency/format_test.go create mode 100644 discovery/vendor/golang.org/x/text/currency/query_test.go create mode 100644 discovery/vendor/golang.org/x/text/currency/tables_test.go create mode 100644 discovery/vendor/golang.org/x/text/date/data_test.go create mode 100644 discovery/vendor/golang.org/x/text/date/gen_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/charmap/charmap_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/encoding_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/htmlindex/htmlindex_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/ianaindex/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/ianaindex/ianaindex_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/japanese/all_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/korean/all_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/simplifiedchinese/all_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/traditionalchinese/all_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/unicode/unicode_test.go create mode 100644 discovery/vendor/golang.org/x/text/encoding/unicode/utf32/utf32_test.go create mode 100644 discovery/vendor/golang.org/x/text/feature/plural/data_test.go create mode 100644 discovery/vendor/golang.org/x/text/feature/plural/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/feature/plural/message_test.go create mode 100644 discovery/vendor/golang.org/x/text/feature/plural/plural_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/catmsg/catmsg_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/catmsg/varint_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/cldrtree/cldrtree_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/collate_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/collelem_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/colltab_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/contract_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/iter_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/numeric_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/trie_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/colltab/weighter_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/common_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/gen10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/gen9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/idna10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/idna9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/idna_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/export/idna/punycode_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/format/parser_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/gen_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/internal_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/match_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/number/decimal_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/number/format_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/number/number_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/number/pattern_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/number/tables_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/stringset/set_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/tag/tag_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/triegen/data_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/triegen/example_compact_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/triegen/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/triegen/gen_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/ucd/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/internal/ucd/ucd_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/coverage_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/display/dict_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/display/display_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/display/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/httpexample_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/language_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/lookup_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/match_test.go create mode 100644 discovery/vendor/golang.org/x/text/language/parse_test.go create mode 100644 discovery/vendor/golang.org/x/text/message/catalog/catalog_test.go create mode 100644 discovery/vendor/golang.org/x/text/message/catalog_test.go create mode 100644 discovery/vendor/golang.org/x/text/message/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/message/fmt_test.go create mode 100644 discovery/vendor/golang.org/x/text/message/message_test.go create mode 100644 discovery/vendor/golang.org/x/text/number/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/number/format_test.go create mode 100644 discovery/vendor/golang.org/x/text/number/number_test.go create mode 100644 discovery/vendor/golang.org/x/text/runes/cond_test.go create mode 100644 discovery/vendor/golang.org/x/text/runes/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/runes/runes_test.go create mode 100644 discovery/vendor/golang.org/x/text/search/pattern_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/bidirule/bench_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/bidirule/bidirule_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/benchmark_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/class_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/enforce10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/enforce9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/enforce_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/profile_test.go create mode 100644 discovery/vendor/golang.org/x/text/secure/precis/tables_test.go create mode 100644 discovery/vendor/golang.org/x/text/transform/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/transform/transform_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/bidi/core_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/bidi/ranges_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/bidi/tables_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/cldr_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/collate_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/data_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/examples_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/resolve_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/cldr/slice_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/composition_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/data10.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/data9.0.0_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/example_iter_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/forminfo_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/iter_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/normalize_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/readwriter_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/transform_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/norm/ucd_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/rangetable/merge_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/rangetable/rangetable_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/runenames/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/unicode/runenames/runenames_test.go create mode 100644 discovery/vendor/golang.org/x/text/width/common_test.go create mode 100644 discovery/vendor/golang.org/x/text/width/example_test.go create mode 100644 discovery/vendor/golang.org/x/text/width/runes_test.go create mode 100644 discovery/vendor/golang.org/x/text/width/tables_test.go create mode 100644 discovery/vendor/golang.org/x/text/width/transform_test.go create mode 100644 discovery/vendor/golang.org/x/time/AUTHORS create mode 100644 discovery/vendor/golang.org/x/time/CONTRIBUTING.md create mode 100644 discovery/vendor/golang.org/x/time/CONTRIBUTORS create mode 100644 discovery/vendor/golang.org/x/time/LICENSE create mode 100644 discovery/vendor/golang.org/x/time/PATENTS create mode 100644 discovery/vendor/golang.org/x/time/README.md create mode 100644 discovery/vendor/golang.org/x/time/rate/rate.go create mode 100644 discovery/vendor/golang.org/x/time/rate/rate_go16.go create mode 100644 discovery/vendor/golang.org/x/time/rate/rate_go17.go create mode 100644 discovery/vendor/golang.org/x/time/rate/rate_test.go create mode 100644 discovery/vendor/golang.org/x/tools/benchmark/parse/parse_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/benchcmp/benchcmp_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/benchcmp/compare_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/bundle/main_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/callgraph/main_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/callgraph/testdata/src/pkg/pkg_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/cover/cover_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/digraph/digraph_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/fiximports/main_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/getgo/download_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/getgo/main_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/getgo/path_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/go-contrib-init/contrib_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/godoc/godoc19_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/godoc/godoc_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/gorename/cgo_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/gorename/gorename_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/guru/guru_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/guru/testdata/src/referrers/ext_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/guru/testdata/src/referrers/int_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/guru/unit_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/stringer/endtoend_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/stringer/golden_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/stringer/util_test.go create mode 100644 discovery/vendor/golang.org/x/tools/cmd/tip/tip_test.go create mode 100644 discovery/vendor/golang.org/x/tools/container/intsets/sparse_test.go create mode 100644 discovery/vendor/golang.org/x/tools/container/intsets/util_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ast/astutil/enclosing_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ast/astutil/imports_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ast/astutil/rewrite_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/buildutil/allpackages_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/buildutil/overlay_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/buildutil/tags_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/buildutil/util_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/buildutil/util_windows_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/callgraph/cha/cha_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/callgraph/rta/rta_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/callgraph/static/static_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gccgoexportdata/gccgoexportdata_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gcexportdata/example_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gcexportdata/gcexportdata_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gcimporter15/bexport19_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gcimporter15/bexport_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/gcimporter15/gcimporter_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/internal/gccgoimporter/gccgoinstallation_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/internal/gccgoimporter/importer19_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/internal/gccgoimporter/importer_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/internal/gccgoimporter/parser_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/internal/gccgoimporter/testenv_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/loader/example_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/loader/loader_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/loader/stdlib_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/pointer/example_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/pointer/pointer_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/pointer/query_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/pointer/stdlib_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/pointer/testdata/a_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/builder_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/example_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/identical_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/interp/interp_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/interp/testdata/a_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/interp/testdata/b_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/interp/testdata/c_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/source_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/stdlib_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/ssa/testmain_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/types/typeutil/example_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/types/typeutil/imports_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/types/typeutil/map_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/types/typeutil/ui_test.go create mode 100644 discovery/vendor/golang.org/x/tools/go/vcs/vcs_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/cmdline_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/dl/dl_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/godoc17_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/godoc_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/index_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/redirect/redirect_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/vfs/emptyvfs_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/vfs/mapfs/mapfs_test.go create mode 100644 discovery/vendor/golang.org/x/tools/godoc/vfs/zipfs/zipfs_test.go create mode 100644 discovery/vendor/golang.org/x/tools/imports/fastwalk_test.go create mode 100644 discovery/vendor/golang.org/x/tools/imports/fix_test.go create mode 100644 discovery/vendor/golang.org/x/tools/playground/socket/socket_test.go create mode 100644 discovery/vendor/golang.org/x/tools/present/code_test.go create mode 100644 discovery/vendor/golang.org/x/tools/present/link_test.go create mode 100644 discovery/vendor/golang.org/x/tools/present/style_test.go create mode 100644 discovery/vendor/golang.org/x/tools/refactor/eg/eg_test.go create mode 100644 discovery/vendor/golang.org/x/tools/refactor/importgraph/graph_test.go create mode 100644 discovery/vendor/golang.org/x/tools/refactor/rename/mvpkg_test.go create mode 100644 discovery/vendor/golang.org/x/tools/refactor/rename/rename_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/benchmark_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/dec_go1_2_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/dec_internal_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/dec_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/example_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/rounder_example_test.go create mode 100644 discovery/vendor/gopkg.in/inf.v0/rounder_test.go create mode 100644 discovery/vendor/gopkg.in/yaml.v2/.travis.yml create mode 100644 discovery/vendor/gopkg.in/yaml.v2/decode_test.go create mode 100644 discovery/vendor/gopkg.in/yaml.v2/encode_test.go create mode 100644 discovery/vendor/gopkg.in/yaml.v2/example_embedded_test.go create mode 100644 discovery/vendor/gopkg.in/yaml.v2/suite_test.go create mode 100644 discovery/vendor/k8s.io/api/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 discovery/vendor/k8s.io/api/CONTRIBUTING.md create mode 100644 discovery/vendor/k8s.io/api/Godeps/OWNERS create mode 100644 discovery/vendor/k8s.io/api/code-of-conduct.md create mode 100644 discovery/vendor/k8s.io/api/core/v1/taint_test.go create mode 100644 discovery/vendor/k8s.io/api/core/v1/toleration_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 discovery/vendor/k8s.io/apimachinery/CONTRIBUTING.md create mode 100644 discovery/vendor/k8s.io/apimachinery/Godeps/OWNERS create mode 100644 discovery/vendor/k8s.io/apimachinery/code-of-conduct.md delete mode 100755 discovery/vendor/k8s.io/apimachinery/hack/godep-deps.sh delete mode 100755 discovery/vendor/k8s.io/apimachinery/hack/sync-from-kubernetes.sh create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/errors/errors_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/meta/meta_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/meta/priority_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/meta/table/table.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/amount_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/math_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_example_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/resource/scale_int_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/testing/fuzzer/valuefuzz_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/api/validation/path/name_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apimachinery/announced/announced_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apimachinery/registered/registered_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apimachinery/types_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/register_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/roundtrip_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/controller_ref_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/conversion_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/duration_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/group_version_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/labels_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/types_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_list_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation_test.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/conversion.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/doc.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/register.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/types.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/types_swagger_doc_generated.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/zz_generated.deepcopy.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/zz_generated.defaults.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/conversion.go rename discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/{v1alpha1 => v1beta1}/deepcopy.go (98%) create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/doc.go rename discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/{v1alpha1 => v1beta1}/generated.pb.go (83%) rename discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/{v1alpha1 => v1beta1}/generated.proto (94%) create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/register.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types_swagger_doc_generated.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.deepcopy.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.defaults.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/testapigroup/install/roundtrip_test.go delete mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/apis/testapigroup/v1/types_swagger_doc_generated.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/conversion/converter_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/conversion/helper_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/conversion/queryparams/convert_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/fields/fields_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/fields/selector_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/labels/labels_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/labels/selector_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/conversion_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/converter_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/embedded_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/extension_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/scheme_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/meta_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing/recognizer_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/api_meta_help_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/api_meta_meta_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/runtime_helper_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/test/runtime_unversioned_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/cache/cache_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/cache/lruexpirecache_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/clock/clock_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/diff/diff_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/duration/duration.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/errors/errors_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/framer/framer_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/httpstream/httpstream_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/connection_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/upgrade_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/intstr/intstr_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/json/json_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/jsonmergepatch/patch_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/mergepatch/util_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/net/http_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/net/interface_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/net/port_range_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/net/port_split_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/net/util_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/proxy/dial_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/proxy/transport_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/proxy/upgradeaware_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/rand/rand_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/sets/set_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/validation/field/errors_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/validation/field/path_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/validation/validation_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/wait/wait_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/waitgroup/waitgroup_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/watch/filter_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/watch/mux_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/watch/streamwatcher_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/watch/until_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/pkg/watch/watch_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/third_party/forked/golang/json/fields_test.go create mode 100644 discovery/vendor/k8s.io/apimachinery/third_party/forked/golang/reflect/deep_equal_test.go create mode 100644 discovery/vendor/k8s.io/client-go/.travis.yml create mode 100644 discovery/vendor/k8s.io/client-go/CONTRIBUTING.md create mode 100644 discovery/vendor/k8s.io/client-go/Godeps/OWNERS create mode 100644 discovery/vendor/k8s.io/client-go/code-of-conduct.md create mode 100644 discovery/vendor/k8s.io/client-go/discovery/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/discovery/cached/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/discovery/cached/memcache_test.go create mode 100644 discovery/vendor/k8s.io/client-go/discovery/discovery_client_test.go create mode 100644 discovery/vendor/k8s.io/client-go/discovery/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/discovery/fake/discovery_test.go create mode 100644 discovery/vendor/k8s.io/client-go/discovery/helper_blackbox_test.go create mode 100644 discovery/vendor/k8s.io/client-go/discovery/restmapper_test.go create mode 100644 discovery/vendor/k8s.io/client-go/dynamic/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/dynamic/client_test.go create mode 100644 discovery/vendor/k8s.io/client-go/dynamic/dynamic_util_test.go create mode 100644 discovery/vendor/k8s.io/client-go/dynamic/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/examples/create-update-delete-deployment/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/examples/workqueue/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/admissionregistration/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/admissionregistration/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/admissionregistration/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/apps/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/apps/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/apps/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/apps/v1beta2/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/autoscaling/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/autoscaling/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/autoscaling/v2beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/batch/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/batch/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/batch/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/batch/v2alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/certificates/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/certificates/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/core/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/core/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/events/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/events/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/extensions/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/extensions/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/internalinterfaces/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/networking/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/networking/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/policy/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/policy/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/policy/v1beta1/podsecuritypolicy.go create mode 100644 discovery/vendor/k8s.io/client-go/informers/rbac/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/rbac/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/rbac/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/rbac/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/scheduling/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/scheduling/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/settings/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/settings/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/storage/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/storage/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/storage/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/storage/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/informers/storage/v1beta1/volumeattachment.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/scheme/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/admissionregistration/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/admissionregistration/v1alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1beta2/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/apps/v1beta2/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authentication/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authentication/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authentication/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authentication/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authorization/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authorization/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authorization/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/authorization/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/autoscaling/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/autoscaling/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/autoscaling/v2beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/autoscaling/v2beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v2alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/batch/v2alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/core/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/core/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/core/v1/fake/fake_serviceaccount_expansion.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/core/v1/serviceaccount_expansion.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/events/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/events/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/networking/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/networking/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/policy/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/policy/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/policy/v1beta1/fake/fake_podsecuritypolicy.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/policy/v1beta1/podsecuritypolicy.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/rbac/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/scheduling/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/scheduling/v1alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/settings/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/settings/v1alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1alpha1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1/fake/fake_volumeattachment.go create mode 100644 discovery/vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1/volumeattachment.go create mode 100644 discovery/vendor/k8s.io/client-go/listers/admissionregistration/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/admissionregistration/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/apps/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/apps/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/apps/v1beta2/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/authentication/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/authentication/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/authorization/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/authorization/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/autoscaling/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/autoscaling/v2beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/batch/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/batch/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/batch/v2alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/certificates/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/core/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/events/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/extensions/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/extensions/v1beta1/daemonset_expansion_test.go create mode 100644 discovery/vendor/k8s.io/client-go/listers/imagepolicy/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/networking/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/policy/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/policy/v1beta1/podsecuritypolicy.go create mode 100644 discovery/vendor/k8s.io/client-go/listers/rbac/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/rbac/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/rbac/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/scheduling/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/settings/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/storage/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/storage/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/storage/v1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/listers/storage/v1beta1/volumeattachment.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/doc.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/install/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/install/install.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/register.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/types.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/doc.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/register.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/types.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/zz_generated.conversion.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/zz_generated.deepcopy.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1/zz_generated.defaults.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/apis/clientauthentication/zz_generated.deepcopy.go create mode 100644 discovery/vendor/k8s.io/client-go/pkg/version/BUILD delete mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/auth/authenticator/token/oidc/testing/provider.go create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/azure/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/azure/azure_test.go create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/exec.go create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/exec_test.go create mode 100755 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/testdata/test-plugin.sh create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/gcp/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp_test.go create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/oidc/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/oidc/oidc_test.go create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/openstack/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/plugin/pkg/client/auth/openstack/openstack_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/rest/client_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/config_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/rest/plugin_test.go create mode 100755 discovery/vendor/k8s.io/client-go/rest/request_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/url_utils_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/urlbackoff_test.go delete mode 100644 discovery/vendor/k8s.io/client-go/rest/versions.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/watch/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/rest/watch/decoder_test.go create mode 100644 discovery/vendor/k8s.io/client-go/rest/watch/encoder_test.go create mode 100644 discovery/vendor/k8s.io/client-go/scale/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/client_test.go create mode 100644 discovery/vendor/k8s.io/client-go/scale/fake/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/roundtrip_test.go create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/appsint/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/appsv1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/appsv1beta2/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/autoscalingv1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/extensionsint/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/scale/scheme/extensionsv1beta1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/testing/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/testing/fixture_test.go create mode 100644 discovery/vendor/k8s.io/client-go/third_party/forked/golang/template/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/auth/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/auth/clientauth_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/api/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/api/OWNERS create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/api/doc.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/api/types.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/util/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/util/helpers.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/bootstrap/token/util/helpers_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/controller_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/expiration_cache_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/fifo_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/heap_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/index_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/mutation_detector_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/processor_listener_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/reflector_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/shared_informer_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/store_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/testing/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/testing/fake_controller_source_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/cache/undelta_store_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/api/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/api/helpers_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/api/latest/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/loader_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/merged_client_builder_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/overrides_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/clientcmd/validation_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/leaderelection/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/metrics/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/pager/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/pager/pager_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/portforward/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/portforward/portforward_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/record/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/record/event_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/record/events_cache_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/reference/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/remotecommand/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/tools/remotecommand/v2_test.go create mode 100644 discovery/vendor/k8s.io/client-go/tools/remotecommand/v4_test.go create mode 100644 discovery/vendor/k8s.io/client-go/transport/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/transport/cache_test.go create mode 100644 discovery/vendor/k8s.io/client-go/transport/round_trippers_test.go create mode 100644 discovery/vendor/k8s.io/client-go/transport/spdy/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/transport/transport_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/buffer/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/buffer/ring_growing_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/cert/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/cert/csr_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/cert/pem_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/cert/triple/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/certificate/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/certificate/certificate_store_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/certificate/csr/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/certificate/csr/csr_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/exec/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/flowcontrol/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/flowcontrol/backoff_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/homedir/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/integer/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/integer/integer_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/jsonpath/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/jsonpath/jsonpath_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/jsonpath/parser_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/retry/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/retry/util_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/testing/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/testing/fake_handler_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/workqueue/BUILD create mode 100644 discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/workqueue/queue_test.go create mode 100644 discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue_test.go create mode 100644 discovery/vendor/k8s.io/code-generator/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 discovery/vendor/k8s.io/code-generator/CONTRIBUTING.md create mode 100644 discovery/vendor/k8s.io/code-generator/Godeps/OWNERS delete mode 100644 discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversions.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags_test.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers_test.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/args/args.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/args/args.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/args/args.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/namer_test.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go delete mode 100644 discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/customargs.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go create mode 100644 discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/args/args.go create mode 100644 discovery/vendor/k8s.io/code-generator/code-of-conduct.md create mode 100644 discovery/vendor/k8s.io/code-generator/hack/boilerplate.go.txt create mode 100644 discovery/vendor/k8s.io/code-generator/pkg/util/build.go create mode 100644 discovery/vendor/k8s.io/gengo/.travis.yml create mode 100644 discovery/vendor/k8s.io/gengo/args/args_test.go create mode 100644 discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy_test.go create mode 100644 discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go create mode 100644 discovery/vendor/k8s.io/gengo/examples/go-to-protobuf/protobuf/namer_test.go create mode 100644 discovery/vendor/k8s.io/gengo/examples/import-boss/generators/import_restrict_test.go create mode 100644 discovery/vendor/k8s.io/gengo/examples/set-gen/sets/set_test.go create mode 100644 discovery/vendor/k8s.io/gengo/generator/snippet_writer_test.go create mode 100644 discovery/vendor/k8s.io/gengo/namer/namer_test.go create mode 100644 discovery/vendor/k8s.io/gengo/namer/plural_namer_test.go create mode 100644 discovery/vendor/k8s.io/gengo/parser/local_parse_test.go create mode 100644 discovery/vendor/k8s.io/gengo/parser/parse_test.go create mode 100644 discovery/vendor/k8s.io/gengo/types/comments_test.go create mode 100644 discovery/vendor/k8s.io/gengo/types/flatten_test.go create mode 100644 discovery/vendor/k8s.io/gengo/types/types_test.go create mode 100644 discovery/vendor/k8s.io/kube-openapi/.travis.yml create mode 100644 discovery/vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator_test.go create mode 100644 discovery/vendor/k8s.io/kube-openapi/pkg/builder/openapi_test.go create mode 100644 discovery/vendor/k8s.io/kube-openapi/pkg/generators/openapi_test.go create mode 100644 discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_suite_test.go create mode 100644 discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_test.go diff --git a/discovery/Gopkg.lock b/discovery/Gopkg.lock index 325b75e0..c9e08ba3 100644 --- a/discovery/Gopkg.lock +++ b/discovery/Gopkg.lock @@ -1,18 +1,6 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. -[[projects]] - name = "github.com/PuerkitoBio/purell" - packages = ["."] - revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4" - version = "v1.1.0" - -[[projects]] - branch = "master" - name = "github.com/PuerkitoBio/urlesc" - packages = ["."] - revision = "de5bf2ad457846296e2031421a34e2568e304e35" - [[projects]] branch = "master" name = "github.com/beorn7/perks" @@ -25,45 +13,12 @@ revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" -[[projects]] - name = "github.com/emicklei/go-restful" - packages = [ - ".", - "log" - ] - revision = "5741799b275a3c4a5a9623a993576d7545cf7b5c" - version = "v2.4.0" - [[projects]] name = "github.com/ghodss/yaml" packages = ["."] revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" version = "v1.0.0" -[[projects]] - branch = "master" - name = "github.com/go-openapi/jsonpointer" - packages = ["."] - revision = "779f45308c19820f1a69e9a4cd965f496e0da10f" - -[[projects]] - branch = "master" - name = "github.com/go-openapi/jsonreference" - packages = ["."] - revision = "36d33bfe519efae5632669801b180bf1a245da3b" - -[[projects]] - branch = "master" - name = "github.com/go-openapi/spec" - packages = ["."] - revision = "01738944bdee0f26bf66420c5b17d54cfdf55341" - -[[projects]] - branch = "master" - name = "github.com/go-openapi/swag" - packages = ["."] - revision = "cf0bdb963811675a4d7e74901cefc7411a1df939" - [[projects]] name = "github.com/gogo/protobuf" packages = [ @@ -91,12 +46,6 @@ ] revision = "1e59b77b52bf8e4b449a57e6f79f21226d571845" -[[projects]] - branch = "master" - name = "github.com/google/btree" - packages = ["."] - revision = "316fb6d3f031ae8f4d457c6c5186b9e3ded70435" - [[projects]] branch = "master" name = "github.com/google/gofuzz" @@ -114,7 +63,6 @@ version = "v0.1.0" [[projects]] - branch = "master" name = "github.com/gophercloud/gophercloud" packages = [ ".", @@ -130,16 +78,7 @@ "openstack/utils", "pagination" ] - revision = "104e2578924bb3b211150c19414d0144b82165bb" - -[[projects]] - branch = "master" - name = "github.com/gregjones/httpcache" - packages = [ - ".", - "diskcache" - ] - revision = "2bcd89a1743fd4b373f7370ce8ddc14dfbd18229" + revision = "f8826f28e31a2f66e771939532bcae910ed2420f" [[projects]] branch = "master" @@ -165,24 +104,7 @@ [[projects]] name = "github.com/json-iterator/go" packages = ["."] - revision = "f7279a603edee96fe7764d3de9c6ff8cf9970994" - version = "1.0.4" - -[[projects]] - branch = "master" - name = "github.com/juju/ratelimit" - packages = ["."] - revision = "59fac5042749a5afb9af70e813da1dd5474f0167" - -[[projects]] - branch = "master" - name = "github.com/mailru/easyjson" - packages = [ - "buffer", - "jlexer", - "jwriter" - ] - revision = "32fa128f234d041f196a9f3e0fea5ac9772c08e1" + revision = "f2b4162afba35581b6d4a50d3b8f34e33c144682" [[projects]] name = "github.com/matttproud/golang_protobuf_extensions" @@ -191,16 +113,16 @@ version = "v1.0.0" [[projects]] - branch = "master" - name = "github.com/petar/GoLLRB" - packages = ["llrb"] - revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" + name = "github.com/modern-go/concurrent" + packages = ["."] + revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" + version = "1.0.3" [[projects]] - name = "github.com/peterbourgon/diskv" + name = "github.com/modern-go/reflect2" packages = ["."] - revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" - version = "v2.0.1" + revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" + version = "1.0.1" [[projects]] name = "github.com/pmezard/go-difflib" @@ -247,8 +169,8 @@ [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] - revision = "d682213848ed68c0a260ca37d6dd5ace8423f5ba" - version = "v1.0.4" + revision = "3e01752db0189b9157070a0e1668a620f9a85da2" + version = "v1.0.6" [[projects]] name = "github.com/spf13/pflag" @@ -309,11 +231,16 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable", - "width" + "unicode/rangetable" ] revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" +[[projects]] + branch = "master" + name = "golang.org/x/time" + packages = ["rate"] + revision = "fbb02b2291d28baffd63558aa44b4b56f178d650" + [[projects]] branch = "master" name = "golang.org/x/tools" @@ -336,7 +263,7 @@ revision = "287cf08546ab5e7e37d55a84f7ed3fd1db036de5" [[projects]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/api" packages = [ "admissionregistration/v1alpha1", @@ -368,10 +295,10 @@ "storage/v1alpha1", "storage/v1beta1" ] - revision = "acf347b865f29325eb61f4cd2df11e86e073a5ee" + revision = "0f11257a8a25954878633ebdc9841c67d8f83bdb" [[projects]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -382,7 +309,7 @@ "pkg/apis/meta/internalversion", "pkg/apis/meta/v1", "pkg/apis/meta/v1/unstructured", - "pkg/apis/meta/v1alpha1", + "pkg/apis/meta/v1beta1", "pkg/conversion", "pkg/conversion/queryparams", "pkg/fields", @@ -418,7 +345,7 @@ "third_party/forked/golang/json", "third_party/forked/golang/reflect" ] - revision = "19e3f5aa3adca672c153d324e6b7d82ff8935f03" + revision = "e386b2658ed20923da8cc9250e552f082899a1ee" [[projects]] name = "k8s.io/client-go" @@ -548,7 +475,10 @@ "listers/storage/v1", "listers/storage/v1alpha1", "listers/storage/v1beta1", + "pkg/apis/clientauthentication", + "pkg/apis/clientauthentication/v1alpha1", "pkg/version", + "plugin/pkg/client/auth/exec", "rest", "rest/watch", "testing", @@ -567,13 +497,14 @@ "util/flowcontrol", "util/homedir", "util/integer", + "util/retry", "util/workqueue" ] - revision = "78700dec6369ba22221b72770783300f143df150" - version = "v6.0.0" + revision = "23781f4d6632d88e869066eaebb743857aa1ef9b" + version = "v7.0.0" [[projects]] - branch = "release-1.9" + branch = "release-1.10" name = "k8s.io/code-generator" packages = [ "cmd/client-gen", @@ -585,13 +516,18 @@ "cmd/client-gen/path", "cmd/client-gen/types", "cmd/deepcopy-gen", + "cmd/deepcopy-gen/args", "cmd/defaulter-gen", + "cmd/defaulter-gen/args", "cmd/informer-gen", + "cmd/informer-gen/args", "cmd/informer-gen/generators", "cmd/lister-gen", - "cmd/lister-gen/generators" + "cmd/lister-gen/args", + "cmd/lister-gen/generators", + "pkg/util" ] - revision = "91d3f6a57905178524105a085085901bb73bd3dc" + revision = "9de8e796a74d16d2a285165727d04c185ebca6dc" [[projects]] branch = "master" @@ -611,15 +547,12 @@ [[projects]] branch = "master" name = "k8s.io/kube-openapi" - packages = [ - "pkg/common", - "pkg/util/proto" - ] + packages = ["pkg/util/proto"] revision = "b16ebc07f5cad97831f961e4b5a9cc1caed33b7e" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "fb8ac300e348c67e9f0a2504f00f59fa02f8618cfa17bbfd1c98abbe53671e6b" + inputs-digest = "1762b0dc3856d92ac5f1b43afb4f101f32b143e743e62304050c352e9855ea95" solver-name = "gps-cdcl" solver-version = 1 diff --git a/discovery/vendor/github.com/PuerkitoBio/purell/.gitignore b/discovery/vendor/github.com/PuerkitoBio/purell/.gitignore deleted file mode 100644 index 748e4c80..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/purell/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.sublime-* -.DS_Store -*.swp -*.swo -tags diff --git a/discovery/vendor/github.com/PuerkitoBio/purell/LICENSE b/discovery/vendor/github.com/PuerkitoBio/purell/LICENSE deleted file mode 100644 index 4b9986de..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/purell/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ -Copyright (c) 2012, Martin Angers -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/discovery/vendor/github.com/PuerkitoBio/purell/README.md b/discovery/vendor/github.com/PuerkitoBio/purell/README.md deleted file mode 100644 index 09e8a32c..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/purell/README.md +++ /dev/null @@ -1,187 +0,0 @@ -# Purell - -Purell is a tiny Go library to normalize URLs. It returns a pure URL. Pure-ell. Sanitizer and all. Yeah, I know... - -Based on the [wikipedia paper][wiki] and the [RFC 3986 document][rfc]. - -[![build status](https://secure.travis-ci.org/PuerkitoBio/purell.png)](http://travis-ci.org/PuerkitoBio/purell) - -## Install - -`go get github.com/PuerkitoBio/purell` - -## Changelog - -* **2016-11-14 (v1.1.0)** : IDN: Conform to RFC 5895: Fold character width (thanks to @beeker1121). -* **2016-07-27 (v1.0.0)** : Normalize IDN to ASCII (thanks to @zenovich). -* **2015-02-08** : Add fix for relative paths issue ([PR #5][pr5]) and add fix for unnecessary encoding of reserved characters ([see issue #7][iss7]). -* **v0.2.0** : Add benchmarks, Attempt IDN support. -* **v0.1.0** : Initial release. - -## Examples - -From `example_test.go` (note that in your code, you would import "github.com/PuerkitoBio/purell", and would prefix references to its methods and constants with "purell."): - -```go -package purell - -import ( - "fmt" - "net/url" -) - -func ExampleNormalizeURLString() { - if normalized, err := NormalizeURLString("hTTp://someWEBsite.com:80/Amazing%3f/url/", - FlagLowercaseScheme|FlagLowercaseHost|FlagUppercaseEscapes); err != nil { - panic(err) - } else { - fmt.Print(normalized) - } - // Output: http://somewebsite.com:80/Amazing%3F/url/ -} - -func ExampleMustNormalizeURLString() { - normalized := MustNormalizeURLString("hTTpS://someWEBsite.com:443/Amazing%fa/url/", - FlagsUnsafeGreedy) - fmt.Print(normalized) - - // Output: http://somewebsite.com/Amazing%FA/url -} - -func ExampleNormalizeURL() { - if u, err := url.Parse("Http://SomeUrl.com:8080/a/b/.././c///g?c=3&a=1&b=9&c=0#target"); err != nil { - panic(err) - } else { - normalized := NormalizeURL(u, FlagsUsuallySafeGreedy|FlagRemoveDuplicateSlashes|FlagRemoveFragment) - fmt.Print(normalized) - } - - // Output: http://someurl.com:8080/a/c/g?c=3&a=1&b=9&c=0 -} -``` - -## API - -As seen in the examples above, purell offers three methods, `NormalizeURLString(string, NormalizationFlags) (string, error)`, `MustNormalizeURLString(string, NormalizationFlags) (string)` and `NormalizeURL(*url.URL, NormalizationFlags) (string)`. They all normalize the provided URL based on the specified flags. Here are the available flags: - -```go -const ( - // Safe normalizations - FlagLowercaseScheme NormalizationFlags = 1 << iota // HTTP://host -> http://host, applied by default in Go1.1 - FlagLowercaseHost // http://HOST -> http://host - FlagUppercaseEscapes // http://host/t%ef -> http://host/t%EF - FlagDecodeUnnecessaryEscapes // http://host/t%41 -> http://host/tA - FlagEncodeNecessaryEscapes // http://host/!"#$ -> http://host/%21%22#$ - FlagRemoveDefaultPort // http://host:80 -> http://host - FlagRemoveEmptyQuerySeparator // http://host/path? -> http://host/path - - // Usually safe normalizations - FlagRemoveTrailingSlash // http://host/path/ -> http://host/path - FlagAddTrailingSlash // http://host/path -> http://host/path/ (should choose only one of these add/remove trailing slash flags) - FlagRemoveDotSegments // http://host/path/./a/b/../c -> http://host/path/a/c - - // Unsafe normalizations - FlagRemoveDirectoryIndex // http://host/path/index.html -> http://host/path/ - FlagRemoveFragment // http://host/path#fragment -> http://host/path - FlagForceHTTP // https://host -> http://host - FlagRemoveDuplicateSlashes // http://host/path//a///b -> http://host/path/a/b - FlagRemoveWWW // http://www.host/ -> http://host/ - FlagAddWWW // http://host/ -> http://www.host/ (should choose only one of these add/remove WWW flags) - FlagSortQuery // http://host/path?c=3&b=2&a=1&b=1 -> http://host/path?a=1&b=1&b=2&c=3 - - // Normalizations not in the wikipedia article, required to cover tests cases - // submitted by jehiah - FlagDecodeDWORDHost // http://1113982867 -> http://66.102.7.147 - FlagDecodeOctalHost // http://0102.0146.07.0223 -> http://66.102.7.147 - FlagDecodeHexHost // http://0x42660793 -> http://66.102.7.147 - FlagRemoveUnnecessaryHostDots // http://.host../path -> http://host/path - FlagRemoveEmptyPortSeparator // http://host:/path -> http://host/path - - // Convenience set of safe normalizations - FlagsSafe NormalizationFlags = FlagLowercaseHost | FlagLowercaseScheme | FlagUppercaseEscapes | FlagDecodeUnnecessaryEscapes | FlagEncodeNecessaryEscapes | FlagRemoveDefaultPort | FlagRemoveEmptyQuerySeparator - - // For convenience sets, "greedy" uses the "remove trailing slash" and "remove www. prefix" flags, - // while "non-greedy" uses the "add (or keep) the trailing slash" and "add www. prefix". - - // Convenience set of usually safe normalizations (includes FlagsSafe) - FlagsUsuallySafeGreedy NormalizationFlags = FlagsSafe | FlagRemoveTrailingSlash | FlagRemoveDotSegments - FlagsUsuallySafeNonGreedy NormalizationFlags = FlagsSafe | FlagAddTrailingSlash | FlagRemoveDotSegments - - // Convenience set of unsafe normalizations (includes FlagsUsuallySafe) - FlagsUnsafeGreedy NormalizationFlags = FlagsUsuallySafeGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagRemoveWWW | FlagSortQuery - FlagsUnsafeNonGreedy NormalizationFlags = FlagsUsuallySafeNonGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagAddWWW | FlagSortQuery - - // Convenience set of all available flags - FlagsAllGreedy = FlagsUnsafeGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator - FlagsAllNonGreedy = FlagsUnsafeNonGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator -) -``` - -For convenience, the set of flags `FlagsSafe`, `FlagsUsuallySafe[Greedy|NonGreedy]`, `FlagsUnsafe[Greedy|NonGreedy]` and `FlagsAll[Greedy|NonGreedy]` are provided for the similarly grouped normalizations on [wikipedia's URL normalization page][wiki]. You can add (using the bitwise OR `|` operator) or remove (using the bitwise AND NOT `&^` operator) individual flags from the sets if required, to build your own custom set. - -The [full godoc reference is available on gopkgdoc][godoc]. - -Some things to note: - -* `FlagDecodeUnnecessaryEscapes`, `FlagEncodeNecessaryEscapes`, `FlagUppercaseEscapes` and `FlagRemoveEmptyQuerySeparator` are always implicitly set, because internally, the URL string is parsed as an URL object, which automatically decodes unnecessary escapes, uppercases and encodes necessary ones, and removes empty query separators (an unnecessary `?` at the end of the url). So this operation cannot **not** be done. For this reason, `FlagRemoveEmptyQuerySeparator` (as well as the other three) has been included in the `FlagsSafe` convenience set, instead of `FlagsUnsafe`, where Wikipedia puts it. - -* The `FlagDecodeUnnecessaryEscapes` decodes the following escapes (*from -> to*): - - %24 -> $ - - %26 -> & - - %2B-%3B -> +,-./0123456789:; - - %3D -> = - - %40-%5A -> @ABCDEFGHIJKLMNOPQRSTUVWXYZ - - %5F -> _ - - %61-%7A -> abcdefghijklmnopqrstuvwxyz - - %7E -> ~ - - -* When the `NormalizeURL` function is used (passing an URL object), this source URL object is modified (that is, after the call, the URL object will be modified to reflect the normalization). - -* The *replace IP with domain name* normalization (`http://208.77.188.166/ → http://www.example.com/`) is obviously not possible for a library without making some network requests. This is not implemented in purell. - -* The *remove unused query string parameters* and *remove default query parameters* are also not implemented, since this is a very case-specific normalization, and it is quite trivial to do with an URL object. - -### Safe vs Usually Safe vs Unsafe - -Purell allows you to control the level of risk you take while normalizing an URL. You can aggressively normalize, play it totally safe, or anything in between. - -Consider the following URL: - -`HTTPS://www.RooT.com/toto/t%45%1f///a/./b/../c/?z=3&w=2&a=4&w=1#invalid` - -Normalizing with the `FlagsSafe` gives: - -`https://www.root.com/toto/tE%1F///a/./b/../c/?z=3&w=2&a=4&w=1#invalid` - -With the `FlagsUsuallySafeGreedy`: - -`https://www.root.com/toto/tE%1F///a/c?z=3&w=2&a=4&w=1#invalid` - -And with `FlagsUnsafeGreedy`: - -`http://root.com/toto/tE%1F/a/c?a=4&w=1&w=2&z=3` - -## TODOs - -* Add a class/default instance to allow specifying custom directory index names? At the moment, removing directory index removes `(^|/)((?:default|index)\.\w{1,4})$`. - -## Thanks / Contributions - -@rogpeppe -@jehiah -@opennota -@pchristopher1275 -@zenovich -@beeker1121 - -## License - -The [BSD 3-Clause license][bsd]. - -[bsd]: http://opensource.org/licenses/BSD-3-Clause -[wiki]: http://en.wikipedia.org/wiki/URL_normalization -[rfc]: http://tools.ietf.org/html/rfc3986#section-6 -[godoc]: http://go.pkgdoc.org/github.com/PuerkitoBio/purell -[pr5]: https://github.com/PuerkitoBio/purell/pull/5 -[iss7]: https://github.com/PuerkitoBio/purell/issues/7 diff --git a/discovery/vendor/github.com/PuerkitoBio/purell/benchmarks/v0.1.0 b/discovery/vendor/github.com/PuerkitoBio/purell/benchmarks/v0.1.0 deleted file mode 100644 index 3bbe7113..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/purell/benchmarks/v0.1.0 +++ /dev/null @@ -1,9 +0,0 @@ -PASS -BenchmarkSafe 500000 6131 ns/op -BenchmarkUsuallySafe 200000 7864 ns/op -BenchmarkUnsafe 100000 28560 ns/op -BenchmarkAllDWORD 50000 38722 ns/op -BenchmarkAllOctal 50000 40941 ns/op -BenchmarkAllHex 50000 44063 ns/op -BenchmarkAllCombined 50000 33613 ns/op -ok github.com/PuerkitoBio/purell 17.404s diff --git a/discovery/vendor/github.com/PuerkitoBio/purell/purell.go b/discovery/vendor/github.com/PuerkitoBio/purell/purell.go deleted file mode 100644 index 645e1b76..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/purell/purell.go +++ /dev/null @@ -1,379 +0,0 @@ -/* -Package purell offers URL normalization as described on the wikipedia page: -http://en.wikipedia.org/wiki/URL_normalization -*/ -package purell - -import ( - "bytes" - "fmt" - "net/url" - "regexp" - "sort" - "strconv" - "strings" - - "github.com/PuerkitoBio/urlesc" - "golang.org/x/net/idna" - "golang.org/x/text/unicode/norm" - "golang.org/x/text/width" -) - -// A set of normalization flags determines how a URL will -// be normalized. -type NormalizationFlags uint - -const ( - // Safe normalizations - FlagLowercaseScheme NormalizationFlags = 1 << iota // HTTP://host -> http://host, applied by default in Go1.1 - FlagLowercaseHost // http://HOST -> http://host - FlagUppercaseEscapes // http://host/t%ef -> http://host/t%EF - FlagDecodeUnnecessaryEscapes // http://host/t%41 -> http://host/tA - FlagEncodeNecessaryEscapes // http://host/!"#$ -> http://host/%21%22#$ - FlagRemoveDefaultPort // http://host:80 -> http://host - FlagRemoveEmptyQuerySeparator // http://host/path? -> http://host/path - - // Usually safe normalizations - FlagRemoveTrailingSlash // http://host/path/ -> http://host/path - FlagAddTrailingSlash // http://host/path -> http://host/path/ (should choose only one of these add/remove trailing slash flags) - FlagRemoveDotSegments // http://host/path/./a/b/../c -> http://host/path/a/c - - // Unsafe normalizations - FlagRemoveDirectoryIndex // http://host/path/index.html -> http://host/path/ - FlagRemoveFragment // http://host/path#fragment -> http://host/path - FlagForceHTTP // https://host -> http://host - FlagRemoveDuplicateSlashes // http://host/path//a///b -> http://host/path/a/b - FlagRemoveWWW // http://www.host/ -> http://host/ - FlagAddWWW // http://host/ -> http://www.host/ (should choose only one of these add/remove WWW flags) - FlagSortQuery // http://host/path?c=3&b=2&a=1&b=1 -> http://host/path?a=1&b=1&b=2&c=3 - - // Normalizations not in the wikipedia article, required to cover tests cases - // submitted by jehiah - FlagDecodeDWORDHost // http://1113982867 -> http://66.102.7.147 - FlagDecodeOctalHost // http://0102.0146.07.0223 -> http://66.102.7.147 - FlagDecodeHexHost // http://0x42660793 -> http://66.102.7.147 - FlagRemoveUnnecessaryHostDots // http://.host../path -> http://host/path - FlagRemoveEmptyPortSeparator // http://host:/path -> http://host/path - - // Convenience set of safe normalizations - FlagsSafe NormalizationFlags = FlagLowercaseHost | FlagLowercaseScheme | FlagUppercaseEscapes | FlagDecodeUnnecessaryEscapes | FlagEncodeNecessaryEscapes | FlagRemoveDefaultPort | FlagRemoveEmptyQuerySeparator - - // For convenience sets, "greedy" uses the "remove trailing slash" and "remove www. prefix" flags, - // while "non-greedy" uses the "add (or keep) the trailing slash" and "add www. prefix". - - // Convenience set of usually safe normalizations (includes FlagsSafe) - FlagsUsuallySafeGreedy NormalizationFlags = FlagsSafe | FlagRemoveTrailingSlash | FlagRemoveDotSegments - FlagsUsuallySafeNonGreedy NormalizationFlags = FlagsSafe | FlagAddTrailingSlash | FlagRemoveDotSegments - - // Convenience set of unsafe normalizations (includes FlagsUsuallySafe) - FlagsUnsafeGreedy NormalizationFlags = FlagsUsuallySafeGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagRemoveWWW | FlagSortQuery - FlagsUnsafeNonGreedy NormalizationFlags = FlagsUsuallySafeNonGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagAddWWW | FlagSortQuery - - // Convenience set of all available flags - FlagsAllGreedy = FlagsUnsafeGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator - FlagsAllNonGreedy = FlagsUnsafeNonGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator -) - -const ( - defaultHttpPort = ":80" - defaultHttpsPort = ":443" -) - -// Regular expressions used by the normalizations -var rxPort = regexp.MustCompile(`(:\d+)/?$`) -var rxDirIndex = regexp.MustCompile(`(^|/)((?:default|index)\.\w{1,4})$`) -var rxDupSlashes = regexp.MustCompile(`/{2,}`) -var rxDWORDHost = regexp.MustCompile(`^(\d+)((?:\.+)?(?:\:\d*)?)$`) -var rxOctalHost = regexp.MustCompile(`^(0\d*)\.(0\d*)\.(0\d*)\.(0\d*)((?:\.+)?(?:\:\d*)?)$`) -var rxHexHost = regexp.MustCompile(`^0x([0-9A-Fa-f]+)((?:\.+)?(?:\:\d*)?)$`) -var rxHostDots = regexp.MustCompile(`^(.+?)(:\d+)?$`) -var rxEmptyPort = regexp.MustCompile(`:+$`) - -// Map of flags to implementation function. -// FlagDecodeUnnecessaryEscapes has no action, since it is done automatically -// by parsing the string as an URL. Same for FlagUppercaseEscapes and FlagRemoveEmptyQuerySeparator. - -// Since maps have undefined traversing order, make a slice of ordered keys -var flagsOrder = []NormalizationFlags{ - FlagLowercaseScheme, - FlagLowercaseHost, - FlagRemoveDefaultPort, - FlagRemoveDirectoryIndex, - FlagRemoveDotSegments, - FlagRemoveFragment, - FlagForceHTTP, // Must be after remove default port (because https=443/http=80) - FlagRemoveDuplicateSlashes, - FlagRemoveWWW, - FlagAddWWW, - FlagSortQuery, - FlagDecodeDWORDHost, - FlagDecodeOctalHost, - FlagDecodeHexHost, - FlagRemoveUnnecessaryHostDots, - FlagRemoveEmptyPortSeparator, - FlagRemoveTrailingSlash, // These two (add/remove trailing slash) must be last - FlagAddTrailingSlash, -} - -// ... and then the map, where order is unimportant -var flags = map[NormalizationFlags]func(*url.URL){ - FlagLowercaseScheme: lowercaseScheme, - FlagLowercaseHost: lowercaseHost, - FlagRemoveDefaultPort: removeDefaultPort, - FlagRemoveDirectoryIndex: removeDirectoryIndex, - FlagRemoveDotSegments: removeDotSegments, - FlagRemoveFragment: removeFragment, - FlagForceHTTP: forceHTTP, - FlagRemoveDuplicateSlashes: removeDuplicateSlashes, - FlagRemoveWWW: removeWWW, - FlagAddWWW: addWWW, - FlagSortQuery: sortQuery, - FlagDecodeDWORDHost: decodeDWORDHost, - FlagDecodeOctalHost: decodeOctalHost, - FlagDecodeHexHost: decodeHexHost, - FlagRemoveUnnecessaryHostDots: removeUnncessaryHostDots, - FlagRemoveEmptyPortSeparator: removeEmptyPortSeparator, - FlagRemoveTrailingSlash: removeTrailingSlash, - FlagAddTrailingSlash: addTrailingSlash, -} - -// MustNormalizeURLString returns the normalized string, and panics if an error occurs. -// It takes an URL string as input, as well as the normalization flags. -func MustNormalizeURLString(u string, f NormalizationFlags) string { - result, e := NormalizeURLString(u, f) - if e != nil { - panic(e) - } - return result -} - -// NormalizeURLString returns the normalized string, or an error if it can't be parsed into an URL object. -// It takes an URL string as input, as well as the normalization flags. -func NormalizeURLString(u string, f NormalizationFlags) (string, error) { - parsed, err := url.Parse(u) - if err != nil { - return "", err - } - - if f&FlagLowercaseHost == FlagLowercaseHost { - parsed.Host = strings.ToLower(parsed.Host) - } - - // The idna package doesn't fully conform to RFC 5895 - // (https://tools.ietf.org/html/rfc5895), so we do it here. - // Taken from Go 1.8 cycle source, courtesy of bradfitz. - // TODO: Remove when (if?) idna package conforms to RFC 5895. - parsed.Host = width.Fold.String(parsed.Host) - parsed.Host = norm.NFC.String(parsed.Host) - if parsed.Host, err = idna.ToASCII(parsed.Host); err != nil { - return "", err - } - - return NormalizeURL(parsed, f), nil -} - -// NormalizeURL returns the normalized string. -// It takes a parsed URL object as input, as well as the normalization flags. -func NormalizeURL(u *url.URL, f NormalizationFlags) string { - for _, k := range flagsOrder { - if f&k == k { - flags[k](u) - } - } - return urlesc.Escape(u) -} - -func lowercaseScheme(u *url.URL) { - if len(u.Scheme) > 0 { - u.Scheme = strings.ToLower(u.Scheme) - } -} - -func lowercaseHost(u *url.URL) { - if len(u.Host) > 0 { - u.Host = strings.ToLower(u.Host) - } -} - -func removeDefaultPort(u *url.URL) { - if len(u.Host) > 0 { - scheme := strings.ToLower(u.Scheme) - u.Host = rxPort.ReplaceAllStringFunc(u.Host, func(val string) string { - if (scheme == "http" && val == defaultHttpPort) || (scheme == "https" && val == defaultHttpsPort) { - return "" - } - return val - }) - } -} - -func removeTrailingSlash(u *url.URL) { - if l := len(u.Path); l > 0 { - if strings.HasSuffix(u.Path, "/") { - u.Path = u.Path[:l-1] - } - } else if l = len(u.Host); l > 0 { - if strings.HasSuffix(u.Host, "/") { - u.Host = u.Host[:l-1] - } - } -} - -func addTrailingSlash(u *url.URL) { - if l := len(u.Path); l > 0 { - if !strings.HasSuffix(u.Path, "/") { - u.Path += "/" - } - } else if l = len(u.Host); l > 0 { - if !strings.HasSuffix(u.Host, "/") { - u.Host += "/" - } - } -} - -func removeDotSegments(u *url.URL) { - if len(u.Path) > 0 { - var dotFree []string - var lastIsDot bool - - sections := strings.Split(u.Path, "/") - for _, s := range sections { - if s == ".." { - if len(dotFree) > 0 { - dotFree = dotFree[:len(dotFree)-1] - } - } else if s != "." { - dotFree = append(dotFree, s) - } - lastIsDot = (s == "." || s == "..") - } - // Special case if host does not end with / and new path does not begin with / - u.Path = strings.Join(dotFree, "/") - if u.Host != "" && !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") { - u.Path = "/" + u.Path - } - // Special case if the last segment was a dot, make sure the path ends with a slash - if lastIsDot && !strings.HasSuffix(u.Path, "/") { - u.Path += "/" - } - } -} - -func removeDirectoryIndex(u *url.URL) { - if len(u.Path) > 0 { - u.Path = rxDirIndex.ReplaceAllString(u.Path, "$1") - } -} - -func removeFragment(u *url.URL) { - u.Fragment = "" -} - -func forceHTTP(u *url.URL) { - if strings.ToLower(u.Scheme) == "https" { - u.Scheme = "http" - } -} - -func removeDuplicateSlashes(u *url.URL) { - if len(u.Path) > 0 { - u.Path = rxDupSlashes.ReplaceAllString(u.Path, "/") - } -} - -func removeWWW(u *url.URL) { - if len(u.Host) > 0 && strings.HasPrefix(strings.ToLower(u.Host), "www.") { - u.Host = u.Host[4:] - } -} - -func addWWW(u *url.URL) { - if len(u.Host) > 0 && !strings.HasPrefix(strings.ToLower(u.Host), "www.") { - u.Host = "www." + u.Host - } -} - -func sortQuery(u *url.URL) { - q := u.Query() - - if len(q) > 0 { - arKeys := make([]string, len(q)) - i := 0 - for k, _ := range q { - arKeys[i] = k - i++ - } - sort.Strings(arKeys) - buf := new(bytes.Buffer) - for _, k := range arKeys { - sort.Strings(q[k]) - for _, v := range q[k] { - if buf.Len() > 0 { - buf.WriteRune('&') - } - buf.WriteString(fmt.Sprintf("%s=%s", k, urlesc.QueryEscape(v))) - } - } - - // Rebuild the raw query string - u.RawQuery = buf.String() - } -} - -func decodeDWORDHost(u *url.URL) { - if len(u.Host) > 0 { - if matches := rxDWORDHost.FindStringSubmatch(u.Host); len(matches) > 2 { - var parts [4]int64 - - dword, _ := strconv.ParseInt(matches[1], 10, 0) - for i, shift := range []uint{24, 16, 8, 0} { - parts[i] = dword >> shift & 0xFF - } - u.Host = fmt.Sprintf("%d.%d.%d.%d%s", parts[0], parts[1], parts[2], parts[3], matches[2]) - } - } -} - -func decodeOctalHost(u *url.URL) { - if len(u.Host) > 0 { - if matches := rxOctalHost.FindStringSubmatch(u.Host); len(matches) > 5 { - var parts [4]int64 - - for i := 1; i <= 4; i++ { - parts[i-1], _ = strconv.ParseInt(matches[i], 8, 0) - } - u.Host = fmt.Sprintf("%d.%d.%d.%d%s", parts[0], parts[1], parts[2], parts[3], matches[5]) - } - } -} - -func decodeHexHost(u *url.URL) { - if len(u.Host) > 0 { - if matches := rxHexHost.FindStringSubmatch(u.Host); len(matches) > 2 { - // Conversion is safe because of regex validation - parsed, _ := strconv.ParseInt(matches[1], 16, 0) - // Set host as DWORD (base 10) encoded host - u.Host = fmt.Sprintf("%d%s", parsed, matches[2]) - // The rest is the same as decoding a DWORD host - decodeDWORDHost(u) - } - } -} - -func removeUnncessaryHostDots(u *url.URL) { - if len(u.Host) > 0 { - if matches := rxHostDots.FindStringSubmatch(u.Host); len(matches) > 1 { - // Trim the leading and trailing dots - u.Host = strings.Trim(matches[1], ".") - if len(matches) > 2 { - u.Host += matches[2] - } - } - } -} - -func removeEmptyPortSeparator(u *url.URL) { - if len(u.Host) > 0 { - u.Host = rxEmptyPort.ReplaceAllString(u.Host, "") - } -} diff --git a/discovery/vendor/github.com/PuerkitoBio/urlesc/LICENSE b/discovery/vendor/github.com/PuerkitoBio/urlesc/LICENSE deleted file mode 100644 index 74487567..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/urlesc/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2012 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/discovery/vendor/github.com/PuerkitoBio/urlesc/README.md b/discovery/vendor/github.com/PuerkitoBio/urlesc/README.md deleted file mode 100644 index 57aff0a5..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/urlesc/README.md +++ /dev/null @@ -1,16 +0,0 @@ -urlesc [![Build Status](https://travis-ci.org/PuerkitoBio/urlesc.svg?branch=master)](https://travis-ci.org/PuerkitoBio/urlesc) [![GoDoc](http://godoc.org/github.com/PuerkitoBio/urlesc?status.svg)](http://godoc.org/github.com/PuerkitoBio/urlesc) -====== - -Package urlesc implements query escaping as per RFC 3986. - -It contains some parts of the net/url package, modified so as to allow -some reserved characters incorrectly escaped by net/url (see [issue 5684](https://github.com/golang/go/issues/5684)). - -## Install - - go get github.com/PuerkitoBio/urlesc - -## License - -Go license (BSD-3-Clause) - diff --git a/discovery/vendor/github.com/PuerkitoBio/urlesc/urlesc.go b/discovery/vendor/github.com/PuerkitoBio/urlesc/urlesc.go deleted file mode 100644 index 1b846245..00000000 --- a/discovery/vendor/github.com/PuerkitoBio/urlesc/urlesc.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package urlesc implements query escaping as per RFC 3986. -// It contains some parts of the net/url package, modified so as to allow -// some reserved characters incorrectly escaped by net/url. -// See https://github.com/golang/go/issues/5684 -package urlesc - -import ( - "bytes" - "net/url" - "strings" -) - -type encoding int - -const ( - encodePath encoding = 1 + iota - encodeUserPassword - encodeQueryComponent - encodeFragment -) - -// Return true if the specified character should be escaped when -// appearing in a URL string, according to RFC 3986. -func shouldEscape(c byte, mode encoding) bool { - // §2.3 Unreserved characters (alphanum) - if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' { - return false - } - - switch c { - case '-', '.', '_', '~': // §2.3 Unreserved characters (mark) - return false - - // §2.2 Reserved characters (reserved) - case ':', '/', '?', '#', '[', ']', '@', // gen-delims - '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=': // sub-delims - // Different sections of the URL allow a few of - // the reserved characters to appear unescaped. - switch mode { - case encodePath: // §3.3 - // The RFC allows sub-delims and : @. - // '/', '[' and ']' can be used to assign meaning to individual path - // segments. This package only manipulates the path as a whole, - // so we allow those as well. That leaves only ? and # to escape. - return c == '?' || c == '#' - - case encodeUserPassword: // §3.2.1 - // The RFC allows : and sub-delims in - // userinfo. The parsing of userinfo treats ':' as special so we must escape - // all the gen-delims. - return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@' - - case encodeQueryComponent: // §3.4 - // The RFC allows / and ?. - return c != '/' && c != '?' - - case encodeFragment: // §4.1 - // The RFC text is silent but the grammar allows - // everything, so escape nothing but # - return c == '#' - } - } - - // Everything else must be escaped. - return true -} - -// QueryEscape escapes the string so it can be safely placed -// inside a URL query. -func QueryEscape(s string) string { - return escape(s, encodeQueryComponent) -} - -func escape(s string, mode encoding) string { - spaceCount, hexCount := 0, 0 - for i := 0; i < len(s); i++ { - c := s[i] - if shouldEscape(c, mode) { - if c == ' ' && mode == encodeQueryComponent { - spaceCount++ - } else { - hexCount++ - } - } - } - - if spaceCount == 0 && hexCount == 0 { - return s - } - - t := make([]byte, len(s)+2*hexCount) - j := 0 - for i := 0; i < len(s); i++ { - switch c := s[i]; { - case c == ' ' && mode == encodeQueryComponent: - t[j] = '+' - j++ - case shouldEscape(c, mode): - t[j] = '%' - t[j+1] = "0123456789ABCDEF"[c>>4] - t[j+2] = "0123456789ABCDEF"[c&15] - j += 3 - default: - t[j] = s[i] - j++ - } - } - return string(t) -} - -var uiReplacer = strings.NewReplacer( - "%21", "!", - "%27", "'", - "%28", "(", - "%29", ")", - "%2A", "*", -) - -// unescapeUserinfo unescapes some characters that need not to be escaped as per RFC3986. -func unescapeUserinfo(s string) string { - return uiReplacer.Replace(s) -} - -// Escape reassembles the URL into a valid URL string. -// The general form of the result is one of: -// -// scheme:opaque -// scheme://userinfo@host/path?query#fragment -// -// If u.Opaque is non-empty, String uses the first form; -// otherwise it uses the second form. -// -// In the second form, the following rules apply: -// - if u.Scheme is empty, scheme: is omitted. -// - if u.User is nil, userinfo@ is omitted. -// - if u.Host is empty, host/ is omitted. -// - if u.Scheme and u.Host are empty and u.User is nil, -// the entire scheme://userinfo@host/ is omitted. -// - if u.Host is non-empty and u.Path begins with a /, -// the form host/path does not add its own /. -// - if u.RawQuery is empty, ?query is omitted. -// - if u.Fragment is empty, #fragment is omitted. -func Escape(u *url.URL) string { - var buf bytes.Buffer - if u.Scheme != "" { - buf.WriteString(u.Scheme) - buf.WriteByte(':') - } - if u.Opaque != "" { - buf.WriteString(u.Opaque) - } else { - if u.Scheme != "" || u.Host != "" || u.User != nil { - buf.WriteString("//") - if ui := u.User; ui != nil { - buf.WriteString(unescapeUserinfo(ui.String())) - buf.WriteByte('@') - } - if h := u.Host; h != "" { - buf.WriteString(h) - } - } - if u.Path != "" && u.Path[0] != '/' && u.Host != "" { - buf.WriteByte('/') - } - buf.WriteString(escape(u.Path, encodePath)) - } - if u.RawQuery != "" { - buf.WriteByte('?') - buf.WriteString(u.RawQuery) - } - if u.Fragment != "" { - buf.WriteByte('#') - buf.WriteString(escape(u.Fragment, encodeFragment)) - } - return buf.String() -} diff --git a/discovery/vendor/github.com/beorn7/perks/histogram/bench_test.go b/discovery/vendor/github.com/beorn7/perks/histogram/bench_test.go new file mode 100644 index 00000000..56c7e551 --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/histogram/bench_test.go @@ -0,0 +1,26 @@ +package histogram + +import ( + "math/rand" + "testing" +) + +func BenchmarkInsert10Bins(b *testing.B) { + b.StopTimer() + h := New(10) + b.StartTimer() + for i := 0; i < b.N; i++ { + f := rand.ExpFloat64() + h.Insert(f) + } +} + +func BenchmarkInsert100Bins(b *testing.B) { + b.StopTimer() + h := New(100) + b.StartTimer() + for i := 0; i < b.N; i++ { + f := rand.ExpFloat64() + h.Insert(f) + } +} diff --git a/discovery/vendor/github.com/beorn7/perks/histogram/histogram_test.go b/discovery/vendor/github.com/beorn7/perks/histogram/histogram_test.go new file mode 100644 index 00000000..0575ebee --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/histogram/histogram_test.go @@ -0,0 +1,38 @@ +package histogram + +import ( + "math/rand" + "testing" +) + +func TestHistogram(t *testing.T) { + const numPoints = 1e6 + const maxBins = 3 + + h := New(maxBins) + for i := 0; i < numPoints; i++ { + f := rand.ExpFloat64() + h.Insert(f) + } + + bins := h.Bins() + if g := len(bins); g > maxBins { + t.Fatalf("got %d bins, wanted <= %d", g, maxBins) + } + + for _, b := range bins { + t.Logf("%+v", b) + } + + if g := count(h.Bins()); g != numPoints { + t.Fatalf("binned %d points, wanted %d", g, numPoints) + } +} + +func count(bins Bins) int { + binCounts := 0 + for _, b := range bins { + binCounts += b.Count + } + return binCounts +} diff --git a/discovery/vendor/github.com/beorn7/perks/quantile/bench_test.go b/discovery/vendor/github.com/beorn7/perks/quantile/bench_test.go new file mode 100644 index 00000000..0bd0e4e7 --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/quantile/bench_test.go @@ -0,0 +1,63 @@ +package quantile + +import ( + "testing" +) + +func BenchmarkInsertTargeted(b *testing.B) { + b.ReportAllocs() + + s := NewTargeted(Targets) + b.ResetTimer() + for i := float64(0); i < float64(b.N); i++ { + s.Insert(i) + } +} + +func BenchmarkInsertTargetedSmallEpsilon(b *testing.B) { + s := NewTargeted(TargetsSmallEpsilon) + b.ResetTimer() + for i := float64(0); i < float64(b.N); i++ { + s.Insert(i) + } +} + +func BenchmarkInsertBiased(b *testing.B) { + s := NewLowBiased(0.01) + b.ResetTimer() + for i := float64(0); i < float64(b.N); i++ { + s.Insert(i) + } +} + +func BenchmarkInsertBiasedSmallEpsilon(b *testing.B) { + s := NewLowBiased(0.0001) + b.ResetTimer() + for i := float64(0); i < float64(b.N); i++ { + s.Insert(i) + } +} + +func BenchmarkQuery(b *testing.B) { + s := NewTargeted(Targets) + for i := float64(0); i < 1e6; i++ { + s.Insert(i) + } + b.ResetTimer() + n := float64(b.N) + for i := float64(0); i < n; i++ { + s.Query(i / n) + } +} + +func BenchmarkQuerySmallEpsilon(b *testing.B) { + s := NewTargeted(TargetsSmallEpsilon) + for i := float64(0); i < 1e6; i++ { + s.Insert(i) + } + b.ResetTimer() + n := float64(b.N) + for i := float64(0); i < n; i++ { + s.Query(i / n) + } +} diff --git a/discovery/vendor/github.com/beorn7/perks/quantile/example_test.go b/discovery/vendor/github.com/beorn7/perks/quantile/example_test.go new file mode 100644 index 00000000..ab3293aa --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/quantile/example_test.go @@ -0,0 +1,121 @@ +// +build go1.1 + +package quantile_test + +import ( + "bufio" + "fmt" + "log" + "os" + "strconv" + "time" + + "github.com/beorn7/perks/quantile" +) + +func Example_simple() { + ch := make(chan float64) + go sendFloats(ch) + + // Compute the 50th, 90th, and 99th percentile. + q := quantile.NewTargeted(map[float64]float64{ + 0.50: 0.005, + 0.90: 0.001, + 0.99: 0.0001, + }) + for v := range ch { + q.Insert(v) + } + + fmt.Println("perc50:", q.Query(0.50)) + fmt.Println("perc90:", q.Query(0.90)) + fmt.Println("perc99:", q.Query(0.99)) + fmt.Println("count:", q.Count()) + // Output: + // perc50: 5 + // perc90: 16 + // perc99: 223 + // count: 2388 +} + +func Example_mergeMultipleStreams() { + // Scenario: + // We have multiple database shards. On each shard, there is a process + // collecting query response times from the database logs and inserting + // them into a Stream (created via NewTargeted(0.90)), much like the + // Simple example. These processes expose a network interface for us to + // ask them to serialize and send us the results of their + // Stream.Samples so we may Merge and Query them. + // + // NOTES: + // * These sample sets are small, allowing us to get them + // across the network much faster than sending the entire list of data + // points. + // + // * For this to work correctly, we must supply the same quantiles + // a priori the process collecting the samples supplied to NewTargeted, + // even if we do not plan to query them all here. + ch := make(chan quantile.Samples) + getDBQuerySamples(ch) + q := quantile.NewTargeted(map[float64]float64{0.90: 0.001}) + for samples := range ch { + q.Merge(samples) + } + fmt.Println("perc90:", q.Query(0.90)) +} + +func Example_window() { + // Scenario: We want the 90th, 95th, and 99th percentiles for each + // minute. + + ch := make(chan float64) + go sendStreamValues(ch) + + tick := time.NewTicker(1 * time.Minute) + q := quantile.NewTargeted(map[float64]float64{ + 0.90: 0.001, + 0.95: 0.0005, + 0.99: 0.0001, + }) + for { + select { + case t := <-tick.C: + flushToDB(t, q.Samples()) + q.Reset() + case v := <-ch: + q.Insert(v) + } + } +} + +func sendStreamValues(ch chan float64) { + // Use your imagination +} + +func flushToDB(t time.Time, samples quantile.Samples) { + // Use your imagination +} + +// This is a stub for the above example. In reality this would hit the remote +// servers via http or something like it. +func getDBQuerySamples(ch chan quantile.Samples) {} + +func sendFloats(ch chan<- float64) { + f, err := os.Open("exampledata.txt") + if err != nil { + log.Fatal(err) + } + sc := bufio.NewScanner(f) + for sc.Scan() { + b := sc.Bytes() + v, err := strconv.ParseFloat(string(b), 64) + if err != nil { + log.Fatal(err) + } + ch <- v + } + if sc.Err() != nil { + log.Fatal(sc.Err()) + } + close(ch) +} diff --git a/discovery/vendor/github.com/beorn7/perks/quantile/stream_test.go b/discovery/vendor/github.com/beorn7/perks/quantile/stream_test.go new file mode 100644 index 00000000..85519509 --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/quantile/stream_test.go @@ -0,0 +1,215 @@ +package quantile + +import ( + "math" + "math/rand" + "sort" + "testing" +) + +var ( + Targets = map[float64]float64{ + 0.01: 0.001, + 0.10: 0.01, + 0.50: 0.05, + 0.90: 0.01, + 0.99: 0.001, + } + TargetsSmallEpsilon = map[float64]float64{ + 0.01: 0.0001, + 0.10: 0.001, + 0.50: 0.005, + 0.90: 0.001, + 0.99: 0.0001, + } + LowQuantiles = []float64{0.01, 0.1, 0.5} + HighQuantiles = []float64{0.99, 0.9, 0.5} +) + +const RelativeEpsilon = 0.01 + +func verifyPercsWithAbsoluteEpsilon(t *testing.T, a []float64, s *Stream) { + sort.Float64s(a) + for quantile, epsilon := range Targets { + n := float64(len(a)) + k := int(quantile * n) + if k < 1 { + k = 1 + } + lower := int((quantile - epsilon) * n) + if lower < 1 { + lower = 1 + } + upper := int(math.Ceil((quantile + epsilon) * n)) + if upper > len(a) { + upper = len(a) + } + w, min, max := a[k-1], a[lower-1], a[upper-1] + if g := s.Query(quantile); g < min || g > max { + t.Errorf("q=%f: want %v [%f,%f], got %v", quantile, w, min, max, g) + } + } +} + +func verifyLowPercsWithRelativeEpsilon(t *testing.T, a []float64, s *Stream) { + sort.Float64s(a) + for _, qu := range LowQuantiles { + n := float64(len(a)) + k := int(qu * n) + + lowerRank := int((1 - RelativeEpsilon) * qu * n) + upperRank := int(math.Ceil((1 + RelativeEpsilon) * qu * n)) + w, min, max := a[k-1], a[lowerRank-1], a[upperRank-1] + if g := s.Query(qu); g < min || g > max { + t.Errorf("q=%f: want %v [%f,%f], got %v", qu, w, min, max, g) + } + } +} + +func verifyHighPercsWithRelativeEpsilon(t *testing.T, a []float64, s *Stream) { + sort.Float64s(a) + for _, qu := range HighQuantiles { + n := float64(len(a)) + k := int(qu * n) + + lowerRank := int((1 - (1+RelativeEpsilon)*(1-qu)) * n) + upperRank := int(math.Ceil((1 - (1-RelativeEpsilon)*(1-qu)) * n)) + w, min, max := a[k-1], a[lowerRank-1], a[upperRank-1] + if g := s.Query(qu); g < min || g > max { + t.Errorf("q=%f: want %v [%f,%f], got %v", qu, w, min, max, g) + } + } +} + +func populateStream(s *Stream) []float64 { + a := make([]float64, 0, 1e5+100) + for i := 0; i < cap(a); i++ { + v := rand.NormFloat64() + // Add 5% asymmetric outliers. + if i%20 == 0 { + v = v*v + 1 + } + s.Insert(v) + a = append(a, v) + } + return a +} + +func TestTargetedQuery(t *testing.T) { + rand.Seed(42) + s := NewTargeted(Targets) + a := populateStream(s) + verifyPercsWithAbsoluteEpsilon(t, a, s) +} + +func TestTargetedQuerySmallSampleSize(t *testing.T) { + rand.Seed(42) + s := NewTargeted(TargetsSmallEpsilon) + a := []float64{1, 2, 3, 4, 5} + for _, v := range a { + s.Insert(v) + } + verifyPercsWithAbsoluteEpsilon(t, a, s) + // If not yet flushed, results should be precise: + if !s.flushed() { + for φ, want := range map[float64]float64{ + 0.01: 1, + 0.10: 1, + 0.50: 3, + 0.90: 5, + 0.99: 5, + } { + if got := s.Query(φ); got != want { + t.Errorf("want %f for φ=%f, got %f", want, φ, got) + } + } + } +} + +func TestLowBiasedQuery(t *testing.T) { + rand.Seed(42) + s := NewLowBiased(RelativeEpsilon) + a := populateStream(s) + verifyLowPercsWithRelativeEpsilon(t, a, s) +} + +func TestHighBiasedQuery(t *testing.T) { + rand.Seed(42) + s := NewHighBiased(RelativeEpsilon) + a := populateStream(s) + verifyHighPercsWithRelativeEpsilon(t, a, s) +} + +// BrokenTestTargetedMerge is broken, see Merge doc comment. +func BrokenTestTargetedMerge(t *testing.T) { + rand.Seed(42) + s1 := NewTargeted(Targets) + s2 := NewTargeted(Targets) + a := populateStream(s1) + a = append(a, populateStream(s2)...) + s1.Merge(s2.Samples()) + verifyPercsWithAbsoluteEpsilon(t, a, s1) +} + +// BrokenTestLowBiasedMerge is broken, see Merge doc comment. +func BrokenTestLowBiasedMerge(t *testing.T) { + rand.Seed(42) + s1 := NewLowBiased(RelativeEpsilon) + s2 := NewLowBiased(RelativeEpsilon) + a := populateStream(s1) + a = append(a, populateStream(s2)...) + s1.Merge(s2.Samples()) + verifyLowPercsWithRelativeEpsilon(t, a, s2) +} + +// BrokenTestHighBiasedMerge is broken, see Merge doc comment. +func BrokenTestHighBiasedMerge(t *testing.T) { + rand.Seed(42) + s1 := NewHighBiased(RelativeEpsilon) + s2 := NewHighBiased(RelativeEpsilon) + a := populateStream(s1) + a = append(a, populateStream(s2)...) + s1.Merge(s2.Samples()) + verifyHighPercsWithRelativeEpsilon(t, a, s2) +} + +func TestUncompressed(t *testing.T) { + q := NewTargeted(Targets) + for i := 100; i > 0; i-- { + q.Insert(float64(i)) + } + if g := q.Count(); g != 100 { + t.Errorf("want count 100, got %d", g) + } + // Before compression, Query should have 100% accuracy. + for quantile := range Targets { + w := quantile * 100 + if g := q.Query(quantile); g != w { + t.Errorf("want %f, got %f", w, g) + } + } +} + +func TestUncompressedSamples(t *testing.T) { + q := NewTargeted(map[float64]float64{0.99: 0.001}) + for i := 1; i <= 100; i++ { + q.Insert(float64(i)) + } + if g := q.Samples().Len(); g != 100 { + t.Errorf("want count 100, got %d", g) + } +} + +func TestUncompressedOne(t *testing.T) { + q := NewTargeted(map[float64]float64{0.99: 0.01}) + q.Insert(3.14) + if g := q.Query(0.90); g != 3.14 { + t.Error("want PI, got", g) + } +} + +func TestDefaults(t *testing.T) { + if g := NewTargeted(map[float64]float64{0.99: 0.001}).Query(0.99); g != 0 { + t.Errorf("want 0, got %f", g) + } +} diff --git a/discovery/vendor/github.com/beorn7/perks/topk/topk_test.go b/discovery/vendor/github.com/beorn7/perks/topk/topk_test.go new file mode 100644 index 00000000..c24f0f72 --- /dev/null +++ b/discovery/vendor/github.com/beorn7/perks/topk/topk_test.go @@ -0,0 +1,57 @@ +package topk + +import ( + "fmt" + "math/rand" + "sort" + "testing" +) + +func TestTopK(t *testing.T) { + stream := New(10) + ss := []*Stream{New(10), New(10), New(10)} + m := make(map[string]int) + for _, s := range ss { + for i := 0; i < 1e6; i++ { + v := fmt.Sprintf("%x", int8(rand.ExpFloat64())) + s.Insert(v) + m[v]++ + } + stream.Merge(s.Query()) + } + + var sm Samples + for x, s := range m { + sm = append(sm, &Element{x, s}) + } + sort.Sort(sort.Reverse(sm)) + + g := stream.Query() + if len(g) != 10 { + t.Fatalf("got %d, want 10", len(g)) + } + for i, e := range g { + if sm[i].Value != e.Value { + t.Errorf("at %d: want %q, got %q", i, sm[i].Value, e.Value) + } + } +} + +func TestQuery(t *testing.T) { + queryTests := []struct { + value string + expected int + }{ + {"a", 1}, + {"b", 2}, + {"c", 2}, + } + + stream := New(2) + for _, tt := range queryTests { + stream.Insert(tt.value) + if n := len(stream.Query()); n != tt.expected { + t.Errorf("want %d, got %d", tt.expected, n) + } + } +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/.travis.yml b/discovery/vendor/github.com/davecgh/go-spew/.travis.yml new file mode 100644 index 00000000..984e0736 --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/.travis.yml @@ -0,0 +1,14 @@ +language: go +go: + - 1.5.4 + - 1.6.3 + - 1.7 +install: + - go get -v golang.org/x/tools/cmd/cover +script: + - go test -v -tags=safe ./spew + - go test -v -tags=testcgo ./spew -covermode=count -coverprofile=profile.cov +after_success: + - go get -v github.com/mattn/goveralls + - export PATH=$PATH:$HOME/gopath/bin + - goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/common_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/common_test.go new file mode 100644 index 00000000..0f5ce47d --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/common_test.go @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "fmt" + "reflect" + "testing" + + "github.com/davecgh/go-spew/spew" +) + +// custom type to test Stinger interface on non-pointer receiver. +type stringer string + +// String implements the Stringer interface for testing invocation of custom +// stringers on types with non-pointer receivers. +func (s stringer) String() string { + return "stringer " + string(s) +} + +// custom type to test Stinger interface on pointer receiver. +type pstringer string + +// String implements the Stringer interface for testing invocation of custom +// stringers on types with only pointer receivers. +func (s *pstringer) String() string { + return "stringer " + string(*s) +} + +// xref1 and xref2 are cross referencing structs for testing circular reference +// detection. +type xref1 struct { + ps2 *xref2 +} +type xref2 struct { + ps1 *xref1 +} + +// indirCir1, indirCir2, and indirCir3 are used to generate an indirect circular +// reference for testing detection. +type indirCir1 struct { + ps2 *indirCir2 +} +type indirCir2 struct { + ps3 *indirCir3 +} +type indirCir3 struct { + ps1 *indirCir1 +} + +// embed is used to test embedded structures. +type embed struct { + a string +} + +// embedwrap is used to test embedded structures. +type embedwrap struct { + *embed + e *embed +} + +// panicer is used to intentionally cause a panic for testing spew properly +// handles them +type panicer int + +func (p panicer) String() string { + panic("test panic") +} + +// customError is used to test custom error interface invocation. +type customError int + +func (e customError) Error() string { + return fmt.Sprintf("error: %d", int(e)) +} + +// stringizeWants converts a slice of wanted test output into a format suitable +// for a test error message. +func stringizeWants(wants []string) string { + s := "" + for i, want := range wants { + if i > 0 { + s += fmt.Sprintf("want%d: %s", i+1, want) + } else { + s += "want: " + want + } + } + return s +} + +// testFailed returns whether or not a test failed by checking if the result +// of the test is in the slice of wanted strings. +func testFailed(result string, wants []string) bool { + for _, want := range wants { + if result == want { + return false + } + } + return true +} + +type sortableStruct struct { + x int +} + +func (ss sortableStruct) String() string { + return fmt.Sprintf("ss.%d", ss.x) +} + +type unsortableStruct struct { + x int +} + +type sortTestCase struct { + input []reflect.Value + expected []reflect.Value +} + +func helpTestSortValues(tests []sortTestCase, cs *spew.ConfigState, t *testing.T) { + getInterfaces := func(values []reflect.Value) []interface{} { + interfaces := []interface{}{} + for _, v := range values { + interfaces = append(interfaces, v.Interface()) + } + return interfaces + } + + for _, test := range tests { + spew.SortValues(test.input, cs) + // reflect.DeepEqual cannot really make sense of reflect.Value, + // probably because of all the pointer tricks. For instance, + // v(2.0) != v(2.0) on a 32-bits system. Turn them into interface{} + // instead. + input := getInterfaces(test.input) + expected := getInterfaces(test.expected) + if !reflect.DeepEqual(input, expected) { + t.Errorf("Sort mismatch:\n %v != %v", input, expected) + } + } +} + +// TestSortValues ensures the sort functionality for relect.Value based sorting +// works as intended. +func TestSortValues(t *testing.T) { + v := reflect.ValueOf + + a := v("a") + b := v("b") + c := v("c") + embedA := v(embed{"a"}) + embedB := v(embed{"b"}) + embedC := v(embed{"c"}) + tests := []sortTestCase{ + // No values. + { + []reflect.Value{}, + []reflect.Value{}, + }, + // Bools. + { + []reflect.Value{v(false), v(true), v(false)}, + []reflect.Value{v(false), v(false), v(true)}, + }, + // Ints. + { + []reflect.Value{v(2), v(1), v(3)}, + []reflect.Value{v(1), v(2), v(3)}, + }, + // Uints. + { + []reflect.Value{v(uint8(2)), v(uint8(1)), v(uint8(3))}, + []reflect.Value{v(uint8(1)), v(uint8(2)), v(uint8(3))}, + }, + // Floats. + { + []reflect.Value{v(2.0), v(1.0), v(3.0)}, + []reflect.Value{v(1.0), v(2.0), v(3.0)}, + }, + // Strings. + { + []reflect.Value{b, a, c}, + []reflect.Value{a, b, c}, + }, + // Array + { + []reflect.Value{v([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})}, + []reflect.Value{v([3]int{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})}, + }, + // Uintptrs. + { + []reflect.Value{v(uintptr(2)), v(uintptr(1)), v(uintptr(3))}, + []reflect.Value{v(uintptr(1)), v(uintptr(2)), v(uintptr(3))}, + }, + // SortableStructs. + { + // Note: not sorted - DisableMethods is set. + []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})}, + []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})}, + }, + // UnsortableStructs. + { + // Note: not sorted - SpewKeys is false. + []reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})}, + []reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})}, + }, + // Invalid. + { + []reflect.Value{embedB, embedA, embedC}, + []reflect.Value{embedB, embedA, embedC}, + }, + } + cs := spew.ConfigState{DisableMethods: true, SpewKeys: false} + helpTestSortValues(tests, &cs, t) +} + +// TestSortValuesWithMethods ensures the sort functionality for relect.Value +// based sorting works as intended when using string methods. +func TestSortValuesWithMethods(t *testing.T) { + v := reflect.ValueOf + + a := v("a") + b := v("b") + c := v("c") + tests := []sortTestCase{ + // Ints. + { + []reflect.Value{v(2), v(1), v(3)}, + []reflect.Value{v(1), v(2), v(3)}, + }, + // Strings. + { + []reflect.Value{b, a, c}, + []reflect.Value{a, b, c}, + }, + // SortableStructs. + { + []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})}, + []reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})}, + }, + // UnsortableStructs. + { + // Note: not sorted - SpewKeys is false. + []reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})}, + []reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})}, + }, + } + cs := spew.ConfigState{DisableMethods: false, SpewKeys: false} + helpTestSortValues(tests, &cs, t) +} + +// TestSortValuesWithSpew ensures the sort functionality for relect.Value +// based sorting works as intended when using spew to stringify keys. +func TestSortValuesWithSpew(t *testing.T) { + v := reflect.ValueOf + + a := v("a") + b := v("b") + c := v("c") + tests := []sortTestCase{ + // Ints. + { + []reflect.Value{v(2), v(1), v(3)}, + []reflect.Value{v(1), v(2), v(3)}, + }, + // Strings. + { + []reflect.Value{b, a, c}, + []reflect.Value{a, b, c}, + }, + // SortableStructs. + { + []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})}, + []reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})}, + }, + // UnsortableStructs. + { + []reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})}, + []reflect.Value{v(unsortableStruct{1}), v(unsortableStruct{2}), v(unsortableStruct{3})}, + }, + } + cs := spew.ConfigState{DisableMethods: true, SpewKeys: true} + helpTestSortValues(tests, &cs, t) +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/dump_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/dump_test.go new file mode 100644 index 00000000..5aad9c7a --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/dump_test.go @@ -0,0 +1,1042 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +Test Summary: +NOTE: For each test, a nil pointer, a single pointer and double pointer to the +base test element are also tested to ensure proper indirection across all types. + +- Max int8, int16, int32, int64, int +- Max uint8, uint16, uint32, uint64, uint +- Boolean true and false +- Standard complex64 and complex128 +- Array containing standard ints +- Array containing type with custom formatter on pointer receiver only +- Array containing interfaces +- Array containing bytes +- Slice containing standard float32 values +- Slice containing type with custom formatter on pointer receiver only +- Slice containing interfaces +- Slice containing bytes +- Nil slice +- Standard string +- Nil interface +- Sub-interface +- Map with string keys and int vals +- Map with custom formatter type on pointer receiver only keys and vals +- Map with interface keys and values +- Map with nil interface value +- Struct with primitives +- Struct that contains another struct +- Struct that contains custom type with Stringer pointer interface via both + exported and unexported fields +- Struct that contains embedded struct and field to same struct +- Uintptr to 0 (null pointer) +- Uintptr address of real variable +- Unsafe.Pointer to 0 (null pointer) +- Unsafe.Pointer to address of real variable +- Nil channel +- Standard int channel +- Function with no params and no returns +- Function with param and no returns +- Function with multiple params and multiple returns +- Struct that is circular through self referencing +- Structs that are circular through cross referencing +- Structs that are indirectly circular +- Type that panics in its Stringer interface +*/ + +package spew_test + +import ( + "bytes" + "fmt" + "testing" + "unsafe" + + "github.com/davecgh/go-spew/spew" +) + +// dumpTest is used to describe a test to be performed against the Dump method. +type dumpTest struct { + in interface{} + wants []string +} + +// dumpTests houses all of the tests to be performed against the Dump method. +var dumpTests = make([]dumpTest, 0) + +// addDumpTest is a helper method to append the passed input and desired result +// to dumpTests +func addDumpTest(in interface{}, wants ...string) { + test := dumpTest{in, wants} + dumpTests = append(dumpTests, test) +} + +func addIntDumpTests() { + // Max int8. + v := int8(127) + nv := (*int8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int8" + vs := "127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Max int16. + v2 := int16(32767) + nv2 := (*int16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "int16" + v2s := "32767" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Max int32. + v3 := int32(2147483647) + nv3 := (*int32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "int32" + v3s := "2147483647" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Max int64. + v4 := int64(9223372036854775807) + nv4 := (*int64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "int64" + v4s := "9223372036854775807" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Max int. + v5 := int(2147483647) + nv5 := (*int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "int" + v5s := "2147483647" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addUintDumpTests() { + // Max uint8. + v := uint8(255) + nv := (*uint8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uint8" + vs := "255" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Max uint16. + v2 := uint16(65535) + nv2 := (*uint16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Max uint32. + v3 := uint32(4294967295) + nv3 := (*uint32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "uint32" + v3s := "4294967295" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Max uint64. + v4 := uint64(18446744073709551615) + nv4 := (*uint64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "uint64" + v4s := "18446744073709551615" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Max uint. + v5 := uint(4294967295) + nv5 := (*uint)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "uint" + v5s := "4294967295" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addBoolDumpTests() { + // Boolean true. + v := bool(true) + nv := (*bool)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "bool" + vs := "true" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Boolean false. + v2 := bool(false) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "bool" + v2s := "false" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addFloatDumpTests() { + // Standard float32. + v := float32(3.1415) + nv := (*float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "3.1415" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Standard float64. + v2 := float64(3.1415926) + nv2 := (*float64)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "float64" + v2s := "3.1415926" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addComplexDumpTests() { + // Standard complex64. + v := complex(float32(6), -2) + nv := (*complex64)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "complex64" + vs := "(6-2i)" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Standard complex128. + v2 := complex(float64(-6), 2) + nv2 := (*complex128)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "complex128" + v2s := "(-6+2i)" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addArrayDumpTests() { + // Array containing standard ints. + v := [3]int{1, 2, 3} + vLen := fmt.Sprintf("%d", len(v)) + vCap := fmt.Sprintf("%d", cap(v)) + nv := (*[3]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int" + vs := "(len=" + vLen + " cap=" + vCap + ") {\n (" + vt + ") 1,\n (" + + vt + ") 2,\n (" + vt + ") 3\n}" + addDumpTest(v, "([3]"+vt+") "+vs+"\n") + addDumpTest(pv, "(*[3]"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**[3]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*[3]"+vt+")()\n") + + // Array containing type with custom formatter on pointer receiver only. + v2i0 := pstringer("1") + v2i1 := pstringer("2") + v2i2 := pstringer("3") + v2 := [3]pstringer{v2i0, v2i1, v2i2} + v2i0Len := fmt.Sprintf("%d", len(v2i0)) + v2i1Len := fmt.Sprintf("%d", len(v2i1)) + v2i2Len := fmt.Sprintf("%d", len(v2i2)) + v2Len := fmt.Sprintf("%d", len(v2)) + v2Cap := fmt.Sprintf("%d", cap(v2)) + nv2 := (*[3]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.pstringer" + v2sp := "(len=" + v2Len + " cap=" + v2Cap + ") {\n (" + v2t + + ") (len=" + v2i0Len + ") stringer 1,\n (" + v2t + + ") (len=" + v2i1Len + ") stringer 2,\n (" + v2t + + ") (len=" + v2i2Len + ") " + "stringer 3\n}" + v2s := v2sp + if spew.UnsafeDisabled { + v2s = "(len=" + v2Len + " cap=" + v2Cap + ") {\n (" + v2t + + ") (len=" + v2i0Len + ") \"1\",\n (" + v2t + ") (len=" + + v2i1Len + ") \"2\",\n (" + v2t + ") (len=" + v2i2Len + + ") " + "\"3\"\n}" + } + addDumpTest(v2, "([3]"+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*[3]"+v2t+")("+v2Addr+")("+v2sp+")\n") + addDumpTest(&pv2, "(**[3]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2sp+")\n") + addDumpTest(nv2, "(*[3]"+v2t+")()\n") + + // Array containing interfaces. + v3i0 := "one" + v3 := [3]interface{}{v3i0, int(2), uint(3)} + v3i0Len := fmt.Sprintf("%d", len(v3i0)) + v3Len := fmt.Sprintf("%d", len(v3)) + v3Cap := fmt.Sprintf("%d", cap(v3)) + nv3 := (*[3]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[3]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") {\n (" + v3t2 + ") " + + "(len=" + v3i0Len + ") \"one\",\n (" + v3t3 + ") 2,\n (" + + v3t4 + ") 3\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Array containing bytes. + v4 := [34]byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + v4Len := fmt.Sprintf("%d", len(v4)) + v4Cap := fmt.Sprintf("%d", cap(v4)) + nv4 := (*[34]byte)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[34]uint8" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" + + " |............... |\n" + + " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" + + " |!\"#$%&'()*+,-./0|\n" + + " 00000020 31 32 " + + " |12|\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") +} + +func addSliceDumpTests() { + // Slice containing standard float32 values. + v := []float32{3.14, 6.28, 12.56} + vLen := fmt.Sprintf("%d", len(v)) + vCap := fmt.Sprintf("%d", cap(v)) + nv := (*[]float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "(len=" + vLen + " cap=" + vCap + ") {\n (" + vt + ") 3.14,\n (" + + vt + ") 6.28,\n (" + vt + ") 12.56\n}" + addDumpTest(v, "([]"+vt+") "+vs+"\n") + addDumpTest(pv, "(*[]"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**[]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*[]"+vt+")()\n") + + // Slice containing type with custom formatter on pointer receiver only. + v2i0 := pstringer("1") + v2i1 := pstringer("2") + v2i2 := pstringer("3") + v2 := []pstringer{v2i0, v2i1, v2i2} + v2i0Len := fmt.Sprintf("%d", len(v2i0)) + v2i1Len := fmt.Sprintf("%d", len(v2i1)) + v2i2Len := fmt.Sprintf("%d", len(v2i2)) + v2Len := fmt.Sprintf("%d", len(v2)) + v2Cap := fmt.Sprintf("%d", cap(v2)) + nv2 := (*[]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.pstringer" + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") {\n (" + v2t + ") (len=" + + v2i0Len + ") stringer 1,\n (" + v2t + ") (len=" + v2i1Len + + ") stringer 2,\n (" + v2t + ") (len=" + v2i2Len + ") " + + "stringer 3\n}" + addDumpTest(v2, "([]"+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*[]"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**[]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*[]"+v2t+")()\n") + + // Slice containing interfaces. + v3i0 := "one" + v3 := []interface{}{v3i0, int(2), uint(3), nil} + v3i0Len := fmt.Sprintf("%d", len(v3i0)) + v3Len := fmt.Sprintf("%d", len(v3)) + v3Cap := fmt.Sprintf("%d", cap(v3)) + nv3 := (*[]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3t5 := "interface {}" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") {\n (" + v3t2 + ") " + + "(len=" + v3i0Len + ") \"one\",\n (" + v3t3 + ") 2,\n (" + + v3t4 + ") 3,\n (" + v3t5 + ") \n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Slice containing bytes. + v4 := []byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + v4Len := fmt.Sprintf("%d", len(v4)) + v4Cap := fmt.Sprintf("%d", cap(v4)) + nv4 := (*[]byte)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[]uint8" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" + + " |............... |\n" + + " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" + + " |!\"#$%&'()*+,-./0|\n" + + " 00000020 31 32 " + + " |12|\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Nil slice. + v5 := []int(nil) + nv5 := (*[]int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "[]int" + v5s := "" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addStringDumpTests() { + // Standard string. + v := "test" + vLen := fmt.Sprintf("%d", len(v)) + nv := (*string)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "string" + vs := "(len=" + vLen + ") \"test\"" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addInterfaceDumpTests() { + // Nil interface. + var v interface{} + nv := (*interface{})(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "interface {}" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addMapDumpTests() { + // Map with string keys and int vals. + k := "one" + kk := "two" + m := map[string]int{k: 1, kk: 2} + klen := fmt.Sprintf("%d", len(k)) // not kLen to shut golint up + kkLen := fmt.Sprintf("%d", len(kk)) + mLen := fmt.Sprintf("%d", len(m)) + nilMap := map[string]int(nil) + nm := (*map[string]int)(nil) + pm := &m + mAddr := fmt.Sprintf("%p", pm) + pmAddr := fmt.Sprintf("%p", &pm) + mt := "map[string]int" + mt1 := "string" + mt2 := "int" + ms := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + klen + ") " + + "\"one\": (" + mt2 + ") 1,\n (" + mt1 + ") (len=" + kkLen + + ") \"two\": (" + mt2 + ") 2\n}" + ms2 := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + kkLen + ") " + + "\"two\": (" + mt2 + ") 2,\n (" + mt1 + ") (len=" + klen + + ") \"one\": (" + mt2 + ") 1\n}" + addDumpTest(m, "("+mt+") "+ms+"\n", "("+mt+") "+ms2+"\n") + addDumpTest(pm, "(*"+mt+")("+mAddr+")("+ms+")\n", + "(*"+mt+")("+mAddr+")("+ms2+")\n") + addDumpTest(&pm, "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms+")\n", + "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms2+")\n") + addDumpTest(nm, "(*"+mt+")()\n") + addDumpTest(nilMap, "("+mt+") \n") + + // Map with custom formatter type on pointer receiver only keys and vals. + k2 := pstringer("one") + v2 := pstringer("1") + m2 := map[pstringer]pstringer{k2: v2} + k2Len := fmt.Sprintf("%d", len(k2)) + v2Len := fmt.Sprintf("%d", len(v2)) + m2Len := fmt.Sprintf("%d", len(m2)) + nilMap2 := map[pstringer]pstringer(nil) + nm2 := (*map[pstringer]pstringer)(nil) + pm2 := &m2 + m2Addr := fmt.Sprintf("%p", pm2) + pm2Addr := fmt.Sprintf("%p", &pm2) + m2t := "map[spew_test.pstringer]spew_test.pstringer" + m2t1 := "spew_test.pstringer" + m2t2 := "spew_test.pstringer" + m2s := "(len=" + m2Len + ") {\n (" + m2t1 + ") (len=" + k2Len + ") " + + "stringer one: (" + m2t2 + ") (len=" + v2Len + ") stringer 1\n}" + if spew.UnsafeDisabled { + m2s = "(len=" + m2Len + ") {\n (" + m2t1 + ") (len=" + k2Len + + ") " + "\"one\": (" + m2t2 + ") (len=" + v2Len + + ") \"1\"\n}" + } + addDumpTest(m2, "("+m2t+") "+m2s+"\n") + addDumpTest(pm2, "(*"+m2t+")("+m2Addr+")("+m2s+")\n") + addDumpTest(&pm2, "(**"+m2t+")("+pm2Addr+"->"+m2Addr+")("+m2s+")\n") + addDumpTest(nm2, "(*"+m2t+")()\n") + addDumpTest(nilMap2, "("+m2t+") \n") + + // Map with interface keys and values. + k3 := "one" + k3Len := fmt.Sprintf("%d", len(k3)) + m3 := map[interface{}]interface{}{k3: 1} + m3Len := fmt.Sprintf("%d", len(m3)) + nilMap3 := map[interface{}]interface{}(nil) + nm3 := (*map[interface{}]interface{})(nil) + pm3 := &m3 + m3Addr := fmt.Sprintf("%p", pm3) + pm3Addr := fmt.Sprintf("%p", &pm3) + m3t := "map[interface {}]interface {}" + m3t1 := "string" + m3t2 := "int" + m3s := "(len=" + m3Len + ") {\n (" + m3t1 + ") (len=" + k3Len + ") " + + "\"one\": (" + m3t2 + ") 1\n}" + addDumpTest(m3, "("+m3t+") "+m3s+"\n") + addDumpTest(pm3, "(*"+m3t+")("+m3Addr+")("+m3s+")\n") + addDumpTest(&pm3, "(**"+m3t+")("+pm3Addr+"->"+m3Addr+")("+m3s+")\n") + addDumpTest(nm3, "(*"+m3t+")()\n") + addDumpTest(nilMap3, "("+m3t+") \n") + + // Map with nil interface value. + k4 := "nil" + k4Len := fmt.Sprintf("%d", len(k4)) + m4 := map[string]interface{}{k4: nil} + m4Len := fmt.Sprintf("%d", len(m4)) + nilMap4 := map[string]interface{}(nil) + nm4 := (*map[string]interface{})(nil) + pm4 := &m4 + m4Addr := fmt.Sprintf("%p", pm4) + pm4Addr := fmt.Sprintf("%p", &pm4) + m4t := "map[string]interface {}" + m4t1 := "string" + m4t2 := "interface {}" + m4s := "(len=" + m4Len + ") {\n (" + m4t1 + ") (len=" + k4Len + ")" + + " \"nil\": (" + m4t2 + ") \n}" + addDumpTest(m4, "("+m4t+") "+m4s+"\n") + addDumpTest(pm4, "(*"+m4t+")("+m4Addr+")("+m4s+")\n") + addDumpTest(&pm4, "(**"+m4t+")("+pm4Addr+"->"+m4Addr+")("+m4s+")\n") + addDumpTest(nm4, "(*"+m4t+")()\n") + addDumpTest(nilMap4, "("+m4t+") \n") +} + +func addStructDumpTests() { + // Struct with primitives. + type s1 struct { + a int8 + b uint8 + } + v := s1{127, 255} + nv := (*s1)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.s1" + vt2 := "int8" + vt3 := "uint8" + vs := "{\n a: (" + vt2 + ") 127,\n b: (" + vt3 + ") 255\n}" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Struct that contains another struct. + type s2 struct { + s1 s1 + b bool + } + v2 := s2{s1{127, 255}, true} + nv2 := (*s2)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.s2" + v2t2 := "spew_test.s1" + v2t3 := "int8" + v2t4 := "uint8" + v2t5 := "bool" + v2s := "{\n s1: (" + v2t2 + ") {\n a: (" + v2t3 + ") 127,\n b: (" + + v2t4 + ") 255\n },\n b: (" + v2t5 + ") true\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Struct that contains custom type with Stringer pointer interface via both + // exported and unexported fields. + type s3 struct { + s pstringer + S pstringer + } + v3 := s3{"test", "test2"} + nv3 := (*s3)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.s3" + v3t2 := "spew_test.pstringer" + v3s := "{\n s: (" + v3t2 + ") (len=4) stringer test,\n S: (" + v3t2 + + ") (len=5) stringer test2\n}" + v3sp := v3s + if spew.UnsafeDisabled { + v3s = "{\n s: (" + v3t2 + ") (len=4) \"test\",\n S: (" + + v3t2 + ") (len=5) \"test2\"\n}" + v3sp = "{\n s: (" + v3t2 + ") (len=4) \"test\",\n S: (" + + v3t2 + ") (len=5) stringer test2\n}" + } + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3sp+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3sp+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Struct that contains embedded struct and field to same struct. + e := embed{"embedstr"} + eLen := fmt.Sprintf("%d", len("embedstr")) + v4 := embedwrap{embed: &e, e: &e} + nv4 := (*embedwrap)(nil) + pv4 := &v4 + eAddr := fmt.Sprintf("%p", &e) + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "spew_test.embedwrap" + v4t2 := "spew_test.embed" + v4t3 := "string" + v4s := "{\n embed: (*" + v4t2 + ")(" + eAddr + ")({\n a: (" + v4t3 + + ") (len=" + eLen + ") \"embedstr\"\n }),\n e: (*" + v4t2 + + ")(" + eAddr + ")({\n a: (" + v4t3 + ") (len=" + eLen + ")" + + " \"embedstr\"\n })\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") +} + +func addUintptrDumpTests() { + // Null pointer. + v := uintptr(0) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uintptr" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + + // Address of real variable. + i := 1 + v2 := uintptr(unsafe.Pointer(&i)) + nv2 := (*uintptr)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uintptr" + v2s := fmt.Sprintf("%p", &i) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addUnsafePointerDumpTests() { + // Null pointer. + v := unsafe.Pointer(uintptr(0)) + nv := (*unsafe.Pointer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "unsafe.Pointer" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Address of real variable. + i := 1 + v2 := unsafe.Pointer(&i) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "unsafe.Pointer" + v2s := fmt.Sprintf("%p", &i) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addChanDumpTests() { + // Nil channel. + var v chan int + pv := &v + nv := (*chan int)(nil) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "chan int" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Real channel. + v2 := make(chan int) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "chan int" + v2s := fmt.Sprintf("%p", v2) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addFuncDumpTests() { + // Function with no params and no returns. + v := addIntDumpTests + nv := (*func())(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "func()" + vs := fmt.Sprintf("%p", v) + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Function with param and no returns. + v2 := TestDump + nv2 := (*func(*testing.T))(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "func(*testing.T)" + v2s := fmt.Sprintf("%p", v2) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Function with multiple params and multiple returns. + var v3 = func(i int, s string) (b bool, err error) { + return true, nil + } + nv3 := (*func(int, string) (bool, error))(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "func(int, string) (bool, error)" + v3s := fmt.Sprintf("%p", v3) + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") +} + +func addCircularDumpTests() { + // Struct that is circular through self referencing. + type circular struct { + c *circular + } + v := circular{nil} + v.c = &v + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.circular" + vs := "{\n c: (*" + vt + ")(" + vAddr + ")({\n c: (*" + vt + ")(" + + vAddr + ")()\n })\n}" + vs2 := "{\n c: (*" + vt + ")(" + vAddr + ")()\n}" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs2+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs2+")\n") + + // Structs that are circular through cross referencing. + v2 := xref1{nil} + ts2 := xref2{&v2} + v2.ps2 = &ts2 + pv2 := &v2 + ts2Addr := fmt.Sprintf("%p", &ts2) + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.xref1" + v2t2 := "spew_test.xref2" + v2s := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t + + ")(" + v2Addr + ")({\n ps2: (*" + v2t2 + ")(" + ts2Addr + + ")()\n })\n })\n}" + v2s2 := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t + + ")(" + v2Addr + ")()\n })\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s2+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s2+")\n") + + // Structs that are indirectly circular. + v3 := indirCir1{nil} + tic2 := indirCir2{nil} + tic3 := indirCir3{&v3} + tic2.ps3 = &tic3 + v3.ps2 = &tic2 + pv3 := &v3 + tic2Addr := fmt.Sprintf("%p", &tic2) + tic3Addr := fmt.Sprintf("%p", &tic3) + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.indirCir1" + v3t2 := "spew_test.indirCir2" + v3t3 := "spew_test.indirCir3" + v3s := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 + + ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr + + ")({\n ps2: (*" + v3t2 + ")(" + tic2Addr + + ")()\n })\n })\n })\n}" + v3s2 := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 + + ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr + + ")()\n })\n })\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s2+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s2+")\n") +} + +func addPanicDumpTests() { + // Type that panics in its Stringer interface. + v := panicer(127) + nv := (*panicer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.panicer" + vs := "(PANIC=test panic)127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addErrorDumpTests() { + // Type that has a custom Error interface. + v := customError(127) + nv := (*customError)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.customError" + vs := "error: 127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +// TestDump executes all of the tests described by dumpTests. +func TestDump(t *testing.T) { + // Setup tests. + addIntDumpTests() + addUintDumpTests() + addBoolDumpTests() + addFloatDumpTests() + addComplexDumpTests() + addArrayDumpTests() + addSliceDumpTests() + addStringDumpTests() + addInterfaceDumpTests() + addMapDumpTests() + addStructDumpTests() + addUintptrDumpTests() + addUnsafePointerDumpTests() + addChanDumpTests() + addFuncDumpTests() + addCircularDumpTests() + addPanicDumpTests() + addErrorDumpTests() + addCgoDumpTests() + + t.Logf("Running %d tests", len(dumpTests)) + for i, test := range dumpTests { + buf := new(bytes.Buffer) + spew.Fdump(buf, test.in) + s := buf.String() + if testFailed(s, test.wants) { + t.Errorf("Dump #%d\n got: %s %s", i, s, stringizeWants(test.wants)) + continue + } + } +} + +func TestDumpSortedKeys(t *testing.T) { + cfg := spew.ConfigState{SortKeys: true} + s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) + expected := "(map[int]string) (len=3) {\n(int) 1: (string) (len=1) " + + "\"1\",\n(int) 2: (string) (len=1) \"2\",\n(int) 3: (string) " + + "(len=1) \"3\"\n" + + "}\n" + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } + + s = cfg.Sdump(map[stringer]int{"1": 1, "3": 3, "2": 2}) + expected = "(map[spew_test.stringer]int) (len=3) {\n" + + "(spew_test.stringer) (len=1) stringer 1: (int) 1,\n" + + "(spew_test.stringer) (len=1) stringer 2: (int) 2,\n" + + "(spew_test.stringer) (len=1) stringer 3: (int) 3\n" + + "}\n" + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } + + s = cfg.Sdump(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2}) + expected = "(map[spew_test.pstringer]int) (len=3) {\n" + + "(spew_test.pstringer) (len=1) stringer 1: (int) 1,\n" + + "(spew_test.pstringer) (len=1) stringer 2: (int) 2,\n" + + "(spew_test.pstringer) (len=1) stringer 3: (int) 3\n" + + "}\n" + if spew.UnsafeDisabled { + expected = "(map[spew_test.pstringer]int) (len=3) {\n" + + "(spew_test.pstringer) (len=1) \"1\": (int) 1,\n" + + "(spew_test.pstringer) (len=1) \"2\": (int) 2,\n" + + "(spew_test.pstringer) (len=1) \"3\": (int) 3\n" + + "}\n" + } + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } + + s = cfg.Sdump(map[customError]int{customError(1): 1, customError(3): 3, customError(2): 2}) + expected = "(map[spew_test.customError]int) (len=3) {\n" + + "(spew_test.customError) error: 1: (int) 1,\n" + + "(spew_test.customError) error: 2: (int) 2,\n" + + "(spew_test.customError) error: 3: (int) 3\n" + + "}\n" + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } + +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go new file mode 100644 index 00000000..6ab18080 --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go @@ -0,0 +1,99 @@ +// Copyright (c) 2013-2016 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when both cgo is supported and "-tags testcgo" is added to the go test +// command line. This means the cgo tests are only added (and hence run) when +// specifially requested. This configuration is used because spew itself +// does not require cgo to run even though it does handle certain cgo types +// specially. Rather than forcing all clients to require cgo and an external +// C compiler just to run the tests, this scheme makes them optional. +// +build cgo,testcgo + +package spew_test + +import ( + "fmt" + + "github.com/davecgh/go-spew/spew/testdata" +) + +func addCgoDumpTests() { + // C char pointer. + v := testdata.GetCgoCharPointer() + nv := testdata.GetCgoNullCharPointer() + pv := &v + vcAddr := fmt.Sprintf("%p", v) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "*testdata._Ctype_char" + vs := "116" + addDumpTest(v, "("+vt+")("+vcAddr+")("+vs+")\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+"->"+vcAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+"->"+vcAddr+")("+vs+")\n") + addDumpTest(nv, "("+vt+")()\n") + + // C char array. + v2, v2l, v2c := testdata.GetCgoCharArray() + v2Len := fmt.Sprintf("%d", v2l) + v2Cap := fmt.Sprintf("%d", v2c) + v2t := "[6]testdata._Ctype_char" + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") " + + "{\n 00000000 74 65 73 74 32 00 " + + " |test2.|\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + + // C unsigned char array. + v3, v3l, v3c := testdata.GetCgoUnsignedCharArray() + v3Len := fmt.Sprintf("%d", v3l) + v3Cap := fmt.Sprintf("%d", v3c) + v3t := "[6]testdata._Ctype_unsignedchar" + v3t2 := "[6]testdata._Ctype_uchar" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") " + + "{\n 00000000 74 65 73 74 33 00 " + + " |test3.|\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n", "("+v3t2+") "+v3s+"\n") + + // C signed char array. + v4, v4l, v4c := testdata.GetCgoSignedCharArray() + v4Len := fmt.Sprintf("%d", v4l) + v4Cap := fmt.Sprintf("%d", v4c) + v4t := "[6]testdata._Ctype_schar" + v4t2 := "testdata._Ctype_schar" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 + + ") 115,\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 52,\n (" + v4t2 + + ") 0\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + + // C uint8_t array. + v5, v5l, v5c := testdata.GetCgoUint8tArray() + v5Len := fmt.Sprintf("%d", v5l) + v5Cap := fmt.Sprintf("%d", v5c) + v5t := "[6]testdata._Ctype_uint8_t" + v5s := "(len=" + v5Len + " cap=" + v5Cap + ") " + + "{\n 00000000 74 65 73 74 35 00 " + + " |test5.|\n}" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + + // C typedefed unsigned char array. + v6, v6l, v6c := testdata.GetCgoTypdefedUnsignedCharArray() + v6Len := fmt.Sprintf("%d", v6l) + v6Cap := fmt.Sprintf("%d", v6c) + v6t := "[6]testdata._Ctype_custom_uchar_t" + v6s := "(len=" + v6Len + " cap=" + v6Cap + ") " + + "{\n 00000000 74 65 73 74 36 00 " + + " |test6.|\n}" + addDumpTest(v6, "("+v6t+") "+v6s+"\n") +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go new file mode 100644 index 00000000..52a0971f --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go @@ -0,0 +1,26 @@ +// Copyright (c) 2013 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when either cgo is not supported or "-tags testcgo" is not added to the go +// test command line. This file intentionally does not setup any cgo tests in +// this scenario. +// +build !cgo !testcgo + +package spew_test + +func addCgoDumpTests() { + // Don't add any tests for cgo since this file is only compiled when + // there should not be any cgo tests. +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/example_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/example_test.go new file mode 100644 index 00000000..c6ec8c6d --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/example_test.go @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "fmt" + + "github.com/davecgh/go-spew/spew" +) + +type Flag int + +const ( + flagOne Flag = iota + flagTwo +) + +var flagStrings = map[Flag]string{ + flagOne: "flagOne", + flagTwo: "flagTwo", +} + +func (f Flag) String() string { + if s, ok := flagStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown flag (%d)", int(f)) +} + +type Bar struct { + data uintptr +} + +type Foo struct { + unexportedField Bar + ExportedField map[interface{}]interface{} +} + +// This example demonstrates how to use Dump to dump variables to stdout. +func ExampleDump() { + // The following package level declarations are assumed for this example: + /* + type Flag int + + const ( + flagOne Flag = iota + flagTwo + ) + + var flagStrings = map[Flag]string{ + flagOne: "flagOne", + flagTwo: "flagTwo", + } + + func (f Flag) String() string { + if s, ok := flagStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown flag (%d)", int(f)) + } + + type Bar struct { + data uintptr + } + + type Foo struct { + unexportedField Bar + ExportedField map[interface{}]interface{} + } + */ + + // Setup some sample data structures for the example. + bar := Bar{uintptr(0)} + s1 := Foo{bar, map[interface{}]interface{}{"one": true}} + f := Flag(5) + b := []byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + + // Dump! + spew.Dump(s1, f, b) + + // Output: + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // (spew_test.Flag) Unknown flag (5) + // ([]uint8) (len=34 cap=34) { + // 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | + // 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| + // 00000020 31 32 |12| + // } + // +} + +// This example demonstrates how to use Printf to display a variable with a +// format string and inline formatting. +func ExamplePrintf() { + // Create a double pointer to a uint 8. + ui8 := uint8(5) + pui8 := &ui8 + ppui8 := &pui8 + + // Create a circular data type. + type circular struct { + ui8 uint8 + c *circular + } + c := circular{ui8: 1} + c.c = &c + + // Print! + spew.Printf("ppui8: %v\n", ppui8) + spew.Printf("circular: %v\n", c) + + // Output: + // ppui8: <**>5 + // circular: {1 <*>{1 <*>}} +} + +// This example demonstrates how to use a ConfigState. +func ExampleConfigState() { + // Modify the indent level of the ConfigState only. The global + // configuration is not modified. + scs := spew.ConfigState{Indent: "\t"} + + // Output using the ConfigState instance. + v := map[string]int{"one": 1} + scs.Printf("v: %v\n", v) + scs.Dump(v) + + // Output: + // v: map[one:1] + // (map[string]int) (len=1) { + // (string) (len=3) "one": (int) 1 + // } +} + +// This example demonstrates how to use ConfigState.Dump to dump variables to +// stdout +func ExampleConfigState_Dump() { + // See the top-level Dump example for details on the types used in this + // example. + + // Create two ConfigState instances with different indentation. + scs := spew.ConfigState{Indent: "\t"} + scs2 := spew.ConfigState{Indent: " "} + + // Setup some sample data structures for the example. + bar := Bar{uintptr(0)} + s1 := Foo{bar, map[interface{}]interface{}{"one": true}} + + // Dump using the ConfigState instances. + scs.Dump(s1) + scs2.Dump(s1) + + // Output: + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // +} + +// This example demonstrates how to use ConfigState.Printf to display a variable +// with a format string and inline formatting. +func ExampleConfigState_Printf() { + // See the top-level Dump example for details on the types used in this + // example. + + // Create two ConfigState instances and modify the method handling of the + // first ConfigState only. + scs := spew.NewDefaultConfig() + scs2 := spew.NewDefaultConfig() + scs.DisableMethods = true + + // Alternatively + // scs := spew.ConfigState{Indent: " ", DisableMethods: true} + // scs2 := spew.ConfigState{Indent: " "} + + // This is of type Flag which implements a Stringer and has raw value 1. + f := flagTwo + + // Dump using the ConfigState instances. + scs.Printf("f: %v\n", f) + scs2.Printf("f: %v\n", f) + + // Output: + // f: 1 + // f: flagTwo +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/format_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/format_test.go new file mode 100644 index 00000000..f9b93abe --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/format_test.go @@ -0,0 +1,1558 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +Test Summary: +NOTE: For each test, a nil pointer, a single pointer and double pointer to the +base test element are also tested to ensure proper indirection across all types. + +- Max int8, int16, int32, int64, int +- Max uint8, uint16, uint32, uint64, uint +- Boolean true and false +- Standard complex64 and complex128 +- Array containing standard ints +- Array containing type with custom formatter on pointer receiver only +- Array containing interfaces +- Slice containing standard float32 values +- Slice containing type with custom formatter on pointer receiver only +- Slice containing interfaces +- Nil slice +- Standard string +- Nil interface +- Sub-interface +- Map with string keys and int vals +- Map with custom formatter type on pointer receiver only keys and vals +- Map with interface keys and values +- Map with nil interface value +- Struct with primitives +- Struct that contains another struct +- Struct that contains custom type with Stringer pointer interface via both + exported and unexported fields +- Struct that contains embedded struct and field to same struct +- Uintptr to 0 (null pointer) +- Uintptr address of real variable +- Unsafe.Pointer to 0 (null pointer) +- Unsafe.Pointer to address of real variable +- Nil channel +- Standard int channel +- Function with no params and no returns +- Function with param and no returns +- Function with multiple params and multiple returns +- Struct that is circular through self referencing +- Structs that are circular through cross referencing +- Structs that are indirectly circular +- Type that panics in its Stringer interface +- Type that has a custom Error interface +- %x passthrough with uint +- %#x passthrough with uint +- %f passthrough with precision +- %f passthrough with width and precision +- %d passthrough with width +- %q passthrough with string +*/ + +package spew_test + +import ( + "bytes" + "fmt" + "testing" + "unsafe" + + "github.com/davecgh/go-spew/spew" +) + +// formatterTest is used to describe a test to be performed against NewFormatter. +type formatterTest struct { + format string + in interface{} + wants []string +} + +// formatterTests houses all of the tests to be performed against NewFormatter. +var formatterTests = make([]formatterTest, 0) + +// addFormatterTest is a helper method to append the passed input and desired +// result to formatterTests. +func addFormatterTest(format string, in interface{}, wants ...string) { + test := formatterTest{format, in, wants} + formatterTests = append(formatterTests, test) +} + +func addIntFormatterTests() { + // Max int8. + v := int8(127) + nv := (*int8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int8" + vs := "127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Max int16. + v2 := int16(32767) + nv2 := (*int16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "int16" + v2s := "32767" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Max int32. + v3 := int32(2147483647) + nv3 := (*int32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "int32" + v3s := "2147483647" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + + // Max int64. + v4 := int64(9223372036854775807) + nv4 := (*int64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "int64" + v4s := "9223372036854775807" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") + + // Max int. + v5 := int(2147483647) + nv5 := (*int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "int" + v5s := "2147483647" + addFormatterTest("%v", v5, v5s) + addFormatterTest("%v", pv5, "<*>"+v5s) + addFormatterTest("%v", &pv5, "<**>"+v5s) + addFormatterTest("%v", nv5, "") + addFormatterTest("%+v", v5, v5s) + addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s) + addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%+v", nv5, "") + addFormatterTest("%#v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s) + addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") + addFormatterTest("%#+v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s) + addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%#+v", nv5, "(*"+v5t+")"+"") +} + +func addUintFormatterTests() { + // Max uint8. + v := uint8(255) + nv := (*uint8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uint8" + vs := "255" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Max uint16. + v2 := uint16(65535) + nv2 := (*uint16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Max uint32. + v3 := uint32(4294967295) + nv3 := (*uint32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "uint32" + v3s := "4294967295" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + + // Max uint64. + v4 := uint64(18446744073709551615) + nv4 := (*uint64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "uint64" + v4s := "18446744073709551615" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") + + // Max uint. + v5 := uint(4294967295) + nv5 := (*uint)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "uint" + v5s := "4294967295" + addFormatterTest("%v", v5, v5s) + addFormatterTest("%v", pv5, "<*>"+v5s) + addFormatterTest("%v", &pv5, "<**>"+v5s) + addFormatterTest("%v", nv5, "") + addFormatterTest("%+v", v5, v5s) + addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s) + addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%+v", nv5, "") + addFormatterTest("%#v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s) + addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") + addFormatterTest("%#+v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s) + addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") +} + +func addBoolFormatterTests() { + // Boolean true. + v := bool(true) + nv := (*bool)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "bool" + vs := "true" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Boolean false. + v2 := bool(false) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "bool" + v2s := "false" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addFloatFormatterTests() { + // Standard float32. + v := float32(3.1415) + nv := (*float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "3.1415" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Standard float64. + v2 := float64(3.1415926) + nv2 := (*float64)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "float64" + v2s := "3.1415926" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") +} + +func addComplexFormatterTests() { + // Standard complex64. + v := complex(float32(6), -2) + nv := (*complex64)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "complex64" + vs := "(6-2i)" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Standard complex128. + v2 := complex(float64(-6), 2) + nv2 := (*complex128)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "complex128" + v2s := "(-6+2i)" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") +} + +func addArrayFormatterTests() { + // Array containing standard ints. + v := [3]int{1, 2, 3} + nv := (*[3]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "[3]int" + vs := "[1 2 3]" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Array containing type with custom formatter on pointer receiver only. + v2 := [3]pstringer{"1", "2", "3"} + nv2 := (*[3]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "[3]spew_test.pstringer" + v2sp := "[stringer 1 stringer 2 stringer 3]" + v2s := v2sp + if spew.UnsafeDisabled { + v2s = "[1 2 3]" + } + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2sp) + addFormatterTest("%v", &pv2, "<**>"+v2sp) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2sp) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2sp) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2sp) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2sp) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2sp) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2sp) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Array containing interfaces. + v3 := [3]interface{}{"one", int(2), uint(3)} + nv3 := (*[3]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[3]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3s := "[one 2 3]" + v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") +} + +func addSliceFormatterTests() { + // Slice containing standard float32 values. + v := []float32{3.14, 6.28, 12.56} + nv := (*[]float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "[]float32" + vs := "[3.14 6.28 12.56]" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Slice containing type with custom formatter on pointer receiver only. + v2 := []pstringer{"1", "2", "3"} + nv2 := (*[]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "[]spew_test.pstringer" + v2s := "[stringer 1 stringer 2 stringer 3]" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Slice containing interfaces. + v3 := []interface{}{"one", int(2), uint(3), nil} + nv3 := (*[]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3t5 := "interface {}" + v3s := "[one 2 3 ]" + v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3 (" + v3t5 + + ")]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Nil slice. + var v4 []int + nv4 := (*[]int)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[]int" + v4s := "" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addStringFormatterTests() { + // Standard string. + v := "test" + nv := (*string)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "string" + vs := "test" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addInterfaceFormatterTests() { + // Nil interface. + var v interface{} + nv := (*interface{})(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "interface {}" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addMapFormatterTests() { + // Map with string keys and int vals. + v := map[string]int{"one": 1, "two": 2} + nilMap := map[string]int(nil) + nv := (*map[string]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "map[string]int" + vs := "map[one:1 two:2]" + vs2 := "map[two:2 one:1]" + addFormatterTest("%v", v, vs, vs2) + addFormatterTest("%v", pv, "<*>"+vs, "<*>"+vs2) + addFormatterTest("%v", &pv, "<**>"+vs, "<**>"+vs2) + addFormatterTest("%+v", nilMap, "") + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs, vs2) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs, "<*>("+vAddr+")"+vs2) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs, + "<**>("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%+v", nilMap, "") + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs, "("+vt+")"+vs2) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs, "(*"+vt+")"+vs2) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs, "(**"+vt+")"+vs2) + addFormatterTest("%#v", nilMap, "("+vt+")"+"") + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs, "("+vt+")"+vs2) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs, + "(*"+vt+")("+vAddr+")"+vs2) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs, + "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%#+v", nilMap, "("+vt+")"+"") + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Map with custom formatter type on pointer receiver only keys and vals. + v2 := map[pstringer]pstringer{"one": "1"} + nv2 := (*map[pstringer]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "map[spew_test.pstringer]spew_test.pstringer" + v2s := "map[stringer one:stringer 1]" + if spew.UnsafeDisabled { + v2s = "map[one:1]" + } + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Map with interface keys and values. + v3 := map[interface{}]interface{}{"one": 1} + nv3 := (*map[interface{}]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "map[interface {}]interface {}" + v3t1 := "string" + v3t2 := "int" + v3s := "map[one:1]" + v3s2 := "map[(" + v3t1 + ")one:(" + v3t2 + ")1]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Map with nil interface value + v4 := map[string]interface{}{"nil": nil} + nv4 := (*map[string]interface{})(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "map[string]interface {}" + v4t1 := "interface {}" + v4s := "map[nil:]" + v4s2 := "map[nil:(" + v4t1 + ")]" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s2) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s2) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s2) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s2) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s2) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s2) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addStructFormatterTests() { + // Struct with primitives. + type s1 struct { + a int8 + b uint8 + } + v := s1{127, 255} + nv := (*s1)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.s1" + vt2 := "int8" + vt3 := "uint8" + vs := "{127 255}" + vs2 := "{a:127 b:255}" + vs3 := "{a:(" + vt2 + ")127 b:(" + vt3 + ")255}" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs2) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs2) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs3) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs3) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs3) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs3) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs3) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs3) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Struct that contains another struct. + type s2 struct { + s1 s1 + b bool + } + v2 := s2{s1{127, 255}, true} + nv2 := (*s2)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.s2" + v2t2 := "spew_test.s1" + v2t3 := "int8" + v2t4 := "uint8" + v2t5 := "bool" + v2s := "{{127 255} true}" + v2s2 := "{s1:{a:127 b:255} b:true}" + v2s3 := "{s1:(" + v2t2 + "){a:(" + v2t3 + ")127 b:(" + v2t4 + ")255} b:(" + + v2t5 + ")true}" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s2) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s2) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s2) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s3) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s3) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s3) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s3) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s3) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s3) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Struct that contains custom type with Stringer pointer interface via both + // exported and unexported fields. + type s3 struct { + s pstringer + S pstringer + } + v3 := s3{"test", "test2"} + nv3 := (*s3)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.s3" + v3t2 := "spew_test.pstringer" + v3s := "{stringer test stringer test2}" + v3sp := v3s + v3s2 := "{s:stringer test S:stringer test2}" + v3s2p := v3s2 + v3s3 := "{s:(" + v3t2 + ")stringer test S:(" + v3t2 + ")stringer test2}" + v3s3p := v3s3 + if spew.UnsafeDisabled { + v3s = "{test test2}" + v3sp = "{test stringer test2}" + v3s2 = "{s:test S:test2}" + v3s2p = "{s:test S:stringer test2}" + v3s3 = "{s:(" + v3t2 + ")test S:(" + v3t2 + ")test2}" + v3s3p = "{s:(" + v3t2 + ")test S:(" + v3t2 + ")stringer test2}" + } + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3sp) + addFormatterTest("%v", &pv3, "<**>"+v3sp) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s2) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s2p) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s2p) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s3) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s3p) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s3p) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s3) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s3p) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s3p) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Struct that contains embedded struct and field to same struct. + e := embed{"embedstr"} + v4 := embedwrap{embed: &e, e: &e} + nv4 := (*embedwrap)(nil) + pv4 := &v4 + eAddr := fmt.Sprintf("%p", &e) + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "spew_test.embedwrap" + v4t2 := "spew_test.embed" + v4t3 := "string" + v4s := "{<*>{embedstr} <*>{embedstr}}" + v4s2 := "{embed:<*>(" + eAddr + "){a:embedstr} e:<*>(" + eAddr + + "){a:embedstr}}" + v4s3 := "{embed:(*" + v4t2 + "){a:(" + v4t3 + ")embedstr} e:(*" + v4t2 + + "){a:(" + v4t3 + ")embedstr}}" + v4s4 := "{embed:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + + ")embedstr} e:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + ")embedstr}}" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s2) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s2) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s2) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s3) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s3) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s3) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s4) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s4) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s4) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addUintptrFormatterTests() { + // Null pointer. + v := uintptr(0) + nv := (*uintptr)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uintptr" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Address of real variable. + i := 1 + v2 := uintptr(unsafe.Pointer(&i)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uintptr" + v2s := fmt.Sprintf("%p", &i) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addUnsafePointerFormatterTests() { + // Null pointer. + v := unsafe.Pointer(uintptr(0)) + nv := (*unsafe.Pointer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "unsafe.Pointer" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Address of real variable. + i := 1 + v2 := unsafe.Pointer(&i) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "unsafe.Pointer" + v2s := fmt.Sprintf("%p", &i) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addChanFormatterTests() { + // Nil channel. + var v chan int + pv := &v + nv := (*chan int)(nil) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "chan int" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Real channel. + v2 := make(chan int) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "chan int" + v2s := fmt.Sprintf("%p", v2) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addFuncFormatterTests() { + // Function with no params and no returns. + v := addIntFormatterTests + nv := (*func())(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "func()" + vs := fmt.Sprintf("%p", v) + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Function with param and no returns. + v2 := TestFormatter + nv2 := (*func(*testing.T))(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "func(*testing.T)" + v2s := fmt.Sprintf("%p", v2) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Function with multiple params and multiple returns. + var v3 = func(i int, s string) (b bool, err error) { + return true, nil + } + nv3 := (*func(int, string) (bool, error))(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "func(int, string) (bool, error)" + v3s := fmt.Sprintf("%p", v3) + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") +} + +func addCircularFormatterTests() { + // Struct that is circular through self referencing. + type circular struct { + c *circular + } + v := circular{nil} + v.c = &v + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.circular" + vs := "{<*>{<*>}}" + vs2 := "{<*>}" + vs3 := "{c:<*>(" + vAddr + "){c:<*>(" + vAddr + ")}}" + vs4 := "{c:<*>(" + vAddr + ")}" + vs5 := "{c:(*" + vt + "){c:(*" + vt + ")}}" + vs6 := "{c:(*" + vt + ")}" + vs7 := "{c:(*" + vt + ")(" + vAddr + "){c:(*" + vt + ")(" + vAddr + + ")}}" + vs8 := "{c:(*" + vt + ")(" + vAddr + ")}" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs2) + addFormatterTest("%v", &pv, "<**>"+vs2) + addFormatterTest("%+v", v, vs3) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs4) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs4) + addFormatterTest("%#v", v, "("+vt+")"+vs5) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs6) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs6) + addFormatterTest("%#+v", v, "("+vt+")"+vs7) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs8) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs8) + + // Structs that are circular through cross referencing. + v2 := xref1{nil} + ts2 := xref2{&v2} + v2.ps2 = &ts2 + pv2 := &v2 + ts2Addr := fmt.Sprintf("%p", &ts2) + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.xref1" + v2t2 := "spew_test.xref2" + v2s := "{<*>{<*>{<*>}}}" + v2s2 := "{<*>{<*>}}" + v2s3 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + "){ps2:<*>(" + + ts2Addr + ")}}}" + v2s4 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + ")}}" + v2s5 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + "){ps2:(*" + v2t2 + + ")}}}" + v2s6 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + ")}}" + v2s7 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t + + ")(" + v2Addr + "){ps2:(*" + v2t2 + ")(" + ts2Addr + + ")}}}" + v2s8 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t + + ")(" + v2Addr + ")}}" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s2) + addFormatterTest("%v", &pv2, "<**>"+v2s2) + addFormatterTest("%+v", v2, v2s3) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s4) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s4) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s5) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s6) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s6) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s7) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s8) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s8) + + // Structs that are indirectly circular. + v3 := indirCir1{nil} + tic2 := indirCir2{nil} + tic3 := indirCir3{&v3} + tic2.ps3 = &tic3 + v3.ps2 = &tic2 + pv3 := &v3 + tic2Addr := fmt.Sprintf("%p", &tic2) + tic3Addr := fmt.Sprintf("%p", &tic3) + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.indirCir1" + v3t2 := "spew_test.indirCir2" + v3t3 := "spew_test.indirCir3" + v3s := "{<*>{<*>{<*>{<*>}}}}" + v3s2 := "{<*>{<*>{<*>}}}" + v3s3 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" + + v3Addr + "){ps2:<*>(" + tic2Addr + ")}}}}" + v3s4 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" + + v3Addr + ")}}}" + v3s5 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t + + "){ps2:(*" + v3t2 + ")}}}}" + v3s6 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t + + ")}}}" + v3s7 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" + + tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + "){ps2:(*" + v3t2 + + ")(" + tic2Addr + ")}}}}" + v3s8 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" + + tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + ")}}}" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s2) + addFormatterTest("%v", &pv3, "<**>"+v3s2) + addFormatterTest("%+v", v3, v3s3) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s4) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s4) + addFormatterTest("%#v", v3, "("+v3t+")"+v3s5) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s6) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s6) + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s7) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s8) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s8) +} + +func addPanicFormatterTests() { + // Type that panics in its Stringer interface. + v := panicer(127) + nv := (*panicer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.panicer" + vs := "(PANIC=test panic)127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addErrorFormatterTests() { + // Type that has a custom Error interface. + v := customError(127) + nv := (*customError)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.customError" + vs := "error: 127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addPassthroughFormatterTests() { + // %x passthrough with uint. + v := uint(4294967295) + pv := &v + vAddr := fmt.Sprintf("%x", pv) + pvAddr := fmt.Sprintf("%x", &pv) + vs := "ffffffff" + addFormatterTest("%x", v, vs) + addFormatterTest("%x", pv, vAddr) + addFormatterTest("%x", &pv, pvAddr) + + // %#x passthrough with uint. + v2 := int(2147483647) + pv2 := &v2 + v2Addr := fmt.Sprintf("%#x", pv2) + pv2Addr := fmt.Sprintf("%#x", &pv2) + v2s := "0x7fffffff" + addFormatterTest("%#x", v2, v2s) + addFormatterTest("%#x", pv2, v2Addr) + addFormatterTest("%#x", &pv2, pv2Addr) + + // %f passthrough with precision. + addFormatterTest("%.2f", 3.1415, "3.14") + addFormatterTest("%.3f", 3.1415, "3.142") + addFormatterTest("%.4f", 3.1415, "3.1415") + + // %f passthrough with width and precision. + addFormatterTest("%5.2f", 3.1415, " 3.14") + addFormatterTest("%6.3f", 3.1415, " 3.142") + addFormatterTest("%7.4f", 3.1415, " 3.1415") + + // %d passthrough with width. + addFormatterTest("%3d", 127, "127") + addFormatterTest("%4d", 127, " 127") + addFormatterTest("%5d", 127, " 127") + + // %q passthrough with string. + addFormatterTest("%q", "test", "\"test\"") +} + +// TestFormatter executes all of the tests described by formatterTests. +func TestFormatter(t *testing.T) { + // Setup tests. + addIntFormatterTests() + addUintFormatterTests() + addBoolFormatterTests() + addFloatFormatterTests() + addComplexFormatterTests() + addArrayFormatterTests() + addSliceFormatterTests() + addStringFormatterTests() + addInterfaceFormatterTests() + addMapFormatterTests() + addStructFormatterTests() + addUintptrFormatterTests() + addUnsafePointerFormatterTests() + addChanFormatterTests() + addFuncFormatterTests() + addCircularFormatterTests() + addPanicFormatterTests() + addErrorFormatterTests() + addPassthroughFormatterTests() + + t.Logf("Running %d tests", len(formatterTests)) + for i, test := range formatterTests { + buf := new(bytes.Buffer) + spew.Fprintf(buf, test.format, test.in) + s := buf.String() + if testFailed(s, test.wants) { + t.Errorf("Formatter #%d format: %s got: %s %s", i, test.format, s, + stringizeWants(test.wants)) + continue + } + } +} + +type testStruct struct { + x int +} + +func (ts testStruct) String() string { + return fmt.Sprintf("ts.%d", ts.x) +} + +type testStructP struct { + x int +} + +func (ts *testStructP) String() string { + return fmt.Sprintf("ts.%d", ts.x) +} + +func TestPrintSortedKeys(t *testing.T) { + cfg := spew.ConfigState{SortKeys: true} + s := cfg.Sprint(map[int]string{1: "1", 3: "3", 2: "2"}) + expected := "map[1:1 2:2 3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch 1:\n %v %v", s, expected) + } + + s = cfg.Sprint(map[stringer]int{"1": 1, "3": 3, "2": 2}) + expected = "map[stringer 1:1 stringer 2:2 stringer 3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch 2:\n %v %v", s, expected) + } + + s = cfg.Sprint(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2}) + expected = "map[stringer 1:1 stringer 2:2 stringer 3:3]" + if spew.UnsafeDisabled { + expected = "map[1:1 2:2 3:3]" + } + if s != expected { + t.Errorf("Sorted keys mismatch 3:\n %v %v", s, expected) + } + + s = cfg.Sprint(map[testStruct]int{testStruct{1}: 1, testStruct{3}: 3, testStruct{2}: 2}) + expected = "map[ts.1:1 ts.2:2 ts.3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch 4:\n %v %v", s, expected) + } + + if !spew.UnsafeDisabled { + s = cfg.Sprint(map[testStructP]int{testStructP{1}: 1, testStructP{3}: 3, testStructP{2}: 2}) + expected = "map[ts.1:1 ts.2:2 ts.3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch 5:\n %v %v", s, expected) + } + } + + s = cfg.Sprint(map[customError]int{customError(1): 1, customError(3): 3, customError(2): 2}) + expected = "map[error: 1:1 error: 2:2 error: 3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch 6:\n %v %v", s, expected) + } +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/internal_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/internal_test.go new file mode 100644 index 00000000..20a9cfef --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/internal_test.go @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +This test file is part of the spew package rather than than the spew_test +package because it needs access to internals to properly test certain cases +which are not possible via the public interface since they should never happen. +*/ + +package spew + +import ( + "bytes" + "reflect" + "testing" +) + +// dummyFmtState implements a fake fmt.State to use for testing invalid +// reflect.Value handling. This is necessary because the fmt package catches +// invalid values before invoking the formatter on them. +type dummyFmtState struct { + bytes.Buffer +} + +func (dfs *dummyFmtState) Flag(f int) bool { + if f == int('+') { + return true + } + return false +} + +func (dfs *dummyFmtState) Precision() (int, bool) { + return 0, false +} + +func (dfs *dummyFmtState) Width() (int, bool) { + return 0, false +} + +// TestInvalidReflectValue ensures the dump and formatter code handles an +// invalid reflect value properly. This needs access to internal state since it +// should never happen in real code and therefore can't be tested via the public +// API. +func TestInvalidReflectValue(t *testing.T) { + i := 1 + + // Dump invalid reflect value. + v := new(reflect.Value) + buf := new(bytes.Buffer) + d := dumpState{w: buf, cs: &Config} + d.dump(*v) + s := buf.String() + want := "" + if s != want { + t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want) + } + i++ + + // Formatter invalid reflect value. + buf2 := new(dummyFmtState) + f := formatState{value: *v, cs: &Config, fs: buf2} + f.format(*v) + s = buf2.String() + want = "" + if s != want { + t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want) + } +} + +// SortValues makes the internal sortValues function available to the test +// package. +func SortValues(values []reflect.Value, cs *ConfigState) { + sortValues(values, cs) +} diff --git a/discovery/vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go b/discovery/vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go new file mode 100644 index 00000000..a0c612ec --- /dev/null +++ b/discovery/vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go @@ -0,0 +1,102 @@ +// Copyright (c) 2013-2016 Dave Collins + +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. + +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is not running on Google App Engine, compiled by GopherJS, and +// "-tags safe" is not added to the go build command line. The "disableunsafe" +// tag is deprecated and thus should not be used. +// +build !js,!appengine,!safe,!disableunsafe + +/* +This test file is part of the spew package rather than than the spew_test +package because it needs access to internals to properly test certain cases +which are not possible via the public interface since they should never happen. +*/ + +package spew + +import ( + "bytes" + "reflect" + "testing" + "unsafe" +) + +// changeKind uses unsafe to intentionally change the kind of a reflect.Value to +// the maximum kind value which does not exist. This is needed to test the +// fallback code which punts to the standard fmt library for new types that +// might get added to the language. +func changeKind(v *reflect.Value, readOnly bool) { + rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag)) + *rvf = *rvf | ((1< + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" + "testing" + + "github.com/davecgh/go-spew/spew" +) + +// spewFunc is used to identify which public function of the spew package or +// ConfigState a test applies to. +type spewFunc int + +const ( + fCSFdump spewFunc = iota + fCSFprint + fCSFprintf + fCSFprintln + fCSPrint + fCSPrintln + fCSSdump + fCSSprint + fCSSprintf + fCSSprintln + fCSErrorf + fCSNewFormatter + fErrorf + fFprint + fFprintln + fPrint + fPrintln + fSdump + fSprint + fSprintf + fSprintln +) + +// Map of spewFunc values to names for pretty printing. +var spewFuncStrings = map[spewFunc]string{ + fCSFdump: "ConfigState.Fdump", + fCSFprint: "ConfigState.Fprint", + fCSFprintf: "ConfigState.Fprintf", + fCSFprintln: "ConfigState.Fprintln", + fCSSdump: "ConfigState.Sdump", + fCSPrint: "ConfigState.Print", + fCSPrintln: "ConfigState.Println", + fCSSprint: "ConfigState.Sprint", + fCSSprintf: "ConfigState.Sprintf", + fCSSprintln: "ConfigState.Sprintln", + fCSErrorf: "ConfigState.Errorf", + fCSNewFormatter: "ConfigState.NewFormatter", + fErrorf: "spew.Errorf", + fFprint: "spew.Fprint", + fFprintln: "spew.Fprintln", + fPrint: "spew.Print", + fPrintln: "spew.Println", + fSdump: "spew.Sdump", + fSprint: "spew.Sprint", + fSprintf: "spew.Sprintf", + fSprintln: "spew.Sprintln", +} + +func (f spewFunc) String() string { + if s, ok := spewFuncStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown spewFunc (%d)", int(f)) +} + +// spewTest is used to describe a test to be performed against the public +// functions of the spew package or ConfigState. +type spewTest struct { + cs *spew.ConfigState + f spewFunc + format string + in interface{} + want string +} + +// spewTests houses the tests to be performed against the public functions of +// the spew package and ConfigState. +// +// These tests are only intended to ensure the public functions are exercised +// and are intentionally not exhaustive of types. The exhaustive type +// tests are handled in the dump and format tests. +var spewTests []spewTest + +// redirStdout is a helper function to return the standard output from f as a +// byte slice. +func redirStdout(f func()) ([]byte, error) { + tempFile, err := ioutil.TempFile("", "ss-test") + if err != nil { + return nil, err + } + fileName := tempFile.Name() + defer os.Remove(fileName) // Ignore error + + origStdout := os.Stdout + os.Stdout = tempFile + f() + os.Stdout = origStdout + tempFile.Close() + + return ioutil.ReadFile(fileName) +} + +func initSpewTests() { + // Config states with various settings. + scsDefault := spew.NewDefaultConfig() + scsNoMethods := &spew.ConfigState{Indent: " ", DisableMethods: true} + scsNoPmethods := &spew.ConfigState{Indent: " ", DisablePointerMethods: true} + scsMaxDepth := &spew.ConfigState{Indent: " ", MaxDepth: 1} + scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true} + scsNoPtrAddr := &spew.ConfigState{DisablePointerAddresses: true} + scsNoCap := &spew.ConfigState{DisableCapacities: true} + + // Variables for tests on types which implement Stringer interface with and + // without a pointer receiver. + ts := stringer("test") + tps := pstringer("test") + + type ptrTester struct { + s *struct{} + } + tptr := &ptrTester{s: &struct{}{}} + + // depthTester is used to test max depth handling for structs, array, slices + // and maps. + type depthTester struct { + ic indirCir1 + arr [1]string + slice []string + m map[string]int + } + dt := depthTester{indirCir1{nil}, [1]string{"arr"}, []string{"slice"}, + map[string]int{"one": 1}} + + // Variable for tests on types which implement error interface. + te := customError(10) + + spewTests = []spewTest{ + {scsDefault, fCSFdump, "", int8(127), "(int8) 127\n"}, + {scsDefault, fCSFprint, "", int16(32767), "32767"}, + {scsDefault, fCSFprintf, "%v", int32(2147483647), "2147483647"}, + {scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"}, + {scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"}, + {scsDefault, fCSPrintln, "", uint8(255), "255\n"}, + {scsDefault, fCSSdump, "", uint8(64), "(uint8) 64\n"}, + {scsDefault, fCSSprint, "", complex(1, 2), "(1+2i)"}, + {scsDefault, fCSSprintf, "%v", complex(float32(3), 4), "(3+4i)"}, + {scsDefault, fCSSprintln, "", complex(float64(5), 6), "(5+6i)\n"}, + {scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"}, + {scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"}, + {scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"}, + {scsDefault, fFprint, "", float32(3.14), "3.14"}, + {scsDefault, fFprintln, "", float64(6.28), "6.28\n"}, + {scsDefault, fPrint, "", true, "true"}, + {scsDefault, fPrintln, "", false, "false\n"}, + {scsDefault, fSdump, "", complex(-10, -20), "(complex128) (-10-20i)\n"}, + {scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"}, + {scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"}, + {scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"}, + {scsNoMethods, fCSFprint, "", ts, "test"}, + {scsNoMethods, fCSFprint, "", &ts, "<*>test"}, + {scsNoMethods, fCSFprint, "", tps, "test"}, + {scsNoMethods, fCSFprint, "", &tps, "<*>test"}, + {scsNoPmethods, fCSFprint, "", ts, "stringer test"}, + {scsNoPmethods, fCSFprint, "", &ts, "<*>stringer test"}, + {scsNoPmethods, fCSFprint, "", tps, "test"}, + {scsNoPmethods, fCSFprint, "", &tps, "<*>stringer test"}, + {scsMaxDepth, fCSFprint, "", dt, "{{} [] [] map[]}"}, + {scsMaxDepth, fCSFdump, "", dt, "(spew_test.depthTester) {\n" + + " ic: (spew_test.indirCir1) {\n \n },\n" + + " arr: ([1]string) (len=1 cap=1) {\n \n },\n" + + " slice: ([]string) (len=1 cap=1) {\n \n },\n" + + " m: (map[string]int) (len=1) {\n \n }\n}\n"}, + {scsContinue, fCSFprint, "", ts, "(stringer test) test"}, + {scsContinue, fCSFdump, "", ts, "(spew_test.stringer) " + + "(len=4) (stringer test) \"test\"\n"}, + {scsContinue, fCSFprint, "", te, "(error: 10) 10"}, + {scsContinue, fCSFdump, "", te, "(spew_test.customError) " + + "(error: 10) 10\n"}, + {scsNoPtrAddr, fCSFprint, "", tptr, "<*>{<*>{}}"}, + {scsNoPtrAddr, fCSSdump, "", tptr, "(*spew_test.ptrTester)({\ns: (*struct {})({\n})\n})\n"}, + {scsNoCap, fCSSdump, "", make([]string, 0, 10), "([]string) {\n}\n"}, + {scsNoCap, fCSSdump, "", make([]string, 1, 10), "([]string) (len=1) {\n(string) \"\"\n}\n"}, + } +} + +// TestSpew executes all of the tests described by spewTests. +func TestSpew(t *testing.T) { + initSpewTests() + + t.Logf("Running %d tests", len(spewTests)) + for i, test := range spewTests { + buf := new(bytes.Buffer) + switch test.f { + case fCSFdump: + test.cs.Fdump(buf, test.in) + + case fCSFprint: + test.cs.Fprint(buf, test.in) + + case fCSFprintf: + test.cs.Fprintf(buf, test.format, test.in) + + case fCSFprintln: + test.cs.Fprintln(buf, test.in) + + case fCSPrint: + b, err := redirStdout(func() { test.cs.Print(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fCSPrintln: + b, err := redirStdout(func() { test.cs.Println(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fCSSdump: + str := test.cs.Sdump(test.in) + buf.WriteString(str) + + case fCSSprint: + str := test.cs.Sprint(test.in) + buf.WriteString(str) + + case fCSSprintf: + str := test.cs.Sprintf(test.format, test.in) + buf.WriteString(str) + + case fCSSprintln: + str := test.cs.Sprintln(test.in) + buf.WriteString(str) + + case fCSErrorf: + err := test.cs.Errorf(test.format, test.in) + buf.WriteString(err.Error()) + + case fCSNewFormatter: + fmt.Fprintf(buf, test.format, test.cs.NewFormatter(test.in)) + + case fErrorf: + err := spew.Errorf(test.format, test.in) + buf.WriteString(err.Error()) + + case fFprint: + spew.Fprint(buf, test.in) + + case fFprintln: + spew.Fprintln(buf, test.in) + + case fPrint: + b, err := redirStdout(func() { spew.Print(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fPrintln: + b, err := redirStdout(func() { spew.Println(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fSdump: + str := spew.Sdump(test.in) + buf.WriteString(str) + + case fSprint: + str := spew.Sprint(test.in) + buf.WriteString(str) + + case fSprintf: + str := spew.Sprintf(test.format, test.in) + buf.WriteString(str) + + case fSprintln: + str := spew.Sprintln(test.in) + buf.WriteString(str) + + default: + t.Errorf("%v #%d unrecognized function", test.f, i) + continue + } + s := buf.String() + if test.want != s { + t.Errorf("ConfigState #%d\n got: %s want: %s", i, s, test.want) + continue + } + } +} diff --git a/discovery/vendor/github.com/emicklei/go-restful/.gitignore b/discovery/vendor/github.com/emicklei/go-restful/.gitignore deleted file mode 100644 index cece7be6..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/.gitignore +++ /dev/null @@ -1,70 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe - -restful.html - -*.out - -tmp.prof - -go-restful.test - -examples/restful-basic-authentication - -examples/restful-encoding-filter - -examples/restful-filters - -examples/restful-hello-world - -examples/restful-resource-functions - -examples/restful-serve-static - -examples/restful-user-service - -*.DS_Store -examples/restful-user-resource - -examples/restful-multi-containers - -examples/restful-form-handling - -examples/restful-CORS-filter - -examples/restful-options-filter - -examples/restful-curly-router - -examples/restful-cpuprofiler-service - -examples/restful-pre-post-filters - -curly.prof - -examples/restful-NCSA-logging - -examples/restful-html-template - -s.html -restful-path-tail diff --git a/discovery/vendor/github.com/emicklei/go-restful/CHANGES.md b/discovery/vendor/github.com/emicklei/go-restful/CHANGES.md deleted file mode 100644 index d90aaa22..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/CHANGES.md +++ /dev/null @@ -1,226 +0,0 @@ -Change history of go-restful -= -2017-09-13 -- added route condition functions using `.If(func)` in route building. - -2017-02-16 -- solved issue #304, make operation names unique - -2017-01-30 - - [IMPORTANT] For swagger users, change your import statement to: - swagger "github.com/emicklei/go-restful-swagger12" - -- moved swagger 1.2 code to go-restful-swagger12 -- created TAG 2.0.0 - -2017-01-27 - -- remove defer request body close -- expose Dispatch for testing filters and Routefunctions -- swagger response model cannot be array -- created TAG 1.0.0 - -2016-12-22 - -- (API change) Remove code related to caching request content. Removes SetCacheReadEntity(doCache bool) - -2016-11-26 - -- Default change! now use CurlyRouter (was RouterJSR311) -- Default change! no more caching of request content -- Default change! do not recover from panics - -2016-09-22 - -- fix the DefaultRequestContentType feature - -2016-02-14 - -- take the qualify factor of the Accept header mediatype into account when deciding the contentype of the response -- add constructors for custom entity accessors for xml and json - -2015-09-27 - -- rename new WriteStatusAnd... to WriteHeaderAnd... for consistency - -2015-09-25 - -- fixed problem with changing Header after WriteHeader (issue 235) - -2015-09-14 - -- changed behavior of WriteHeader (immediate write) and WriteEntity (no status write) -- added support for custom EntityReaderWriters. - -2015-08-06 - -- add support for reading entities from compressed request content -- use sync.Pool for compressors of http response and request body -- add Description to Parameter for documentation in Swagger UI - -2015-03-20 - -- add configurable logging - -2015-03-18 - -- if not specified, the Operation is derived from the Route function - -2015-03-17 - -- expose Parameter creation functions -- make trace logger an interface -- fix OPTIONSFilter -- customize rendering of ServiceError -- JSR311 router now handles wildcards -- add Notes to Route - -2014-11-27 - -- (api add) PrettyPrint per response. (as proposed in #167) - -2014-11-12 - -- (api add) ApiVersion(.) for documentation in Swagger UI - -2014-11-10 - -- (api change) struct fields tagged with "description" show up in Swagger UI - -2014-10-31 - -- (api change) ReturnsError -> Returns -- (api add) RouteBuilder.Do(aBuilder) for DRY use of RouteBuilder -- fix swagger nested structs -- sort Swagger response messages by code - -2014-10-23 - -- (api add) ReturnsError allows you to document Http codes in swagger -- fixed problem with greedy CurlyRouter -- (api add) Access-Control-Max-Age in CORS -- add tracing functionality (injectable) for debugging purposes -- support JSON parse 64bit int -- fix empty parameters for swagger -- WebServicesUrl is now optional for swagger -- fixed duplicate AccessControlAllowOrigin in CORS -- (api change) expose ServeMux in container -- (api add) added AllowedDomains in CORS -- (api add) ParameterNamed for detailed documentation - -2014-04-16 - -- (api add) expose constructor of Request for testing. - -2014-06-27 - -- (api add) ParameterNamed gives access to a Parameter definition and its data (for further specification). -- (api add) SetCacheReadEntity allow scontrol over whether or not the request body is being cached (default true for compatibility reasons). - -2014-07-03 - -- (api add) CORS can be configured with a list of allowed domains - -2014-03-12 - -- (api add) Route path parameters can use wildcard or regular expressions. (requires CurlyRouter) - -2014-02-26 - -- (api add) Request now provides information about the matched Route, see method SelectedRoutePath - -2014-02-17 - -- (api change) renamed parameter constants (go-lint checks) - -2014-01-10 - -- (api add) support for CloseNotify, see http://golang.org/pkg/net/http/#CloseNotifier - -2014-01-07 - -- (api change) Write* methods in Response now return the error or nil. -- added example of serving HTML from a Go template. -- fixed comparing Allowed headers in CORS (is now case-insensitive) - -2013-11-13 - -- (api add) Response knows how many bytes are written to the response body. - -2013-10-29 - -- (api add) RecoverHandler(handler RecoverHandleFunction) to change how panic recovery is handled. Default behavior is to log and return a stacktrace. This may be a security issue as it exposes sourcecode information. - -2013-10-04 - -- (api add) Response knows what HTTP status has been written -- (api add) Request can have attributes (map of string->interface, also called request-scoped variables - -2013-09-12 - -- (api change) Router interface simplified -- Implemented CurlyRouter, a Router that does not use|allow regular expressions in paths - -2013-08-05 - - add OPTIONS support - - add CORS support - -2013-08-27 - -- fixed some reported issues (see github) -- (api change) deprecated use of WriteError; use WriteErrorString instead - -2014-04-15 - -- (fix) v1.0.1 tag: fix Issue 111: WriteErrorString - -2013-08-08 - -- (api add) Added implementation Container: a WebServices collection with its own http.ServeMux allowing multiple endpoints per program. Existing uses of go-restful will register their services to the DefaultContainer. -- (api add) the swagger package has be extended to have a UI per container. -- if panic is detected then a small stack trace is printed (thanks to runner-mei) -- (api add) WriteErrorString to Response - -Important API changes: - -- (api remove) package variable DoNotRecover no longer works ; use restful.DefaultContainer.DoNotRecover(true) instead. -- (api remove) package variable EnableContentEncoding no longer works ; use restful.DefaultContainer.EnableContentEncoding(true) instead. - - -2013-07-06 - -- (api add) Added support for response encoding (gzip and deflate(zlib)). This feature is disabled on default (for backwards compatibility). Use restful.EnableContentEncoding = true in your initialization to enable this feature. - -2013-06-19 - -- (improve) DoNotRecover option, moved request body closer, improved ReadEntity - -2013-06-03 - -- (api change) removed Dispatcher interface, hide PathExpression -- changed receiver names of type functions to be more idiomatic Go - -2013-06-02 - -- (optimize) Cache the RegExp compilation of Paths. - -2013-05-22 - -- (api add) Added support for request/response filter functions - -2013-05-18 - - -- (api add) Added feature to change the default Http Request Dispatch function (travis cline) -- (api change) Moved Swagger Webservice to swagger package (see example restful-user) - -[2012-11-14 .. 2013-05-18> - -- See https://github.com/emicklei/go-restful/commits - -2012-11-14 - -- Initial commit - - diff --git a/discovery/vendor/github.com/emicklei/go-restful/LICENSE b/discovery/vendor/github.com/emicklei/go-restful/LICENSE deleted file mode 100644 index ece7ec61..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2012,2013 Ernest Micklei - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/Makefile b/discovery/vendor/github.com/emicklei/go-restful/Makefile deleted file mode 100644 index b40081cc..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: test - -test: - go test -v . - -ex: - cd examples && ls *.go | xargs go build -o /tmp/ignore \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/README.md b/discovery/vendor/github.com/emicklei/go-restful/README.md deleted file mode 100644 index 002a08d9..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/README.md +++ /dev/null @@ -1,75 +0,0 @@ -go-restful -========== -package for building REST-style Web Services using Google Go - -[![Build Status](https://travis-ci.org/emicklei/go-restful.png)](https://travis-ci.org/emicklei/go-restful) -[![Go Report Card](https://goreportcard.com/badge/github.com/emicklei/go-restful)](https://goreportcard.com/report/github.com/emicklei/go-restful) -[![GoDoc](https://godoc.org/github.com/emicklei/go-restful?status.svg)](https://godoc.org/github.com/emicklei/go-restful) - -- [Code examples](https://github.com/emicklei/go-restful/tree/master/examples) - -REST asks developers to use HTTP methods explicitly and in a way that's consistent with the protocol definition. This basic REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations and HTTP methods. According to this mapping: - -- GET = Retrieve a representation of a resource -- POST = Create if you are sending content to the server to create a subordinate of the specified resource collection, using some server-side algorithm. -- PUT = Create if you are sending the full content of the specified resource (URI). -- PUT = Update if you are updating the full content of the specified resource. -- DELETE = Delete if you are requesting the server to delete the resource -- PATCH = Update partial content of a resource -- OPTIONS = Get information about the communication options for the request URI - -### Example - -```Go -ws := new(restful.WebService) -ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) - -ws.Route(ws.GET("/{user-id}").To(u.findUser). - Doc("get a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). - Writes(User{})) -... - -func (u UserResource) findUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - ... -} -``` - -[Full API of a UserResource](https://github.com/emicklei/go-restful/tree/master/examples/restful-user-resource.go) - -### Features - -- Routes for request → function mapping with path parameter (e.g. {id}) support -- Configurable router: - - (default) Fast routing algorithm that allows static elements, regular expressions and dynamic parameters in the URL path (e.g. /meetings/{id} or /static/{subpath:*} - - Routing algorithm after [JSR311](http://jsr311.java.net/nonav/releases/1.1/spec/spec.html) that is implemented using (but does **not** accept) regular expressions -- Request API for reading structs from JSON/XML and accesing parameters (path,query,header) -- Response API for writing structs to JSON/XML and setting headers -- Customizable encoding using EntityReaderWriter registration -- Filters for intercepting the request → response flow on Service or Route level -- Request-scoped variables using attributes -- Containers for WebServices on different HTTP endpoints -- Content encoding (gzip,deflate) of request and response payloads -- Automatic responses on OPTIONS (using a filter) -- Automatic CORS request handling (using a filter) -- API declaration for Swagger UI ([go-restful-openapi](https://github.com/emicklei/go-restful-openapi), see [go-restful-swagger12](https://github.com/emicklei/go-restful-swagger12)) -- Panic recovery to produce HTTP 500, customizable using RecoverHandler(...) -- Route errors produce HTTP 404/405/406/415 errors, customizable using ServiceErrorHandler(...) -- Configurable (trace) logging -- Customizable gzip/deflate readers and writers using CompressorProvider registration - -### Resources - -- [Example posted on blog](http://ernestmicklei.com/2012/11/go-restful-first-working-example/) -- [Design explained on blog](http://ernestmicklei.com/2012/11/go-restful-api-design/) -- [sourcegraph](https://sourcegraph.com/github.com/emicklei/go-restful) -- [showcase: Zazkia - tcp proxy for testing resiliency](https://github.com/emicklei/zazkia) -- [showcase: Mora - MongoDB REST Api server](https://github.com/emicklei/mora) - -Type ```git shortlog -s``` for a full list of contributors. - -© 2012 - 2017, http://ernestmicklei.com. MIT License. Contributions are welcome. diff --git a/discovery/vendor/github.com/emicklei/go-restful/Srcfile b/discovery/vendor/github.com/emicklei/go-restful/Srcfile deleted file mode 100644 index 16fd1868..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/Srcfile +++ /dev/null @@ -1 +0,0 @@ -{"SkipDirs": ["examples"]} diff --git a/discovery/vendor/github.com/emicklei/go-restful/bench_test.sh b/discovery/vendor/github.com/emicklei/go-restful/bench_test.sh deleted file mode 100644 index 47ffbe4a..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/bench_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#go test -run=none -file bench_test.go -test.bench . -cpuprofile=bench_test.out - -go test -c -./go-restful.test -test.run=none -test.cpuprofile=tmp.prof -test.bench=BenchmarkMany -./go-restful.test -test.run=none -test.cpuprofile=curly.prof -test.bench=BenchmarkManyCurly - -#go tool pprof go-restful.test tmp.prof -go tool pprof go-restful.test curly.prof - - diff --git a/discovery/vendor/github.com/emicklei/go-restful/compress.go b/discovery/vendor/github.com/emicklei/go-restful/compress.go deleted file mode 100644 index 220b3771..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/compress.go +++ /dev/null @@ -1,123 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bufio" - "compress/gzip" - "compress/zlib" - "errors" - "io" - "net" - "net/http" - "strings" -) - -// OBSOLETE : use restful.DefaultContainer.EnableContentEncoding(true) to change this setting. -var EnableContentEncoding = false - -// CompressingResponseWriter is a http.ResponseWriter that can perform content encoding (gzip and zlib) -type CompressingResponseWriter struct { - writer http.ResponseWriter - compressor io.WriteCloser - encoding string -} - -// Header is part of http.ResponseWriter interface -func (c *CompressingResponseWriter) Header() http.Header { - return c.writer.Header() -} - -// WriteHeader is part of http.ResponseWriter interface -func (c *CompressingResponseWriter) WriteHeader(status int) { - c.writer.WriteHeader(status) -} - -// Write is part of http.ResponseWriter interface -// It is passed through the compressor -func (c *CompressingResponseWriter) Write(bytes []byte) (int, error) { - if c.isCompressorClosed() { - return -1, errors.New("Compressing error: tried to write data using closed compressor") - } - return c.compressor.Write(bytes) -} - -// CloseNotify is part of http.CloseNotifier interface -func (c *CompressingResponseWriter) CloseNotify() <-chan bool { - return c.writer.(http.CloseNotifier).CloseNotify() -} - -// Close the underlying compressor -func (c *CompressingResponseWriter) Close() error { - if c.isCompressorClosed() { - return errors.New("Compressing error: tried to close already closed compressor") - } - - c.compressor.Close() - if ENCODING_GZIP == c.encoding { - currentCompressorProvider.ReleaseGzipWriter(c.compressor.(*gzip.Writer)) - } - if ENCODING_DEFLATE == c.encoding { - currentCompressorProvider.ReleaseZlibWriter(c.compressor.(*zlib.Writer)) - } - // gc hint needed? - c.compressor = nil - return nil -} - -func (c *CompressingResponseWriter) isCompressorClosed() bool { - return nil == c.compressor -} - -// Hijack implements the Hijacker interface -// This is especially useful when combining Container.EnabledContentEncoding -// in combination with websockets (for instance gorilla/websocket) -func (c *CompressingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - hijacker, ok := c.writer.(http.Hijacker) - if !ok { - return nil, nil, errors.New("ResponseWriter doesn't support Hijacker interface") - } - return hijacker.Hijack() -} - -// WantsCompressedResponse reads the Accept-Encoding header to see if and which encoding is requested. -func wantsCompressedResponse(httpRequest *http.Request) (bool, string) { - header := httpRequest.Header.Get(HEADER_AcceptEncoding) - gi := strings.Index(header, ENCODING_GZIP) - zi := strings.Index(header, ENCODING_DEFLATE) - // use in order of appearance - if gi == -1 { - return zi != -1, ENCODING_DEFLATE - } else if zi == -1 { - return gi != -1, ENCODING_GZIP - } else { - if gi < zi { - return true, ENCODING_GZIP - } - return true, ENCODING_DEFLATE - } -} - -// NewCompressingResponseWriter create a CompressingResponseWriter for a known encoding = {gzip,deflate} -func NewCompressingResponseWriter(httpWriter http.ResponseWriter, encoding string) (*CompressingResponseWriter, error) { - httpWriter.Header().Set(HEADER_ContentEncoding, encoding) - c := new(CompressingResponseWriter) - c.writer = httpWriter - var err error - if ENCODING_GZIP == encoding { - w := currentCompressorProvider.AcquireGzipWriter() - w.Reset(httpWriter) - c.compressor = w - c.encoding = ENCODING_GZIP - } else if ENCODING_DEFLATE == encoding { - w := currentCompressorProvider.AcquireZlibWriter() - w.Reset(httpWriter) - c.compressor = w - c.encoding = ENCODING_DEFLATE - } else { - return nil, errors.New("Unknown encoding:" + encoding) - } - return c, err -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/compressor_cache.go b/discovery/vendor/github.com/emicklei/go-restful/compressor_cache.go deleted file mode 100644 index ee426010..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/compressor_cache.go +++ /dev/null @@ -1,103 +0,0 @@ -package restful - -// Copyright 2015 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "compress/gzip" - "compress/zlib" -) - -// BoundedCachedCompressors is a CompressorProvider that uses a cache with a fixed amount -// of writers and readers (resources). -// If a new resource is acquired and all are in use, it will return a new unmanaged resource. -type BoundedCachedCompressors struct { - gzipWriters chan *gzip.Writer - gzipReaders chan *gzip.Reader - zlibWriters chan *zlib.Writer - writersCapacity int - readersCapacity int -} - -// NewBoundedCachedCompressors returns a new, with filled cache, BoundedCachedCompressors. -func NewBoundedCachedCompressors(writersCapacity, readersCapacity int) *BoundedCachedCompressors { - b := &BoundedCachedCompressors{ - gzipWriters: make(chan *gzip.Writer, writersCapacity), - gzipReaders: make(chan *gzip.Reader, readersCapacity), - zlibWriters: make(chan *zlib.Writer, writersCapacity), - writersCapacity: writersCapacity, - readersCapacity: readersCapacity, - } - for ix := 0; ix < writersCapacity; ix++ { - b.gzipWriters <- newGzipWriter() - b.zlibWriters <- newZlibWriter() - } - for ix := 0; ix < readersCapacity; ix++ { - b.gzipReaders <- newGzipReader() - } - return b -} - -// AcquireGzipWriter returns an resettable *gzip.Writer. Needs to be released. -func (b *BoundedCachedCompressors) AcquireGzipWriter() *gzip.Writer { - var writer *gzip.Writer - select { - case writer, _ = <-b.gzipWriters: - default: - // return a new unmanaged one - writer = newGzipWriter() - } - return writer -} - -// ReleaseGzipWriter accepts a writer (does not have to be one that was cached) -// only when the cache has room for it. It will ignore it otherwise. -func (b *BoundedCachedCompressors) ReleaseGzipWriter(w *gzip.Writer) { - // forget the unmanaged ones - if len(b.gzipWriters) < b.writersCapacity { - b.gzipWriters <- w - } -} - -// AcquireGzipReader returns a *gzip.Reader. Needs to be released. -func (b *BoundedCachedCompressors) AcquireGzipReader() *gzip.Reader { - var reader *gzip.Reader - select { - case reader, _ = <-b.gzipReaders: - default: - // return a new unmanaged one - reader = newGzipReader() - } - return reader -} - -// ReleaseGzipReader accepts a reader (does not have to be one that was cached) -// only when the cache has room for it. It will ignore it otherwise. -func (b *BoundedCachedCompressors) ReleaseGzipReader(r *gzip.Reader) { - // forget the unmanaged ones - if len(b.gzipReaders) < b.readersCapacity { - b.gzipReaders <- r - } -} - -// AcquireZlibWriter returns an resettable *zlib.Writer. Needs to be released. -func (b *BoundedCachedCompressors) AcquireZlibWriter() *zlib.Writer { - var writer *zlib.Writer - select { - case writer, _ = <-b.zlibWriters: - default: - // return a new unmanaged one - writer = newZlibWriter() - } - return writer -} - -// ReleaseZlibWriter accepts a writer (does not have to be one that was cached) -// only when the cache has room for it. It will ignore it otherwise. -func (b *BoundedCachedCompressors) ReleaseZlibWriter(w *zlib.Writer) { - // forget the unmanaged ones - if len(b.zlibWriters) < b.writersCapacity { - b.zlibWriters <- w - } -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/compressor_pools.go b/discovery/vendor/github.com/emicklei/go-restful/compressor_pools.go deleted file mode 100644 index d866ce64..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/compressor_pools.go +++ /dev/null @@ -1,91 +0,0 @@ -package restful - -// Copyright 2015 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bytes" - "compress/gzip" - "compress/zlib" - "sync" -) - -// SyncPoolCompessors is a CompressorProvider that use the standard sync.Pool. -type SyncPoolCompessors struct { - GzipWriterPool *sync.Pool - GzipReaderPool *sync.Pool - ZlibWriterPool *sync.Pool -} - -// NewSyncPoolCompessors returns a new ("empty") SyncPoolCompessors. -func NewSyncPoolCompessors() *SyncPoolCompessors { - return &SyncPoolCompessors{ - GzipWriterPool: &sync.Pool{ - New: func() interface{} { return newGzipWriter() }, - }, - GzipReaderPool: &sync.Pool{ - New: func() interface{} { return newGzipReader() }, - }, - ZlibWriterPool: &sync.Pool{ - New: func() interface{} { return newZlibWriter() }, - }, - } -} - -func (s *SyncPoolCompessors) AcquireGzipWriter() *gzip.Writer { - return s.GzipWriterPool.Get().(*gzip.Writer) -} - -func (s *SyncPoolCompessors) ReleaseGzipWriter(w *gzip.Writer) { - s.GzipWriterPool.Put(w) -} - -func (s *SyncPoolCompessors) AcquireGzipReader() *gzip.Reader { - return s.GzipReaderPool.Get().(*gzip.Reader) -} - -func (s *SyncPoolCompessors) ReleaseGzipReader(r *gzip.Reader) { - s.GzipReaderPool.Put(r) -} - -func (s *SyncPoolCompessors) AcquireZlibWriter() *zlib.Writer { - return s.ZlibWriterPool.Get().(*zlib.Writer) -} - -func (s *SyncPoolCompessors) ReleaseZlibWriter(w *zlib.Writer) { - s.ZlibWriterPool.Put(w) -} - -func newGzipWriter() *gzip.Writer { - // create with an empty bytes writer; it will be replaced before using the gzipWriter - writer, err := gzip.NewWriterLevel(new(bytes.Buffer), gzip.BestSpeed) - if err != nil { - panic(err.Error()) - } - return writer -} - -func newGzipReader() *gzip.Reader { - // create with an empty reader (but with GZIP header); it will be replaced before using the gzipReader - // we can safely use currentCompressProvider because it is set on package initialization. - w := currentCompressorProvider.AcquireGzipWriter() - defer currentCompressorProvider.ReleaseGzipWriter(w) - b := new(bytes.Buffer) - w.Reset(b) - w.Flush() - w.Close() - reader, err := gzip.NewReader(bytes.NewReader(b.Bytes())) - if err != nil { - panic(err.Error()) - } - return reader -} - -func newZlibWriter() *zlib.Writer { - writer, err := zlib.NewWriterLevel(new(bytes.Buffer), gzip.BestSpeed) - if err != nil { - panic(err.Error()) - } - return writer -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/compressors.go b/discovery/vendor/github.com/emicklei/go-restful/compressors.go deleted file mode 100644 index 9db4a8c8..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/compressors.go +++ /dev/null @@ -1,54 +0,0 @@ -package restful - -// Copyright 2015 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "compress/gzip" - "compress/zlib" -) - -// CompressorProvider describes a component that can provider compressors for the std methods. -type CompressorProvider interface { - // Returns a *gzip.Writer which needs to be released later. - // Before using it, call Reset(). - AcquireGzipWriter() *gzip.Writer - - // Releases an acquired *gzip.Writer. - ReleaseGzipWriter(w *gzip.Writer) - - // Returns a *gzip.Reader which needs to be released later. - AcquireGzipReader() *gzip.Reader - - // Releases an acquired *gzip.Reader. - ReleaseGzipReader(w *gzip.Reader) - - // Returns a *zlib.Writer which needs to be released later. - // Before using it, call Reset(). - AcquireZlibWriter() *zlib.Writer - - // Releases an acquired *zlib.Writer. - ReleaseZlibWriter(w *zlib.Writer) -} - -// DefaultCompressorProvider is the actual provider of compressors (zlib or gzip). -var currentCompressorProvider CompressorProvider - -func init() { - currentCompressorProvider = NewSyncPoolCompessors() -} - -// CurrentCompressorProvider returns the current CompressorProvider. -// It is initialized using a SyncPoolCompessors. -func CurrentCompressorProvider() CompressorProvider { - return currentCompressorProvider -} - -// SetCompressorProvider sets the actual provider of compressors (zlib or gzip). -func SetCompressorProvider(p CompressorProvider) { - if p == nil { - panic("cannot set compressor provider to nil") - } - currentCompressorProvider = p -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/constants.go b/discovery/vendor/github.com/emicklei/go-restful/constants.go deleted file mode 100644 index 203439c5..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/constants.go +++ /dev/null @@ -1,30 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -const ( - MIME_XML = "application/xml" // Accept or Content-Type used in Consumes() and/or Produces() - MIME_JSON = "application/json" // Accept or Content-Type used in Consumes() and/or Produces() - MIME_OCTET = "application/octet-stream" // If Content-Type is not present in request, use the default - - HEADER_Allow = "Allow" - HEADER_Accept = "Accept" - HEADER_Origin = "Origin" - HEADER_ContentType = "Content-Type" - HEADER_LastModified = "Last-Modified" - HEADER_AcceptEncoding = "Accept-Encoding" - HEADER_ContentEncoding = "Content-Encoding" - HEADER_AccessControlExposeHeaders = "Access-Control-Expose-Headers" - HEADER_AccessControlRequestMethod = "Access-Control-Request-Method" - HEADER_AccessControlRequestHeaders = "Access-Control-Request-Headers" - HEADER_AccessControlAllowMethods = "Access-Control-Allow-Methods" - HEADER_AccessControlAllowOrigin = "Access-Control-Allow-Origin" - HEADER_AccessControlAllowCredentials = "Access-Control-Allow-Credentials" - HEADER_AccessControlAllowHeaders = "Access-Control-Allow-Headers" - HEADER_AccessControlMaxAge = "Access-Control-Max-Age" - - ENCODING_GZIP = "gzip" - ENCODING_DEFLATE = "deflate" -) diff --git a/discovery/vendor/github.com/emicklei/go-restful/container.go b/discovery/vendor/github.com/emicklei/go-restful/container.go deleted file mode 100644 index 4196180e..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/container.go +++ /dev/null @@ -1,366 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bytes" - "errors" - "fmt" - "net/http" - "os" - "runtime" - "strings" - "sync" - - "github.com/emicklei/go-restful/log" -) - -// Container holds a collection of WebServices and a http.ServeMux to dispatch http requests. -// The requests are further dispatched to routes of WebServices using a RouteSelector -type Container struct { - webServicesLock sync.RWMutex - webServices []*WebService - ServeMux *http.ServeMux - isRegisteredOnRoot bool - containerFilters []FilterFunction - doNotRecover bool // default is true - recoverHandleFunc RecoverHandleFunction - serviceErrorHandleFunc ServiceErrorHandleFunction - router RouteSelector // default is a CurlyRouter (RouterJSR311 is a slower alternative) - contentEncodingEnabled bool // default is false -} - -// NewContainer creates a new Container using a new ServeMux and default router (CurlyRouter) -func NewContainer() *Container { - return &Container{ - webServices: []*WebService{}, - ServeMux: http.NewServeMux(), - isRegisteredOnRoot: false, - containerFilters: []FilterFunction{}, - doNotRecover: true, - recoverHandleFunc: logStackOnRecover, - serviceErrorHandleFunc: writeServiceError, - router: CurlyRouter{}, - contentEncodingEnabled: false} -} - -// RecoverHandleFunction declares functions that can be used to handle a panic situation. -// The first argument is what recover() returns. The second must be used to communicate an error response. -type RecoverHandleFunction func(interface{}, http.ResponseWriter) - -// RecoverHandler changes the default function (logStackOnRecover) to be called -// when a panic is detected. DoNotRecover must be have its default value (=false). -func (c *Container) RecoverHandler(handler RecoverHandleFunction) { - c.recoverHandleFunc = handler -} - -// ServiceErrorHandleFunction declares functions that can be used to handle a service error situation. -// The first argument is the service error, the second is the request that resulted in the error and -// the third must be used to communicate an error response. -type ServiceErrorHandleFunction func(ServiceError, *Request, *Response) - -// ServiceErrorHandler changes the default function (writeServiceError) to be called -// when a ServiceError is detected. -func (c *Container) ServiceErrorHandler(handler ServiceErrorHandleFunction) { - c.serviceErrorHandleFunc = handler -} - -// DoNotRecover controls whether panics will be caught to return HTTP 500. -// If set to true, Route functions are responsible for handling any error situation. -// Default value is true. -func (c *Container) DoNotRecover(doNot bool) { - c.doNotRecover = doNot -} - -// Router changes the default Router (currently CurlyRouter) -func (c *Container) Router(aRouter RouteSelector) { - c.router = aRouter -} - -// EnableContentEncoding (default=false) allows for GZIP or DEFLATE encoding of responses. -func (c *Container) EnableContentEncoding(enabled bool) { - c.contentEncodingEnabled = enabled -} - -// Add a WebService to the Container. It will detect duplicate root paths and exit in that case. -func (c *Container) Add(service *WebService) *Container { - c.webServicesLock.Lock() - defer c.webServicesLock.Unlock() - - // if rootPath was not set then lazy initialize it - if len(service.rootPath) == 0 { - service.Path("/") - } - - // cannot have duplicate root paths - for _, each := range c.webServices { - if each.RootPath() == service.RootPath() { - log.Printf("[restful] WebService with duplicate root path detected:['%v']", each) - os.Exit(1) - } - } - - // If not registered on root then add specific mapping - if !c.isRegisteredOnRoot { - c.isRegisteredOnRoot = c.addHandler(service, c.ServeMux) - } - c.webServices = append(c.webServices, service) - return c -} - -// addHandler may set a new HandleFunc for the serveMux -// this function must run inside the critical region protected by the webServicesLock. -// returns true if the function was registered on root ("/") -func (c *Container) addHandler(service *WebService, serveMux *http.ServeMux) bool { - pattern := fixedPrefixPath(service.RootPath()) - // check if root path registration is needed - if "/" == pattern || "" == pattern { - serveMux.HandleFunc("/", c.dispatch) - return true - } - // detect if registration already exists - alreadyMapped := false - for _, each := range c.webServices { - if each.RootPath() == service.RootPath() { - alreadyMapped = true - break - } - } - if !alreadyMapped { - serveMux.HandleFunc(pattern, c.dispatch) - if !strings.HasSuffix(pattern, "/") { - serveMux.HandleFunc(pattern+"/", c.dispatch) - } - } - return false -} - -func (c *Container) Remove(ws *WebService) error { - if c.ServeMux == http.DefaultServeMux { - errMsg := fmt.Sprintf("[restful] cannot remove a WebService from a Container using the DefaultServeMux: ['%v']", ws) - log.Print(errMsg) - return errors.New(errMsg) - } - c.webServicesLock.Lock() - defer c.webServicesLock.Unlock() - // build a new ServeMux and re-register all WebServices - newServeMux := http.NewServeMux() - newServices := []*WebService{} - newIsRegisteredOnRoot := false - for _, each := range c.webServices { - if each.rootPath != ws.rootPath { - // If not registered on root then add specific mapping - if !newIsRegisteredOnRoot { - newIsRegisteredOnRoot = c.addHandler(each, newServeMux) - } - newServices = append(newServices, each) - } - } - c.webServices, c.ServeMux, c.isRegisteredOnRoot = newServices, newServeMux, newIsRegisteredOnRoot - return nil -} - -// logStackOnRecover is the default RecoverHandleFunction and is called -// when DoNotRecover is false and the recoverHandleFunc is not set for the container. -// Default implementation logs the stacktrace and writes the stacktrace on the response. -// This may be a security issue as it exposes sourcecode information. -func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) { - var buffer bytes.Buffer - buffer.WriteString(fmt.Sprintf("[restful] recover from panic situation: - %v\r\n", panicReason)) - for i := 2; ; i += 1 { - _, file, line, ok := runtime.Caller(i) - if !ok { - break - } - buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line)) - } - log.Print(buffer.String()) - httpWriter.WriteHeader(http.StatusInternalServerError) - httpWriter.Write(buffer.Bytes()) -} - -// writeServiceError is the default ServiceErrorHandleFunction and is called -// when a ServiceError is returned during route selection. Default implementation -// calls resp.WriteErrorString(err.Code, err.Message) -func writeServiceError(err ServiceError, req *Request, resp *Response) { - resp.WriteErrorString(err.Code, err.Message) -} - -// Dispatch the incoming Http Request to a matching WebService. -func (c *Container) Dispatch(httpWriter http.ResponseWriter, httpRequest *http.Request) { - if httpWriter == nil { - panic("httpWriter cannot be nil") - } - if httpRequest == nil { - panic("httpRequest cannot be nil") - } - c.dispatch(httpWriter, httpRequest) -} - -// Dispatch the incoming Http Request to a matching WebService. -func (c *Container) dispatch(httpWriter http.ResponseWriter, httpRequest *http.Request) { - writer := httpWriter - - // CompressingResponseWriter should be closed after all operations are done - defer func() { - if compressWriter, ok := writer.(*CompressingResponseWriter); ok { - compressWriter.Close() - } - }() - - // Instal panic recovery unless told otherwise - if !c.doNotRecover { // catch all for 500 response - defer func() { - if r := recover(); r != nil { - c.recoverHandleFunc(r, writer) - return - } - }() - } - - // Detect if compression is needed - // assume without compression, test for override - if c.contentEncodingEnabled { - doCompress, encoding := wantsCompressedResponse(httpRequest) - if doCompress { - var err error - writer, err = NewCompressingResponseWriter(httpWriter, encoding) - if err != nil { - log.Print("[restful] unable to install compressor: ", err) - httpWriter.WriteHeader(http.StatusInternalServerError) - return - } - } - } - // Find best match Route ; err is non nil if no match was found - var webService *WebService - var route *Route - var err error - func() { - c.webServicesLock.RLock() - defer c.webServicesLock.RUnlock() - webService, route, err = c.router.SelectRoute( - c.webServices, - httpRequest) - }() - if err != nil { - // a non-200 response has already been written - // run container filters anyway ; they should not touch the response... - chain := FilterChain{Filters: c.containerFilters, Target: func(req *Request, resp *Response) { - switch err.(type) { - case ServiceError: - ser := err.(ServiceError) - c.serviceErrorHandleFunc(ser, req, resp) - } - // TODO - }} - chain.ProcessFilter(NewRequest(httpRequest), NewResponse(writer)) - return - } - wrappedRequest, wrappedResponse := route.wrapRequestResponse(writer, httpRequest) - // pass through filters (if any) - if len(c.containerFilters)+len(webService.filters)+len(route.Filters) > 0 { - // compose filter chain - allFilters := []FilterFunction{} - allFilters = append(allFilters, c.containerFilters...) - allFilters = append(allFilters, webService.filters...) - allFilters = append(allFilters, route.Filters...) - chain := FilterChain{Filters: allFilters, Target: func(req *Request, resp *Response) { - // handle request by route after passing all filters - route.Function(wrappedRequest, wrappedResponse) - }} - chain.ProcessFilter(wrappedRequest, wrappedResponse) - } else { - // no filters, handle request by route - route.Function(wrappedRequest, wrappedResponse) - } -} - -// fixedPrefixPath returns the fixed part of the partspec ; it may include template vars {} -func fixedPrefixPath(pathspec string) string { - varBegin := strings.Index(pathspec, "{") - if -1 == varBegin { - return pathspec - } - return pathspec[:varBegin] -} - -// ServeHTTP implements net/http.Handler therefore a Container can be a Handler in a http.Server -func (c *Container) ServeHTTP(httpwriter http.ResponseWriter, httpRequest *http.Request) { - c.ServeMux.ServeHTTP(httpwriter, httpRequest) -} - -// Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics. -func (c *Container) Handle(pattern string, handler http.Handler) { - c.ServeMux.Handle(pattern, handler) -} - -// HandleWithFilter registers the handler for the given pattern. -// Container's filter chain is applied for handler. -// If a handler already exists for pattern, HandleWithFilter panics. -func (c *Container) HandleWithFilter(pattern string, handler http.Handler) { - f := func(httpResponse http.ResponseWriter, httpRequest *http.Request) { - if len(c.containerFilters) == 0 { - handler.ServeHTTP(httpResponse, httpRequest) - return - } - - chain := FilterChain{Filters: c.containerFilters, Target: func(req *Request, resp *Response) { - handler.ServeHTTP(httpResponse, httpRequest) - }} - chain.ProcessFilter(NewRequest(httpRequest), NewResponse(httpResponse)) - } - - c.Handle(pattern, http.HandlerFunc(f)) -} - -// Filter appends a container FilterFunction. These are called before dispatching -// a http.Request to a WebService from the container -func (c *Container) Filter(filter FilterFunction) { - c.containerFilters = append(c.containerFilters, filter) -} - -// RegisteredWebServices returns the collections of added WebServices -func (c *Container) RegisteredWebServices() []*WebService { - c.webServicesLock.RLock() - defer c.webServicesLock.RUnlock() - result := make([]*WebService, len(c.webServices)) - for ix := range c.webServices { - result[ix] = c.webServices[ix] - } - return result -} - -// computeAllowedMethods returns a list of HTTP methods that are valid for a Request -func (c *Container) computeAllowedMethods(req *Request) []string { - // Go through all RegisteredWebServices() and all its Routes to collect the options - methods := []string{} - requestPath := req.Request.URL.Path - for _, ws := range c.RegisteredWebServices() { - matches := ws.pathExpr.Matcher.FindStringSubmatch(requestPath) - if matches != nil { - finalMatch := matches[len(matches)-1] - for _, rt := range ws.Routes() { - matches := rt.pathExpr.Matcher.FindStringSubmatch(finalMatch) - if matches != nil { - lastMatch := matches[len(matches)-1] - if lastMatch == "" || lastMatch == "/" { // do not include if value is neither empty nor ‘/’. - methods = append(methods, rt.Method) - } - } - } - } - } - // methods = append(methods, "OPTIONS") not sure about this - return methods -} - -// newBasicRequestResponse creates a pair of Request,Response from its http versions. -// It is basic because no parameter or (produces) content-type information is given. -func newBasicRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request) (*Request, *Response) { - resp := NewResponse(httpWriter) - resp.requestAccept = httpRequest.Header.Get(HEADER_Accept) - return NewRequest(httpRequest), resp -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/cors_filter.go b/discovery/vendor/github.com/emicklei/go-restful/cors_filter.go deleted file mode 100644 index 1efeef07..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/cors_filter.go +++ /dev/null @@ -1,202 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "regexp" - "strconv" - "strings" -) - -// CrossOriginResourceSharing is used to create a Container Filter that implements CORS. -// Cross-origin resource sharing (CORS) is a mechanism that allows JavaScript on a web page -// to make XMLHttpRequests to another domain, not the domain the JavaScript originated from. -// -// http://en.wikipedia.org/wiki/Cross-origin_resource_sharing -// http://enable-cors.org/server.html -// http://www.html5rocks.com/en/tutorials/cors/#toc-handling-a-not-so-simple-request -type CrossOriginResourceSharing struct { - ExposeHeaders []string // list of Header names - AllowedHeaders []string // list of Header names - AllowedDomains []string // list of allowed values for Http Origin. An allowed value can be a regular expression to support subdomain matching. If empty all are allowed. - AllowedMethods []string - MaxAge int // number of seconds before requiring new Options request - CookiesAllowed bool - Container *Container - - allowedOriginPatterns []*regexp.Regexp // internal field for origin regexp check. -} - -// Filter is a filter function that implements the CORS flow as documented on http://enable-cors.org/server.html -// and http://www.html5rocks.com/static/images/cors_server_flowchart.png -func (c CrossOriginResourceSharing) Filter(req *Request, resp *Response, chain *FilterChain) { - origin := req.Request.Header.Get(HEADER_Origin) - if len(origin) == 0 { - if trace { - traceLogger.Print("no Http header Origin set") - } - chain.ProcessFilter(req, resp) - return - } - if !c.isOriginAllowed(origin) { // check whether this origin is allowed - if trace { - traceLogger.Printf("HTTP Origin:%s is not part of %v, neither matches any part of %v", origin, c.AllowedDomains, c.allowedOriginPatterns) - } - chain.ProcessFilter(req, resp) - return - } - if req.Request.Method != "OPTIONS" { - c.doActualRequest(req, resp) - chain.ProcessFilter(req, resp) - return - } - if acrm := req.Request.Header.Get(HEADER_AccessControlRequestMethod); acrm != "" { - c.doPreflightRequest(req, resp) - } else { - c.doActualRequest(req, resp) - chain.ProcessFilter(req, resp) - return - } -} - -func (c CrossOriginResourceSharing) doActualRequest(req *Request, resp *Response) { - c.setOptionsHeaders(req, resp) - // continue processing the response -} - -func (c *CrossOriginResourceSharing) doPreflightRequest(req *Request, resp *Response) { - if len(c.AllowedMethods) == 0 { - if c.Container == nil { - c.AllowedMethods = DefaultContainer.computeAllowedMethods(req) - } else { - c.AllowedMethods = c.Container.computeAllowedMethods(req) - } - } - - acrm := req.Request.Header.Get(HEADER_AccessControlRequestMethod) - if !c.isValidAccessControlRequestMethod(acrm, c.AllowedMethods) { - if trace { - traceLogger.Printf("Http header %s:%s is not in %v", - HEADER_AccessControlRequestMethod, - acrm, - c.AllowedMethods) - } - return - } - acrhs := req.Request.Header.Get(HEADER_AccessControlRequestHeaders) - if len(acrhs) > 0 { - for _, each := range strings.Split(acrhs, ",") { - if !c.isValidAccessControlRequestHeader(strings.Trim(each, " ")) { - if trace { - traceLogger.Printf("Http header %s:%s is not in %v", - HEADER_AccessControlRequestHeaders, - acrhs, - c.AllowedHeaders) - } - return - } - } - } - resp.AddHeader(HEADER_AccessControlAllowMethods, strings.Join(c.AllowedMethods, ",")) - resp.AddHeader(HEADER_AccessControlAllowHeaders, acrhs) - c.setOptionsHeaders(req, resp) - - // return http 200 response, no body -} - -func (c CrossOriginResourceSharing) setOptionsHeaders(req *Request, resp *Response) { - c.checkAndSetExposeHeaders(resp) - c.setAllowOriginHeader(req, resp) - c.checkAndSetAllowCredentials(resp) - if c.MaxAge > 0 { - resp.AddHeader(HEADER_AccessControlMaxAge, strconv.Itoa(c.MaxAge)) - } -} - -func (c CrossOriginResourceSharing) isOriginAllowed(origin string) bool { - if len(origin) == 0 { - return false - } - if len(c.AllowedDomains) == 0 { - return true - } - - allowed := false - for _, domain := range c.AllowedDomains { - if domain == origin { - allowed = true - break - } - } - - if !allowed { - if len(c.allowedOriginPatterns) == 0 { - // compile allowed domains to allowed origin patterns - allowedOriginRegexps, err := compileRegexps(c.AllowedDomains) - if err != nil { - return false - } - c.allowedOriginPatterns = allowedOriginRegexps - } - - for _, pattern := range c.allowedOriginPatterns { - if allowed = pattern.MatchString(origin); allowed { - break - } - } - } - - return allowed -} - -func (c CrossOriginResourceSharing) setAllowOriginHeader(req *Request, resp *Response) { - origin := req.Request.Header.Get(HEADER_Origin) - if c.isOriginAllowed(origin) { - resp.AddHeader(HEADER_AccessControlAllowOrigin, origin) - } -} - -func (c CrossOriginResourceSharing) checkAndSetExposeHeaders(resp *Response) { - if len(c.ExposeHeaders) > 0 { - resp.AddHeader(HEADER_AccessControlExposeHeaders, strings.Join(c.ExposeHeaders, ",")) - } -} - -func (c CrossOriginResourceSharing) checkAndSetAllowCredentials(resp *Response) { - if c.CookiesAllowed { - resp.AddHeader(HEADER_AccessControlAllowCredentials, "true") - } -} - -func (c CrossOriginResourceSharing) isValidAccessControlRequestMethod(method string, allowedMethods []string) bool { - for _, each := range allowedMethods { - if each == method { - return true - } - } - return false -} - -func (c CrossOriginResourceSharing) isValidAccessControlRequestHeader(header string) bool { - for _, each := range c.AllowedHeaders { - if strings.ToLower(each) == strings.ToLower(header) { - return true - } - } - return false -} - -// Take a list of strings and compile them into a list of regular expressions. -func compileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) { - regexps := []*regexp.Regexp{} - for _, regexpStr := range regexpStrings { - r, err := regexp.Compile(regexpStr) - if err != nil { - return regexps, err - } - regexps = append(regexps, r) - } - return regexps, nil -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/coverage.sh b/discovery/vendor/github.com/emicklei/go-restful/coverage.sh deleted file mode 100644 index e27dbf1a..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/coverage.sh +++ /dev/null @@ -1,2 +0,0 @@ -go test -coverprofile=coverage.out -go tool cover -html=coverage.out \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/curly.go b/discovery/vendor/github.com/emicklei/go-restful/curly.go deleted file mode 100644 index 79f1f5aa..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/curly.go +++ /dev/null @@ -1,164 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "net/http" - "regexp" - "sort" - "strings" -) - -// CurlyRouter expects Routes with paths that contain zero or more parameters in curly brackets. -type CurlyRouter struct{} - -// SelectRoute is part of the Router interface and returns the best match -// for the WebService and its Route for the given Request. -func (c CurlyRouter) SelectRoute( - webServices []*WebService, - httpRequest *http.Request) (selectedService *WebService, selected *Route, err error) { - - requestTokens := tokenizePath(httpRequest.URL.Path) - - detectedService := c.detectWebService(requestTokens, webServices) - if detectedService == nil { - if trace { - traceLogger.Printf("no WebService was found to match URL path:%s\n", httpRequest.URL.Path) - } - return nil, nil, NewError(http.StatusNotFound, "404: Page Not Found") - } - candidateRoutes := c.selectRoutes(detectedService, requestTokens) - if len(candidateRoutes) == 0 { - if trace { - traceLogger.Printf("no Route in WebService with path %s was found to match URL path:%s\n", detectedService.rootPath, httpRequest.URL.Path) - } - return detectedService, nil, NewError(http.StatusNotFound, "404: Page Not Found") - } - selectedRoute, err := c.detectRoute(candidateRoutes, httpRequest) - if selectedRoute == nil { - return detectedService, nil, err - } - return detectedService, selectedRoute, nil -} - -// selectRoutes return a collection of Route from a WebService that matches the path tokens from the request. -func (c CurlyRouter) selectRoutes(ws *WebService, requestTokens []string) sortableCurlyRoutes { - candidates := sortableCurlyRoutes{} - for _, each := range ws.routes { - matches, paramCount, staticCount := c.matchesRouteByPathTokens(each.pathParts, requestTokens) - if matches { - candidates.add(curlyRoute{each, paramCount, staticCount}) // TODO make sure Routes() return pointers? - } - } - sort.Sort(sort.Reverse(candidates)) - return candidates -} - -// matchesRouteByPathTokens computes whether it matches, howmany parameters do match and what the number of static path elements are. -func (c CurlyRouter) matchesRouteByPathTokens(routeTokens, requestTokens []string) (matches bool, paramCount int, staticCount int) { - if len(routeTokens) < len(requestTokens) { - // proceed in matching only if last routeToken is wildcard - count := len(routeTokens) - if count == 0 || !strings.HasSuffix(routeTokens[count-1], "*}") { - return false, 0, 0 - } - // proceed - } - for i, routeToken := range routeTokens { - if i == len(requestTokens) { - // reached end of request path - return false, 0, 0 - } - requestToken := requestTokens[i] - if strings.HasPrefix(routeToken, "{") { - paramCount++ - if colon := strings.Index(routeToken, ":"); colon != -1 { - // match by regex - matchesToken, matchesRemainder := c.regularMatchesPathToken(routeToken, colon, requestToken) - if !matchesToken { - return false, 0, 0 - } - if matchesRemainder { - break - } - } - } else { // no { prefix - if requestToken != routeToken { - return false, 0, 0 - } - staticCount++ - } - } - return true, paramCount, staticCount -} - -// regularMatchesPathToken tests whether the regular expression part of routeToken matches the requestToken or all remaining tokens -// format routeToken is {someVar:someExpression}, e.g. {zipcode:[\d][\d][\d][\d][A-Z][A-Z]} -func (c CurlyRouter) regularMatchesPathToken(routeToken string, colon int, requestToken string) (matchesToken bool, matchesRemainder bool) { - regPart := routeToken[colon+1 : len(routeToken)-1] - if regPart == "*" { - if trace { - traceLogger.Printf("wildcard parameter detected in route token %s that matches %s\n", routeToken, requestToken) - } - return true, true - } - matched, err := regexp.MatchString(regPart, requestToken) - return (matched && err == nil), false -} - -var jsr311Router = RouterJSR311{} - -// detectRoute selectes from a list of Route the first match by inspecting both the Accept and Content-Type -// headers of the Request. See also RouterJSR311 in jsr311.go -func (c CurlyRouter) detectRoute(candidateRoutes sortableCurlyRoutes, httpRequest *http.Request) (*Route, error) { - // tracing is done inside detectRoute - return jsr311Router.detectRoute(candidateRoutes.routes(), httpRequest) -} - -// detectWebService returns the best matching webService given the list of path tokens. -// see also computeWebserviceScore -func (c CurlyRouter) detectWebService(requestTokens []string, webServices []*WebService) *WebService { - var best *WebService - score := -1 - for _, each := range webServices { - matches, eachScore := c.computeWebserviceScore(requestTokens, each.pathExpr.tokens) - if matches && (eachScore > score) { - best = each - score = eachScore - } - } - return best -} - -// computeWebserviceScore returns whether tokens match and -// the weighted score of the longest matching consecutive tokens from the beginning. -func (c CurlyRouter) computeWebserviceScore(requestTokens []string, tokens []string) (bool, int) { - if len(tokens) > len(requestTokens) { - return false, 0 - } - score := 0 - for i := 0; i < len(tokens); i++ { - each := requestTokens[i] - other := tokens[i] - if len(each) == 0 && len(other) == 0 { - score++ - continue - } - if len(other) > 0 && strings.HasPrefix(other, "{") { - // no empty match - if len(each) == 0 { - return false, score - } - score += 1 - } else { - // not a parameter - if each != other { - return false, score - } - score += (len(tokens) - i) * 10 //fuzzy - } - } - return true, score -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/curly_route.go b/discovery/vendor/github.com/emicklei/go-restful/curly_route.go deleted file mode 100644 index 296f9465..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/curly_route.go +++ /dev/null @@ -1,52 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -// curlyRoute exits for sorting Routes by the CurlyRouter based on number of parameters and number of static path elements. -type curlyRoute struct { - route Route - paramCount int - staticCount int -} - -type sortableCurlyRoutes []curlyRoute - -func (s *sortableCurlyRoutes) add(route curlyRoute) { - *s = append(*s, route) -} - -func (s sortableCurlyRoutes) routes() (routes []Route) { - for _, each := range s { - routes = append(routes, each.route) // TODO change return type - } - return routes -} - -func (s sortableCurlyRoutes) Len() int { - return len(s) -} -func (s sortableCurlyRoutes) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} -func (s sortableCurlyRoutes) Less(i, j int) bool { - ci := s[i] - cj := s[j] - - // primary key - if ci.staticCount < cj.staticCount { - return true - } - if ci.staticCount > cj.staticCount { - return false - } - // secundary key - if ci.paramCount < cj.paramCount { - return true - } - if ci.paramCount > cj.paramCount { - return false - } - return ci.route.Path < cj.route.Path -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/doc.go b/discovery/vendor/github.com/emicklei/go-restful/doc.go deleted file mode 100644 index f7c16b01..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/doc.go +++ /dev/null @@ -1,185 +0,0 @@ -/* -Package restful , a lean package for creating REST-style WebServices without magic. - -WebServices and Routes - -A WebService has a collection of Route objects that dispatch incoming Http Requests to a function calls. -Typically, a WebService has a root path (e.g. /users) and defines common MIME types for its routes. -WebServices must be added to a container (see below) in order to handler Http requests from a server. - -A Route is defined by a HTTP method, an URL path and (optionally) the MIME types it consumes (Content-Type) and produces (Accept). -This package has the logic to find the best matching Route and if found, call its Function. - - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_JSON, restful.MIME_XML). - Produces(restful.MIME_JSON, restful.MIME_XML) - - ws.Route(ws.GET("/{user-id}").To(u.findUser)) // u is a UserResource - - ... - - // GET http://localhost:8080/users/1 - func (u UserResource) findUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - ... - } - -The (*Request, *Response) arguments provide functions for reading information from the request and writing information back to the response. - -See the example https://github.com/emicklei/go-restful/blob/master/examples/restful-user-resource.go with a full implementation. - -Regular expression matching Routes - -A Route parameter can be specified using the format "uri/{var[:regexp]}" or the special version "uri/{var:*}" for matching the tail of the path. -For example, /persons/{name:[A-Z][A-Z]} can be used to restrict values for the parameter "name" to only contain capital alphabetic characters. -Regular expressions must use the standard Go syntax as described in the regexp package. (https://code.google.com/p/re2/wiki/Syntax) -This feature requires the use of a CurlyRouter. - -Containers - -A Container holds a collection of WebServices, Filters and a http.ServeMux for multiplexing http requests. -Using the statements "restful.Add(...) and restful.Filter(...)" will register WebServices and Filters to the Default Container. -The Default container of go-restful uses the http.DefaultServeMux. -You can create your own Container and create a new http.Server for that particular container. - - container := restful.NewContainer() - server := &http.Server{Addr: ":8081", Handler: container} - -Filters - -A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. -You can use filters to perform generic logging, measurement, authentication, redirect, set response headers etc. -In the restful package there are three hooks into the request,response flow where filters can be added. -Each filter must define a FilterFunction: - - func (req *restful.Request, resp *restful.Response, chain *restful.FilterChain) - -Use the following statement to pass the request,response pair to the next filter or RouteFunction - - chain.ProcessFilter(req, resp) - -Container Filters - -These are processed before any registered WebService. - - // install a (global) filter for the default container (processed before any webservice) - restful.Filter(globalLogging) - -WebService Filters - -These are processed before any Route of a WebService. - - // install a webservice filter (processed before any route) - ws.Filter(webserviceLogging).Filter(measureTime) - - -Route Filters - -These are processed before calling the function associated with the Route. - - // install 2 chained route filters (processed before calling findUser) - ws.Route(ws.GET("/{user-id}").Filter(routeLogging).Filter(NewCountFilter().routeCounter).To(findUser)) - -See the example https://github.com/emicklei/go-restful/blob/master/examples/restful-filters.go with full implementations. - -Response Encoding - -Two encodings are supported: gzip and deflate. To enable this for all responses: - - restful.DefaultContainer.EnableContentEncoding(true) - -If a Http request includes the Accept-Encoding header then the response content will be compressed using the specified encoding. -Alternatively, you can create a Filter that performs the encoding and install it per WebService or Route. - -See the example https://github.com/emicklei/go-restful/blob/master/examples/restful-encoding-filter.go - -OPTIONS support - -By installing a pre-defined container filter, your Webservice(s) can respond to the OPTIONS Http request. - - Filter(OPTIONSFilter()) - -CORS - -By installing the filter of a CrossOriginResourceSharing (CORS), your WebService(s) can handle CORS requests. - - cors := CrossOriginResourceSharing{ExposeHeaders: []string{"X-My-Header"}, CookiesAllowed: false, Container: DefaultContainer} - Filter(cors.Filter) - -Error Handling - -Unexpected things happen. If a request cannot be processed because of a failure, your service needs to tell via the response what happened and why. -For this reason HTTP status codes exist and it is important to use the correct code in every exceptional situation. - - 400: Bad Request - -If path or query parameters are not valid (content or type) then use http.StatusBadRequest. - - 404: Not Found - -Despite a valid URI, the resource requested may not be available - - 500: Internal Server Error - -If the application logic could not process the request (or write the response) then use http.StatusInternalServerError. - - 405: Method Not Allowed - -The request has a valid URL but the method (GET,PUT,POST,...) is not allowed. - - 406: Not Acceptable - -The request does not have or has an unknown Accept Header set for this operation. - - 415: Unsupported Media Type - -The request does not have or has an unknown Content-Type Header set for this operation. - -ServiceError - -In addition to setting the correct (error) Http status code, you can choose to write a ServiceError message on the response. - -Performance options - -This package has several options that affect the performance of your service. It is important to understand them and how you can change it. - - restful.DefaultContainer.DoNotRecover(false) - -DoNotRecover controls whether panics will be caught to return HTTP 500. -If set to false, the container will recover from panics. -Default value is true - - restful.SetCompressorProvider(NewBoundedCachedCompressors(20, 20)) - -If content encoding is enabled then the default strategy for getting new gzip/zlib writers and readers is to use a sync.Pool. -Because writers are expensive structures, performance is even more improved when using a preloaded cache. You can also inject your own implementation. - -Trouble shooting - -This package has the means to produce detail logging of the complete Http request matching process and filter invocation. -Enabling this feature requires you to set an implementation of restful.StdLogger (e.g. log.Logger) instance such as: - - restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile)) - -Logging - -The restful.SetLogger() method allows you to override the logger used by the package. By default restful -uses the standard library `log` package and logs to stdout. Different logging packages are supported as -long as they conform to `StdLogger` interface defined in the `log` sub-package, writing an adapter for your -preferred package is simple. - -Resources - -[project]: https://github.com/emicklei/go-restful - -[examples]: https://github.com/emicklei/go-restful/blob/master/examples - -[design]: http://ernestmicklei.com/2012/11/11/go-restful-api-design/ - -[showcases]: https://github.com/emicklei/mora, https://github.com/emicklei/landskape - -(c) 2012-2015, http://ernestmicklei.com. MIT License -*/ -package restful diff --git a/discovery/vendor/github.com/emicklei/go-restful/entity_accessors.go b/discovery/vendor/github.com/emicklei/go-restful/entity_accessors.go deleted file mode 100644 index 6ecf6c7f..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/entity_accessors.go +++ /dev/null @@ -1,163 +0,0 @@ -package restful - -// Copyright 2015 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "encoding/json" - "encoding/xml" - "strings" - "sync" -) - -// EntityReaderWriter can read and write values using an encoding such as JSON,XML. -type EntityReaderWriter interface { - // Read a serialized version of the value from the request. - // The Request may have a decompressing reader. Depends on Content-Encoding. - Read(req *Request, v interface{}) error - - // Write a serialized version of the value on the response. - // The Response may have a compressing writer. Depends on Accept-Encoding. - // status should be a valid Http Status code - Write(resp *Response, status int, v interface{}) error -} - -// entityAccessRegistry is a singleton -var entityAccessRegistry = &entityReaderWriters{ - protection: new(sync.RWMutex), - accessors: map[string]EntityReaderWriter{}, -} - -// entityReaderWriters associates MIME to an EntityReaderWriter -type entityReaderWriters struct { - protection *sync.RWMutex - accessors map[string]EntityReaderWriter -} - -func init() { - RegisterEntityAccessor(MIME_JSON, NewEntityAccessorJSON(MIME_JSON)) - RegisterEntityAccessor(MIME_XML, NewEntityAccessorXML(MIME_XML)) -} - -// RegisterEntityAccessor add/overrides the ReaderWriter for encoding content with this MIME type. -func RegisterEntityAccessor(mime string, erw EntityReaderWriter) { - entityAccessRegistry.protection.Lock() - defer entityAccessRegistry.protection.Unlock() - entityAccessRegistry.accessors[mime] = erw -} - -// NewEntityAccessorJSON returns a new EntityReaderWriter for accessing JSON content. -// This package is already initialized with such an accessor using the MIME_JSON contentType. -func NewEntityAccessorJSON(contentType string) EntityReaderWriter { - return entityJSONAccess{ContentType: contentType} -} - -// NewEntityAccessorXML returns a new EntityReaderWriter for accessing XML content. -// This package is already initialized with such an accessor using the MIME_XML contentType. -func NewEntityAccessorXML(contentType string) EntityReaderWriter { - return entityXMLAccess{ContentType: contentType} -} - -// accessorAt returns the registered ReaderWriter for this MIME type. -func (r *entityReaderWriters) accessorAt(mime string) (EntityReaderWriter, bool) { - r.protection.RLock() - defer r.protection.RUnlock() - er, ok := r.accessors[mime] - if !ok { - // retry with reverse lookup - // more expensive but we are in an exceptional situation anyway - for k, v := range r.accessors { - if strings.Contains(mime, k) { - return v, true - } - } - } - return er, ok -} - -// entityXMLAccess is a EntityReaderWriter for XML encoding -type entityXMLAccess struct { - // This is used for setting the Content-Type header when writing - ContentType string -} - -// Read unmarshalls the value from XML -func (e entityXMLAccess) Read(req *Request, v interface{}) error { - return xml.NewDecoder(req.Request.Body).Decode(v) -} - -// Write marshalls the value to JSON and set the Content-Type Header. -func (e entityXMLAccess) Write(resp *Response, status int, v interface{}) error { - return writeXML(resp, status, e.ContentType, v) -} - -// writeXML marshalls the value to JSON and set the Content-Type Header. -func writeXML(resp *Response, status int, contentType string, v interface{}) error { - if v == nil { - resp.WriteHeader(status) - // do not write a nil representation - return nil - } - if resp.prettyPrint { - // pretty output must be created and written explicitly - output, err := xml.MarshalIndent(v, " ", " ") - if err != nil { - return err - } - resp.Header().Set(HEADER_ContentType, contentType) - resp.WriteHeader(status) - _, err = resp.Write([]byte(xml.Header)) - if err != nil { - return err - } - _, err = resp.Write(output) - return err - } - // not-so-pretty - resp.Header().Set(HEADER_ContentType, contentType) - resp.WriteHeader(status) - return xml.NewEncoder(resp).Encode(v) -} - -// entityJSONAccess is a EntityReaderWriter for JSON encoding -type entityJSONAccess struct { - // This is used for setting the Content-Type header when writing - ContentType string -} - -// Read unmarshalls the value from JSON -func (e entityJSONAccess) Read(req *Request, v interface{}) error { - decoder := json.NewDecoder(req.Request.Body) - decoder.UseNumber() - return decoder.Decode(v) -} - -// Write marshalls the value to JSON and set the Content-Type Header. -func (e entityJSONAccess) Write(resp *Response, status int, v interface{}) error { - return writeJSON(resp, status, e.ContentType, v) -} - -// write marshalls the value to JSON and set the Content-Type Header. -func writeJSON(resp *Response, status int, contentType string, v interface{}) error { - if v == nil { - resp.WriteHeader(status) - // do not write a nil representation - return nil - } - if resp.prettyPrint { - // pretty output must be created and written explicitly - output, err := json.MarshalIndent(v, " ", " ") - if err != nil { - return err - } - resp.Header().Set(HEADER_ContentType, contentType) - resp.WriteHeader(status) - _, err = resp.Write(output) - return err - } - // not-so-pretty - resp.Header().Set(HEADER_ContentType, contentType) - resp.WriteHeader(status) - return json.NewEncoder(resp).Encode(v) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/.goconvey b/discovery/vendor/github.com/emicklei/go-restful/examples/.goconvey deleted file mode 100644 index 8485e986..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/.goconvey +++ /dev/null @@ -1 +0,0 @@ -ignore \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/.goconvey b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/.goconvey deleted file mode 100644 index 8485e986..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/.goconvey +++ /dev/null @@ -1 +0,0 @@ -ignore \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/app.yaml b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/app.yaml deleted file mode 100644 index 362db6b0..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/app.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# -# Include your application ID here -# -application: -version: 1 -runtime: go -api_version: go1 - -handlers: -# -# Regex for all swagger files to make as static content. -# You should create the folder static/swagger and copy -# swagger-ui into it. -# -- url: /apidocs/(.*?)/(.*\.(js|html|css)) - static_files: static/swagger/\1/\2 - upload: static/swagger/(.*?)/(.*\.(js|html|css)) - -- url: /.* - script: _go_app diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/.goconvey b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/.goconvey deleted file mode 100644 index 8485e986..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/.goconvey +++ /dev/null @@ -1 +0,0 @@ -ignore \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/app.yaml b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/app.yaml deleted file mode 100644 index 1ac9dca2..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/app.yaml +++ /dev/null @@ -1,18 +0,0 @@ -application: -version: 1 -runtime: go -api_version: go1 - -handlers: -# Regex for all swagger files to make as static content. -# You should create the folder static/swagger and copy -# swagger-ui into it. -# -- url: /apidocs/(.*?)/(.*\.(js|html|css)) - static_files: static/swagger/\1/\2 - upload: static/swagger/(.*?)/(.*\.(js|html|css)) - -# Catch all. -- url: /.* - script: _go_app - login: required diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/main.go b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/main.go deleted file mode 100644 index 33e5b2ea..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/datastore/main.go +++ /dev/null @@ -1,267 +0,0 @@ -package main - -import ( - "net/http" - "time" - - "github.com/emicklei/go-restful" - "github.com/emicklei/go-restful-swagger12" - "google.golang.org/appengine" - "google.golang.org/appengine/datastore" - "google.golang.org/appengine/user" -) - -// This example demonstrates a reasonably complete suite of RESTful operations backed -// by DataStore on Google App Engine. - -// Our simple example struct. -type Profile struct { - LastModified time.Time `json:"-" xml:"-"` - Email string `json:"-" xml:"-"` - FirstName string `json:"first_name" xml:"first-name"` - NickName string `json:"nick_name" xml:"nick-name"` - LastName string `json:"last_name" xml:"last-name"` -} - -type ProfileApi struct { - Path string -} - -func gaeUrl() string { - if appengine.IsDevAppServer() { - return "http://localhost:8080" - } else { - // Include your URL on App Engine here. - // I found no way to get AppID without appengine.Context and this always - // based on a http.Request. - return "http://federatedservices.appspot.com" - } -} - -func init() { - u := ProfileApi{Path: "/profiles"} - u.register() - - // Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API - // You need to download the Swagger HTML5 assets and change the FilePath location in the config below. - // Open .appspot.com/apidocs and enter - // Place the Swagger UI files into a folder called static/swagger if you wish to use Swagger - // http://.appspot.com/apidocs.json in the api input field. - // For testing, you can use http://localhost:8080/apidocs.json - config := swagger.Config{ - // You control what services are visible - WebServices: restful.RegisteredWebServices(), - WebServicesUrl: gaeUrl(), - ApiPath: "/apidocs.json", - - // Optionally, specify where the UI is located - SwaggerPath: "/apidocs/", - - // GAE support static content which is configured in your app.yaml. - // This example expect the swagger-ui in static/swagger so you should place it there :) - SwaggerFilePath: "static/swagger"} - swagger.InstallSwaggerService(config) -} - -func (u ProfileApi) register() { - ws := new(restful.WebService) - - ws. - Path(u.Path). - // You can specify consumes and produces per route as well. - Consumes(restful.MIME_JSON, restful.MIME_XML). - Produces(restful.MIME_JSON, restful.MIME_XML) - - ws.Route(ws.POST("").To(u.insert). - // Swagger documentation. - Doc("insert a new profile"). - Param(ws.BodyParameter("Profile", "representation of a profile").DataType("main.Profile")). - Reads(Profile{})) - - ws.Route(ws.GET("/{profile-id}").To(u.read). - // Swagger documentation. - Doc("read a profile"). - Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string")). - Writes(Profile{})) - - ws.Route(ws.PUT("/{profile-id}").To(u.update). - // Swagger documentation. - Doc("update an existing profile"). - Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string")). - Param(ws.BodyParameter("Profile", "representation of a profile").DataType("main.Profile")). - Reads(Profile{})) - - ws.Route(ws.DELETE("/{profile-id}").To(u.remove). - // Swagger documentation. - Doc("remove a profile"). - Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string"))) - - restful.Add(ws) -} - -// POST http://localhost:8080/profiles -// {"first_name": "Ivan", "nick_name": "Socks", "last_name": "Hawkes"} -// -func (u *ProfileApi) insert(r *restful.Request, w *restful.Response) { - c := appengine.NewContext(r.Request) - - // Marshall the entity from the request into a struct. - p := new(Profile) - err := r.ReadEntity(&p) - if err != nil { - w.WriteError(http.StatusNotAcceptable, err) - return - } - - // Ensure we start with a sensible value for this field. - p.LastModified = time.Now() - - // The profile belongs to this user. - p.Email = user.Current(c).String() - - k, err := datastore.Put(c, datastore.NewIncompleteKey(c, "profiles", nil), p) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Let them know the location of the newly created resource. - // TODO: Use a safe Url path append function. - w.AddHeader("Location", u.Path+"/"+k.Encode()) - - // Return the resultant entity. - w.WriteHeader(http.StatusCreated) - w.WriteEntity(p) -} - -// GET http://localhost:8080/profiles/ahdkZXZ-ZmVkZXJhdGlvbi1zZXJ2aWNlc3IVCxIIcHJvZmlsZXMYgICAgICAgAoM -// -func (u ProfileApi) read(r *restful.Request, w *restful.Response) { - c := appengine.NewContext(r.Request) - - // Decode the request parameter to determine the key for the entity. - k, err := datastore.DecodeKey(r.PathParameter("profile-id")) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - // Retrieve the entity from the datastore. - p := Profile{} - if err := datastore.Get(c, k, &p); err != nil { - if err.Error() == "datastore: no such entity" { - http.Error(w, err.Error(), http.StatusNotFound) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Check we own the profile before allowing them to view it. - // Optionally, return a 404 instead to help prevent guessing ids. - // TODO: Allow admins access. - if p.Email != user.Current(c).String() { - http.Error(w, "You do not have access to this resource", http.StatusForbidden) - return - } - - w.WriteEntity(p) -} - -// PUT http://localhost:8080/profiles/ahdkZXZ-ZmVkZXJhdGlvbi1zZXJ2aWNlc3IVCxIIcHJvZmlsZXMYgICAgICAgAoM -// {"first_name": "Ivan", "nick_name": "Socks", "last_name": "Hawkes"} -// -func (u *ProfileApi) update(r *restful.Request, w *restful.Response) { - c := appengine.NewContext(r.Request) - - // Decode the request parameter to determine the key for the entity. - k, err := datastore.DecodeKey(r.PathParameter("profile-id")) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - // Marshall the entity from the request into a struct. - p := new(Profile) - err = r.ReadEntity(&p) - if err != nil { - w.WriteError(http.StatusNotAcceptable, err) - return - } - - // Retrieve the old entity from the datastore. - old := Profile{} - if err := datastore.Get(c, k, &old); err != nil { - if err.Error() == "datastore: no such entity" { - http.Error(w, err.Error(), http.StatusNotFound) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Check we own the profile before allowing them to update it. - // Optionally, return a 404 instead to help prevent guessing ids. - // TODO: Allow admins access. - if old.Email != user.Current(c).String() { - http.Error(w, "You do not have access to this resource", http.StatusForbidden) - return - } - - // Since the whole entity is re-written, we need to assign any invariant fields again - // e.g. the owner of the entity. - p.Email = user.Current(c).String() - - // Keep track of the last modification date. - p.LastModified = time.Now() - - // Attempt to overwrite the old entity. - _, err = datastore.Put(c, k, p) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Let them know it succeeded. - w.WriteHeader(http.StatusNoContent) -} - -// DELETE http://localhost:8080/profiles/ahdkZXZ-ZmVkZXJhdGlvbi1zZXJ2aWNlc3IVCxIIcHJvZmlsZXMYgICAgICAgAoM -// -func (u *ProfileApi) remove(r *restful.Request, w *restful.Response) { - c := appengine.NewContext(r.Request) - - // Decode the request parameter to determine the key for the entity. - k, err := datastore.DecodeKey(r.PathParameter("profile-id")) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - // Retrieve the old entity from the datastore. - old := Profile{} - if err := datastore.Get(c, k, &old); err != nil { - if err.Error() == "datastore: no such entity" { - http.Error(w, err.Error(), http.StatusNotFound) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Check we own the profile before allowing them to delete it. - // Optionally, return a 404 instead to help prevent guessing ids. - // TODO: Allow admins access. - if old.Email != user.Current(c).String() { - http.Error(w, "You do not have access to this resource", http.StatusForbidden) - return - } - - // Delete the entity. - if err := datastore.Delete(c, k); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - - // Success notification. - w.WriteHeader(http.StatusNoContent) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-appstats-integration.go b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-appstats-integration.go deleted file mode 100644 index a871133b..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-appstats-integration.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "github.com/mjibson/appstats" -) - -func stats(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - c := appstats.NewContext(req.Request) - chain.ProcessFilter(req, resp) - c.Stats.Status = resp.StatusCode() - c.Save() -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-user-service.go b/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-user-service.go deleted file mode 100644 index e1b462c3..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/google_app_engine/restful-user-service.go +++ /dev/null @@ -1,162 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/emicklei/go-restful" - "github.com/emicklei/go-restful-swagger12" - "google.golang.org/appengine" - "google.golang.org/appengine/memcache" -) - -// This example is functionally the same as ../restful-user-service.go -// but it`s supposed to run on Goole App Engine (GAE) -// -// contributed by ivanhawkes - -type User struct { - Id, Name string -} - -type UserService struct { - // normally one would use DAO (data access object) - // but in this example we simple use memcache. -} - -func (u UserService) Register() { - ws := new(restful.WebService) - - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this per route as well - - ws.Route(ws.GET("/{user-id}").To(u.findUser). - // docs - Doc("get a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). - Writes(User{})) // on the response - - ws.Route(ws.PATCH("").To(u.updateUser). - // docs - Doc("update a user"). - Reads(User{})) // from the request - - ws.Route(ws.PUT("/{user-id}").To(u.createUser). - // docs - Doc("create a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). - Reads(User{})) // from the request - - ws.Route(ws.DELETE("/{user-id}").To(u.removeUser). - // docs - Doc("delete a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string"))) - - restful.Add(ws) -} - -// GET http://localhost:8080/users/1 -// -func (u UserService) findUser(request *restful.Request, response *restful.Response) { - c := appengine.NewContext(request.Request) - id := request.PathParameter("user-id") - usr := new(User) - _, err := memcache.Gob.Get(c, id, &usr) - if err != nil || len(usr.Id) == 0 { - response.WriteErrorString(http.StatusNotFound, "User could not be found.") - } else { - response.WriteEntity(usr) - } -} - -// PATCH http://localhost:8080/users -// 1Melissa Raspberry -// -func (u *UserService) updateUser(request *restful.Request, response *restful.Response) { - c := appengine.NewContext(request.Request) - usr := new(User) - err := request.ReadEntity(&usr) - if err == nil { - item := &memcache.Item{ - Key: usr.Id, - Object: &usr, - } - err = memcache.Gob.Set(c, item) - if err != nil { - response.WriteError(http.StatusInternalServerError, err) - return - } - response.WriteEntity(usr) - } else { - response.WriteError(http.StatusInternalServerError, err) - } -} - -// PUT http://localhost:8080/users/1 -// 1Melissa -// -func (u *UserService) createUser(request *restful.Request, response *restful.Response) { - c := appengine.NewContext(request.Request) - usr := User{Id: request.PathParameter("user-id")} - err := request.ReadEntity(&usr) - if err == nil { - item := &memcache.Item{ - Key: usr.Id, - Object: &usr, - } - err = memcache.Gob.Add(c, item) - if err != nil { - response.WriteError(http.StatusInternalServerError, err) - return - } - response.WriteHeader(http.StatusCreated) - response.WriteEntity(usr) - } else { - response.WriteError(http.StatusInternalServerError, err) - } -} - -// DELETE http://localhost:8080/users/1 -// -func (u *UserService) removeUser(request *restful.Request, response *restful.Response) { - c := appengine.NewContext(request.Request) - id := request.PathParameter("user-id") - err := memcache.Delete(c, id) - if err != nil { - response.WriteError(http.StatusInternalServerError, err) - } -} - -func getGaeURL() string { - if appengine.IsDevAppServer() { - return "http://localhost:8080" - } else { - /** - * Include your URL on App Engine here. - * I found no way to get AppID without appengine.Context and this always - * based on a http.Request. - */ - return "http://.appspot.com" - } -} - -func init() { - u := UserService{} - u.Register() - - // Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API - // You need to download the Swagger HTML5 assets and change the FilePath location in the config below. - // Open .appspot.com/apidocs and enter http://.appspot.com/apidocs.json in the api input field. - config := swagger.Config{ - WebServices: restful.RegisteredWebServices(), // you control what services are visible - WebServicesUrl: getGaeURL(), - ApiPath: "/apidocs.json", - - // Optionally, specify where the UI is located - SwaggerPath: "/apidocs/", - // GAE support static content which is configured in your app.yaml. - // This example expect the swagger-ui in static/swagger so you should place it there :) - SwaggerFilePath: "static/swagger"} - swagger.InstallSwaggerService(config) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/home.html b/discovery/vendor/github.com/emicklei/go-restful/examples/home.html deleted file mode 100644 index e5d49b42..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/home.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - -

{{.Text}}

- - \ No newline at end of file diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/msgpack/msgpack_entity.go b/discovery/vendor/github.com/emicklei/go-restful/examples/msgpack/msgpack_entity.go deleted file mode 100644 index 330e4589..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/msgpack/msgpack_entity.go +++ /dev/null @@ -1,34 +0,0 @@ -package restPack - -import ( - restful "github.com/emicklei/go-restful" - "gopkg.in/vmihailenco/msgpack.v2" -) - -const MIME_MSGPACK = "application/x-msgpack" // Accept or Content-Type used in Consumes() and/or Produces() - -// NewEntityAccessorMPack returns a new EntityReaderWriter for accessing MessagePack content. -// This package is not initialized with such an accessor using the MIME_MSGPACK contentType. -func NewEntityAccessorMsgPack() restful.EntityReaderWriter { - return entityMsgPackAccess{} -} - -// entityOctetAccess is a EntityReaderWriter for Octet encoding -type entityMsgPackAccess struct { -} - -// Read unmarshalls the value from byte slice and using msgpack to unmarshal -func (e entityMsgPackAccess) Read(req *restful.Request, v interface{}) error { - return msgpack.NewDecoder(req.Request.Body).Decode(v) -} - -// Write marshals the value to byte slice and set the Content-Type Header. -func (e entityMsgPackAccess) Write(resp *restful.Response, status int, v interface{}) error { - if v == nil { - resp.WriteHeader(status) - // do not write a nil representation - return nil - } - resp.WriteHeader(status) - return msgpack.NewEncoder(resp).Encode(v) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-CORS-filter.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-CORS-filter.go deleted file mode 100644 index d682d43e..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-CORS-filter.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" - - "github.com/emicklei/go-restful" -) - -// Cross-origin resource sharing (CORS) is a mechanism that allows JavaScript on a web page -// to make XMLHttpRequests to another domain, not the domain the JavaScript originated from. -// -// http://en.wikipedia.org/wiki/Cross-origin_resource_sharing -// http://enable-cors.org/server.html -// -// GET http://localhost:8080/users -// -// GET http://localhost:8080/users/1 -// -// PUT http://localhost:8080/users/1 -// -// DELETE http://localhost:8080/users/1 -// -// OPTIONS http://localhost:8080/users/1 with Header "Origin" set to some domain and - -type UserResource struct{} - -func (u UserResource) RegisterTo(container *restful.Container) { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes("*/*"). - Produces("*/*") - - ws.Route(ws.GET("/{user-id}").To(u.nop)) - ws.Route(ws.POST("").To(u.nop)) - ws.Route(ws.PUT("/{user-id}").To(u.nop)) - ws.Route(ws.DELETE("/{user-id}").To(u.nop)) - - container.Add(ws) -} - -func (u UserResource) nop(request *restful.Request, response *restful.Response) { - io.WriteString(response.ResponseWriter, "this would be a normal response") -} - -func main() { - wsContainer := restful.NewContainer() - u := UserResource{} - u.RegisterTo(wsContainer) - - // Add container filter to enable CORS - cors := restful.CrossOriginResourceSharing{ - ExposeHeaders: []string{"X-My-Header"}, - AllowedHeaders: []string{"Content-Type", "Accept"}, - AllowedMethods: []string{"GET", "POST"}, - CookiesAllowed: false, - Container: wsContainer} - wsContainer.Filter(cors.Filter) - - // Add container filter to respond to OPTIONS - wsContainer.Filter(wsContainer.OPTIONSFilter) - - log.Print("start listening on localhost:8080") - server := &http.Server{Addr: ":8080", Handler: wsContainer} - log.Fatal(server.ListenAndServe()) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-NCSA-logging.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-NCSA-logging.go deleted file mode 100644 index 7066b96d..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-NCSA-logging.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" - "os" - "strings" - "time" -) - -// This example shows how to create a filter that produces log lines -// according to the Common Log Format, also known as the NCSA standard. -// -// kindly contributed by leehambley -// -// GET http://localhost:8080/ping - -var logger *log.Logger = log.New(os.Stdout, "", 0) - -func NCSACommonLogFormatLogger() restful.FilterFunction { - return func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - var username = "-" - if req.Request.URL.User != nil { - if name := req.Request.URL.User.Username(); name != "" { - username = name - } - } - chain.ProcessFilter(req, resp) - logger.Printf("%s - %s [%s] \"%s %s %s\" %d %d", - strings.Split(req.Request.RemoteAddr, ":")[0], - username, - time.Now().Format("02/Jan/2006:15:04:05 -0700"), - req.Request.Method, - req.Request.URL.RequestURI(), - req.Request.Proto, - resp.StatusCode(), - resp.ContentLength(), - ) - } -} - -func main() { - ws := new(restful.WebService) - ws.Filter(NCSACommonLogFormatLogger()) - ws.Route(ws.GET("/ping").To(hello)) - restful.Add(ws) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func hello(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "pong") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go deleted file mode 100644 index f4fd5ce1..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows how to create a (Route) Filter that performs Basic Authentication on the Http request. -// -// GET http://localhost:8080/secret -// and use admin,admin for the credentials - -func main() { - ws := new(restful.WebService) - ws.Route(ws.GET("/secret").Filter(basicAuthenticate).To(secret)) - restful.Add(ws) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func basicAuthenticate(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - // usr/pwd = admin/admin - u, p, ok := req.Request.BasicAuth() - if !ok || u != "admin" || p != "admin" { - resp.AddHeader("WWW-Authenticate", "Basic realm=Protected Area") - resp.WriteErrorString(401, "401: Not Authorized") - return - } - chain.ProcessFilter(req, resp) -} - -func secret(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "42") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-cpuprofiler-service.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-cpuprofiler-service.go deleted file mode 100644 index 9148213c..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-cpuprofiler-service.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "os" - "runtime/pprof" -) - -// ProfilingService is a WebService that can start/stop a CPU profile and write results to a file -// GET /{rootPath}/start will activate CPU profiling -// GET /{rootPath}/stop will stop profiling -// -// NewProfileService("/profiler", "ace.prof").AddWebServiceTo(restful.DefaultContainer) -// -type ProfilingService struct { - rootPath string // the base (root) of the service, e.g. /profiler - cpuprofile string // the output filename to write profile results, e.g. myservice.prof - cpufile *os.File // if not nil, then profiling is active -} - -func NewProfileService(rootPath string, outputFilename string) *ProfilingService { - ps := new(ProfilingService) - ps.rootPath = rootPath - ps.cpuprofile = outputFilename - return ps -} - -// Add this ProfileService to a restful Container -func (p ProfilingService) AddWebServiceTo(container *restful.Container) { - ws := new(restful.WebService) - ws.Path(p.rootPath).Consumes("*/*").Produces(restful.MIME_JSON) - ws.Route(ws.GET("/start").To(p.startProfiler)) - ws.Route(ws.GET("/stop").To(p.stopProfiler)) - container.Add(ws) -} - -func (p *ProfilingService) startProfiler(req *restful.Request, resp *restful.Response) { - if p.cpufile != nil { - io.WriteString(resp.ResponseWriter, "[restful] CPU profiling already running") - return // error? - } - cpufile, err := os.Create(p.cpuprofile) - if err != nil { - log.Fatal(err) - } - // remember for close - p.cpufile = cpufile - pprof.StartCPUProfile(cpufile) - io.WriteString(resp.ResponseWriter, "[restful] CPU profiling started, writing on:"+p.cpuprofile) -} - -func (p *ProfilingService) stopProfiler(req *restful.Request, resp *restful.Response) { - if p.cpufile == nil { - io.WriteString(resp.ResponseWriter, "[restful] CPU profiling not active") - return // error? - } - pprof.StopCPUProfile() - p.cpufile.Close() - p.cpufile = nil - io.WriteString(resp.ResponseWriter, "[restful] CPU profiling stopped, closing:"+p.cpuprofile) -} - -func main() {} // exists for example compilation only diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-curly-router.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-curly-router.go deleted file mode 100644 index 1bddb34a..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-curly-router.go +++ /dev/null @@ -1,107 +0,0 @@ -package main - -import ( - "log" - "net/http" - - "github.com/emicklei/go-restful" -) - -// This example has the same service definition as restful-user-resource -// but uses a different router (CurlyRouter) that does not use regular expressions -// -// POST http://localhost:8080/users -// 1Melissa Raspberry -// -// GET http://localhost:8080/users/1 -// -// PUT http://localhost:8080/users/1 -// 1Melissa -// -// DELETE http://localhost:8080/users/1 -// - -type User struct { - Id, Name string -} - -type UserResource struct { - // normally one would use DAO (data access object) - users map[string]User -} - -func (u UserResource) Register(container *restful.Container) { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this per route as well - - ws.Route(ws.GET("/{user-id}").To(u.findUser)) - ws.Route(ws.POST("").To(u.updateUser)) - ws.Route(ws.PUT("/{user-id}").To(u.createUser)) - ws.Route(ws.DELETE("/{user-id}").To(u.removeUser)) - - container.Add(ws) -} - -// GET http://localhost:8080/users/1 -// -func (u UserResource) findUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - usr := u.users[id] - if len(usr.Id) == 0 { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusNotFound, "User could not be found.") - } else { - response.WriteEntity(usr) - } -} - -// POST http://localhost:8080/users -// 1Melissa Raspberry -// -func (u *UserResource) updateUser(request *restful.Request, response *restful.Response) { - usr := new(User) - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.Id] = *usr - response.WriteEntity(usr) - } else { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusInternalServerError, err.Error()) - } -} - -// PUT http://localhost:8080/users/1 -// 1Melissa -// -func (u *UserResource) createUser(request *restful.Request, response *restful.Response) { - usr := User{Id: request.PathParameter("user-id")} - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.Id] = usr - response.WriteHeaderAndEntity(http.StatusCreated, usr) - } else { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusInternalServerError, err.Error()) - } -} - -// DELETE http://localhost:8080/users/1 -// -func (u *UserResource) removeUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - delete(u.users, id) -} - -func main() { - wsContainer := restful.NewContainer() - wsContainer.Router(restful.CurlyRouter{}) - u := UserResource{map[string]User{}} - u.Register(wsContainer) - - log.Print("start listening on localhost:8080") - server := &http.Server{Addr: ":8080", Handler: wsContainer} - log.Fatal(server.ListenAndServe()) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-encoding-filter.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-encoding-filter.go deleted file mode 100644 index 177d5a99..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-encoding-filter.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "log" - "net/http" -) - -type User struct { - Id, Name string -} - -type UserList struct { - Users []User -} - -// -// This example shows how to use the CompressingResponseWriter by a Filter -// such that encoding can be enabled per WebService or per Route (instead of per container) -// Using restful.DefaultContainer.EnableContentEncoding(true) will encode all responses served by WebServices in the DefaultContainer. -// -// Set Accept-Encoding to gzip or deflate -// GET http://localhost:8080/users/42 -// and look at the response headers - -func main() { - restful.Add(NewUserService()) - log.Print("start listening on localhost:8080") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func NewUserService() *restful.WebService { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) - - // install a response encoding filter - ws.Route(ws.GET("/{user-id}").Filter(encodingFilter).To(findUser)) - return ws -} - -// Route Filter (defines FilterFunction) -func encodingFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - log.Printf("[encoding-filter] %s,%s\n", req.Request.Method, req.Request.URL) - // wrap responseWriter into a compressing one - compress, _ := restful.NewCompressingResponseWriter(resp.ResponseWriter, restful.ENCODING_GZIP) - resp.ResponseWriter = compress - defer func() { - compress.Close() - }() - chain.ProcessFilter(req, resp) -} - -// GET http://localhost:8080/users/42 -// -func findUser(request *restful.Request, response *restful.Response) { - log.Print("findUser") - response.WriteEntity(User{"42", "Gandalf"}) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-filters.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-filters.go deleted file mode 100644 index aaadb9d2..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-filters.go +++ /dev/null @@ -1,114 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "log" - "net/http" - "time" -) - -type User struct { - Id, Name string -} - -type UserList struct { - Users []User -} - -// This example show how to create and use the three different Filters (Container,WebService and Route) -// When applied to the restful.DefaultContainer, we refer to them as a global filter. -// -// GET http://localhost:8080/users/42 -// and see the logging per filter (try repeating this request) - -func main() { - // install a global (=DefaultContainer) filter (processed before any webservice in the DefaultContainer) - restful.Filter(globalLogging) - - restful.Add(NewUserService()) - log.Print("start listening on localhost:8080") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func NewUserService() *restful.WebService { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) - - // install a webservice filter (processed before any route) - ws.Filter(webserviceLogging).Filter(measureTime) - - // install a counter filter - ws.Route(ws.GET("").Filter(NewCountFilter().routeCounter).To(getAllUsers)) - - // install 2 chained route filters (processed before calling findUser) - ws.Route(ws.GET("/{user-id}").Filter(routeLogging).Filter(NewCountFilter().routeCounter).To(findUser)) - return ws -} - -// Global Filter -func globalLogging(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - log.Printf("[global-filter (logger)] %s,%s\n", req.Request.Method, req.Request.URL) - chain.ProcessFilter(req, resp) -} - -// WebService Filter -func webserviceLogging(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - log.Printf("[webservice-filter (logger)] %s,%s\n", req.Request.Method, req.Request.URL) - chain.ProcessFilter(req, resp) -} - -// WebService (post-process) Filter (as a struct that defines a FilterFunction) -func measureTime(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - now := time.Now() - chain.ProcessFilter(req, resp) - log.Printf("[webservice-filter (timer)] %v\n", time.Now().Sub(now)) -} - -// Route Filter (defines FilterFunction) -func routeLogging(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - log.Printf("[route-filter (logger)] %s,%s\n", req.Request.Method, req.Request.URL) - chain.ProcessFilter(req, resp) -} - -// Route Filter (as a struct that defines a FilterFunction) -// CountFilter implements a FilterFunction for counting requests. -type CountFilter struct { - count int - counter chan int // for go-routine safe count increments -} - -// NewCountFilter creates and initializes a new CountFilter. -func NewCountFilter() *CountFilter { - c := new(CountFilter) - c.counter = make(chan int) - go func() { - for { - c.count += <-c.counter - } - }() - return c -} - -// routeCounter increments the count of the filter (through a channel) -func (c *CountFilter) routeCounter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - c.counter <- 1 - log.Printf("[route-filter (counter)] count:%d", c.count) - chain.ProcessFilter(req, resp) -} - -// GET http://localhost:8080/users -// -func getAllUsers(request *restful.Request, response *restful.Response) { - log.Print("getAllUsers") - response.WriteEntity(UserList{[]User{{"42", "Gandalf"}, {"3.14", "Pi"}}}) -} - -// GET http://localhost:8080/users/42 -// -func findUser(request *restful.Request, response *restful.Response) { - log.Print("findUser") - response.WriteEntity(User{"42", "Gandalf"}) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-form-handling.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-form-handling.go deleted file mode 100644 index e85608c9..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-form-handling.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "fmt" - "github.com/emicklei/go-restful" - "github.com/gorilla/schema" - "io" - "log" - "net/http" -) - -// This example shows how to handle a POST of a HTML form that uses the standard x-www-form-urlencoded content-type. -// It uses the gorilla web tool kit schema package to decode the form data into a struct. -// -// GET http://localhost:8080/profiles -// - -type Profile struct { - Name string - Age int -} - -var decoder *schema.Decoder - -func main() { - decoder = schema.NewDecoder() - ws := new(restful.WebService) - ws.Route(ws.POST("/profiles").Consumes("application/x-www-form-urlencoded").To(postAdddress)) - ws.Route(ws.GET("/profiles").To(addresssForm)) - restful.Add(ws) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func postAdddress(req *restful.Request, resp *restful.Response) { - err := req.Request.ParseForm() - if err != nil { - resp.WriteErrorString(http.StatusBadRequest, err.Error()) - return - } - p := new(Profile) - err = decoder.Decode(p, req.Request.PostForm) - if err != nil { - resp.WriteErrorString(http.StatusBadRequest, err.Error()) - return - } - io.WriteString(resp.ResponseWriter, fmt.Sprintf("Name=%s, Age=%d", p.Name, p.Age)) -} - -func addresssForm(req *restful.Request, resp *restful.Response) { - io.WriteString(resp.ResponseWriter, - ` - -

Enter Profile

-
- - - - - -
- - `) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-hello-world.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-hello-world.go deleted file mode 100644 index bf987b80..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-hello-world.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows the minimal code needed to get a restful.WebService working. -// -// GET http://localhost:8080/hello - -func main() { - ws := new(restful.WebService) - ws.Route(ws.GET("/hello").To(hello)) - restful.Add(ws) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func hello(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "world") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-html-template.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-html-template.go deleted file mode 100644 index d76d9d1e..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-html-template.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "log" - "net/http" - "text/template" - - "github.com/emicklei/go-restful" -) - -// This example shows how to serve a HTML page using the standard Go template engine. -// -// GET http://localhost:8080/ - -func main() { - ws := new(restful.WebService) - ws.Route(ws.GET("/").To(home)) - restful.Add(ws) - print("open browser on http://localhost:8080/\n") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -type Message struct { - Text string -} - -func home(req *restful.Request, resp *restful.Response) { - p := &Message{"restful-html-template demo"} - // you might want to cache compiled templates - t, err := template.ParseFiles("home.html") - if err != nil { - log.Fatalf("Template gave: %s", err) - } - t.Execute(resp.ResponseWriter, p) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-multi-containers.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-multi-containers.go deleted file mode 100644 index 3056d3ea..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-multi-containers.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows how to have a program with 2 WebServices containers -// each having a http server listening on its own port. -// -// The first "hello" is added to the restful.DefaultContainer (and uses DefaultServeMux) -// For the second "hello", a new container and ServeMux is created -// and requires a new http.Server with the container being the Handler. -// This first server is spawn in its own go-routine such that the program proceeds to create the second. -// -// GET http://localhost:8080/hello -// GET http://localhost:8081/hello - -func main() { - ws := new(restful.WebService) - ws.Route(ws.GET("/hello").To(hello)) - restful.Add(ws) - go func() { - log.Fatal(http.ListenAndServe(":8080", nil)) - }() - - container2 := restful.NewContainer() - ws2 := new(restful.WebService) - ws2.Route(ws2.GET("/hello").To(hello2)) - container2.Add(ws2) - server := &http.Server{Addr: ":8081", Handler: container2} - log.Fatal(server.ListenAndServe()) -} - -func hello(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "default world") -} - -func hello2(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "second world") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-no-cache-filter.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-no-cache-filter.go deleted file mode 100644 index 8e4540f4..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-no-cache-filter.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" - - "github.com/emicklei/go-restful" -) - -// This example shows how to use a WebService filter that passed the Http headers to disable browser cacheing. -// -// GET http://localhost:8080/hello - -func main() { - ws := new(restful.WebService) - ws.Filter(restful.NoBrowserCacheFilter) - ws.Route(ws.GET("/hello").To(hello)) - restful.Add(ws) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func hello(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "world") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-options-filter.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-options-filter.go deleted file mode 100644 index 79ccce55..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-options-filter.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows how to use the OPTIONSFilter on a Container -// -// OPTIONS http://localhost:8080/users -// -// OPTIONS http://localhost:8080/users/1 - -type UserResource struct{} - -func (u UserResource) RegisterTo(container *restful.Container) { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes("*/*"). - Produces("*/*") - - ws.Route(ws.GET("/{user-id}").To(u.nop)) - ws.Route(ws.POST("").To(u.nop)) - ws.Route(ws.PUT("/{user-id}").To(u.nop)) - ws.Route(ws.DELETE("/{user-id}").To(u.nop)) - - container.Add(ws) -} - -func (u UserResource) nop(request *restful.Request, response *restful.Response) { - io.WriteString(response.ResponseWriter, "this would be a normal response") -} - -func main() { - wsContainer := restful.NewContainer() - u := UserResource{} - u.RegisterTo(wsContainer) - - // Add container filter to respond to OPTIONS - wsContainer.Filter(wsContainer.OPTIONSFilter) - - // For use on the default container, you can write - // restful.Filter(restful.OPTIONSFilter()) - - log.Print("start listening on localhost:8080") - server := &http.Server{Addr: ":8080", Handler: wsContainer} - log.Fatal(server.ListenAndServe()) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-path-tail.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-path-tail.go deleted file mode 100644 index f30d6716..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-path-tail.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - . "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows how to create a Route matching the "tail" of a path. -// Requires the use of a CurlyRouter and the star "*" path parameter pattern. -// -// GET http://localhost:8080/basepath/some/other/location/test.xml - -func main() { - DefaultContainer.Router(CurlyRouter{}) - ws := new(WebService) - ws.Route(ws.GET("/basepath/{resource:*}").To(staticFromPathParam)) - Add(ws) - - println("[go-restful] serve path tails from http://localhost:8080/basepath") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func staticFromPathParam(req *Request, resp *Response) { - io.WriteString(resp, "Tail="+req.PathParameter("resource")) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-pre-post-filters.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-pre-post-filters.go deleted file mode 100644 index 0b55f149..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-pre-post-filters.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "io" - "log" - "net/http" -) - -// This example shows how the different types of filters are called in the request-response flow. -// The call chain is logged on the console when sending an http request. -// -// GET http://localhost:8080/1 -// GET http://localhost:8080/2 - -var indentLevel int - -func container_filter_A(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - log.Printf("url path:%v\n", req.Request.URL) - trace("container_filter_A: before", 1) - chain.ProcessFilter(req, resp) - trace("container_filter_A: after", -1) -} - -func container_filter_B(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - trace("container_filter_B: before", 1) - chain.ProcessFilter(req, resp) - trace("container_filter_B: after", -1) -} - -func service_filter_A(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - trace("service_filter_A: before", 1) - chain.ProcessFilter(req, resp) - trace("service_filter_A: after", -1) -} - -func service_filter_B(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - trace("service_filter_B: before", 1) - chain.ProcessFilter(req, resp) - trace("service_filter_B: after", -1) -} - -func route_filter_A(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - trace("route_filter_A: before", 1) - chain.ProcessFilter(req, resp) - trace("route_filter_A: after", -1) -} - -func route_filter_B(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) { - trace("route_filter_B: before", 1) - chain.ProcessFilter(req, resp) - trace("route_filter_B: after", -1) -} - -func trace(what string, delta int) { - indented := what - if delta < 0 { - indentLevel += delta - } - for t := 0; t < indentLevel; t++ { - indented = "." + indented - } - log.Printf("%s", indented) - if delta > 0 { - indentLevel += delta - } -} - -func main() { - restful.Filter(container_filter_A) - restful.Filter(container_filter_B) - - ws1 := new(restful.WebService) - ws1.Path("/1") - ws1.Filter(service_filter_A) - ws1.Filter(service_filter_B) - ws1.Route(ws1.GET("").To(doit1).Filter(route_filter_A).Filter(route_filter_B)) - - ws2 := new(restful.WebService) - ws2.Path("/2") - ws2.Filter(service_filter_A) - ws2.Filter(service_filter_B) - ws2.Route(ws2.GET("").To(doit2).Filter(route_filter_A).Filter(route_filter_B)) - - restful.Add(ws1) - restful.Add(ws2) - - log.Print("go-restful example listing on http://localhost:8080/1 and http://localhost:8080/2") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func doit1(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "nothing to see in 1") -} - -func doit2(req *restful.Request, resp *restful.Response) { - io.WriteString(resp, "nothing to see in 2") -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-resource-functions.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-resource-functions.go deleted file mode 100644 index 09e6e566..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-resource-functions.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "github.com/emicklei/go-restful" - "log" - "net/http" -) - -// This example shows how to use methods as RouteFunctions for WebServices. -// The ProductResource has a Register() method that creates and initializes -// a WebService to expose its methods as REST operations. -// The WebService is added to the restful.DefaultContainer. -// A ProductResource is typically created using some data access object. -// -// GET http://localhost:8080/products/1 -// POST http://localhost:8080/products -// 1The First - -type Product struct { - Id, Title string -} - -type ProductResource struct { - // typically reference a DAO (data-access-object) -} - -func (p ProductResource) getOne(req *restful.Request, resp *restful.Response) { - id := req.PathParameter("id") - log.Println("getting product with id:" + id) - resp.WriteEntity(Product{Id: id, Title: "test"}) -} - -func (p ProductResource) postOne(req *restful.Request, resp *restful.Response) { - updatedProduct := new(Product) - err := req.ReadEntity(updatedProduct) - if err != nil { // bad request - resp.WriteErrorString(http.StatusBadRequest, err.Error()) - return - } - log.Println("updating product with id:" + updatedProduct.Id) -} - -func (p ProductResource) Register() { - ws := new(restful.WebService) - ws.Path("/products") - ws.Consumes(restful.MIME_XML) - ws.Produces(restful.MIME_XML) - - ws.Route(ws.GET("/{id}").To(p.getOne). - Doc("get the product by its id"). - Param(ws.PathParameter("id", "identifier of the product").DataType("string"))) - - ws.Route(ws.POST("").To(p.postOne). - Doc("update or create a product"). - Param(ws.BodyParameter("Product", "a Product (XML)").DataType("main.Product"))) - - restful.Add(ws) -} - -func main() { - ProductResource{}.Register() - log.Fatal(http.ListenAndServe(":8080", nil)) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-serve-static.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-serve-static.go deleted file mode 100644 index 34faf607..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-serve-static.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "path" - - "github.com/emicklei/go-restful" -) - -// This example shows how to define methods that serve static files -// It uses the standard http.ServeFile method -// -// GET http://localhost:8080/static/test.xml -// GET http://localhost:8080/static/ -// -// GET http://localhost:8080/static?resource=subdir/test.xml - -var rootdir = "/tmp" - -func main() { - restful.DefaultContainer.Router(restful.CurlyRouter{}) - - ws := new(restful.WebService) - ws.Route(ws.GET("/static/{subpath:*}").To(staticFromPathParam)) - ws.Route(ws.GET("/static").To(staticFromQueryParam)) - restful.Add(ws) - - println("[go-restful] serving files on http://localhost:8080/static from local /tmp") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func staticFromPathParam(req *restful.Request, resp *restful.Response) { - actual := path.Join(rootdir, req.PathParameter("subpath")) - fmt.Printf("serving %s ... (from %s)\n", actual, req.PathParameter("subpath")) - http.ServeFile( - resp.ResponseWriter, - req.Request, - actual) -} - -func staticFromQueryParam(req *restful.Request, resp *restful.Response) { - http.ServeFile( - resp.ResponseWriter, - req.Request, - path.Join(rootdir, req.QueryParameter("resource"))) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-swagger.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-swagger.go deleted file mode 100644 index ecbd71b2..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-swagger.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "log" - "net/http" - - "github.com/emicklei/go-restful" - "github.com/emicklei/go-restful-swagger12" -) - -type Book struct { - Title string - Author string -} - -func main() { - ws := new(restful.WebService) - ws.Path("/books") - ws.Consumes(restful.MIME_JSON, restful.MIME_XML) - ws.Produces(restful.MIME_JSON, restful.MIME_XML) - restful.Add(ws) - - ws.Route(ws.GET("/{medium}").To(noop). - Doc("Search all books"). - Param(ws.PathParameter("medium", "digital or paperback").DataType("string")). - Param(ws.QueryParameter("language", "en,nl,de").DataType("string")). - Param(ws.HeaderParameter("If-Modified-Since", "last known timestamp").DataType("datetime")). - Do(returns200, returns500)) - - ws.Route(ws.PUT("/{medium}").To(noop). - Doc("Add a new book"). - Param(ws.PathParameter("medium", "digital or paperback").DataType("string")). - Reads(Book{})) - - // You can install the Swagger Service which provides a nice Web UI on your REST API - // You need to download the Swagger HTML5 assets and change the FilePath location in the config below. - // Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field. - config := swagger.Config{ - WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible - WebServicesUrl: "http://localhost:8080", - ApiPath: "/apidocs.json", - - // Optionally, specify where the UI is located - SwaggerPath: "/apidocs/", - SwaggerFilePath: "/Users/emicklei/xProjects/swagger-ui/dist"} - swagger.RegisterSwaggerService(config, restful.DefaultContainer) - - log.Print("start listening on localhost:8080") - server := &http.Server{Addr: ":8080", Handler: restful.DefaultContainer} - log.Fatal(server.ListenAndServe()) -} - -func noop(req *restful.Request, resp *restful.Response) {} - -func returns200(b *restful.RouteBuilder) { - b.Returns(http.StatusOK, "OK", Book{}) -} - -func returns500(b *restful.RouteBuilder) { - b.Returns(http.StatusInternalServerError, "Bummer, something went wrong", nil) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-user-resource.go b/discovery/vendor/github.com/emicklei/go-restful/examples/restful-user-resource.go deleted file mode 100644 index 118d2f0b..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/examples/restful-user-resource.go +++ /dev/null @@ -1,170 +0,0 @@ -package main - -import ( - "log" - "net/http" - - "github.com/emicklei/go-restful" - restfulspec "github.com/emicklei/go-restful-openapi" - "github.com/go-openapi/spec" -) - -// UserResource is the REST layer to the User domain -type UserResource struct { - // normally one would use DAO (data access object) - users map[string]User -} - -// WebService creates a new service that can handle REST requests for User resources. -func (u UserResource) WebService() *restful.WebService { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this per route as well - - tags := []string{"users"} - - ws.Route(ws.GET("/").To(u.findAllUsers). - // docs - Doc("get all users"). - Metadata(restfulspec.KeyOpenAPITags, tags). - Writes([]User{}). - Returns(200, "OK", []User{})) - - ws.Route(ws.GET("/{user-id}").To(u.findUser). - // docs - Doc("get a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("integer").DefaultValue("1")). - Metadata(restfulspec.KeyOpenAPITags, tags). - Writes(User{}). // on the response - Returns(200, "OK", User{}). - Returns(404, "Not Found", nil)) - - ws.Route(ws.PUT("/{user-id}").To(u.updateUser). - // docs - Doc("update a user"). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). - Metadata(restfulspec.KeyOpenAPITags, tags). - Reads(User{})) // from the request - - ws.Route(ws.PUT("").To(u.createUser). - // docs - Doc("create a user"). - Metadata(restfulspec.KeyOpenAPITags, tags). - Reads(User{})) // from the request - - ws.Route(ws.DELETE("/{user-id}").To(u.removeUser). - // docs - Doc("delete a user"). - Metadata(restfulspec.KeyOpenAPITags, tags). - Param(ws.PathParameter("user-id", "identifier of the user").DataType("string"))) - - return ws -} - -// GET http://localhost:8080/users -// -func (u UserResource) findAllUsers(request *restful.Request, response *restful.Response) { - list := []User{} - for _, each := range u.users { - list = append(list, each) - } - response.WriteEntity(list) -} - -// GET http://localhost:8080/users/1 -// -func (u UserResource) findUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - usr := u.users[id] - if len(usr.ID) == 0 { - response.WriteErrorString(http.StatusNotFound, "User could not be found.") - } else { - response.WriteEntity(usr) - } -} - -// PUT http://localhost:8080/users/1 -// 1Melissa Raspberry -// -func (u *UserResource) updateUser(request *restful.Request, response *restful.Response) { - usr := new(User) - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.ID] = *usr - response.WriteEntity(usr) - } else { - response.WriteError(http.StatusInternalServerError, err) - } -} - -// PUT http://localhost:8080/users/1 -// 1Melissa -// -func (u *UserResource) createUser(request *restful.Request, response *restful.Response) { - usr := User{ID: request.PathParameter("user-id")} - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.ID] = usr - response.WriteHeaderAndEntity(http.StatusCreated, usr) - } else { - response.WriteError(http.StatusInternalServerError, err) - } -} - -// DELETE http://localhost:8080/users/1 -// -func (u *UserResource) removeUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - delete(u.users, id) -} - -func main() { - u := UserResource{map[string]User{}} - restful.DefaultContainer.Add(u.WebService()) - - config := restfulspec.Config{ - WebServices: restful.RegisteredWebServices(), // you control what services are visible - WebServicesURL: "http://localhost:8080", - APIPath: "/apidocs.json", - PostBuildSwaggerObjectHandler: enrichSwaggerObject} - restful.DefaultContainer.Add(restfulspec.NewOpenAPIService(config)) - - // Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API - // You need to download the Swagger HTML5 assets and change the FilePath location in the config below. - // Open http://localhost:8080/apidocs/?url=http://localhost:8080/apidocs.json - http.Handle("/apidocs/", http.StripPrefix("/apidocs/", http.FileServer(http.Dir("/Users/emicklei/Projects/swagger-ui/dist")))) - - log.Printf("start listening on localhost:8080") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func enrichSwaggerObject(swo *spec.Swagger) { - swo.Info = &spec.Info{ - InfoProps: spec.InfoProps{ - Title: "UserService", - Description: "Resource for managing Users", - Contact: &spec.ContactInfo{ - Name: "john", - Email: "john@doe.rp", - URL: "http://johndoe.org", - }, - License: &spec.License{ - Name: "MIT", - URL: "http://mit.org", - }, - Version: "1.0.0", - }, - } - swo.Tags = []spec.Tag{spec.Tag{TagProps: spec.TagProps{ - Name: "users", - Description: "Managing users"}}} -} - -// User is just a sample type -type User struct { - ID string `json:"id" description:"identifier of the user"` - Name string `json:"name" description:"name of the user" default:"john"` - Age int `json:"age" description:"age of the user" default:"21"` -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/filter.go b/discovery/vendor/github.com/emicklei/go-restful/filter.go deleted file mode 100644 index c23bfb59..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/filter.go +++ /dev/null @@ -1,35 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -// FilterChain is a request scoped object to process one or more filters before calling the target RouteFunction. -type FilterChain struct { - Filters []FilterFunction // ordered list of FilterFunction - Index int // index into filters that is currently in progress - Target RouteFunction // function to call after passing all filters -} - -// ProcessFilter passes the request,response pair through the next of Filters. -// Each filter can decide to proceed to the next Filter or handle the Response itself. -func (f *FilterChain) ProcessFilter(request *Request, response *Response) { - if f.Index < len(f.Filters) { - f.Index++ - f.Filters[f.Index-1](request, response, f) - } else { - f.Target(request, response) - } -} - -// FilterFunction definitions must call ProcessFilter on the FilterChain to pass on the control and eventually call the RouteFunction -type FilterFunction func(*Request, *Response, *FilterChain) - -// NoBrowserCacheFilter is a filter function to set HTTP headers that disable browser caching -// See examples/restful-no-cache-filter.go for usage -func NoBrowserCacheFilter(req *Request, resp *Response, chain *FilterChain) { - resp.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") // HTTP 1.1. - resp.Header().Set("Pragma", "no-cache") // HTTP 1.0. - resp.Header().Set("Expires", "0") // Proxies. - chain.ProcessFilter(req, resp) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/jsr311.go b/discovery/vendor/github.com/emicklei/go-restful/jsr311.go deleted file mode 100644 index 9e812241..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/jsr311.go +++ /dev/null @@ -1,268 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "errors" - "fmt" - "net/http" - "sort" -) - -// RouterJSR311 implements the flow for matching Requests to Routes (and consequently Resource Functions) -// as specified by the JSR311 http://jsr311.java.net/nonav/releases/1.1/spec/spec.html. -// RouterJSR311 implements the Router interface. -// Concept of locators is not implemented. -type RouterJSR311 struct{} - -// SelectRoute is part of the Router interface and returns the best match -// for the WebService and its Route for the given Request. -func (r RouterJSR311) SelectRoute( - webServices []*WebService, - httpRequest *http.Request) (selectedService *WebService, selectedRoute *Route, err error) { - - // Identify the root resource class (WebService) - dispatcher, finalMatch, err := r.detectDispatcher(httpRequest.URL.Path, webServices) - if err != nil { - return nil, nil, NewError(http.StatusNotFound, "") - } - // Obtain the set of candidate methods (Routes) - routes := r.selectRoutes(dispatcher, finalMatch) - if len(routes) == 0 { - return dispatcher, nil, NewError(http.StatusNotFound, "404: Page Not Found") - } - - // Identify the method (Route) that will handle the request - route, ok := r.detectRoute(routes, httpRequest) - return dispatcher, route, ok -} - -// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2 -func (r RouterJSR311) detectRoute(routes []Route, httpRequest *http.Request) (*Route, error) { - ifOk := []Route{} - for _, each := range routes { - ok := true - for _, fn := range each.If { - if !fn(httpRequest) { - ok = false - break - } - } - if ok { - ifOk = append(ifOk, each) - } - } - if len(ifOk) == 0 { - if trace { - traceLogger.Printf("no Route found (from %d) that passes conditional checks", len(routes)) - } - return nil, NewError(http.StatusNotFound, "404: Not Found") - } - - // http method - methodOk := []Route{} - for _, each := range ifOk { - if httpRequest.Method == each.Method { - methodOk = append(methodOk, each) - } - } - if len(methodOk) == 0 { - if trace { - traceLogger.Printf("no Route found (in %d routes) that matches HTTP method %s\n", len(routes), httpRequest.Method) - } - return nil, NewError(http.StatusMethodNotAllowed, "405: Method Not Allowed") - } - inputMediaOk := methodOk - - // content-type - contentType := httpRequest.Header.Get(HEADER_ContentType) - inputMediaOk = []Route{} - for _, each := range methodOk { - if each.matchesContentType(contentType) { - inputMediaOk = append(inputMediaOk, each) - } - } - if len(inputMediaOk) == 0 { - if trace { - traceLogger.Printf("no Route found (from %d) that matches HTTP Content-Type: %s\n", len(methodOk), contentType) - } - return nil, NewError(http.StatusUnsupportedMediaType, "415: Unsupported Media Type") - } - - // accept - outputMediaOk := []Route{} - accept := httpRequest.Header.Get(HEADER_Accept) - if len(accept) == 0 { - accept = "*/*" - } - for _, each := range inputMediaOk { - if each.matchesAccept(accept) { - outputMediaOk = append(outputMediaOk, each) - } - } - if len(outputMediaOk) == 0 { - if trace { - traceLogger.Printf("no Route found (from %d) that matches HTTP Accept: %s\n", len(inputMediaOk), accept) - } - return nil, NewError(http.StatusNotAcceptable, "406: Not Acceptable") - } - // return r.bestMatchByMedia(outputMediaOk, contentType, accept), nil - return &outputMediaOk[0], nil -} - -// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2 -// n/m > n/* > */* -func (r RouterJSR311) bestMatchByMedia(routes []Route, contentType string, accept string) *Route { - // TODO - return &routes[0] -} - -// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2 (step 2) -func (r RouterJSR311) selectRoutes(dispatcher *WebService, pathRemainder string) []Route { - filtered := &sortableRouteCandidates{} - for _, each := range dispatcher.Routes() { - pathExpr := each.pathExpr - matches := pathExpr.Matcher.FindStringSubmatch(pathRemainder) - if matches != nil { - lastMatch := matches[len(matches)-1] - if len(lastMatch) == 0 || lastMatch == "/" { // do not include if value is neither empty nor ‘/’. - filtered.candidates = append(filtered.candidates, - routeCandidate{each, len(matches) - 1, pathExpr.LiteralCount, pathExpr.VarCount}) - } - } - } - if len(filtered.candidates) == 0 { - if trace { - traceLogger.Printf("WebService on path %s has no routes that match URL path remainder:%s\n", dispatcher.rootPath, pathRemainder) - } - return []Route{} - } - sort.Sort(sort.Reverse(filtered)) - - // select other routes from candidates whoes expression matches rmatch - matchingRoutes := []Route{filtered.candidates[0].route} - for c := 1; c < len(filtered.candidates); c++ { - each := filtered.candidates[c] - if each.route.pathExpr.Matcher.MatchString(pathRemainder) { - matchingRoutes = append(matchingRoutes, each.route) - } - } - return matchingRoutes -} - -// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2 (step 1) -func (r RouterJSR311) detectDispatcher(requestPath string, dispatchers []*WebService) (*WebService, string, error) { - filtered := &sortableDispatcherCandidates{} - for _, each := range dispatchers { - matches := each.pathExpr.Matcher.FindStringSubmatch(requestPath) - if matches != nil { - filtered.candidates = append(filtered.candidates, - dispatcherCandidate{each, matches[len(matches)-1], len(matches), each.pathExpr.LiteralCount, each.pathExpr.VarCount}) - } - } - if len(filtered.candidates) == 0 { - if trace { - traceLogger.Printf("no WebService was found to match URL path:%s\n", requestPath) - } - return nil, "", errors.New("not found") - } - sort.Sort(sort.Reverse(filtered)) - return filtered.candidates[0].dispatcher, filtered.candidates[0].finalMatch, nil -} - -// Types and functions to support the sorting of Routes - -type routeCandidate struct { - route Route - matchesCount int // the number of capturing groups - literalCount int // the number of literal characters (means those not resulting from template variable substitution) - nonDefaultCount int // the number of capturing groups with non-default regular expressions (i.e. not ‘([^ /]+?)’) -} - -func (r routeCandidate) expressionToMatch() string { - return r.route.pathExpr.Source -} - -func (r routeCandidate) String() string { - return fmt.Sprintf("(m=%d,l=%d,n=%d)", r.matchesCount, r.literalCount, r.nonDefaultCount) -} - -type sortableRouteCandidates struct { - candidates []routeCandidate -} - -func (rcs *sortableRouteCandidates) Len() int { - return len(rcs.candidates) -} -func (rcs *sortableRouteCandidates) Swap(i, j int) { - rcs.candidates[i], rcs.candidates[j] = rcs.candidates[j], rcs.candidates[i] -} -func (rcs *sortableRouteCandidates) Less(i, j int) bool { - ci := rcs.candidates[i] - cj := rcs.candidates[j] - // primary key - if ci.literalCount < cj.literalCount { - return true - } - if ci.literalCount > cj.literalCount { - return false - } - // secundary key - if ci.matchesCount < cj.matchesCount { - return true - } - if ci.matchesCount > cj.matchesCount { - return false - } - // tertiary key - if ci.nonDefaultCount < cj.nonDefaultCount { - return true - } - if ci.nonDefaultCount > cj.nonDefaultCount { - return false - } - // quaternary key ("source" is interpreted as Path) - return ci.route.Path < cj.route.Path -} - -// Types and functions to support the sorting of Dispatchers - -type dispatcherCandidate struct { - dispatcher *WebService - finalMatch string - matchesCount int // the number of capturing groups - literalCount int // the number of literal characters (means those not resulting from template variable substitution) - nonDefaultCount int // the number of capturing groups with non-default regular expressions (i.e. not ‘([^ /]+?)’) -} -type sortableDispatcherCandidates struct { - candidates []dispatcherCandidate -} - -func (dc *sortableDispatcherCandidates) Len() int { - return len(dc.candidates) -} -func (dc *sortableDispatcherCandidates) Swap(i, j int) { - dc.candidates[i], dc.candidates[j] = dc.candidates[j], dc.candidates[i] -} -func (dc *sortableDispatcherCandidates) Less(i, j int) bool { - ci := dc.candidates[i] - cj := dc.candidates[j] - // primary key - if ci.matchesCount < cj.matchesCount { - return true - } - if ci.matchesCount > cj.matchesCount { - return false - } - // secundary key - if ci.literalCount < cj.literalCount { - return true - } - if ci.literalCount > cj.literalCount { - return false - } - // tertiary key - return ci.nonDefaultCount < cj.nonDefaultCount -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/log/log.go b/discovery/vendor/github.com/emicklei/go-restful/log/log.go deleted file mode 100644 index 6cd44c7a..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/log/log.go +++ /dev/null @@ -1,34 +0,0 @@ -package log - -import ( - stdlog "log" - "os" -) - -// StdLogger corresponds to a minimal subset of the interface satisfied by stdlib log.Logger -type StdLogger interface { - Print(v ...interface{}) - Printf(format string, v ...interface{}) -} - -var Logger StdLogger - -func init() { - // default Logger - SetLogger(stdlog.New(os.Stderr, "[restful] ", stdlog.LstdFlags|stdlog.Lshortfile)) -} - -// SetLogger sets the logger for this package -func SetLogger(customLogger StdLogger) { - Logger = customLogger -} - -// Print delegates to the Logger -func Print(v ...interface{}) { - Logger.Print(v...) -} - -// Printf delegates to the Logger -func Printf(format string, v ...interface{}) { - Logger.Printf(format, v...) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/logger.go b/discovery/vendor/github.com/emicklei/go-restful/logger.go deleted file mode 100644 index 6595df00..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/logger.go +++ /dev/null @@ -1,32 +0,0 @@ -package restful - -// Copyright 2014 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. -import ( - "github.com/emicklei/go-restful/log" -) - -var trace bool = false -var traceLogger log.StdLogger - -func init() { - traceLogger = log.Logger // use the package logger by default -} - -// TraceLogger enables detailed logging of Http request matching and filter invocation. Default no logger is set. -// You may call EnableTracing() directly to enable trace logging to the package-wide logger. -func TraceLogger(logger log.StdLogger) { - traceLogger = logger - EnableTracing(logger != nil) -} - -// SetLogger exposes the setter for the global logger on the top-level package -func SetLogger(customLogger log.StdLogger) { - log.SetLogger(customLogger) -} - -// EnableTracing can be used to Trace logging on and off. -func EnableTracing(enabled bool) { - trace = enabled -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/mime.go b/discovery/vendor/github.com/emicklei/go-restful/mime.go deleted file mode 100644 index d7ea2b61..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/mime.go +++ /dev/null @@ -1,45 +0,0 @@ -package restful - -import ( - "strconv" - "strings" -) - -type mime struct { - media string - quality float64 -} - -// insertMime adds a mime to a list and keeps it sorted by quality. -func insertMime(l []mime, e mime) []mime { - for i, each := range l { - // if current mime has lower quality then insert before - if e.quality > each.quality { - left := append([]mime{}, l[0:i]...) - return append(append(left, e), l[i:]...) - } - } - return append(l, e) -} - -// sortedMimes returns a list of mime sorted (desc) by its specified quality. -func sortedMimes(accept string) (sorted []mime) { - for _, each := range strings.Split(accept, ",") { - typeAndQuality := strings.Split(strings.Trim(each, " "), ";") - if len(typeAndQuality) == 1 { - sorted = insertMime(sorted, mime{typeAndQuality[0], 1.0}) - } else { - // take factor - parts := strings.Split(typeAndQuality[1], "=") - if len(parts) == 2 { - f, err := strconv.ParseFloat(parts[1], 64) - if err != nil { - traceLogger.Printf("unable to parse quality in %s, %v", each, err) - } else { - sorted = insertMime(sorted, mime{typeAndQuality[0], f}) - } - } - } - } - return -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/options_filter.go b/discovery/vendor/github.com/emicklei/go-restful/options_filter.go deleted file mode 100644 index 5c1b3425..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/options_filter.go +++ /dev/null @@ -1,34 +0,0 @@ -package restful - -import "strings" - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -// OPTIONSFilter is a filter function that inspects the Http Request for the OPTIONS method -// and provides the response with a set of allowed methods for the request URL Path. -// As for any filter, you can also install it for a particular WebService within a Container. -// Note: this filter is not needed when using CrossOriginResourceSharing (for CORS). -func (c *Container) OPTIONSFilter(req *Request, resp *Response, chain *FilterChain) { - if "OPTIONS" != req.Request.Method { - chain.ProcessFilter(req, resp) - return - } - - archs := req.Request.Header.Get(HEADER_AccessControlRequestHeaders) - methods := strings.Join(c.computeAllowedMethods(req), ",") - origin := req.Request.Header.Get(HEADER_Origin) - - resp.AddHeader(HEADER_Allow, methods) - resp.AddHeader(HEADER_AccessControlAllowOrigin, origin) - resp.AddHeader(HEADER_AccessControlAllowHeaders, archs) - resp.AddHeader(HEADER_AccessControlAllowMethods, methods) -} - -// OPTIONSFilter is a filter function that inspects the Http Request for the OPTIONS method -// and provides the response with a set of allowed methods for the request URL Path. -// Note: this filter is not needed when using CrossOriginResourceSharing (for CORS). -func OPTIONSFilter() FilterFunction { - return DefaultContainer.OPTIONSFilter -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/parameter.go b/discovery/vendor/github.com/emicklei/go-restful/parameter.go deleted file mode 100644 index e11c8162..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/parameter.go +++ /dev/null @@ -1,114 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -const ( - // PathParameterKind = indicator of Request parameter type "path" - PathParameterKind = iota - - // QueryParameterKind = indicator of Request parameter type "query" - QueryParameterKind - - // BodyParameterKind = indicator of Request parameter type "body" - BodyParameterKind - - // HeaderParameterKind = indicator of Request parameter type "header" - HeaderParameterKind - - // FormParameterKind = indicator of Request parameter type "form" - FormParameterKind -) - -// Parameter is for documententing the parameter used in a Http Request -// ParameterData kinds are Path,Query and Body -type Parameter struct { - data *ParameterData -} - -// ParameterData represents the state of a Parameter. -// It is made public to make it accessible to e.g. the Swagger package. -type ParameterData struct { - Name, Description, DataType, DataFormat string - Kind int - Required bool - AllowableValues map[string]string - AllowMultiple bool - DefaultValue string -} - -// Data returns the state of the Parameter -func (p *Parameter) Data() ParameterData { - return *p.data -} - -// Kind returns the parameter type indicator (see const for valid values) -func (p *Parameter) Kind() int { - return p.data.Kind -} - -func (p *Parameter) bePath() *Parameter { - p.data.Kind = PathParameterKind - return p -} -func (p *Parameter) beQuery() *Parameter { - p.data.Kind = QueryParameterKind - return p -} -func (p *Parameter) beBody() *Parameter { - p.data.Kind = BodyParameterKind - return p -} - -func (p *Parameter) beHeader() *Parameter { - p.data.Kind = HeaderParameterKind - return p -} - -func (p *Parameter) beForm() *Parameter { - p.data.Kind = FormParameterKind - return p -} - -// Required sets the required field and returns the receiver -func (p *Parameter) Required(required bool) *Parameter { - p.data.Required = required - return p -} - -// AllowMultiple sets the allowMultiple field and returns the receiver -func (p *Parameter) AllowMultiple(multiple bool) *Parameter { - p.data.AllowMultiple = multiple - return p -} - -// AllowableValues sets the allowableValues field and returns the receiver -func (p *Parameter) AllowableValues(values map[string]string) *Parameter { - p.data.AllowableValues = values - return p -} - -// DataType sets the dataType field and returns the receiver -func (p *Parameter) DataType(typeName string) *Parameter { - p.data.DataType = typeName - return p -} - -// DataFormat sets the dataFormat field for Swagger UI -func (p *Parameter) DataFormat(formatName string) *Parameter { - p.data.DataFormat = formatName - return p -} - -// DefaultValue sets the default value field and returns the receiver -func (p *Parameter) DefaultValue(stringRepresentation string) *Parameter { - p.data.DefaultValue = stringRepresentation - return p -} - -// Description sets the description value field and returns the receiver -func (p *Parameter) Description(doc string) *Parameter { - p.data.Description = doc - return p -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/path_expression.go b/discovery/vendor/github.com/emicklei/go-restful/path_expression.go deleted file mode 100644 index a921e6f2..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/path_expression.go +++ /dev/null @@ -1,69 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bytes" - "fmt" - "regexp" - "strings" -) - -// PathExpression holds a compiled path expression (RegExp) needed to match against -// Http request paths and to extract path parameter values. -type pathExpression struct { - LiteralCount int // the number of literal characters (means those not resulting from template variable substitution) - VarCount int // the number of named parameters (enclosed by {}) in the path - Matcher *regexp.Regexp - Source string // Path as defined by the RouteBuilder - tokens []string -} - -// NewPathExpression creates a PathExpression from the input URL path. -// Returns an error if the path is invalid. -func newPathExpression(path string) (*pathExpression, error) { - expression, literalCount, varCount, tokens := templateToRegularExpression(path) - compiled, err := regexp.Compile(expression) - if err != nil { - return nil, err - } - return &pathExpression{literalCount, varCount, compiled, expression, tokens}, nil -} - -// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-370003.7.3 -func templateToRegularExpression(template string) (expression string, literalCount int, varCount int, tokens []string) { - var buffer bytes.Buffer - buffer.WriteString("^") - //tokens = strings.Split(template, "/") - tokens = tokenizePath(template) - for _, each := range tokens { - if each == "" { - continue - } - buffer.WriteString("/") - if strings.HasPrefix(each, "{") { - // check for regular expression in variable - colon := strings.Index(each, ":") - if colon != -1 { - // extract expression - paramExpr := strings.TrimSpace(each[colon+1 : len(each)-1]) - if paramExpr == "*" { // special case - buffer.WriteString("(.*)") - } else { - buffer.WriteString(fmt.Sprintf("(%s)", paramExpr)) // between colon and closing moustache - } - } else { - // plain var - buffer.WriteString("([^/]+?)") - } - varCount += 1 - } else { - literalCount += len(each) - encoded := each // TODO URI encode - buffer.WriteString(regexp.QuoteMeta(encoded)) - } - } - return strings.TrimRight(buffer.String(), "/") + "(/.*)?$", literalCount, varCount, tokens -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/request.go b/discovery/vendor/github.com/emicklei/go-restful/request.go deleted file mode 100644 index 8c23af12..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/request.go +++ /dev/null @@ -1,113 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "compress/zlib" - "net/http" -) - -var defaultRequestContentType string - -// Request is a wrapper for a http Request that provides convenience methods -type Request struct { - Request *http.Request - pathParameters map[string]string - attributes map[string]interface{} // for storing request-scoped values - selectedRoutePath string // root path + route path that matched the request, e.g. /meetings/{id}/attendees -} - -func NewRequest(httpRequest *http.Request) *Request { - return &Request{ - Request: httpRequest, - pathParameters: map[string]string{}, - attributes: map[string]interface{}{}, - } // empty parameters, attributes -} - -// If ContentType is missing or */* is given then fall back to this type, otherwise -// a "Unable to unmarshal content of type:" response is returned. -// Valid values are restful.MIME_JSON and restful.MIME_XML -// Example: -// restful.DefaultRequestContentType(restful.MIME_JSON) -func DefaultRequestContentType(mime string) { - defaultRequestContentType = mime -} - -// PathParameter accesses the Path parameter value by its name -func (r *Request) PathParameter(name string) string { - return r.pathParameters[name] -} - -// PathParameters accesses the Path parameter values -func (r *Request) PathParameters() map[string]string { - return r.pathParameters -} - -// QueryParameter returns the (first) Query parameter value by its name -func (r *Request) QueryParameter(name string) string { - return r.Request.FormValue(name) -} - -// BodyParameter parses the body of the request (once for typically a POST or a PUT) and returns the value of the given name or an error. -func (r *Request) BodyParameter(name string) (string, error) { - err := r.Request.ParseForm() - if err != nil { - return "", err - } - return r.Request.PostFormValue(name), nil -} - -// HeaderParameter returns the HTTP Header value of a Header name or empty if missing -func (r *Request) HeaderParameter(name string) string { - return r.Request.Header.Get(name) -} - -// ReadEntity checks the Accept header and reads the content into the entityPointer. -func (r *Request) ReadEntity(entityPointer interface{}) (err error) { - contentType := r.Request.Header.Get(HEADER_ContentType) - contentEncoding := r.Request.Header.Get(HEADER_ContentEncoding) - - // check if the request body needs decompression - if ENCODING_GZIP == contentEncoding { - gzipReader := currentCompressorProvider.AcquireGzipReader() - defer currentCompressorProvider.ReleaseGzipReader(gzipReader) - gzipReader.Reset(r.Request.Body) - r.Request.Body = gzipReader - } else if ENCODING_DEFLATE == contentEncoding { - zlibReader, err := zlib.NewReader(r.Request.Body) - if err != nil { - return err - } - r.Request.Body = zlibReader - } - - // lookup the EntityReader, use defaultRequestContentType if needed and provided - entityReader, ok := entityAccessRegistry.accessorAt(contentType) - if !ok { - if len(defaultRequestContentType) != 0 { - entityReader, ok = entityAccessRegistry.accessorAt(defaultRequestContentType) - } - if !ok { - return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType) - } - } - return entityReader.Read(r, entityPointer) -} - -// SetAttribute adds or replaces the attribute with the given value. -func (r *Request) SetAttribute(name string, value interface{}) { - r.attributes[name] = value -} - -// Attribute returns the value associated to the given name. Returns nil if absent. -func (r Request) Attribute(name string) interface{} { - return r.attributes[name] -} - -// SelectedRoutePath root path + route path that matched the request, e.g. /meetings/{id}/attendees -func (r Request) SelectedRoutePath() string { - return r.selectedRoutePath -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/response.go b/discovery/vendor/github.com/emicklei/go-restful/response.go deleted file mode 100644 index 4d987d13..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/response.go +++ /dev/null @@ -1,250 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bufio" - "errors" - "net" - "net/http" -) - -// DefaultResponseMimeType is DEPRECATED, use DefaultResponseContentType(mime) -var DefaultResponseMimeType string - -//PrettyPrintResponses controls the indentation feature of XML and JSON serialization -var PrettyPrintResponses = true - -// Response is a wrapper on the actual http ResponseWriter -// It provides several convenience methods to prepare and write response content. -type Response struct { - http.ResponseWriter - requestAccept string // mime-type what the Http Request says it wants to receive - routeProduces []string // mime-types what the Route says it can produce - statusCode int // HTTP status code that has been written explicitly (if zero then net/http has written 200) - contentLength int // number of bytes written for the response body - prettyPrint bool // controls the indentation feature of XML and JSON serialization. It is initialized using var PrettyPrintResponses. - err error // err property is kept when WriteError is called - hijacker http.Hijacker // if underlying ResponseWriter supports it -} - -// NewResponse creates a new response based on a http ResponseWriter. -func NewResponse(httpWriter http.ResponseWriter) *Response { - hijacker, _ := httpWriter.(http.Hijacker) - return &Response{ResponseWriter: httpWriter, routeProduces: []string{}, statusCode: http.StatusOK, prettyPrint: PrettyPrintResponses, hijacker: hijacker} -} - -// DefaultResponseContentType set a default. -// If Accept header matching fails, fall back to this type. -// Valid values are restful.MIME_JSON and restful.MIME_XML -// Example: -// restful.DefaultResponseContentType(restful.MIME_JSON) -func DefaultResponseContentType(mime string) { - DefaultResponseMimeType = mime -} - -// InternalServerError writes the StatusInternalServerError header. -// DEPRECATED, use WriteErrorString(http.StatusInternalServerError,reason) -func (r Response) InternalServerError() Response { - r.WriteHeader(http.StatusInternalServerError) - return r -} - -// Hijack implements the http.Hijacker interface. This expands -// the Response to fulfill http.Hijacker if the underlying -// http.ResponseWriter supports it. -func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) { - if r.hijacker == nil { - return nil, nil, errors.New("http.Hijacker not implemented by underlying http.ResponseWriter") - } - return r.hijacker.Hijack() -} - -// PrettyPrint changes whether this response must produce pretty (line-by-line, indented) JSON or XML output. -func (r *Response) PrettyPrint(bePretty bool) { - r.prettyPrint = bePretty -} - -// AddHeader is a shortcut for .Header().Add(header,value) -func (r Response) AddHeader(header string, value string) Response { - r.Header().Add(header, value) - return r -} - -// SetRequestAccepts tells the response what Mime-type(s) the HTTP request said it wants to accept. Exposed for testing. -func (r *Response) SetRequestAccepts(mime string) { - r.requestAccept = mime -} - -// EntityWriter returns the registered EntityWriter that the entity (requested resource) -// can write according to what the request wants (Accept) and what the Route can produce or what the restful defaults say. -// If called before WriteEntity and WriteHeader then a false return value can be used to write a 406: Not Acceptable. -func (r *Response) EntityWriter() (EntityReaderWriter, bool) { - sorted := sortedMimes(r.requestAccept) - for _, eachAccept := range sorted { - for _, eachProduce := range r.routeProduces { - if eachProduce == eachAccept.media { - if w, ok := entityAccessRegistry.accessorAt(eachAccept.media); ok { - return w, true - } - } - } - if eachAccept.media == "*/*" { - for _, each := range r.routeProduces { - if w, ok := entityAccessRegistry.accessorAt(each); ok { - return w, true - } - } - } - } - // if requestAccept is empty - writer, ok := entityAccessRegistry.accessorAt(r.requestAccept) - if !ok { - // if not registered then fallback to the defaults (if set) - if DefaultResponseMimeType == MIME_JSON { - return entityAccessRegistry.accessorAt(MIME_JSON) - } - if DefaultResponseMimeType == MIME_XML { - return entityAccessRegistry.accessorAt(MIME_XML) - } - // Fallback to whatever the route says it can produce. - // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html - for _, each := range r.routeProduces { - if w, ok := entityAccessRegistry.accessorAt(each); ok { - return w, true - } - } - if trace { - traceLogger.Printf("no registered EntityReaderWriter found for %s", r.requestAccept) - } - } - return writer, ok -} - -// WriteEntity calls WriteHeaderAndEntity with Http Status OK (200) -func (r *Response) WriteEntity(value interface{}) error { - return r.WriteHeaderAndEntity(http.StatusOK, value) -} - -// WriteHeaderAndEntity marshals the value using the representation denoted by the Accept Header and the registered EntityWriters. -// If no Accept header is specified (or */*) then respond with the Content-Type as specified by the first in the Route.Produces. -// If an Accept header is specified then respond with the Content-Type as specified by the first in the Route.Produces that is matched with the Accept header. -// If the value is nil then no response is send except for the Http status. You may want to call WriteHeader(http.StatusNotFound) instead. -// If there is no writer available that can represent the value in the requested MIME type then Http Status NotAcceptable is written. -// Current implementation ignores any q-parameters in the Accept Header. -// Returns an error if the value could not be written on the response. -func (r *Response) WriteHeaderAndEntity(status int, value interface{}) error { - writer, ok := r.EntityWriter() - if !ok { - r.WriteHeader(http.StatusNotAcceptable) - return nil - } - return writer.Write(r, status, value) -} - -// WriteAsXml is a convenience method for writing a value in xml (requires Xml tags on the value) -// It uses the standard encoding/xml package for marshalling the value ; not using a registered EntityReaderWriter. -func (r *Response) WriteAsXml(value interface{}) error { - return writeXML(r, http.StatusOK, MIME_XML, value) -} - -// WriteHeaderAndXml is a convenience method for writing a status and value in xml (requires Xml tags on the value) -// It uses the standard encoding/xml package for marshalling the value ; not using a registered EntityReaderWriter. -func (r *Response) WriteHeaderAndXml(status int, value interface{}) error { - return writeXML(r, status, MIME_XML, value) -} - -// WriteAsJson is a convenience method for writing a value in json. -// It uses the standard encoding/json package for marshalling the value ; not using a registered EntityReaderWriter. -func (r *Response) WriteAsJson(value interface{}) error { - return writeJSON(r, http.StatusOK, MIME_JSON, value) -} - -// WriteJson is a convenience method for writing a value in Json with a given Content-Type. -// It uses the standard encoding/json package for marshalling the value ; not using a registered EntityReaderWriter. -func (r *Response) WriteJson(value interface{}, contentType string) error { - return writeJSON(r, http.StatusOK, contentType, value) -} - -// WriteHeaderAndJson is a convenience method for writing the status and a value in Json with a given Content-Type. -// It uses the standard encoding/json package for marshalling the value ; not using a registered EntityReaderWriter. -func (r *Response) WriteHeaderAndJson(status int, value interface{}, contentType string) error { - return writeJSON(r, status, contentType, value) -} - -// WriteError write the http status and the error string on the response. -func (r *Response) WriteError(httpStatus int, err error) error { - r.err = err - return r.WriteErrorString(httpStatus, err.Error()) -} - -// WriteServiceError is a convenience method for a responding with a status and a ServiceError -func (r *Response) WriteServiceError(httpStatus int, err ServiceError) error { - r.err = err - return r.WriteHeaderAndEntity(httpStatus, err) -} - -// WriteErrorString is a convenience method for an error status with the actual error -func (r *Response) WriteErrorString(httpStatus int, errorReason string) error { - if r.err == nil { - // if not called from WriteError - r.err = errors.New(errorReason) - } - r.WriteHeader(httpStatus) - if _, err := r.Write([]byte(errorReason)); err != nil { - return err - } - return nil -} - -// Flush implements http.Flusher interface, which sends any buffered data to the client. -func (r *Response) Flush() { - if f, ok := r.ResponseWriter.(http.Flusher); ok { - f.Flush() - } else if trace { - traceLogger.Printf("ResponseWriter %v doesn't support Flush", r) - } -} - -// WriteHeader is overridden to remember the Status Code that has been written. -// Changes to the Header of the response have no effect after this. -func (r *Response) WriteHeader(httpStatus int) { - r.statusCode = httpStatus - r.ResponseWriter.WriteHeader(httpStatus) -} - -// StatusCode returns the code that has been written using WriteHeader. -func (r Response) StatusCode() int { - if 0 == r.statusCode { - // no status code has been written yet; assume OK - return http.StatusOK - } - return r.statusCode -} - -// Write writes the data to the connection as part of an HTTP reply. -// Write is part of http.ResponseWriter interface. -func (r *Response) Write(bytes []byte) (int, error) { - written, err := r.ResponseWriter.Write(bytes) - r.contentLength += written - return written, err -} - -// ContentLength returns the number of bytes written for the response content. -// Note that this value is only correct if all data is written through the Response using its Write* methods. -// Data written directly using the underlying http.ResponseWriter is not accounted for. -func (r Response) ContentLength() int { - return r.contentLength -} - -// CloseNotify is part of http.CloseNotifier interface -func (r Response) CloseNotify() <-chan bool { - return r.ResponseWriter.(http.CloseNotifier).CloseNotify() -} - -// Error returns the err created by WriteError -func (r Response) Error() error { - return r.err -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/route.go b/discovery/vendor/github.com/emicklei/go-restful/route.go deleted file mode 100644 index 9d5b156e..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/route.go +++ /dev/null @@ -1,192 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "bytes" - "net/http" - "strings" -) - -// RouteFunction declares the signature of a function that can be bound to a Route. -type RouteFunction func(*Request, *Response) - -// RouteSelectionConditionFunction declares the signature of a function that -// can be used to add extra conditional logic when selecting whether the route -// matches the HTTP request. -type RouteSelectionConditionFunction func(httpRequest *http.Request) bool - -// Route binds a HTTP Method,Path,Consumes combination to a RouteFunction. -type Route struct { - Method string - Produces []string - Consumes []string - Path string // webservice root path + described path - Function RouteFunction - Filters []FilterFunction - If []RouteSelectionConditionFunction - - // cached values for dispatching - relativePath string - pathParts []string - pathExpr *pathExpression // cached compilation of relativePath as RegExp - - // documentation - Doc string - Notes string - Operation string - ParameterDocs []*Parameter - ResponseErrors map[int]ResponseError - ReadSample, WriteSample interface{} // structs that model an example request or response payload - - // Extra information used to store custom information about the route. - Metadata map[string]interface{} -} - -// Initialize for Route -func (r *Route) postBuild() { - r.pathParts = tokenizePath(r.Path) -} - -// Create Request and Response from their http versions -func (r *Route) wrapRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request) (*Request, *Response) { - params := r.extractParameters(httpRequest.URL.Path) - wrappedRequest := NewRequest(httpRequest) - wrappedRequest.pathParameters = params - wrappedRequest.selectedRoutePath = r.Path - wrappedResponse := NewResponse(httpWriter) - wrappedResponse.requestAccept = httpRequest.Header.Get(HEADER_Accept) - wrappedResponse.routeProduces = r.Produces - return wrappedRequest, wrappedResponse -} - -// dispatchWithFilters call the function after passing through its own filters -func (r *Route) dispatchWithFilters(wrappedRequest *Request, wrappedResponse *Response) { - if len(r.Filters) > 0 { - chain := FilterChain{Filters: r.Filters, Target: r.Function} - chain.ProcessFilter(wrappedRequest, wrappedResponse) - } else { - // unfiltered - r.Function(wrappedRequest, wrappedResponse) - } -} - -// Return whether the mimeType matches to what this Route can produce. -func (r Route) matchesAccept(mimeTypesWithQuality string) bool { - parts := strings.Split(mimeTypesWithQuality, ",") - for _, each := range parts { - var withoutQuality string - if strings.Contains(each, ";") { - withoutQuality = strings.Split(each, ";")[0] - } else { - withoutQuality = each - } - // trim before compare - withoutQuality = strings.Trim(withoutQuality, " ") - if withoutQuality == "*/*" { - return true - } - for _, producibleType := range r.Produces { - if producibleType == "*/*" || producibleType == withoutQuality { - return true - } - } - } - return false -} - -// Return whether this Route can consume content with a type specified by mimeTypes (can be empty). -func (r Route) matchesContentType(mimeTypes string) bool { - - if len(r.Consumes) == 0 { - // did not specify what it can consume ; any media type (“*/*”) is assumed - return true - } - - if len(mimeTypes) == 0 { - // idempotent methods with (most-likely or guaranteed) empty content match missing Content-Type - m := r.Method - if m == "GET" || m == "HEAD" || m == "OPTIONS" || m == "DELETE" || m == "TRACE" { - return true - } - // proceed with default - mimeTypes = MIME_OCTET - } - - parts := strings.Split(mimeTypes, ",") - for _, each := range parts { - var contentType string - if strings.Contains(each, ";") { - contentType = strings.Split(each, ";")[0] - } else { - contentType = each - } - // trim before compare - contentType = strings.Trim(contentType, " ") - for _, consumeableType := range r.Consumes { - if consumeableType == "*/*" || consumeableType == contentType { - return true - } - } - } - return false -} - -// Extract the parameters from the request url path -func (r Route) extractParameters(urlPath string) map[string]string { - urlParts := tokenizePath(urlPath) - pathParameters := map[string]string{} - for i, key := range r.pathParts { - var value string - if i >= len(urlParts) { - value = "" - } else { - value = urlParts[i] - } - if strings.HasPrefix(key, "{") { // path-parameter - if colon := strings.Index(key, ":"); colon != -1 { - // extract by regex - regPart := key[colon+1 : len(key)-1] - keyPart := key[1:colon] - if regPart == "*" { - pathParameters[keyPart] = untokenizePath(i, urlParts) - break - } else { - pathParameters[keyPart] = value - } - } else { - // without enclosing {} - pathParameters[key[1:len(key)-1]] = value - } - } - } - return pathParameters -} - -// Untokenize back into an URL path using the slash separator -func untokenizePath(offset int, parts []string) string { - var buffer bytes.Buffer - for p := offset; p < len(parts); p++ { - buffer.WriteString(parts[p]) - // do not end - if p < len(parts)-1 { - buffer.WriteString("/") - } - } - return buffer.String() -} - -// Tokenize an URL path using the slash separator ; the result does not have empty tokens -func tokenizePath(path string) []string { - if "/" == path { - return []string{} - } - return strings.Split(strings.Trim(path, "/"), "/") -} - -// for debugging -func (r Route) String() string { - return r.Method + " " + r.Path -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/route_builder.go b/discovery/vendor/github.com/emicklei/go-restful/route_builder.go deleted file mode 100644 index 83db02b7..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/route_builder.go +++ /dev/null @@ -1,310 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "fmt" - "os" - "reflect" - "runtime" - "strings" - "sync/atomic" - - "github.com/emicklei/go-restful/log" -) - -// RouteBuilder is a helper to construct Routes. -type RouteBuilder struct { - rootPath string - currentPath string - produces []string - consumes []string - httpMethod string // required - function RouteFunction // required - filters []FilterFunction - conditions []RouteSelectionConditionFunction - - typeNameHandleFunc TypeNameHandleFunction // required - - // documentation - doc string - notes string - operation string - readSample, writeSample interface{} - parameters []*Parameter - errorMap map[int]ResponseError - metadata map[string]interface{} -} - -// Do evaluates each argument with the RouteBuilder itself. -// This allows you to follow DRY principles without breaking the fluent programming style. -// Example: -// ws.Route(ws.DELETE("/{name}").To(t.deletePerson).Do(Returns200, Returns500)) -// -// func Returns500(b *RouteBuilder) { -// b.Returns(500, "Internal Server Error", restful.ServiceError{}) -// } -func (b *RouteBuilder) Do(oneArgBlocks ...func(*RouteBuilder)) *RouteBuilder { - for _, each := range oneArgBlocks { - each(b) - } - return b -} - -// To bind the route to a function. -// If this route is matched with the incoming Http Request then call this function with the *Request,*Response pair. Required. -func (b *RouteBuilder) To(function RouteFunction) *RouteBuilder { - b.function = function - return b -} - -// Method specifies what HTTP method to match. Required. -func (b *RouteBuilder) Method(method string) *RouteBuilder { - b.httpMethod = method - return b -} - -// Produces specifies what MIME types can be produced ; the matched one will appear in the Content-Type Http header. -func (b *RouteBuilder) Produces(mimeTypes ...string) *RouteBuilder { - b.produces = mimeTypes - return b -} - -// Consumes specifies what MIME types can be consumes ; the Accept Http header must matched any of these -func (b *RouteBuilder) Consumes(mimeTypes ...string) *RouteBuilder { - b.consumes = mimeTypes - return b -} - -// Path specifies the relative (w.r.t WebService root path) URL path to match. Default is "/". -func (b *RouteBuilder) Path(subPath string) *RouteBuilder { - b.currentPath = subPath - return b -} - -// Doc tells what this route is all about. Optional. -func (b *RouteBuilder) Doc(documentation string) *RouteBuilder { - b.doc = documentation - return b -} - -// Notes is a verbose explanation of the operation behavior. Optional. -func (b *RouteBuilder) Notes(notes string) *RouteBuilder { - b.notes = notes - return b -} - -// Reads tells what resource type will be read from the request payload. Optional. -// A parameter of type "body" is added ,required is set to true and the dataType is set to the qualified name of the sample's type. -func (b *RouteBuilder) Reads(sample interface{}) *RouteBuilder { - fn := b.typeNameHandleFunc - if fn == nil { - fn = reflectTypeName - } - typeAsName := fn(sample) - - b.readSample = sample - bodyParameter := &Parameter{&ParameterData{Name: "body"}} - bodyParameter.beBody() - bodyParameter.Required(true) - bodyParameter.DataType(typeAsName) - b.Param(bodyParameter) - return b -} - -// ParameterNamed returns a Parameter already known to the RouteBuilder. Returns nil if not. -// Use this to modify or extend information for the Parameter (through its Data()). -func (b RouteBuilder) ParameterNamed(name string) (p *Parameter) { - for _, each := range b.parameters { - if each.Data().Name == name { - return each - } - } - return p -} - -// Writes tells what resource type will be written as the response payload. Optional. -func (b *RouteBuilder) Writes(sample interface{}) *RouteBuilder { - b.writeSample = sample - return b -} - -// Param allows you to document the parameters of the Route. It adds a new Parameter (does not check for duplicates). -func (b *RouteBuilder) Param(parameter *Parameter) *RouteBuilder { - if b.parameters == nil { - b.parameters = []*Parameter{} - } - b.parameters = append(b.parameters, parameter) - return b -} - -// Operation allows you to document what the actual method/function call is of the Route. -// Unless called, the operation name is derived from the RouteFunction set using To(..). -func (b *RouteBuilder) Operation(name string) *RouteBuilder { - b.operation = name - return b -} - -// ReturnsError is deprecated, use Returns instead. -func (b *RouteBuilder) ReturnsError(code int, message string, model interface{}) *RouteBuilder { - log.Print("ReturnsError is deprecated, use Returns instead.") - return b.Returns(code, message, model) -} - -// Returns allows you to document what responses (errors or regular) can be expected. -// The model parameter is optional ; either pass a struct instance or use nil if not applicable. -func (b *RouteBuilder) Returns(code int, message string, model interface{}) *RouteBuilder { - err := ResponseError{ - Code: code, - Message: message, - Model: model, - IsDefault: false, - } - // lazy init because there is no NewRouteBuilder (yet) - if b.errorMap == nil { - b.errorMap = map[int]ResponseError{} - } - b.errorMap[code] = err - return b -} - -// DefaultReturns is a special Returns call that sets the default of the response ; the code is zero. -func (b *RouteBuilder) DefaultReturns(message string, model interface{}) *RouteBuilder { - b.Returns(0, message, model) - // Modify the ResponseError just added/updated - re := b.errorMap[0] - // errorMap is initialized - b.errorMap[0] = ResponseError{ - Code: re.Code, - Message: re.Message, - Model: re.Model, - IsDefault: true, - } - return b -} - -// Metadata adds or updates a key=value pair to the metadata map. -func (b *RouteBuilder) Metadata(key string, value interface{}) *RouteBuilder { - if b.metadata == nil { - b.metadata = map[string]interface{}{} - } - b.metadata[key] = value - return b -} - -// ResponseError represents a response; not necessarily an error. -type ResponseError struct { - Code int - Message string - Model interface{} - IsDefault bool -} - -func (b *RouteBuilder) servicePath(path string) *RouteBuilder { - b.rootPath = path - return b -} - -// Filter appends a FilterFunction to the end of filters for this Route to build. -func (b *RouteBuilder) Filter(filter FilterFunction) *RouteBuilder { - b.filters = append(b.filters, filter) - return b -} - -// If sets a condition function that controls matching the Route based on custom logic. -// The condition function is provided the HTTP request and should return true if the route -// should be considered. -// -// Efficiency note: the condition function is called before checking the method, produces, and -// consumes criteria, so that the correct HTTP status code can be returned. -// -// Lifecycle note: no filter functions have been called prior to calling the condition function, -// so the condition function should not depend on any context that might be set up by container -// or route filters. -func (b *RouteBuilder) If(condition RouteSelectionConditionFunction) *RouteBuilder { - b.conditions = append(b.conditions, condition) - return b -} - -// If no specific Route path then set to rootPath -// If no specific Produces then set to rootProduces -// If no specific Consumes then set to rootConsumes -func (b *RouteBuilder) copyDefaults(rootProduces, rootConsumes []string) { - if len(b.produces) == 0 { - b.produces = rootProduces - } - if len(b.consumes) == 0 { - b.consumes = rootConsumes - } -} - -// typeNameHandler sets the function that will convert types to strings in the parameter -// and model definitions. -func (b *RouteBuilder) typeNameHandler(handler TypeNameHandleFunction) *RouteBuilder { - b.typeNameHandleFunc = handler - return b -} - -// Build creates a new Route using the specification details collected by the RouteBuilder -func (b *RouteBuilder) Build() Route { - pathExpr, err := newPathExpression(b.currentPath) - if err != nil { - log.Printf("[restful] Invalid path:%s because:%v", b.currentPath, err) - os.Exit(1) - } - if b.function == nil { - log.Printf("[restful] No function specified for route:" + b.currentPath) - os.Exit(1) - } - operationName := b.operation - if len(operationName) == 0 && b.function != nil { - // extract from definition - operationName = nameOfFunction(b.function) - } - route := Route{ - Method: b.httpMethod, - Path: concatPath(b.rootPath, b.currentPath), - Produces: b.produces, - Consumes: b.consumes, - Function: b.function, - Filters: b.filters, - If: b.conditions, - relativePath: b.currentPath, - pathExpr: pathExpr, - Doc: b.doc, - Notes: b.notes, - Operation: operationName, - ParameterDocs: b.parameters, - ResponseErrors: b.errorMap, - ReadSample: b.readSample, - WriteSample: b.writeSample, - Metadata: b.metadata} - route.postBuild() - return route -} - -func concatPath(path1, path2 string) string { - return strings.TrimRight(path1, "/") + "/" + strings.TrimLeft(path2, "/") -} - -var anonymousFuncCount int32 - -// nameOfFunction returns the short name of the function f for documentation. -// It uses a runtime feature for debugging ; its value may change for later Go versions. -func nameOfFunction(f interface{}) string { - fun := runtime.FuncForPC(reflect.ValueOf(f).Pointer()) - tokenized := strings.Split(fun.Name(), ".") - last := tokenized[len(tokenized)-1] - last = strings.TrimSuffix(last, ")·fm") // < Go 1.5 - last = strings.TrimSuffix(last, ")-fm") // Go 1.5 - last = strings.TrimSuffix(last, "·fm") // < Go 1.5 - last = strings.TrimSuffix(last, "-fm") // Go 1.5 - if last == "func1" { // this could mean conflicts in API docs - val := atomic.AddInt32(&anonymousFuncCount, 1) - last = "func" + fmt.Sprintf("%d", val) - atomic.StoreInt32(&anonymousFuncCount, val) - } - return last -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/router.go b/discovery/vendor/github.com/emicklei/go-restful/router.go deleted file mode 100644 index 9b32fb67..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/router.go +++ /dev/null @@ -1,18 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import "net/http" - -// A RouteSelector finds the best matching Route given the input HTTP Request -type RouteSelector interface { - - // SelectRoute finds a Route given the input HTTP Request and a list of WebServices. - // It returns a selected Route and its containing WebService or an error indicating - // a problem. - SelectRoute( - webServices []*WebService, - httpRequest *http.Request) (selectedService *WebService, selected *Route, err error) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/service_error.go b/discovery/vendor/github.com/emicklei/go-restful/service_error.go deleted file mode 100644 index 62d1108b..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/service_error.go +++ /dev/null @@ -1,23 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import "fmt" - -// ServiceError is a transport object to pass information about a non-Http error occurred in a WebService while processing a request. -type ServiceError struct { - Code int - Message string -} - -// NewError returns a ServiceError using the code and reason -func NewError(code int, message string) ServiceError { - return ServiceError{Code: code, Message: message} -} - -// Error returns a text representation of the service error -func (s ServiceError) Error() string { - return fmt.Sprintf("[ServiceError:%v] %v", s.Code, s.Message) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/web_service.go b/discovery/vendor/github.com/emicklei/go-restful/web_service.go deleted file mode 100644 index 094c0a02..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/web_service.go +++ /dev/null @@ -1,290 +0,0 @@ -package restful - -import ( - "errors" - "os" - "reflect" - "sync" - - "github.com/emicklei/go-restful/log" -) - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -// WebService holds a collection of Route values that bind a Http Method + URL Path to a function. -type WebService struct { - rootPath string - pathExpr *pathExpression // cached compilation of rootPath as RegExp - routes []Route - produces []string - consumes []string - pathParameters []*Parameter - filters []FilterFunction - documentation string - apiVersion string - - typeNameHandleFunc TypeNameHandleFunction - - dynamicRoutes bool - - // protects 'routes' if dynamic routes are enabled - routesLock sync.RWMutex -} - -func (w *WebService) SetDynamicRoutes(enable bool) { - w.dynamicRoutes = enable -} - -// TypeNameHandleFunction declares functions that can handle translating the name of a sample object -// into the restful documentation for the service. -type TypeNameHandleFunction func(sample interface{}) string - -// TypeNameHandler sets the function that will convert types to strings in the parameter -// and model definitions. If not set, the web service will invoke -// reflect.TypeOf(object).String(). -func (w *WebService) TypeNameHandler(handler TypeNameHandleFunction) *WebService { - w.typeNameHandleFunc = handler - return w -} - -// reflectTypeName is the default TypeNameHandleFunction and for a given object -// returns the name that Go identifies it with (e.g. "string" or "v1.Object") via -// the reflection API. -func reflectTypeName(sample interface{}) string { - return reflect.TypeOf(sample).String() -} - -// compilePathExpression ensures that the path is compiled into a RegEx for those routers that need it. -func (w *WebService) compilePathExpression() { - compiled, err := newPathExpression(w.rootPath) - if err != nil { - log.Printf("[restful] invalid path:%s because:%v", w.rootPath, err) - os.Exit(1) - } - w.pathExpr = compiled -} - -// ApiVersion sets the API version for documentation purposes. -func (w *WebService) ApiVersion(apiVersion string) *WebService { - w.apiVersion = apiVersion - return w -} - -// Version returns the API version for documentation purposes. -func (w *WebService) Version() string { return w.apiVersion } - -// Path specifies the root URL template path of the WebService. -// All Routes will be relative to this path. -func (w *WebService) Path(root string) *WebService { - w.rootPath = root - if len(w.rootPath) == 0 { - w.rootPath = "/" - } - w.compilePathExpression() - return w -} - -// Param adds a PathParameter to document parameters used in the root path. -func (w *WebService) Param(parameter *Parameter) *WebService { - if w.pathParameters == nil { - w.pathParameters = []*Parameter{} - } - w.pathParameters = append(w.pathParameters, parameter) - return w -} - -// PathParameter creates a new Parameter of kind Path for documentation purposes. -// It is initialized as required with string as its DataType. -func (w *WebService) PathParameter(name, description string) *Parameter { - return PathParameter(name, description) -} - -// PathParameter creates a new Parameter of kind Path for documentation purposes. -// It is initialized as required with string as its DataType. -func PathParameter(name, description string) *Parameter { - p := &Parameter{&ParameterData{Name: name, Description: description, Required: true, DataType: "string"}} - p.bePath() - return p -} - -// QueryParameter creates a new Parameter of kind Query for documentation purposes. -// It is initialized as not required with string as its DataType. -func (w *WebService) QueryParameter(name, description string) *Parameter { - return QueryParameter(name, description) -} - -// QueryParameter creates a new Parameter of kind Query for documentation purposes. -// It is initialized as not required with string as its DataType. -func QueryParameter(name, description string) *Parameter { - p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string"}} - p.beQuery() - return p -} - -// BodyParameter creates a new Parameter of kind Body for documentation purposes. -// It is initialized as required without a DataType. -func (w *WebService) BodyParameter(name, description string) *Parameter { - return BodyParameter(name, description) -} - -// BodyParameter creates a new Parameter of kind Body for documentation purposes. -// It is initialized as required without a DataType. -func BodyParameter(name, description string) *Parameter { - p := &Parameter{&ParameterData{Name: name, Description: description, Required: true}} - p.beBody() - return p -} - -// HeaderParameter creates a new Parameter of kind (Http) Header for documentation purposes. -// It is initialized as not required with string as its DataType. -func (w *WebService) HeaderParameter(name, description string) *Parameter { - return HeaderParameter(name, description) -} - -// HeaderParameter creates a new Parameter of kind (Http) Header for documentation purposes. -// It is initialized as not required with string as its DataType. -func HeaderParameter(name, description string) *Parameter { - p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string"}} - p.beHeader() - return p -} - -// FormParameter creates a new Parameter of kind Form (using application/x-www-form-urlencoded) for documentation purposes. -// It is initialized as required with string as its DataType. -func (w *WebService) FormParameter(name, description string) *Parameter { - return FormParameter(name, description) -} - -// FormParameter creates a new Parameter of kind Form (using application/x-www-form-urlencoded) for documentation purposes. -// It is initialized as required with string as its DataType. -func FormParameter(name, description string) *Parameter { - p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string"}} - p.beForm() - return p -} - -// Route creates a new Route using the RouteBuilder and add to the ordered list of Routes. -func (w *WebService) Route(builder *RouteBuilder) *WebService { - w.routesLock.Lock() - defer w.routesLock.Unlock() - builder.copyDefaults(w.produces, w.consumes) - w.routes = append(w.routes, builder.Build()) - return w -} - -// RemoveRoute removes the specified route, looks for something that matches 'path' and 'method' -func (w *WebService) RemoveRoute(path, method string) error { - if !w.dynamicRoutes { - return errors.New("dynamic routes are not enabled.") - } - w.routesLock.Lock() - defer w.routesLock.Unlock() - newRoutes := make([]Route, (len(w.routes) - 1)) - current := 0 - for ix := range w.routes { - if w.routes[ix].Method == method && w.routes[ix].Path == path { - continue - } - newRoutes[current] = w.routes[ix] - current = current + 1 - } - w.routes = newRoutes - return nil -} - -// Method creates a new RouteBuilder and initialize its http method -func (w *WebService) Method(httpMethod string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method(httpMethod) -} - -// Produces specifies that this WebService can produce one or more MIME types. -// Http requests must have one of these values set for the Accept header. -func (w *WebService) Produces(contentTypes ...string) *WebService { - w.produces = contentTypes - return w -} - -// Consumes specifies that this WebService can consume one or more MIME types. -// Http requests must have one of these values set for the Content-Type header. -func (w *WebService) Consumes(accepts ...string) *WebService { - w.consumes = accepts - return w -} - -// Routes returns the Routes associated with this WebService -func (w *WebService) Routes() []Route { - if !w.dynamicRoutes { - return w.routes - } - // Make a copy of the array to prevent concurrency problems - w.routesLock.RLock() - defer w.routesLock.RUnlock() - result := make([]Route, len(w.routes)) - for ix := range w.routes { - result[ix] = w.routes[ix] - } - return result -} - -// RootPath returns the RootPath associated with this WebService. Default "/" -func (w *WebService) RootPath() string { - return w.rootPath -} - -// PathParameters return the path parameter names for (shared among its Routes) -func (w *WebService) PathParameters() []*Parameter { - return w.pathParameters -} - -// Filter adds a filter function to the chain of filters applicable to all its Routes -func (w *WebService) Filter(filter FilterFunction) *WebService { - w.filters = append(w.filters, filter) - return w -} - -// Doc is used to set the documentation of this service. -func (w *WebService) Doc(plainText string) *WebService { - w.documentation = plainText - return w -} - -// Documentation returns it. -func (w *WebService) Documentation() string { - return w.documentation -} - -/* - Convenience methods -*/ - -// HEAD is a shortcut for .Method("HEAD").Path(subPath) -func (w *WebService) HEAD(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("HEAD").Path(subPath) -} - -// GET is a shortcut for .Method("GET").Path(subPath) -func (w *WebService) GET(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("GET").Path(subPath) -} - -// POST is a shortcut for .Method("POST").Path(subPath) -func (w *WebService) POST(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("POST").Path(subPath) -} - -// PUT is a shortcut for .Method("PUT").Path(subPath) -func (w *WebService) PUT(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("PUT").Path(subPath) -} - -// PATCH is a shortcut for .Method("PATCH").Path(subPath) -func (w *WebService) PATCH(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("PATCH").Path(subPath) -} - -// DELETE is a shortcut for .Method("DELETE").Path(subPath) -func (w *WebService) DELETE(subPath string) *RouteBuilder { - return new(RouteBuilder).typeNameHandler(w.typeNameHandleFunc).servicePath(w.rootPath).Method("DELETE").Path(subPath) -} diff --git a/discovery/vendor/github.com/emicklei/go-restful/web_service_container.go b/discovery/vendor/github.com/emicklei/go-restful/web_service_container.go deleted file mode 100644 index c9d31b06..00000000 --- a/discovery/vendor/github.com/emicklei/go-restful/web_service_container.go +++ /dev/null @@ -1,39 +0,0 @@ -package restful - -// Copyright 2013 Ernest Micklei. All rights reserved. -// Use of this source code is governed by a license -// that can be found in the LICENSE file. - -import ( - "net/http" -) - -// DefaultContainer is a restful.Container that uses http.DefaultServeMux -var DefaultContainer *Container - -func init() { - DefaultContainer = NewContainer() - DefaultContainer.ServeMux = http.DefaultServeMux -} - -// If set the true then panics will not be caught to return HTTP 500. -// In that case, Route functions are responsible for handling any error situation. -// Default value is false = recover from panics. This has performance implications. -// OBSOLETE ; use restful.DefaultContainer.DoNotRecover(true) -var DoNotRecover = false - -// Add registers a new WebService add it to the DefaultContainer. -func Add(service *WebService) { - DefaultContainer.Add(service) -} - -// Filter appends a container FilterFunction from the DefaultContainer. -// These are called before dispatching a http.Request to a WebService. -func Filter(filter FilterFunction) { - DefaultContainer.Filter(filter) -} - -// RegisteredWebServices returns the collections of WebServices from the DefaultContainer -func RegisteredWebServices() []*WebService { - return DefaultContainer.RegisteredWebServices() -} diff --git a/discovery/vendor/github.com/ghodss/yaml/.travis.yml b/discovery/vendor/github.com/ghodss/yaml/.travis.yml new file mode 100644 index 00000000..0e9d6edc --- /dev/null +++ b/discovery/vendor/github.com/ghodss/yaml/.travis.yml @@ -0,0 +1,7 @@ +language: go +go: + - 1.3 + - 1.4 +script: + - go test + - go build diff --git a/discovery/vendor/github.com/ghodss/yaml/yaml_test.go b/discovery/vendor/github.com/ghodss/yaml/yaml_test.go new file mode 100644 index 00000000..505af453 --- /dev/null +++ b/discovery/vendor/github.com/ghodss/yaml/yaml_test.go @@ -0,0 +1,287 @@ +package yaml + +import ( + "fmt" + "math" + "reflect" + "strconv" + "testing" +) + +type MarshalTest struct { + A string + B int64 + // Would like to test float64, but it's not supported in go-yaml. + // (See https://github.com/go-yaml/yaml/issues/83.) + C float32 +} + +func TestMarshal(t *testing.T) { + f32String := strconv.FormatFloat(math.MaxFloat32, 'g', -1, 32) + s := MarshalTest{"a", math.MaxInt64, math.MaxFloat32} + e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", math.MaxInt64, f32String)) + + y, err := Marshal(s) + if err != nil { + t.Errorf("error marshaling YAML: %v", err) + } + + if !reflect.DeepEqual(y, e) { + t.Errorf("marshal YAML was unsuccessful, expected: %#v, got: %#v", + string(e), string(y)) + } +} + +type UnmarshalString struct { + A string + True string +} + +type UnmarshalStringMap struct { + A map[string]string +} + +type UnmarshalNestedString struct { + A NestedString +} + +type NestedString struct { + A string +} + +type UnmarshalSlice struct { + A []NestedSlice +} + +type NestedSlice struct { + B string + C *string +} + +func TestUnmarshal(t *testing.T) { + y := []byte("a: 1") + s1 := UnmarshalString{} + e1 := UnmarshalString{A: "1"} + unmarshal(t, y, &s1, &e1) + + y = []byte("a: true") + s1 = UnmarshalString{} + e1 = UnmarshalString{A: "true"} + unmarshal(t, y, &s1, &e1) + + y = []byte("true: 1") + s1 = UnmarshalString{} + e1 = UnmarshalString{True: "1"} + unmarshal(t, y, &s1, &e1) + + y = []byte("a:\n a: 1") + s2 := UnmarshalNestedString{} + e2 := UnmarshalNestedString{NestedString{"1"}} + unmarshal(t, y, &s2, &e2) + + y = []byte("a:\n - b: abc\n c: def\n - b: 123\n c: 456\n") + s3 := UnmarshalSlice{} + e3 := UnmarshalSlice{[]NestedSlice{NestedSlice{"abc", strPtr("def")}, NestedSlice{"123", strPtr("456")}}} + unmarshal(t, y, &s3, &e3) + + y = []byte("a:\n b: 1") + s4 := UnmarshalStringMap{} + e4 := UnmarshalStringMap{map[string]string{"b": "1"}} + unmarshal(t, y, &s4, &e4) + + y = []byte(` +a: + name: TestA +b: + name: TestB +`) + type NamedThing struct { + Name string `json:"name"` + } + s5 := map[string]*NamedThing{} + e5 := map[string]*NamedThing{ + "a": &NamedThing{Name: "TestA"}, + "b": &NamedThing{Name: "TestB"}, + } + unmarshal(t, y, &s5, &e5) +} + +func unmarshal(t *testing.T, y []byte, s, e interface{}) { + err := Unmarshal(y, s) + if err != nil { + t.Errorf("error unmarshaling YAML: %v", err) + } + + if !reflect.DeepEqual(s, e) { + t.Errorf("unmarshal YAML was unsuccessful, expected: %+#v, got: %+#v", + e, s) + } +} + +type Case struct { + input string + output string + // By default we test that reversing the output == input. But if there is a + // difference in the reversed output, you can optionally specify it here. + reverse *string +} + +type RunType int + +const ( + RunTypeJSONToYAML RunType = iota + RunTypeYAMLToJSON +) + +func TestJSONToYAML(t *testing.T) { + cases := []Case{ + { + `{"t":"a"}`, + "t: a\n", + nil, + }, { + `{"t":null}`, + "t: null\n", + nil, + }, + } + + runCases(t, RunTypeJSONToYAML, cases) +} + +func TestYAMLToJSON(t *testing.T) { + cases := []Case{ + { + "t: a\n", + `{"t":"a"}`, + nil, + }, { + "t: \n", + `{"t":null}`, + strPtr("t: null\n"), + }, { + "t: null\n", + `{"t":null}`, + nil, + }, { + "1: a\n", + `{"1":"a"}`, + strPtr("\"1\": a\n"), + }, { + "1000000000000000000000000000000000000: a\n", + `{"1e+36":"a"}`, + strPtr("\"1e+36\": a\n"), + }, { + "1e+36: a\n", + `{"1e+36":"a"}`, + strPtr("\"1e+36\": a\n"), + }, { + "\"1e+36\": a\n", + `{"1e+36":"a"}`, + nil, + }, { + "\"1.2\": a\n", + `{"1.2":"a"}`, + nil, + }, { + "- t: a\n", + `[{"t":"a"}]`, + nil, + }, { + "- t: a\n" + + "- t:\n" + + " b: 1\n" + + " c: 2\n", + `[{"t":"a"},{"t":{"b":1,"c":2}}]`, + nil, + }, { + `[{t: a}, {t: {b: 1, c: 2}}]`, + `[{"t":"a"},{"t":{"b":1,"c":2}}]`, + strPtr("- t: a\n" + + "- t:\n" + + " b: 1\n" + + " c: 2\n"), + }, { + "- t: \n", + `[{"t":null}]`, + strPtr("- t: null\n"), + }, { + "- t: null\n", + `[{"t":null}]`, + nil, + }, + } + + // Cases that should produce errors. + _ = []Case{ + { + "~: a", + `{"null":"a"}`, + nil, + }, { + "a: !!binary gIGC\n", + "{\"a\":\"\x80\x81\x82\"}", + nil, + }, + } + + runCases(t, RunTypeYAMLToJSON, cases) +} + +func runCases(t *testing.T, runType RunType, cases []Case) { + var f func([]byte) ([]byte, error) + var invF func([]byte) ([]byte, error) + var msg string + var invMsg string + if runType == RunTypeJSONToYAML { + f = JSONToYAML + invF = YAMLToJSON + msg = "JSON to YAML" + invMsg = "YAML back to JSON" + } else { + f = YAMLToJSON + invF = JSONToYAML + msg = "YAML to JSON" + invMsg = "JSON back to YAML" + } + + for _, c := range cases { + // Convert the string. + t.Logf("converting %s\n", c.input) + output, err := f([]byte(c.input)) + if err != nil { + t.Errorf("Failed to convert %s, input: `%s`, err: %v", msg, c.input, err) + } + + // Check it against the expected output. + if string(output) != c.output { + t.Errorf("Failed to convert %s, input: `%s`, expected `%s`, got `%s`", + msg, c.input, c.output, string(output)) + } + + // Set the string that we will compare the reversed output to. + reverse := c.input + // If a special reverse string was specified, use that instead. + if c.reverse != nil { + reverse = *c.reverse + } + + // Reverse the output. + input, err := invF(output) + if err != nil { + t.Errorf("Failed to convert %s, input: `%s`, err: %v", invMsg, string(output), err) + } + + // Check the reverse is equal to the input (or to *c.reverse). + if string(input) != reverse { + t.Errorf("Failed to convert %s, input: `%s`, expected `%s`, got `%s`", + invMsg, string(output), reverse, string(input)) + } + } + +} + +// To be able to easily fill in the *Case.reverse string above. +func strPtr(s string) *string { + return &s +} diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/.editorconfig b/discovery/vendor/github.com/go-openapi/jsonpointer/.editorconfig deleted file mode 100644 index 3152da69..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/.editorconfig +++ /dev/null @@ -1,26 +0,0 @@ -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -end_of_line = lf -insert_final_newline = true -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true - -# Set default charset -[*.{js,py,go,scala,rb,java,html,css,less,sass,md}] -charset = utf-8 - -# Tab indentation (no size specified) -[*.go] -indent_style = tab - -[*.md] -trim_trailing_whitespace = false - -# Matches the exact files either package.json or .travis.yml -[{package.json,.travis.yml}] -indent_style = space -indent_size = 2 diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/.github/CONTRIBUTING.md b/discovery/vendor/github.com/go-openapi/jsonpointer/.github/CONTRIBUTING.md deleted file mode 100644 index 7dea4240..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/.github/CONTRIBUTING.md +++ /dev/null @@ -1,117 +0,0 @@ -## Contribution Guidelines - -### Pull requests are always welcome - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep go-swagger lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* go-swagger. - - -### Conventions - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Update the documentation when creating or modifying features. Test -your documentation changes for clarity, concision, and correctness, as -well as a clean documentation build. See ``docs/README.md`` for more -information on building the docs and how docs get released. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run `gofmt -s -w file.go` on each changed file before -committing your changes. Most editors have plugins that do this automatically. - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Pull requests must not contain commits from other users or branches. - -Commit messages must start with a capitalized and short summary (max. 50 -chars) written in the imperative, followed by an optional, more detailed -explanatory text which is separated from the summary by an empty line. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using `git rebase -i` and `git push -f`. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like `Closes #XXX` -or `Fixes #XXX`, which will automatically close the issue when merged. - -### Sign your work - -The sign-off is a simple line at the end of the explanation for the -patch, which certifies that you wrote it or otherwise have the right to -pass it on as an open-source patch. The rules are pretty simple: if you -can certify the below (from -[developercertificate.org](http://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -660 York Street, Suite 102, -San Francisco, CA 94110 USA - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -then you just add a line to every git commit message: - - Signed-off-by: Joe Smith - -using your real name (sorry, no pseudonyms or anonymous contributions.) - -You can add the sign off when creating the git commit via `git commit -s`. diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/.gitignore b/discovery/vendor/github.com/go-openapi/jsonpointer/.gitignore deleted file mode 100644 index 769c2440..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/.gitignore +++ /dev/null @@ -1 +0,0 @@ -secrets.yml diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md b/discovery/vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md deleted file mode 100644 index 9322b065..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at ivan+abuse@flanders.co.nz. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/LICENSE b/discovery/vendor/github.com/go-openapi/jsonpointer/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/README.md b/discovery/vendor/github.com/go-openapi/jsonpointer/README.md deleted file mode 100644 index 813788af..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# gojsonpointer [![Build Status](https://travis-ci.org/go-openapi/jsonpointer.svg?branch=master)](https://travis-ci.org/go-openapi/jsonpointer) [![codecov](https://codecov.io/gh/go-openapi/jsonpointer/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/jsonpointer) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) - -[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/jsonpointer/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/jsonpointer?status.svg)](http://godoc.org/github.com/go-openapi/jsonpointer) -An implementation of JSON Pointer - Go language - -## Status -Completed YES - -Tested YES - -## References -http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07 - -### Note -The 4.Evaluation part of the previous reference, starting with 'If the currently referenced value is a JSON array, the reference token MUST contain either...' is not implemented. diff --git a/discovery/vendor/github.com/go-openapi/jsonpointer/pointer.go b/discovery/vendor/github.com/go-openapi/jsonpointer/pointer.go deleted file mode 100644 index fe2d6ee5..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonpointer/pointer.go +++ /dev/null @@ -1,390 +0,0 @@ -// Copyright 2013 sigu-399 ( https://github.com/sigu-399 ) -// -// 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. - -// author sigu-399 -// author-github https://github.com/sigu-399 -// author-mail sigu.399@gmail.com -// -// repository-name jsonpointer -// repository-desc An implementation of JSON Pointer - Go language -// -// description Main and unique file. -// -// created 25-02-2013 - -package jsonpointer - -import ( - "errors" - "fmt" - "reflect" - "strconv" - "strings" - - "github.com/go-openapi/swag" -) - -const ( - emptyPointer = `` - pointerSeparator = `/` - - invalidStart = `JSON pointer must be empty or start with a "` + pointerSeparator -) - -var jsonPointableType = reflect.TypeOf(new(JSONPointable)).Elem() -var jsonSetableType = reflect.TypeOf(new(JSONSetable)).Elem() - -// JSONPointable is an interface for structs to implement when they need to customize the -// json pointer process -type JSONPointable interface { - JSONLookup(string) (interface{}, error) -} - -// JSONSetable is an interface for structs to implement when they need to customize the -// json pointer process -type JSONSetable interface { - JSONSet(string, interface{}) error -} - -// New creates a new json pointer for the given string -func New(jsonPointerString string) (Pointer, error) { - - var p Pointer - err := p.parse(jsonPointerString) - return p, err - -} - -// Pointer the json pointer reprsentation -type Pointer struct { - referenceTokens []string -} - -// "Constructor", parses the given string JSON pointer -func (p *Pointer) parse(jsonPointerString string) error { - - var err error - - if jsonPointerString != emptyPointer { - if !strings.HasPrefix(jsonPointerString, pointerSeparator) { - err = errors.New(invalidStart) - } else { - referenceTokens := strings.Split(jsonPointerString, pointerSeparator) - for _, referenceToken := range referenceTokens[1:] { - p.referenceTokens = append(p.referenceTokens, referenceToken) - } - } - } - - return err -} - -// Get uses the pointer to retrieve a value from a JSON document -func (p *Pointer) Get(document interface{}) (interface{}, reflect.Kind, error) { - return p.get(document, swag.DefaultJSONNameProvider) -} - -// Set uses the pointer to set a value from a JSON document -func (p *Pointer) Set(document interface{}, value interface{}) (interface{}, error) { - return document, p.set(document, value, swag.DefaultJSONNameProvider) -} - -// GetForToken gets a value for a json pointer token 1 level deep -func GetForToken(document interface{}, decodedToken string) (interface{}, reflect.Kind, error) { - return getSingleImpl(document, decodedToken, swag.DefaultJSONNameProvider) -} - -// SetForToken gets a value for a json pointer token 1 level deep -func SetForToken(document interface{}, decodedToken string, value interface{}) (interface{}, error) { - return document, setSingleImpl(document, value, decodedToken, swag.DefaultJSONNameProvider) -} - -func getSingleImpl(node interface{}, decodedToken string, nameProvider *swag.NameProvider) (interface{}, reflect.Kind, error) { - rValue := reflect.Indirect(reflect.ValueOf(node)) - kind := rValue.Kind() - - switch kind { - - case reflect.Struct: - if rValue.Type().Implements(jsonPointableType) { - r, err := node.(JSONPointable).JSONLookup(decodedToken) - if err != nil { - return nil, kind, err - } - return r, kind, nil - } - nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken) - if !ok { - return nil, kind, fmt.Errorf("object has no field %q", decodedToken) - } - fld := rValue.FieldByName(nm) - return fld.Interface(), kind, nil - - case reflect.Map: - kv := reflect.ValueOf(decodedToken) - mv := rValue.MapIndex(kv) - - if mv.IsValid() && !swag.IsZero(mv) { - return mv.Interface(), kind, nil - } - return nil, kind, fmt.Errorf("object has no key %q", decodedToken) - - case reflect.Slice: - tokenIndex, err := strconv.Atoi(decodedToken) - if err != nil { - return nil, kind, err - } - sLength := rValue.Len() - if tokenIndex < 0 || tokenIndex >= sLength { - return nil, kind, fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength-1, tokenIndex) - } - - elem := rValue.Index(tokenIndex) - return elem.Interface(), kind, nil - - default: - return nil, kind, fmt.Errorf("invalid token reference %q", decodedToken) - } - -} - -func setSingleImpl(node, data interface{}, decodedToken string, nameProvider *swag.NameProvider) error { - rValue := reflect.Indirect(reflect.ValueOf(node)) - switch rValue.Kind() { - - case reflect.Struct: - if ns, ok := node.(JSONSetable); ok { // pointer impl - return ns.JSONSet(decodedToken, data) - } - - if rValue.Type().Implements(jsonSetableType) { - return node.(JSONSetable).JSONSet(decodedToken, data) - } - - nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken) - if !ok { - return fmt.Errorf("object has no field %q", decodedToken) - } - fld := rValue.FieldByName(nm) - if fld.IsValid() { - fld.Set(reflect.ValueOf(data)) - } - return nil - - case reflect.Map: - kv := reflect.ValueOf(decodedToken) - rValue.SetMapIndex(kv, reflect.ValueOf(data)) - return nil - - case reflect.Slice: - tokenIndex, err := strconv.Atoi(decodedToken) - if err != nil { - return err - } - sLength := rValue.Len() - if tokenIndex < 0 || tokenIndex >= sLength { - return fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength, tokenIndex) - } - - elem := rValue.Index(tokenIndex) - if !elem.CanSet() { - return fmt.Errorf("can't set slice index %s to %v", decodedToken, data) - } - elem.Set(reflect.ValueOf(data)) - return nil - - default: - return fmt.Errorf("invalid token reference %q", decodedToken) - } - -} - -func (p *Pointer) get(node interface{}, nameProvider *swag.NameProvider) (interface{}, reflect.Kind, error) { - - if nameProvider == nil { - nameProvider = swag.DefaultJSONNameProvider - } - - kind := reflect.Invalid - - // Full document when empty - if len(p.referenceTokens) == 0 { - return node, kind, nil - } - - for _, token := range p.referenceTokens { - - decodedToken := Unescape(token) - - r, knd, err := getSingleImpl(node, decodedToken, nameProvider) - if err != nil { - return nil, knd, err - } - node, kind = r, knd - - } - - rValue := reflect.ValueOf(node) - kind = rValue.Kind() - - return node, kind, nil -} - -func (p *Pointer) set(node, data interface{}, nameProvider *swag.NameProvider) error { - knd := reflect.ValueOf(node).Kind() - - if knd != reflect.Ptr && knd != reflect.Struct && knd != reflect.Map && knd != reflect.Slice && knd != reflect.Array { - return fmt.Errorf("only structs, pointers, maps and slices are supported for setting values") - } - - if nameProvider == nil { - nameProvider = swag.DefaultJSONNameProvider - } - - // Full document when empty - if len(p.referenceTokens) == 0 { - return nil - } - - lastI := len(p.referenceTokens) - 1 - for i, token := range p.referenceTokens { - isLastToken := i == lastI - decodedToken := Unescape(token) - - if isLastToken { - - return setSingleImpl(node, data, decodedToken, nameProvider) - } - - rValue := reflect.Indirect(reflect.ValueOf(node)) - kind := rValue.Kind() - - switch kind { - - case reflect.Struct: - if rValue.Type().Implements(jsonPointableType) { - r, err := node.(JSONPointable).JSONLookup(decodedToken) - if err != nil { - return err - } - fld := reflect.ValueOf(r) - if fld.CanAddr() && fld.Kind() != reflect.Interface && fld.Kind() != reflect.Map && fld.Kind() != reflect.Slice && fld.Kind() != reflect.Ptr { - node = fld.Addr().Interface() - continue - } - node = r - continue - } - nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken) - if !ok { - return fmt.Errorf("object has no field %q", decodedToken) - } - fld := rValue.FieldByName(nm) - if fld.CanAddr() && fld.Kind() != reflect.Interface && fld.Kind() != reflect.Map && fld.Kind() != reflect.Slice && fld.Kind() != reflect.Ptr { - node = fld.Addr().Interface() - continue - } - node = fld.Interface() - - case reflect.Map: - kv := reflect.ValueOf(decodedToken) - mv := rValue.MapIndex(kv) - - if !mv.IsValid() { - return fmt.Errorf("object has no key %q", decodedToken) - } - if mv.CanAddr() && mv.Kind() != reflect.Interface && mv.Kind() != reflect.Map && mv.Kind() != reflect.Slice && mv.Kind() != reflect.Ptr { - node = mv.Addr().Interface() - continue - } - node = mv.Interface() - - case reflect.Slice: - tokenIndex, err := strconv.Atoi(decodedToken) - if err != nil { - return err - } - sLength := rValue.Len() - if tokenIndex < 0 || tokenIndex >= sLength { - return fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength, tokenIndex) - } - - elem := rValue.Index(tokenIndex) - if elem.CanAddr() && elem.Kind() != reflect.Interface && elem.Kind() != reflect.Map && elem.Kind() != reflect.Slice && elem.Kind() != reflect.Ptr { - node = elem.Addr().Interface() - continue - } - node = elem.Interface() - - default: - return fmt.Errorf("invalid token reference %q", decodedToken) - } - - } - - return nil -} - -// DecodedTokens returns the decoded tokens -func (p *Pointer) DecodedTokens() []string { - result := make([]string, 0, len(p.referenceTokens)) - for _, t := range p.referenceTokens { - result = append(result, Unescape(t)) - } - return result -} - -// IsEmpty returns true if this is an empty json pointer -// this indicates that it points to the root document -func (p *Pointer) IsEmpty() bool { - return len(p.referenceTokens) == 0 -} - -// Pointer to string representation function -func (p *Pointer) String() string { - - if len(p.referenceTokens) == 0 { - return emptyPointer - } - - pointerString := pointerSeparator + strings.Join(p.referenceTokens, pointerSeparator) - - return pointerString -} - -// Specific JSON pointer encoding here -// ~0 => ~ -// ~1 => / -// ... and vice versa - -const ( - encRefTok0 = `~0` - encRefTok1 = `~1` - decRefTok0 = `~` - decRefTok1 = `/` -) - -// Unescape unescapes a json pointer reference token string to the original representation -func Unescape(token string) string { - step1 := strings.Replace(token, encRefTok1, decRefTok1, -1) - step2 := strings.Replace(step1, encRefTok0, decRefTok0, -1) - return step2 -} - -// Escape escapes a pointer reference token string -func Escape(token string) string { - step1 := strings.Replace(token, decRefTok0, encRefTok0, -1) - step2 := strings.Replace(step1, decRefTok1, encRefTok1, -1) - return step2 -} diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/.github/CONTRIBUTING.md b/discovery/vendor/github.com/go-openapi/jsonreference/.github/CONTRIBUTING.md deleted file mode 100644 index 7dea4240..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/.github/CONTRIBUTING.md +++ /dev/null @@ -1,117 +0,0 @@ -## Contribution Guidelines - -### Pull requests are always welcome - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep go-swagger lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* go-swagger. - - -### Conventions - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Update the documentation when creating or modifying features. Test -your documentation changes for clarity, concision, and correctness, as -well as a clean documentation build. See ``docs/README.md`` for more -information on building the docs and how docs get released. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run `gofmt -s -w file.go` on each changed file before -committing your changes. Most editors have plugins that do this automatically. - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Pull requests must not contain commits from other users or branches. - -Commit messages must start with a capitalized and short summary (max. 50 -chars) written in the imperative, followed by an optional, more detailed -explanatory text which is separated from the summary by an empty line. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using `git rebase -i` and `git push -f`. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like `Closes #XXX` -or `Fixes #XXX`, which will automatically close the issue when merged. - -### Sign your work - -The sign-off is a simple line at the end of the explanation for the -patch, which certifies that you wrote it or otherwise have the right to -pass it on as an open-source patch. The rules are pretty simple: if you -can certify the below (from -[developercertificate.org](http://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -660 York Street, Suite 102, -San Francisco, CA 94110 USA - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -then you just add a line to every git commit message: - - Signed-off-by: Joe Smith - -using your real name (sorry, no pseudonyms or anonymous contributions.) - -You can add the sign off when creating the git commit via `git commit -s`. diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/.gitignore b/discovery/vendor/github.com/go-openapi/jsonreference/.gitignore deleted file mode 100644 index 769c2440..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/.gitignore +++ /dev/null @@ -1 +0,0 @@ -secrets.yml diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md b/discovery/vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md deleted file mode 100644 index 9322b065..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at ivan+abuse@flanders.co.nz. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/LICENSE b/discovery/vendor/github.com/go-openapi/jsonreference/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/README.md b/discovery/vendor/github.com/go-openapi/jsonreference/README.md deleted file mode 100644 index 66345f4c..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# gojsonreference [![Build Status](https://travis-ci.org/go-openapi/jsonreference.svg?branch=master)](https://travis-ci.org/go-openapi/jsonreference) [![codecov](https://codecov.io/gh/go-openapi/jsonreference/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/jsonreference) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) - -[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/jsonreference/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/jsonreference?status.svg)](http://godoc.org/github.com/go-openapi/jsonreference) -An implementation of JSON Reference - Go language - -## Status -Work in progress ( 90% done ) - -## Dependencies -https://github.com/go-openapi/jsonpointer - -## References -http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07 - -http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 diff --git a/discovery/vendor/github.com/go-openapi/jsonreference/reference.go b/discovery/vendor/github.com/go-openapi/jsonreference/reference.go deleted file mode 100644 index 3bc0a6e2..00000000 --- a/discovery/vendor/github.com/go-openapi/jsonreference/reference.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2013 sigu-399 ( https://github.com/sigu-399 ) -// -// 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. - -// author sigu-399 -// author-github https://github.com/sigu-399 -// author-mail sigu.399@gmail.com -// -// repository-name jsonreference -// repository-desc An implementation of JSON Reference - Go language -// -// description Main and unique file. -// -// created 26-02-2013 - -package jsonreference - -import ( - "errors" - "net/url" - "strings" - - "github.com/PuerkitoBio/purell" - "github.com/go-openapi/jsonpointer" -) - -const ( - fragmentRune = `#` -) - -// New creates a new reference for the given string -func New(jsonReferenceString string) (Ref, error) { - - var r Ref - err := r.parse(jsonReferenceString) - return r, err - -} - -// MustCreateRef parses the ref string and panics when it's invalid. -// Use the New method for a version that returns an error -func MustCreateRef(ref string) Ref { - r, err := New(ref) - if err != nil { - panic(err) - } - return r -} - -// Ref represents a json reference object -type Ref struct { - referenceURL *url.URL - referencePointer jsonpointer.Pointer - - HasFullURL bool - HasURLPathOnly bool - HasFragmentOnly bool - HasFileScheme bool - HasFullFilePath bool -} - -// GetURL gets the URL for this reference -func (r *Ref) GetURL() *url.URL { - return r.referenceURL -} - -// GetPointer gets the json pointer for this reference -func (r *Ref) GetPointer() *jsonpointer.Pointer { - return &r.referencePointer -} - -// String returns the best version of the url for this reference -func (r *Ref) String() string { - - if r.referenceURL != nil { - return r.referenceURL.String() - } - - if r.HasFragmentOnly { - return fragmentRune + r.referencePointer.String() - } - - return r.referencePointer.String() -} - -// IsRoot returns true if this reference is a root document -func (r *Ref) IsRoot() bool { - return r.referenceURL != nil && - !r.IsCanonical() && - !r.HasURLPathOnly && - r.referenceURL.Fragment == "" -} - -// IsCanonical returns true when this pointer starts with http(s):// or file:// -func (r *Ref) IsCanonical() bool { - return (r.HasFileScheme && r.HasFullFilePath) || (!r.HasFileScheme && r.HasFullURL) -} - -// "Constructor", parses the given string JSON reference -func (r *Ref) parse(jsonReferenceString string) error { - - parsed, err := url.Parse(jsonReferenceString) - if err != nil { - return err - } - - r.referenceURL, _ = url.Parse(purell.NormalizeURL(parsed, purell.FlagsSafe|purell.FlagRemoveDuplicateSlashes)) - refURL := r.referenceURL - - if refURL.Scheme != "" && refURL.Host != "" { - r.HasFullURL = true - } else { - if refURL.Path != "" { - r.HasURLPathOnly = true - } else if refURL.RawQuery == "" && refURL.Fragment != "" { - r.HasFragmentOnly = true - } - } - - r.HasFileScheme = refURL.Scheme == "file" - r.HasFullFilePath = strings.HasPrefix(refURL.Path, "/") - - // invalid json-pointer error means url has no json-pointer fragment. simply ignore error - r.referencePointer, _ = jsonpointer.New(refURL.Fragment) - - return nil -} - -// Inherits creates a new reference from a parent and a child -// If the child cannot inherit from the parent, an error is returned -func (r *Ref) Inherits(child Ref) (*Ref, error) { - childURL := child.GetURL() - parentURL := r.GetURL() - if childURL == nil { - return nil, errors.New("child url is nil") - } - if parentURL == nil { - return &child, nil - } - - ref, err := New(parentURL.ResolveReference(childURL).String()) - if err != nil { - return nil, err - } - return &ref, nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/.editorconfig b/discovery/vendor/github.com/go-openapi/spec/.editorconfig deleted file mode 100644 index 3152da69..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/.editorconfig +++ /dev/null @@ -1,26 +0,0 @@ -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -end_of_line = lf -insert_final_newline = true -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true - -# Set default charset -[*.{js,py,go,scala,rb,java,html,css,less,sass,md}] -charset = utf-8 - -# Tab indentation (no size specified) -[*.go] -indent_style = tab - -[*.md] -trim_trailing_whitespace = false - -# Matches the exact files either package.json or .travis.yml -[{package.json,.travis.yml}] -indent_style = space -indent_size = 2 diff --git a/discovery/vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md b/discovery/vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md deleted file mode 100644 index 7dea4240..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md +++ /dev/null @@ -1,117 +0,0 @@ -## Contribution Guidelines - -### Pull requests are always welcome - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep go-swagger lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* go-swagger. - - -### Conventions - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Update the documentation when creating or modifying features. Test -your documentation changes for clarity, concision, and correctness, as -well as a clean documentation build. See ``docs/README.md`` for more -information on building the docs and how docs get released. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run `gofmt -s -w file.go` on each changed file before -committing your changes. Most editors have plugins that do this automatically. - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Pull requests must not contain commits from other users or branches. - -Commit messages must start with a capitalized and short summary (max. 50 -chars) written in the imperative, followed by an optional, more detailed -explanatory text which is separated from the summary by an empty line. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using `git rebase -i` and `git push -f`. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like `Closes #XXX` -or `Fixes #XXX`, which will automatically close the issue when merged. - -### Sign your work - -The sign-off is a simple line at the end of the explanation for the -patch, which certifies that you wrote it or otherwise have the right to -pass it on as an open-source patch. The rules are pretty simple: if you -can certify the below (from -[developercertificate.org](http://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -660 York Street, Suite 102, -San Francisco, CA 94110 USA - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -then you just add a line to every git commit message: - - Signed-off-by: Joe Smith - -using your real name (sorry, no pseudonyms or anonymous contributions.) - -You can add the sign off when creating the git commit via `git commit -s`. diff --git a/discovery/vendor/github.com/go-openapi/spec/.gitignore b/discovery/vendor/github.com/go-openapi/spec/.gitignore deleted file mode 100644 index dd91ed6a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -secrets.yml -coverage.out diff --git a/discovery/vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md b/discovery/vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md deleted file mode 100644 index 9322b065..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at ivan+abuse@flanders.co.nz. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/discovery/vendor/github.com/go-openapi/spec/LICENSE b/discovery/vendor/github.com/go-openapi/spec/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/discovery/vendor/github.com/go-openapi/spec/README.md b/discovery/vendor/github.com/go-openapi/spec/README.md deleted file mode 100644 index 1d162208..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# OAI object model [![Build Status](https://travis-ci.org/go-openapi/spec.svg?branch=master)](https://travis-ci.org/go-openapi/spec) [![codecov](https://codecov.io/gh/go-openapi/spec/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/spec) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) - -[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/spec/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/spec?status.svg)](http://godoc.org/github.com/go-openapi/spec) - -The object model for OpenAPI specification documents diff --git a/discovery/vendor/github.com/go-openapi/spec/bindata.go b/discovery/vendor/github.com/go-openapi/spec/bindata.go deleted file mode 100644 index 9afb5df1..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/bindata.go +++ /dev/null @@ -1,260 +0,0 @@ -// Code generated by go-bindata. -// sources: -// schemas/jsonschema-draft-04.json -// schemas/v2/schema.json -// DO NOT EDIT! - -package spec - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) - -func bindataRead(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - clErr := gz.Close() - - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - if clErr != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -func (fi bindataFileInfo) Name() string { - return fi.name -} -func (fi bindataFileInfo) Size() int64 { - return fi.size -} -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} -func (fi bindataFileInfo) IsDir() bool { - return false -} -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var _jsonschemaDraft04JSON = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xc4\x57\x3b\x6f\xdb\x3e\x10\xdf\xf3\x29\x08\x26\x63\xf2\x97\xff\x40\x27\x6f\x45\xbb\x18\x68\xd1\x0c\xdd\x0c\x0f\xb4\x75\xb2\x19\x50\xa4\x42\x51\x81\x0d\x43\xdf\xbd\xa0\xa8\x07\x29\x91\x92\x2d\xbb\x8d\x97\x28\xbc\xd7\xef\x8e\xf7\xe2\xf9\x01\x21\x84\x30\x8d\xf1\x12\xe1\x83\x52\xd9\x32\x8a\xde\x72\xc1\x5f\xf2\xdd\x01\x52\xf2\x9f\x90\xfb\x28\x96\x24\x51\x2f\x8b\x2f\x91\x39\x7b\xc4\xcf\x46\xe8\xc9\xfc\x3f\x43\x32\x86\x7c\x27\x69\xa6\xa8\xe0\x5a\xfa\x9b\x90\x80\x0c\x0b\x4a\x41\x91\x5a\x45\xc7\x9d\x50\x4e\x35\x73\x8e\x97\xc8\x20\xae\x08\x86\xed\xab\x94\xe4\xe4\x10\x2a\xa2\x3a\x65\xa0\x95\x93\x8a\xfc\xec\x12\x53\xca\x57\x0a\x52\xad\xef\xff\x1e\x89\xd6\xe7\x67\x84\x9f\x24\x24\x5a\xc5\x23\x46\x65\xcb\x54\x76\xfc\x38\x13\x39\x55\xf4\x03\x56\x5c\xc1\x1e\x64\x18\x04\xad\x19\x86\x30\x68\x5a\xa4\x78\x89\x16\x97\xe8\xff\x0e\x09\x29\x98\x5a\x0c\xed\x10\xc6\x7e\x69\xa8\x6b\x07\x76\x64\x45\x2e\xea\x63\x45\xe5\xb3\x66\x8e\x8d\x4e\x0d\x01\x95\x68\xe3\x85\x91\xd3\x34\x63\xf0\xfb\x94\x41\x3e\x34\x0d\xbc\x72\x60\xdd\x46\x1a\xe1\xad\x10\x0c\x08\xd7\x9f\xad\xe3\x08\xf3\x82\x31\xf3\x37\xdd\x9a\x13\xb1\x7d\x83\x9d\xd2\x5f\xb9\x92\x94\xef\x71\xc8\x7e\x45\x9d\x73\xcf\xd6\x65\x36\x7c\x8d\xa9\xf2\xf2\x94\x28\x38\x7d\x2f\xa0\xa1\x2a\x59\x40\x07\xf3\xc1\x02\xdb\xda\x68\x1c\x33\xa7\x99\x14\x19\x48\x45\x7b\xd1\x33\x45\x17\xf0\xa6\x46\xd9\x03\x92\x08\x99\x12\x7d\x57\xb8\x90\x14\x7b\x63\xd5\x15\xe5\xbd\x35\x2b\xaa\x18\x4c\xea\xf5\x8a\xba\xf5\x3e\x4b\x41\x93\xa5\x67\xfb\x38\x2d\x98\xa2\x19\x83\x2a\xf7\x03\x6a\x9b\x74\x0b\x56\x5e\x8f\x02\xc7\x1d\x2b\x72\xfa\x01\x3f\x5b\x16\xf7\xc6\x6d\xfb\xe4\x58\xb3\x8c\x1b\xf7\x0a\x77\x86\xa6\xb4\xb4\xf5\xe4\x92\xbb\xa0\x24\x84\xe5\x01\x84\xad\x13\x37\x21\x9c\xd2\x72\x0b\x42\x72\xfc\x01\x7c\xaf\x0e\xbd\x9e\x3b\xd5\xbc\x1c\x1f\xaf\xd6\xd0\xb6\x52\xb7\xdf\x12\xa5\x40\x4e\xe7\x68\xb0\x78\x24\xec\xe1\xe8\x0f\x26\x89\xe3\x0a\x0a\x61\x4d\x23\xe9\xf7\x70\x7e\x32\x3d\xdc\x39\xd6\xbf\xf3\x30\xd0\xfd\xf6\x55\xb3\x79\x27\x96\xfe\x6d\x82\x37\x73\xf6\x8f\x36\x3a\x03\xa4\x6d\x7d\x1c\x9e\x73\x35\xf6\x18\xbf\x15\x76\x4a\x8e\x2b\xcf\x00\xbf\x2a\x99\xae\x55\xe0\xcf\x25\x77\x68\xfc\x95\xba\x79\x75\x06\xcb\x5c\x77\x67\x69\xf1\xfb\x2c\xe1\xbd\xa0\x12\xe2\x31\x45\xf6\x30\x0f\x14\xc8\xab\x7f\x60\x4e\x27\xe0\x3f\xaf\x92\xd0\x6a\x8a\x82\xdb\xc0\xa4\xbb\x63\x65\x34\x0d\x28\xb0\x6b\x7c\x1e\x1e\xd3\x51\xc7\x6e\xf4\x33\x60\xc5\x90\x01\x8f\x81\xef\xee\x88\x68\x90\x69\x23\xb9\x8a\x2e\x69\x98\x7d\xa6\x91\x32\x1a\xc8\x6e\x9c\x13\x7f\x10\xea\xcd\xfd\x4e\xef\xa6\xb1\x25\xd9\xde\x22\x8d\xfa\x59\x63\xc5\x0d\x80\xf5\x28\xf1\xd6\xb9\x37\x9e\xa3\xee\xb5\x4c\xbe\x37\xe0\x55\xc6\x27\x82\x75\x49\xd0\xda\xe0\xb9\x1d\xca\xbf\x5b\xd4\xcf\xbf\x0b\x47\xac\x2d\x59\x07\xfe\x7a\x49\xc1\x61\xa6\x24\x17\x2a\xf0\xbe\x2e\xdb\x17\x7f\xa0\x3c\x7d\x4b\xf3\xba\xdb\xc3\xed\x06\xee\xdb\x5e\xd7\xdd\x42\x5c\x47\xb2\xb3\x68\x75\x8c\xf2\xe1\x4f\x00\x00\x00\xff\xff\x4e\x9b\x8d\xdf\x17\x11\x00\x00") - -func jsonschemaDraft04JSONBytes() ([]byte, error) { - return bindataRead( - _jsonschemaDraft04JSON, - "jsonschema-draft-04.json", - ) -} - -func jsonschemaDraft04JSON() (*asset, error) { - bytes, err := jsonschemaDraft04JSONBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "jsonschema-draft-04.json", size: 4375, mode: os.FileMode(420), modTime: time.Unix(1482389892, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _v2SchemaJSON = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xec\x5d\x4f\x93\xdb\x36\xb2\xbf\xfb\x53\xa0\x14\x57\xd9\xae\xd8\x92\xe3\xf7\x2e\xcf\x97\xd4\xbc\xd8\x49\x66\x37\x5e\x4f\x79\x26\xbb\x87\x78\x5c\x05\x91\x2d\x09\x09\x09\x30\x00\x38\x33\x5a\xef\x7c\xf7\x2d\xf0\x9f\x08\x02\x20\x41\x8a\xd2\xc8\x0e\x0f\xa9\x78\x28\xa0\xd1\xdd\x68\x34\x7e\xdd\xf8\xf7\xf9\x11\x42\x33\x49\x64\x04\xb3\xd7\x68\x76\x86\xfe\x76\xf9\xfe\x1f\xe8\x32\xd8\x40\x8c\xd1\x8a\x71\x74\x79\x8b\xd7\x6b\xe0\xe8\xd5\xfc\x25\x3a\xbb\x38\x9f\xcf\x9e\xab\x0a\x24\x54\xa5\x37\x52\x26\xaf\x17\x0b\x91\x17\x99\x13\xb6\xb8\x79\xb5\x10\x59\xdd\xf9\xef\x82\xd1\x6f\xf2\xc2\x8f\xf3\x4f\xb5\x1a\xea\xc7\x17\x45\x41\xc6\xd7\x8b\x90\xe3\x95\x7c\xf1\xf2\x7f\x8b\xca\x45\x3d\xb9\x4d\x32\xa6\xd8\xf2\x77\x08\x64\xfe\x8d\xc3\x9f\x29\xe1\xa0\x9a\xff\xed\x11\x42\x08\xcd\x8a\xd6\xb3\x9f\x15\x67\x74\xc5\xca\x7f\x27\x58\x6e\xc4\xec\x11\x42\xd7\x59\x5d\x1c\x86\x44\x12\x46\x71\x74\xc1\x59\x02\x5c\x12\x10\xb3\xd7\x68\x85\x23\x01\x59\x81\x04\x4b\x09\x9c\x6a\xbf\x7e\xce\x49\x7d\xba\x7b\x51\xfd\xa1\x44\xe2\xb0\x52\xac\x7d\xb3\x08\x61\x45\x68\x46\x56\x2c\x6e\x80\x86\x8c\xbf\xbd\x93\x40\x05\x61\x74\x96\x95\xbe\x7f\x84\xd0\x7d\x4e\xde\x42\xb7\xe4\xbe\x46\xbb\x14\x5b\x48\x4e\xe8\xba\x90\x05\xa1\x19\xd0\x34\xae\xc4\xce\xbe\xbc\x9a\xbf\x9c\x15\x7f\x5d\x57\xc5\x42\x10\x01\x27\x89\xe2\x48\x51\xb9\xda\x40\xd5\x87\x37\xc0\x15\x5f\x88\xad\x90\xdc\x10\x81\x42\x16\xa4\x31\x50\x39\x2f\x38\xad\xab\xb0\x53\xd8\xac\x94\x56\x6f\xc3\x84\xf4\x11\xa4\x50\xb3\xfa\xe9\xd3\x6f\x9f\x3e\xdf\x2f\xd0\xeb\x8f\x1f\x3f\x7e\xbc\xfe\xf6\xe9\xf7\xaf\x5f\x7f\xfc\x18\x7e\xfb\xec\xfb\xc7\xb3\x36\x79\x54\x43\xe8\x29\xc5\x31\x20\xc6\x11\x49\x9e\xe5\x12\x41\x66\xa0\xe8\xed\x1d\x8e\x93\x08\x5e\xa3\x27\x3b\xc3\x7c\xa2\x73\xba\xc4\x02\x2e\xb0\xdc\xf4\xe5\x76\xd1\xca\x96\xa2\x8a\x94\xcd\x21\xc9\x6c\xec\x2c\x70\x42\x9e\x34\x74\x9d\x19\x7c\xcd\x20\x9c\xea\x2e\x0a\xfe\x42\x84\xd4\x29\x04\x8c\x8a\xb4\x41\xa2\xc1\xdc\x19\x8a\x88\x90\x4a\x49\xef\xce\xdf\xbd\x45\x4a\x52\x81\x70\x10\x40\x22\x21\x44\xcb\x6d\xc5\xec\x4e\x3c\x1c\x45\xef\x57\x9a\xb5\x7d\xae\xfe\xe5\xe4\x31\x86\x90\xe0\xab\x6d\x02\x3b\x2e\xcb\x11\x90\xd9\xa8\xc6\x77\xc2\x59\x98\x06\xfd\xf9\x2e\x78\x45\x01\xa6\xa8\xa0\x71\x5c\xbe\x33\xa7\xd2\xd9\x5f\x95\xef\xd9\xd5\xac\xfd\xdc\x5d\xbf\x5e\xb8\xd1\x3e\xc7\x31\x48\xe0\x5e\x4c\x14\x65\xdf\xb8\xa8\x71\x10\x09\xa3\xc2\xc7\x02\xcb\xa2\x4e\x5a\x02\x82\x94\x13\xb9\xf5\x30\xe6\xb2\xa4\xb5\xfe\x9b\x3e\x7a\xb2\x55\xd2\xa8\x4a\xbc\x16\xb6\x71\x8e\x39\xc7\xdb\x9d\xe1\x10\x09\x71\xbd\x9c\xb3\x41\x89\xd7\xa5\x89\xdc\x57\xb5\x53\x4a\xfe\x4c\xe1\xbc\xa0\x21\x79\x0a\x1a\x0f\x70\xa7\x5c\x08\x8e\xde\xb0\xc0\x43\x24\xad\x74\x63\x0e\xb1\xd9\x90\xe1\xb0\x2d\x13\xa7\x6d\x78\xfd\x04\x14\x38\x8e\x90\xaa\xce\x63\xac\x3e\x23\xbc\x64\xa9\xb4\xf8\x03\x63\xde\xcd\xbe\x16\x13\x4a\x55\xac\x82\x12\xc6\xac\xd4\x35\xf7\x22\xd4\x3a\xff\x22\x73\x0e\x6e\x51\xa0\x75\x1e\xae\x8f\xe8\x5d\xc7\x59\xe6\xe4\x9a\x18\x8d\xd6\x1c\x53\x84\x4d\xb7\x67\x28\x37\x09\x84\x69\x88\x12\x0e\x01\x11\x80\x32\xa2\xf5\xb9\xaa\xc6\xd9\x73\x53\xab\xfb\xb4\x2e\x20\xc6\x54\x92\xa0\x9a\xf3\x69\x1a\x2f\x81\x77\x37\xae\x53\x1a\xce\x40\xc4\xa8\x82\x1c\xb5\xef\xda\x24\x7d\xb9\x61\x69\x14\xa2\x25\xa0\x90\xac\x56\xc0\x81\x4a\xb4\xe2\x2c\xce\x4a\x64\x7a\x9a\x23\xf4\x13\x91\x3f\xa7\x4b\xf4\x63\x84\x6f\x18\x87\x10\xbd\xc3\xfc\x8f\x90\xdd\x52\x44\x04\xc2\x51\xc4\x6e\x21\x74\x48\x21\x81\xc7\xe2\xfd\xea\x12\xf8\x0d\x09\xf6\xe9\x47\x35\xaf\x67\xc4\x14\xf7\x22\x27\x97\xe1\xe2\x76\x2d\x06\x8c\x4a\x1c\x48\x3f\x73\x2d\x0b\x5b\x29\x45\x24\x00\x2a\x0c\x11\xec\x94\xca\xc2\xa6\xc1\x37\x21\x43\x83\x3b\x5f\x97\xf1\x43\x5e\x53\x73\x19\xa5\x36\xd8\x2d\x05\x2e\x34\x0b\xeb\x39\xfc\x1d\x63\x51\x01\xbd\x3d\xbb\x90\x84\x40\x25\x59\x6d\x09\x5d\xa3\x1c\x37\xe6\x5c\x16\x9a\x40\x09\x70\xc1\xe8\x82\xf1\x35\xa6\xe4\xdf\x99\x5c\x8e\x9e\x4d\x79\xb4\x27\x2f\xbf\x7e\xf8\x05\x25\x8c\x50\xa9\x98\x29\x90\x62\x60\xea\x75\xae\x13\xca\xbf\x2b\x1a\x29\x27\x76\xd6\x20\xc6\x64\x5f\xe6\x32\x1a\x08\x87\x21\x07\x21\xbc\xb4\xe4\xe0\x32\x67\xa6\xcd\xf3\x1e\xcd\xd9\x6b\xb6\x6f\x8e\x27\xa7\xed\xdb\xe7\xbc\xcc\x1a\x07\xce\x6f\x87\x33\xf0\xba\x51\x17\x22\x66\x78\x79\x8e\xce\xe5\x13\x81\x80\x06\x2c\xe5\x78\x0d\xa1\xb2\xb8\x54\xa8\x79\x09\xbd\xbf\x3c\x47\x01\x8b\x13\x2c\xc9\x32\xaa\xaa\x1d\xd5\xee\xab\x36\xbd\x6c\xfd\x54\x6c\xc8\x08\x01\x3c\xbd\xe7\x07\x88\xb0\x24\x37\x79\x90\x28\x4a\x1d\x10\x1a\x92\x1b\x12\xa6\x38\x42\x40\xc3\x4c\x43\x62\x8e\xae\x36\xb0\x45\x71\x2a\xa4\x9a\x23\x79\x59\xb1\xa8\xf2\xa4\x0c\x60\x9f\xcc\x8d\x40\xf5\x80\xca\xa8\x99\xc3\xa7\x85\x1f\x31\x25\xa9\x82\xc5\x6d\xbd\xd8\x36\x76\x7c\x02\x28\x97\xf6\x1d\x74\x3b\x11\x7e\x91\xae\x32\xf8\x6c\xf4\xe6\x7b\x9a\xa5\x1f\x62\xc6\x21\xcf\x9a\xe5\xed\x8b\x02\xf3\x2c\x33\x33\xdf\x00\xca\xc9\x09\xb4\x04\xf5\xa5\x08\xd7\xc3\x02\x18\x66\xf1\xab\x1e\x83\x37\x4c\xcd\x12\xc1\x1d\x50\xf6\xaa\xbd\xfe\xe2\x73\x48\x38\x08\xa0\x32\x9b\x18\x44\x86\x0b\x6a\xc1\xaa\x26\x96\x2d\x96\x3c\xa0\x54\x65\x73\x87\x15\xca\x15\xe5\xf5\x94\x46\x9f\x33\x1a\x0c\x9a\xb1\x5a\xd9\x6a\x95\xcd\xcb\x7e\xec\x9a\xc5\x94\x3b\x37\x26\x31\xd7\xfc\xe4\x1f\x13\x8c\x31\x75\x9c\xba\xf7\x87\x3c\xa1\xb7\x4f\x17\x1b\x09\x82\x98\xc4\x70\x95\xd3\xe8\x4c\x48\x5a\xa6\xd6\x2a\x3d\x56\x42\x80\x9f\xaf\xae\x2e\x50\x0c\x42\xe0\x35\x34\x3c\x8a\x62\x03\x37\xba\xb2\x27\x04\xda\x25\x8d\x06\xe2\xa0\x13\x8a\xf3\xf5\xec\x10\x72\x67\x88\x90\x3d\x4b\x64\xeb\xaa\xda\x8f\xf7\x5a\x75\x47\x9a\xa8\x51\x70\x26\xd2\x38\xc6\x7c\xbb\x57\xfc\xbd\xe4\x04\x56\xa8\xa0\x54\x9a\x45\xd5\xf7\x0f\x16\xfc\x57\x1c\x3c\xdf\x23\xba\x77\x38\xda\x16\x4b\x31\x53\x6a\x4d\x9a\x15\x63\xe7\xe1\x18\x69\x9f\x22\xe0\x24\xbb\x94\x4b\x97\xee\x2d\xf9\x70\x87\x72\x7b\xe6\xc4\x33\x2a\x66\x5e\x1c\x35\x72\xe3\x2d\xda\x73\xe4\xc7\x51\x6d\xa4\xa1\x2a\x4f\xde\x94\xcb\xb2\x3e\x31\x48\xae\x82\xce\xc9\xc8\x65\xcd\xc3\xb7\x34\xb6\x2b\xdf\x58\x65\x78\x6e\x73\xac\x5e\x24\x0d\x3f\xdc\x70\x23\xc6\xda\x52\x0b\x2d\x63\x7d\xa9\x49\x2d\x54\x48\x28\xc0\x12\x9c\xe3\x63\xc9\x58\x04\x98\x36\x07\xc8\x0a\xa7\x91\xd4\xf0\xbc\xc1\xa8\xb9\x70\xd0\xc6\xa9\xb6\x78\x80\x5a\xa3\xb4\x2c\xf4\x18\x0b\x8a\x9d\xd0\xb4\x55\x10\xee\x0d\xc5\xd6\xe0\x99\x93\xdc\xa1\x04\xbb\xf1\xa7\x23\xd1\xd1\x97\x8c\x87\x13\x0a\x21\x02\xe9\x99\x25\xed\x20\xc5\x92\x66\x3c\x32\x9c\xd6\x06\xb0\x31\x5c\x86\x29\x0a\xcb\x60\x33\x12\xa5\x91\xfc\x96\x75\xd0\x59\xd7\x13\xbd\xd3\x23\x79\xdd\x2a\x90\xa6\x38\x06\x91\x39\x7f\x20\x72\x03\x1c\x2d\x01\x61\xba\x45\x37\x38\x22\x61\x8e\x71\x85\xc4\x32\x15\x28\x60\x61\x16\xb8\x3d\x29\xdc\x4d\x3d\x2f\x12\x13\x7d\xc8\x7e\x37\xee\xa8\x7f\xfa\xdb\xcb\x17\xff\x77\xfd\xf9\x7f\xee\x9f\x3d\xfe\xcf\xa7\xa7\x45\xfb\xcf\x1e\xf7\xf3\xe0\xff\xc4\x51\x0a\x8e\x4c\xcb\x01\xdc\x0a\x65\xb2\x01\x83\xed\x3d\xe4\xa9\xa3\x4e\x2d\x59\xc5\xe8\x2f\x48\x7d\x5a\x6e\x37\xbf\x5c\x9f\x35\x13\x64\x14\xfa\xef\x0b\x68\xa6\x0d\xb4\x8e\xf1\xa8\xff\xbb\x60\xf4\x03\x64\xab\x5b\x81\x65\x51\xe6\xda\xca\xfa\xf0\xb0\xac\x3e\x9c\xca\x26\x0e\x1d\xdb\x57\x5b\xbb\xb4\x9a\xa6\xb6\x9b\x1a\x6b\xd1\x9a\x9e\x7e\x33\x9a\xec\x41\x69\x45\x22\xb8\xb4\x51\xeb\x04\x77\xca\x6f\x7b\x7b\xc8\xb2\xb0\x95\x92\x25\x5b\xd0\x42\xaa\x2a\xdd\x32\x78\x4f\x0c\xab\x68\x46\x6c\xea\x6d\xf4\x5c\x5e\xde\xc4\xac\xa5\xf9\xd1\x00\x9f\x7d\x98\x65\x24\xbd\xc7\x97\xd4\xb3\x3a\xa8\x2b\xa0\x34\x76\xf9\x65\x5f\x2d\x25\x95\x1b\xcf\xd6\xf4\x9b\x5f\x09\x95\xb0\x36\x3f\xdb\xd0\x39\x2a\x93\x1c\x9d\x03\xa2\x4a\xca\xf5\xf6\x10\xb6\x94\x89\x0b\x6a\x70\x12\x13\x49\x6e\x40\xe4\x29\x12\x2b\xbd\x80\x45\x11\x04\xaa\xc2\x8f\x56\x9e\x5c\x6b\xec\x8d\x5a\x0e\x14\x59\x06\x2b\x1e\x24\xcb\xc2\x56\x4a\x31\xbe\x23\x71\x1a\xfb\x51\x2a\x0b\x3b\x1c\x48\x10\xa5\x82\xdc\xc0\xbb\x3e\x24\x8d\x5a\x76\x2e\x09\xed\xc1\x65\x51\xb8\x83\xcb\x3e\x24\x8d\x5a\x2e\x5d\xfe\x02\x74\x2d\x3d\xf1\xef\xae\xb8\x4b\xe6\x5e\xd4\xaa\xe2\x2e\x5c\x5e\xec\x0e\xf5\x5b\x0c\xcb\x0a\xbb\xa4\x3c\xf7\x1f\x2a\x55\x69\x97\x8c\x7d\x68\x95\xa5\xad\xb4\xf4\x9c\xa5\x07\xb9\x7a\x05\xbb\xad\x50\x6f\xfb\xa0\x4e\x9b\x48\x23\x49\x92\x28\x87\x19\x3e\x32\xee\xca\x3b\x46\x7e\x7f\x18\x64\xcc\xcc\x0f\x34\xe9\x36\x8b\xb7\x6c\xa8\xa5\x5b\x54\x4c\x54\x5b\x15\x3a\xf1\x6c\x2d\xfe\x96\xc8\x0d\xba\x7b\x81\x88\xc8\x23\xab\xee\x7d\x3b\x92\xa7\x60\x29\xe3\xdc\xff\xb8\x64\xe1\xf6\xa2\x5a\x59\xdc\x6f\xeb\x45\x7d\x6a\xd1\x76\x1e\xea\xb8\xf1\xfa\x14\xd3\x36\x63\xe5\xd7\xf3\xe4\xbe\x25\xbd\x5e\x05\xeb\x73\x74\xb5\x21\x2a\x2e\x4e\xa3\x30\xdf\xbf\x43\x28\x2a\xd1\xa5\x2a\x9d\x8a\xfd\x76\xd8\x8d\xbc\x67\x65\xc7\xb8\x03\x45\xec\xa3\xb0\x37\x8a\x70\x4c\x68\x91\x51\x8e\x58\x80\xed\x4a\xf3\x81\x62\xca\x96\xbb\xf1\x52\xcd\x80\xfb\xe4\x4a\x5d\x6c\xdf\x6e\x20\x4b\x80\x30\x8e\x28\x93\xf9\xe9\x8d\x8a\x6d\xd5\x59\x65\x7b\xaa\x44\x9e\xc0\xc2\xd1\x7c\x40\x26\xd6\x1a\xce\xf9\xc5\x69\x7b\x6c\xec\xc8\x71\x7b\xe5\x21\x2e\xd3\xe5\x65\x93\x91\x53\x0b\x7b\x3a\xc7\xfa\x17\x6a\x01\xa7\x33\xd0\xf4\x40\x0f\x39\x87\xda\xe4\x54\x87\x3a\xd5\xe3\xc7\xa6\x8e\x20\xd4\x11\xb2\x4e\xb1\xe9\x14\x9b\x4e\xb1\xe9\x14\x9b\xfe\x15\x63\xd3\x47\xf5\xff\x97\x38\xe9\xcf\x14\xf8\x76\x82\x49\x13\x4c\xaa\x7d\xcd\x6c\x62\x42\x49\x87\x43\x49\x19\x33\x6f\xe3\x44\x6e\x9b\xab\x8a\x3e\x86\xaa\x99\x52\x1b\x5b\x59\x33\x02\x09\xa0\x21\xa1\x6b\x84\x6b\x66\xbb\xdc\x16\x0c\xd3\x68\xab\xec\x36\x4b\xd8\x60\x8a\x40\x31\x85\x6e\x14\x57\x13\xc2\xfb\x92\x10\xde\xbf\x88\xdc\xbc\x53\x5e\x7f\x82\x7a\x13\xd4\x9b\xa0\xde\x04\xf5\x90\x01\xf5\x94\xcb\x7b\x83\x25\x9e\xd0\xde\x84\xf6\x6a\x5f\x4b\xb3\x98\x00\xdf\x04\xf8\x6c\xbc\x7f\x19\x80\xaf\xf1\x71\x45\x22\x98\x40\xe0\x04\x02\x27\x10\xd8\x29\xf5\x04\x02\xff\x4a\x20\x30\xc1\x72\xf3\x65\x02\x40\xd7\xc1\xd1\xe2\x6b\xf1\xa9\x7b\xfb\xe4\x20\xc0\x68\x9d\xd4\xb4\xd3\x96\xb5\xa6\xd1\x41\x20\xe6\x89\xc3\x48\x65\x58\x13\x84\x9c\x56\x56\x3b\x0c\xe0\x6b\x83\x5c\x13\xd2\x9a\x90\xd6\x84\xb4\x26\xa4\x85\x0c\xa4\x45\x19\xfd\xff\x63\x6c\x52\xb5\x1f\x1e\x19\x74\x3a\xcd\xb9\x69\xce\xa6\x3a\x0f\x7a\x2d\x19\xc7\x81\x14\x5d\xcb\xd5\x03\xc9\x39\xd0\xb0\xd1\xb3\xcd\xfb\x7a\x2d\x5d\x3a\x48\xe1\xfa\x2e\xe6\x81\x42\x18\x86\xd6\xc1\xbe\xb1\x23\xd3\xf7\x34\xed\x19\x0a\x0b\xc4\x48\x44\xfd\x22\x50\xb6\x42\x58\xbb\xe5\x3d\xa7\x73\xd4\x8b\xc4\x8c\x70\x61\xec\x73\xee\xc3\x81\x8b\xf5\xe2\xd7\x52\x3e\xcf\xeb\xeb\x17\x3b\x71\x16\xda\x7d\xb8\xde\xf0\x7a\x8f\x06\x2d\xa7\x40\x7b\xc1\x9d\x41\x4d\xb6\x61\xa2\x4e\x9f\x3d\xa0\xc5\xae\xe3\x1c\x1d\x40\x6c\x48\x8b\x63\xa0\xb5\x01\xed\x8e\x02\xe9\x86\xc8\x3b\x06\xee\xdb\x4b\xde\xbd\xc0\xa1\x6f\xcb\xda\xfc\xc2\x44\x16\x87\x9c\x17\x31\xd3\x30\x20\x39\x42\xcb\x6f\xf2\xf1\xf4\x72\x10\xf8\x1c\xa0\xf3\xbd\x10\xea\x21\x35\x7d\xe8\x86\xdb\x15\xed\x81\x81\x07\x28\xbb\x13\x28\xc7\xf8\xce\x7d\x8d\xc2\x31\xb4\x7e\x94\xd6\xdb\x55\xef\x4a\xfb\xed\xc3\x40\x3e\xeb\x9f\xe9\x99\x0f\xdf\x08\x65\x88\x27\x73\x86\x31\x9d\x47\xdf\x55\x19\xba\x3d\xee\x15\x0a\xcd\x8c\xaa\x5e\xb9\xf6\x57\x33\x73\x5a\xa1\x89\x7b\x3b\xa0\xb2\xa4\xc2\xf6\xc1\x53\xb5\x00\xca\x23\xe5\xf4\x60\x6a\xb4\x2d\x74\xea\x4e\xed\x3b\xe3\x47\xfb\xed\x82\x3d\x19\xd4\x3b\x6b\xaf\xae\x2b\x2f\x57\xb3\x82\x68\xcb\xed\x88\x2e\xe1\x5c\xd7\x26\xfa\x0a\x65\xe7\xce\x11\x33\xb4\xdd\x66\xe3\x37\xf6\xfa\x70\xd6\x4f\xa1\x21\x51\xd8\x3c\x26\x14\x4b\xc6\x87\x44\x27\x1c\x70\xf8\x9e\x46\xce\xab\x21\x07\x5f\xc1\x76\x17\x1b\x77\xb4\xda\x75\xa0\x0a\x3a\x30\xe1\xf8\x97\x32\x16\x2b\x00\x75\x85\xee\x62\x46\xef\xd3\x85\xb5\x6b\x60\xbe\xf2\x30\x7a\x8c\x0b\x4b\xa6\xd0\xf9\x64\x42\xe7\x07\x41\x41\xe3\x2c\x5d\xf9\x6d\xe9\x39\x98\x3b\x3b\x5d\x67\xd4\x5c\xed\xf2\xf0\x48\x7b\xbd\x2d\x31\xdd\x3f\x34\xad\x44\x76\x51\x9a\x56\x22\xa7\x95\xc8\x69\x25\xf2\xe1\x56\x22\x1f\x00\x32\x6a\x73\x92\xed\xe1\xc6\x7d\x9f\x49\x2c\x69\x7e\xc8\x31\x4c\x0c\xb4\xf2\x54\x3b\x79\x3b\x9e\x4d\xb4\xd1\x18\x3e\x5f\x9a\x93\xa2\x11\xc3\xda\x27\x0b\xaf\x37\x2e\x5c\x37\xfb\xeb\x9a\xd6\xc3\xac\xc3\xcc\xf8\x1e\x5b\x9d\xac\x22\x64\xb7\xed\x26\xb8\xf3\xb9\x3c\xbb\x1f\xe2\xb0\x22\x77\x43\x6a\x62\x29\x39\x59\xa6\xe6\xe5\xcd\x7b\x83\xc0\x5b\x8e\x93\x64\xac\xeb\xca\x4f\x65\xac\x4a\xbc\x1e\xcd\x82\xfa\x3c\x70\x36\xb6\xb5\xed\x79\xef\xec\x68\x00\xff\x54\xfa\xb5\xe3\xf1\xdb\xe1\xbe\xce\x76\x17\xaf\x57\xb6\x6b\x89\x05\x09\xce\x52\xb9\x01\x2a\x49\xbe\xd9\xf4\xd2\xb8\x7a\xbf\x91\x02\xf3\x22\x8c\x13\xf2\x77\xd8\x8e\x43\x8b\xe1\x54\x6e\x5e\x9d\xc7\x49\x44\x02\x22\xc7\xa4\x79\x81\x85\xb8\x65\x3c\x1c\x93\xe6\x59\xa2\xf8\x1c\x51\x95\x05\xd9\x20\x00\x21\x7e\x60\x21\x58\xa9\x56\xff\xbe\xb6\x5a\x5e\x5b\x3f\x1f\xd6\xd3\x3c\xc4\x4d\xba\x99\xb4\x63\x6e\x7d\x3e\x3d\x57\xd2\x18\x5f\x47\xe8\xc3\x06\x8a\x68\x6c\x7f\x3b\x72\x0f\xe7\xe2\x77\x77\xf1\xd0\x99\xab\xdf\x2e\xfe\xd6\xbb\xcd\x1a\xb9\x90\xd1\xaf\xf2\x38\x3d\xdb\x74\xf8\xeb\xe3\xda\xe8\x2a\x62\xb7\xda\x1b\x07\xa9\xdc\x30\x5e\xbc\x68\xfb\x6b\x9f\x97\xf1\xc6\xb1\xd8\x5c\x29\x1e\x49\x30\xc5\xf7\xde\xad\x91\x42\xf9\xdd\xed\x89\x80\x25\xbe\x37\xd7\xe7\x32\x5c\xe6\x35\xac\xd4\x0c\x2d\xf7\x90\xc4\xe3\xf5\xe3\x2f\x7f\x54\x18\x88\xe3\x61\x47\x85\x64\x7f\xc0\xd7\x3f\x1a\x92\x42\xe9\xc7\x1e\x0d\x95\x76\xa7\x51\xa0\x8f\x02\x1b\x46\x9e\x06\x42\xd1\xf2\x01\x07\x02\xde\xe9\x7d\x1a\x0b\xa7\x32\x16\xcc\xc0\xee\xc4\x90\xd2\x5f\x6f\x98\x54\x5d\xf2\x95\xe1\xa7\x69\x10\x3a\x06\xe1\x65\xb3\x17\x47\x58\x78\xd0\x45\xd6\x5b\xd5\x5f\x25\x1d\x71\x49\xa6\x7a\x64\xda\xd0\x6f\xc7\x3a\x4c\xe3\x09\xc0\x6e\x96\x2c\xa7\xa7\x77\x34\x10\x05\x08\x21\x44\x92\x65\x77\xdf\x20\x5c\xbc\xe7\x97\x3f\xf4\x1a\x45\xd6\xe7\x27\x4a\xde\x74\x27\x66\x11\x7d\x70\xba\xd3\x78\xf9\x1e\x0d\xca\xc8\x39\xde\x7c\xb3\xa6\xe1\xbc\xd7\xc1\x6a\x6f\xb3\x0e\x52\xbe\xe4\x98\x8a\x15\x70\x94\x70\x26\x59\xc0\xa2\xf2\x1c\xfb\xd9\xc5\xf9\xbc\xd5\x92\x9c\xa3\xdf\xe6\x1e\xb3\x0d\x49\xba\x87\x50\x5f\x84\xfe\xe9\xd6\xf8\xbb\xe6\xf0\x7a\xeb\xa6\x65\x3b\x86\x8b\x79\x93\xf5\x59\x20\x6e\xb4\xa7\x44\xf4\x3f\xa5\xfe\x67\x42\x12\xdb\xd3\xe7\xbb\xa5\xa3\x8c\x5c\x2b\x97\xbb\xbb\x7f\x8e\xc5\x6e\xed\x43\x5c\xbf\x74\xc8\x8f\xff\xe6\xd6\xbe\x91\xb6\xf5\x95\xe4\xed\x93\xc4\xa8\x5b\xf9\x76\x4d\x35\xb7\xd8\x8c\xb6\x7d\xaf\x72\xe0\xb6\xbd\x01\x63\x9e\x76\xab\x1a\x32\x76\xe4\x8c\x76\xc2\xad\x6c\xa2\x65\xf7\xcf\xf8\xa7\xda\x2a\xb9\x8c\x3d\x3c\xa3\x9d\x64\x33\xe5\x1a\xb5\x2d\xfb\x86\xa2\x5a\x7f\x19\x5b\x7f\xc6\x3f\xd1\x53\xd3\xe2\x41\x5b\xd3\x4f\xf0\xec\xb0\x42\x73\x43\xd2\x68\x27\xd3\x6a\x6a\x34\xf6\x4e\x1e\x52\x8b\x87\x6c\xcc\xae\x44\xfb\x9e\xa7\x51\x4f\x9d\x55\x03\x81\x8e\x67\xfc\xb4\x69\xf0\x3a\x18\xf2\x40\xd0\xf6\xa8\x34\xe3\xc9\x98\xaf\xf6\xda\x24\xd3\xeb\x60\xb9\x0e\xd3\x1f\xa9\xff\xee\x1f\xfd\x37\x00\x00\xff\xff\x69\x5d\x0a\x6a\x39\x9d\x00\x00") - -func v2SchemaJSONBytes() ([]byte, error) { - return bindataRead( - _v2SchemaJSON, - "v2/schema.json", - ) -} - -func v2SchemaJSON() (*asset, error) { - bytes, err := v2SchemaJSONBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "v2/schema.json", size: 40249, mode: os.FileMode(420), modTime: time.Unix(1482389892, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "jsonschema-draft-04.json": jsonschemaDraft04JSON, - "v2/schema.json": v2SchemaJSON, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} -var _bintree = &bintree{nil, map[string]*bintree{ - "jsonschema-draft-04.json": &bintree{jsonschemaDraft04JSON, map[string]*bintree{}}, - "v2": &bintree{nil, map[string]*bintree{ - "schema.json": &bintree{v2SchemaJSON, map[string]*bintree{}}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) -} - diff --git a/discovery/vendor/github.com/go-openapi/spec/contact_info.go b/discovery/vendor/github.com/go-openapi/spec/contact_info.go deleted file mode 100644 index f285970a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/contact_info.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -// ContactInfo contact information for the exposed API. -// -// For more information: http://goo.gl/8us55a#contactObject -type ContactInfo struct { - Name string `json:"name,omitempty"` - URL string `json:"url,omitempty"` - Email string `json:"email,omitempty"` -} diff --git a/discovery/vendor/github.com/go-openapi/spec/expander.go b/discovery/vendor/github.com/go-openapi/spec/expander.go deleted file mode 100644 index 140daf6e..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/expander.go +++ /dev/null @@ -1,894 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/url" - "os" - "path" - "path/filepath" - "reflect" - "strings" - "sync" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -var ( - // Debug enables logging when SWAGGER_DEBUG env var is not empty - Debug = os.Getenv("SWAGGER_DEBUG") != "" -) - -// ExpandOptions provides options for expand. -type ExpandOptions struct { - RelativeBase string - SkipSchemas bool - ContinueOnError bool -} - -// ResolutionCache a cache for resolving urls -type ResolutionCache interface { - Get(string) (interface{}, bool) - Set(string, interface{}) -} - -type simpleCache struct { - lock sync.Mutex - store map[string]interface{} -} - -var resCache ResolutionCache - -func init() { - resCache = initResolutionCache() -} - -func initResolutionCache() ResolutionCache { - return &simpleCache{store: map[string]interface{}{ - "http://swagger.io/v2/schema.json": MustLoadSwagger20Schema(), - "http://json-schema.org/draft-04/schema": MustLoadJSONSchemaDraft04(), - }} -} - -func (s *simpleCache) Get(uri string) (interface{}, bool) { - debugLog("getting %q from resolution cache", uri) - s.lock.Lock() - v, ok := s.store[uri] - debugLog("got %q from resolution cache: %t", uri, ok) - - s.lock.Unlock() - return v, ok -} - -func (s *simpleCache) Set(uri string, data interface{}) { - s.lock.Lock() - s.store[uri] = data - s.lock.Unlock() -} - -// ResolveRefWithBase resolves a reference against a context root with preservation of base path -func ResolveRefWithBase(root interface{}, ref *Ref, opts *ExpandOptions) (*Schema, error) { - resolver, err := defaultSchemaLoader(root, opts, nil) - if err != nil { - return nil, err - } - specBasePath := "" - if opts != nil { - specBasePath, _ = absPath(opts.RelativeBase) - } - - result := new(Schema) - if err := resolver.Resolve(ref, result, specBasePath); err != nil { - return nil, err - } - return result, nil -} - -// ResolveRef resolves a reference against a context root -// ref is guaranteed to be in root (no need to go to external files) -// ResolveRef is ONLY called from the code generation module -func ResolveRef(root interface{}, ref *Ref) (*Schema, error) { - res, _, err := ref.GetPointer().Get(root) - if err != nil { - panic(err) - } - switch sch := res.(type) { - case Schema: - return &sch, nil - case *Schema: - return sch, nil - case map[string]interface{}: - b, _ := json.Marshal(sch) - newSch := new(Schema) - json.Unmarshal(b, newSch) - return newSch, nil - default: - return nil, fmt.Errorf("unknown type for the resolved reference") - } -} - -// ResolveParameter resolves a paramter reference against a context root -func ResolveParameter(root interface{}, ref Ref) (*Parameter, error) { - return ResolveParameterWithBase(root, ref, nil) -} - -// ResolveParameterWithBase resolves a paramter reference against a context root and base path -func ResolveParameterWithBase(root interface{}, ref Ref, opts *ExpandOptions) (*Parameter, error) { - resolver, err := defaultSchemaLoader(root, opts, nil) - if err != nil { - return nil, err - } - - result := new(Parameter) - if err := resolver.Resolve(&ref, result, ""); err != nil { - return nil, err - } - return result, nil -} - -// ResolveResponse resolves response a reference against a context root -func ResolveResponse(root interface{}, ref Ref) (*Response, error) { - return ResolveResponseWithBase(root, ref, nil) -} - -// ResolveResponseWithBase resolves response a reference against a context root and base path -func ResolveResponseWithBase(root interface{}, ref Ref, opts *ExpandOptions) (*Response, error) { - resolver, err := defaultSchemaLoader(root, opts, nil) - if err != nil { - return nil, err - } - - result := new(Response) - if err := resolver.Resolve(&ref, result, ""); err != nil { - return nil, err - } - return result, nil -} - -// ResolveItems resolves header and parameter items reference against a context root and base path -func ResolveItems(root interface{}, ref Ref, opts *ExpandOptions) (*Items, error) { - resolver, err := defaultSchemaLoader(root, opts, nil) - if err != nil { - return nil, err - } - basePath := "" - if opts.RelativeBase != "" { - basePath = opts.RelativeBase - } - result := new(Items) - if err := resolver.Resolve(&ref, result, basePath); err != nil { - return nil, err - } - return result, nil -} - -// ResolvePathItem resolves response a path item against a context root and base path -func ResolvePathItem(root interface{}, ref Ref, opts *ExpandOptions) (*PathItem, error) { - resolver, err := defaultSchemaLoader(root, opts, nil) - if err != nil { - return nil, err - } - basePath := "" - if opts.RelativeBase != "" { - basePath = opts.RelativeBase - } - result := new(PathItem) - if err := resolver.Resolve(&ref, result, basePath); err != nil { - return nil, err - } - return result, nil -} - -type schemaLoader struct { - root interface{} - options *ExpandOptions - cache ResolutionCache - loadDoc func(string) (json.RawMessage, error) -} - -var idPtr, _ = jsonpointer.New("/id") -var refPtr, _ = jsonpointer.New("/$ref") - -// PathLoader function to use when loading remote refs -var PathLoader func(string) (json.RawMessage, error) - -func init() { - PathLoader = func(path string) (json.RawMessage, error) { - data, err := swag.LoadFromFileOrHTTP(path) - if err != nil { - return nil, err - } - return json.RawMessage(data), nil - } -} - -func defaultSchemaLoader( - root interface{}, - expandOptions *ExpandOptions, - cache ResolutionCache) (*schemaLoader, error) { - - if cache == nil { - cache = resCache - } - if expandOptions == nil { - expandOptions = &ExpandOptions{} - } - - return &schemaLoader{ - root: root, - options: expandOptions, - cache: cache, - loadDoc: func(path string) (json.RawMessage, error) { - debugLog("fetching document at %q", path) - return PathLoader(path) - }, - }, nil -} - -func idFromNode(node interface{}) (*Ref, error) { - if idValue, _, err := idPtr.Get(node); err == nil { - if refStr, ok := idValue.(string); ok && refStr != "" { - idRef, err := NewRef(refStr) - if err != nil { - return nil, err - } - return &idRef, nil - } - } - return nil, nil -} - -func nextRef(startingNode interface{}, startingRef *Ref, ptr *jsonpointer.Pointer) *Ref { - if startingRef == nil { - return nil - } - - if ptr == nil { - return startingRef - } - - ret := startingRef - var idRef *Ref - node := startingNode - - for _, tok := range ptr.DecodedTokens() { - node, _, _ = jsonpointer.GetForToken(node, tok) - if node == nil { - break - } - - idRef, _ = idFromNode(node) - if idRef != nil { - nw, err := ret.Inherits(*idRef) - if err != nil { - break - } - ret = nw - } - - refRef, _, _ := refPtr.Get(node) - if refRef != nil { - var rf Ref - switch value := refRef.(type) { - case string: - rf, _ = NewRef(value) - } - nw, err := ret.Inherits(rf) - if err != nil { - break - } - nwURL := nw.GetURL() - if nwURL.Scheme == "file" || (nwURL.Scheme == "" && nwURL.Host == "") { - nwpt := filepath.ToSlash(nwURL.Path) - if filepath.IsAbs(nwpt) { - _, err := os.Stat(nwpt) - if err != nil { - nwURL.Path = filepath.Join(".", nwpt) - } - } - } - - ret = nw - } - - } - - return ret -} - -func debugLog(msg string, args ...interface{}) { - if Debug { - log.Printf(msg, args...) - } -} - -// base or refPath could be a file path or a URL -// given a base absolute path and a ref path, return the absolute path of refPath -// 1) if refPath is absolute, return it -// 2) if refPath is relative, join it with basePath keeping the scheme, hosts, and ports if exists -// base could be a directory or a full file path -func normalizePaths(refPath, base string) string { - refURL, _ := url.Parse(refPath) - if path.IsAbs(refURL.Path) { - // refPath is actually absolute - if refURL.Host != "" { - return refPath - } - return filepath.FromSlash(refPath) - } - - // relative refPath - baseURL, _ := url.Parse(base) - if !strings.HasPrefix(refPath, "#") { - // combining paths - if baseURL.Host != "" { - baseURL.Path = path.Join(path.Dir(baseURL.Path), refURL.Path) - } else { // base is a file - newBase := fmt.Sprintf("%s#%s", filepath.Join(filepath.Dir(base), filepath.FromSlash(refURL.Path)), refURL.Fragment) - return newBase - } - - } - // copying fragment from ref to base - baseURL.Fragment = refURL.Fragment - return baseURL.String() -} - -// relativeBase could be an ABSOLUTE file path or an ABSOLUTE URL -func normalizeFileRef(ref *Ref, relativeBase string) *Ref { - // This is important for when the reference is pointing to the root schema - if ref.String() == "" { - r, _ := NewRef(relativeBase) - return &r - } - - refURL := ref.GetURL() - debugLog("normalizing %s against %s (%s)", ref.String(), relativeBase, refURL.String()) - - s := normalizePaths(ref.String(), relativeBase) - r, _ := NewRef(s) - return &r -} - -func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath string) error { - tgt := reflect.ValueOf(target) - if tgt.Kind() != reflect.Ptr { - return fmt.Errorf("resolve ref: target needs to be a pointer") - } - - refURL := ref.GetURL() - if refURL == nil { - return nil - } - - // if no basePath is provided, we attempt to resolve the reference against root - if basePath == "" { - var b []byte - switch rr := r.root.(type) { - case *Schema: - b, _ = rr.MarshalJSON() - case *Swagger: - b, _ = rr.MarshalJSON() - } - f, err := ioutil.TempFile(os.TempDir(), "tmproot") - if err != nil { - return err - } - f.Write(b) - f.Close() - basePath = f.Name() - } - - baseRef := normalizeFileRef(ref, basePath) - debugLog("current ref normalized file: %s", baseRef.String()) - data, _, _, err := r.load(baseRef.GetURL()) - if err != nil { - return err - } - - var res interface{} - res = data - if ref.String() != "" { - res, _, err = ref.GetPointer().Get(data) - if err != nil { - return err - } - } - if err := swag.DynamicJSONToStruct(res, target); err != nil { - return err - } - return nil -} - -func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error) { - debugLog("loading schema from url: %s", refURL) - toFetch := *refURL - toFetch.Fragment = "" - - data, fromCache := r.cache.Get(toFetch.String()) - if !fromCache { - b, err := r.loadDoc(toFetch.String()) - if err != nil { - return nil, url.URL{}, false, err - } - - if err := json.Unmarshal(b, &data); err != nil { - return nil, url.URL{}, false, err - } - r.cache.Set(toFetch.String(), data) - } - - return data, toFetch, fromCache, nil -} - -// Resolve resolves a reference against basePath and stores the result in target -// Resolve is not in charge of following references, it only resolves ref by following its URL -// if the schema that ref is referring to has more refs in it. Resolve doesn't resolve them -// if basePath is an empty string, ref is resolved against the root schema stored in the schemaLoader struct -func (r *schemaLoader) Resolve(ref *Ref, target interface{}, basePath string) error { - return r.resolveRef(ref, target, basePath) -} - -// absPath returns the absolute path of a file -func absPath(fname string) (string, error) { - if filepath.IsAbs(fname) { - return fname, nil - } - wd, err := os.Getwd() - return filepath.Join(wd, fname), err -} - -// ExpandSpec expands the references in a swagger spec -func ExpandSpec(spec *Swagger, options *ExpandOptions) error { - resolver, err := defaultSchemaLoader(spec, options, nil) - // Just in case this ever returns an error. - if shouldStopOnError(err, resolver.options) { - return err - } - - // getting the base path of the spec to adjust all subsequent reference resolutions - specBasePath := "" - if options != nil { - specBasePath, _ = absPath(options.RelativeBase) - } - - if options == nil || !options.SkipSchemas { - rt := fmt.Sprintf("%s#/definitions/", specBasePath) - for key, definition := range spec.Definitions { - var def *Schema - var err error - if def, err = expandSchema(definition, []string{rt + key}, resolver, specBasePath); shouldStopOnError(err, resolver.options) { - return err - } - if def != nil { - spec.Definitions[key] = *def - } - } - } - - for key, parameter := range spec.Parameters { - if err := expandParameter(¶meter, resolver, specBasePath); shouldStopOnError(err, resolver.options) { - return err - } - spec.Parameters[key] = parameter - } - - for key, response := range spec.Responses { - if err := expandResponse(&response, resolver, specBasePath); shouldStopOnError(err, resolver.options) { - return err - } - spec.Responses[key] = response - } - - if spec.Paths != nil { - for key, path := range spec.Paths.Paths { - if err := expandPathItem(&path, resolver, specBasePath); shouldStopOnError(err, resolver.options) { - return err - } - spec.Paths.Paths[key] = path - } - } - - return nil -} - -func shouldStopOnError(err error, opts *ExpandOptions) bool { - if err != nil && !opts.ContinueOnError { - return true - } - - if err != nil { - log.Println(err) - } - - return false -} - -// ExpandSchema expands the refs in the schema object with reference to the root object -// go-openapi/validate uses this function -// notice that it is impossible to reference a json scema in a different file other than root -func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error { - // if root is passed as nil, assume root is the same as schema - if root == nil { - root = schema - } - - file, err := ioutil.TempFile(os.TempDir(), "root") - if err != nil { - return err - } - - switch r := root.(type) { - case *Schema: - b, _ := r.MarshalJSON() - file.Write(b) - case *Swagger: - b, _ := r.MarshalJSON() - file.Write(b) - } - file.Close() - - opts := &ExpandOptions{ - RelativeBase: file.Name(), - SkipSchemas: false, - ContinueOnError: false, - } - return ExpandSchemaWithBasePath(schema, cache, opts) -} - -// ExpandSchemaWithBasePath expands the refs in the schema object, base path configured through expand options -func ExpandSchemaWithBasePath(schema *Schema, cache ResolutionCache, opts *ExpandOptions) error { - if schema == nil { - return nil - } - - if opts == nil { - return errors.New("cannot expand schema without a basPath") - } - basePath, _ := absPath(opts.RelativeBase) - - resolver, err := defaultSchemaLoader(nil, opts, cache) - if err != nil { - return err - } - - refs := []string{""} - var s *Schema - if s, err = expandSchema(*schema, refs, resolver, basePath); err != nil { - return err - } - *schema = *s - return nil -} - -func expandItems(target Schema, parentRefs []string, resolver *schemaLoader, basePath string) (*Schema, error) { - if target.Items != nil { - if target.Items.Schema != nil { - t, err := expandSchema(*target.Items.Schema, parentRefs, resolver, basePath) - if err != nil { - return nil, err - } - *target.Items.Schema = *t - } - for i := range target.Items.Schemas { - t, err := expandSchema(target.Items.Schemas[i], parentRefs, resolver, basePath) - if err != nil { - return nil, err - } - target.Items.Schemas[i] = *t - } - } - return &target, nil -} - -// basePathFromSchemaID returns a new basePath based on an existing basePath and a schema ID -func basePathFromSchemaID(oldBasePath, id string) string { - u, err := url.Parse(oldBasePath) - if err != nil { - panic(err) - } - uid, err := url.Parse(id) - if err != nil { - panic(err) - } - - if path.IsAbs(uid.Path) { - return id - } - u.Path = path.Join(path.Dir(u.Path), uid.Path) - return u.String() -} - -func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader, basePath string) (*Schema, error) { - if target.Ref.String() == "" && target.Ref.IsRoot() { - // normalizing is important - newRef := normalizeFileRef(&target.Ref, basePath) - target.Ref = *newRef - return &target, nil - - } - - /* change the base path of resolution when an ID is encountered - otherwise the basePath should inherit the parent's */ - // important: ID can be relative path - if target.ID != "" { - // handling the case when id is a folder - // remember that basePath has to be a file - refPath := target.ID - if strings.HasSuffix(target.ID, "/") { - // path.Clean here would not work correctly if basepath is http - refPath = fmt.Sprintf("%s%s", refPath, "placeholder.json") - } - basePath = normalizePaths(refPath, basePath) - } - - /* Explain here what this function does */ - - var t *Schema - /* if Ref is found, everything else doesn't matter */ - /* Ref also changes the resolution scope of children expandSchema */ - if target.Ref.String() != "" { - /* Here the resolution scope is changed because a $ref was encountered */ - newRef := normalizeFileRef(&target.Ref, basePath) - newBasePath := newRef.RemoteURI() - /* this means there is a circle in the recursion tree */ - /* return the Ref */ - if swag.ContainsStringsCI(parentRefs, newRef.String()) { - target.Ref = *newRef - return &target, nil - } - debugLog("\nbasePath: %s", basePath) - b, _ := json.Marshal(target) - debugLog("calling Resolve with target: %s", string(b)) - if err := resolver.Resolve(&target.Ref, &t, basePath); shouldStopOnError(err, resolver.options) { - return nil, err - } - - if t != nil { - parentRefs = append(parentRefs, newRef.String()) - return expandSchema(*t, parentRefs, resolver, newBasePath) - } - } - - t, err := expandItems(target, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - target = *t - } - - for i := range target.AllOf { - t, err := expandSchema(target.AllOf[i], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - target.AllOf[i] = *t - } - for i := range target.AnyOf { - t, err := expandSchema(target.AnyOf[i], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - target.AnyOf[i] = *t - } - for i := range target.OneOf { - t, err := expandSchema(target.OneOf[i], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - target.OneOf[i] = *t - } - } - if target.Not != nil { - t, err := expandSchema(*target.Not, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - *target.Not = *t - } - } - for k := range target.Properties { - t, err := expandSchema(target.Properties[k], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - target.Properties[k] = *t - } - } - if target.AdditionalProperties != nil && target.AdditionalProperties.Schema != nil { - t, err := expandSchema(*target.AdditionalProperties.Schema, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - *target.AdditionalProperties.Schema = *t - } - } - for k := range target.PatternProperties { - t, err := expandSchema(target.PatternProperties[k], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - target.PatternProperties[k] = *t - } - } - for k := range target.Dependencies { - if target.Dependencies[k].Schema != nil { - t, err := expandSchema(*target.Dependencies[k].Schema, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - *target.Dependencies[k].Schema = *t - } - } - } - if target.AdditionalItems != nil && target.AdditionalItems.Schema != nil { - t, err := expandSchema(*target.AdditionalItems.Schema, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - *target.AdditionalItems.Schema = *t - } - } - for k := range target.Definitions { - t, err := expandSchema(target.Definitions[k], parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return &target, err - } - if t != nil { - target.Definitions[k] = *t - } - } - return &target, nil -} - -func expandPathItem(pathItem *PathItem, resolver *schemaLoader, basePath string) error { - if pathItem == nil { - return nil - } - - if pathItem.Ref.String() != "" { - if err := resolver.Resolve(&pathItem.Ref, &pathItem, basePath); err != nil { - return err - } - pathItem.Ref = Ref{} - } - - for idx := range pathItem.Parameters { - if err := expandParameter(&(pathItem.Parameters[idx]), resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - } - if err := expandOperation(pathItem.Get, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Head, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Options, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Put, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Post, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Patch, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - if err := expandOperation(pathItem.Delete, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - return nil -} - -func expandOperation(op *Operation, resolver *schemaLoader, basePath string) error { - if op == nil { - return nil - } - - for i, param := range op.Parameters { - if err := expandParameter(¶m, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - op.Parameters[i] = param - } - - if op.Responses != nil { - responses := op.Responses - if err := expandResponse(responses.Default, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - for code, response := range responses.StatusCodeResponses { - if err := expandResponse(&response, resolver, basePath); shouldStopOnError(err, resolver.options) { - return err - } - responses.StatusCodeResponses[code] = response - } - } - return nil -} - -func expandResponse(response *Response, resolver *schemaLoader, basePath string) error { - if response == nil { - return nil - } - - var parentRefs []string - - if response.Ref.String() != "" { - parentRefs = append(parentRefs, response.Ref.String()) - sch := new(Schema) - b, _ := response.MarshalJSON() - json.Unmarshal(b, sch) - s, _ := expandSchema(*sch, parentRefs, resolver, basePath) - // if err := resolver.Resolve(&response.Ref, response, basePath); shouldStopOnError(err, resolver.options) { - // return err - // } - b, _ = s.MarshalJSON() - json.Unmarshal(b, response) - response.Ref = Ref{} - } - - if !resolver.options.SkipSchemas && response.Schema != nil { - parentRefs = append(parentRefs, response.Schema.Ref.String()) - debugLog("response ref: %s", response.Schema.Ref) - s, err := expandSchema(*response.Schema, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return err - } - *response.Schema = *s - } - return nil -} - -func expandParameter(parameter *Parameter, resolver *schemaLoader, basePath string) error { - if parameter == nil { - return nil - } - - var parentRefs []string - - if parameter.Ref.String() != "" { - parentRefs = append(parentRefs, parameter.Ref.String()) - if err := resolver.Resolve(¶meter.Ref, parameter, basePath); shouldStopOnError(err, resolver.options) { - return err - } - parameter.Ref = Ref{} - } - if !resolver.options.SkipSchemas && parameter.Schema != nil { - parentRefs = append(parentRefs, parameter.Schema.Ref.String()) - s, err := expandSchema(*parameter.Schema, parentRefs, resolver, basePath) - if shouldStopOnError(err, resolver.options) { - return err - } - *parameter.Schema = *s - } - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/external_docs.go b/discovery/vendor/github.com/go-openapi/spec/external_docs.go deleted file mode 100644 index 88add91b..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/external_docs.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -// ExternalDocumentation allows referencing an external resource for -// extended documentation. -// -// For more information: http://goo.gl/8us55a#externalDocumentationObject -type ExternalDocumentation struct { - Description string `json:"description,omitempty"` - URL string `json:"url,omitempty"` -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json deleted file mode 100644 index 42e6f24e..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json +++ /dev/null @@ -1,254 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Swagger Petstore", - "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - "termsOfService": "http://helloreverb.com/terms/", - "contact": { - "name": "Wordnik API Team" - }, - "license": { - "name": "MIT" - } - }, - "host": "petstore.swagger.wordnik.com", - "basePath": "/api", - "schemes": [ - "http" - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": { - "idParam": { - "name": "id", - "in": "path", - "description": "ID of pet to fetch", - "required": true, - "type": "integer", - "format": "int64" - }, - "tag": { - "type": "string", - "in": "query", - "required": false - }, - "query": { - "$ref": "#/parameters/tag" - } - }, - "responses": { - "petResponse": { - "description": "pet response", - "schema": { - "$ref": "#/definitions/pet" - } - }, - "stringResponse": { - "descripion": "string response", - "schema": { - "type": "string" - } - }, - "anotherPet": { - "$ref": "#/responses/petResponse" - } - }, - "paths": { - "/": { - "get": { - "operationId": "indexStuff", - "responses": { - "default": { - "$ref": "#/responses/stringResponse" - }, - "200": { - "$ref": "#/responses/anotherPet" - } - } - } - }, - "/pets": { - "get": { - "description": "Returns all pets from the system that the user has access to", - "operationId": "findPets", - "produces": [ - "application/json", - "application/xml", - "text/xml", - "text/html" - ], - "parameters": [ - { - "name": "tags", - "in": "query", - "description": "tags to filter by", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv" - }, - { - "name": "limit", - "in": "query", - "description": "maximum number of results to return", - "required": false, - "type": "integer", - "format": "int32" - } - ], - "responses": { - "200": { - "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pet" - } - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - }, - "post": { - "description": "Creates a new pet in the store. Duplicates are allowed", - "operationId": "addPet", - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "pet", - "in": "body", - "description": "Pet to add to the store", - "required": true, - "schema": { - "$ref": "#/definitions/petInput" - } - } - ], - "responses": { - "200": { "$ref": "#/responses/petResponse" }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - } - }, - "/pets/{id}": { - "get": { - "description": "Returns a user based on a single ID, if the user does not have access to the pet", - "operationId": "findPetById", - "produces": [ - "application/json", - "application/xml", - "text/xml", - "text/html" - ], - "parameters": [ - { - "$ref": "#/parameters/idParam" - } - ], - "responses": { - "200": { - "$ref": "#/responses/petResponse" - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - }, - "delete": { - "description": "deletes a single pet based on the ID supplied", - "operationId": "deletePet", - "parameters": [ - { - "$ref": "#/parameters/idParam" - } - ], - "responses": { - "204": { - "description": "pet deleted" - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - } - } - }, - "definitions": { - "pet": { - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "tag": { - "type": "string" - } - } - }, - "petInput": { - "allOf": [ - { - "$ref": "#/definitions/pet" - }, - { - "required": [ - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - } - } - } - ] - }, - "errorModel": { - "required": [ - "code", - "message" - ], - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - } - } - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json deleted file mode 100644 index f501aa14..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "definitions": { - "brand": { - "type": "object", - "properties": { - "name": { - "type": "string" - } - } - }, - "category": { - "type": "object", - "properties": { - "children": { - "type": "array", - "items": { - "$ref": "#/definitions/category" - } - } - } - }, - "car": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "make": { - "type": "string" - }, - "similar": { - "items": { - "$ref": "#/definitions/car" - } - }, - "notSimilar": { - "additionalProperties": { - "$ref": "#/definitions/car" - } - }, - "oneCar": { - "$ref": "#/definitions/car" - }, - "category": { - "$ref": "#/definitions/category" - }, - "brand": { - "$ref": "#/definitions/brand" - } - } - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json deleted file mode 100644 index 7b39b999..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json +++ /dev/null @@ -1 +0,0 @@ -{"swagger":"2.0","info":{"title":"Swagger Sample","description":"Sample API Playground.","version":"1.0.0"},"basePath":"/v1","schemes":["http"],"consumes":["application/vdn.sample.v1+json"],"produces":["application/vdn.sample.v1+json"],"paths":{"/books":{"get":{"summary":"List all books","operationId":"listBooks","tags":["books"],"responses":{"200":{"headers":{"Link":{"type":"string"}},"description":"An array of books","schema":{"type":"array","items":{"$ref":"#/definitions/Book"}}},"default":{"description":"generic error response","schema":{"$ref":"#/definitions/Error"}}}}}},"definitions":{"Book":{"type":"object","required":["title","summary"],"properties":{"title":{"type":"string","example":"Winnie the Pooh"},"summary":{"type":"string","example":"Famous children's book"},"related_books":{"type":"array","items":{"$ref":"#/definitions/Book"}}}},"Error":{"type":"object","readOnly":true,"properties":{"code":{"type":"integer","format":"int64","example":400},"message":{"type":"string","example":"Unexpected error"}},"required":["message"]}}} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml deleted file mode 100644 index d43bd464..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml +++ /dev/null @@ -1,67 +0,0 @@ ---- -swagger: "2.0" -info: - title: Swagger Sample - description: Sample API Playground. - version: 1.0.0 -basePath: /v1 -schemes: -- http -consumes: -- application/vdn.sample.v1+json -produces: -- application/vdn.sample.v1+json - -paths: - /books: - get: - summary: List all books - operationId: listBooks - tags: - - books - responses: - 200: - headers: - Link: - type: string - description: An array of books - schema: - type: array - items: - $ref: "#/definitions/Book" - default: - description: generic error response - schema: - $ref: "#/definitions/Error" - -definitions: - Book: - type: object - required: - - title - - summary - properties: - title: - type: string - example: Winnie the Pooh - summary: - type: string - example: Famous children's book - related_books: - type: array - items: - $ref: "#/definitions/Book" - - Error: - type: object - readOnly: true - properties: - code: - type: integer - format: int64 - example: 400 - message: - type: string - example: Unexpected error - required: - - message diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json deleted file mode 100644 index 27e819aa..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json +++ /dev/null @@ -1 +0,0 @@ -{"swagger":"2.0","schemes":["http","https"],"host":"apiv2.clickmeter.com:80","info":{"contact":{"email":"api@clickmeter.com","name":"Api Support","url":"http://www.clickmeter.com/api"},"description":"Api dashboard for ClickMeter API","title":"ClickMeter","version":"v2","x-logo":{"url":"https://s3.amazonaws.com/clickmeter.com/Web/static/cmlogo.svg"},"x-origin":{"format":"swagger","url":"http://api.v2.clickmeter.com.s3.amazonaws.com/docs/api-docs-v2.json","version":"2.0"},"x-providerName":"clickmeter.com"},"securityDefinitions":{"api_key":{"description":"API Key Authentication","in":"header","name":"X-Clickmeter-AuthKey","type":"apiKey"}},"security":[{"api_key":[]}],"paths":{"/account":{"get":{"consumes":[],"deprecated":false,"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.User"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve current account data","tags":["Account"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.User"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.User"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Update current account data","tags":["Account"]}},"/account/domainwhitelist":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.DomainWhitelistEntry]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve list of a domains allowed to redirect in DDU mode","tags":["Account"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The entry to add","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Create an domain entry","tags":["Account"]}},"/account/domainwhitelist/{whitelistId}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the domain to delete","in":"path","name":"whitelistId","required":true,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete an domain entry","tags":["Account"]}},"/account/guests":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve list of a guest","tags":["Account"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Guest object to create","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Guest"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Guest"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Create a guest","tags":["Account"]}},"/account/guests/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve count of guests","tags":["Account"]}},"/account/guests/{guestId}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete a guest","tags":["Account"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Guest"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a guest","tags":["Account"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"},{"description":"Guest object with field updated","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Guest"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Guest"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Update a guest","tags":["Account"]}},"/account/guests/{guestId}/permissions":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"},{"description":"Can be \"datapoint\" or \"group\"","enum":["datapoint","group"],"in":"query","name":"entityType","required":false,"type":"string"},{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Can be \"w\" or \"r\"","enum":["r","w"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Optional id of the datapoint/group entity to filter by","format":"int64","in":"query","name":"entityId","required":false,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Grants.Grant]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve permissions for a guest","tags":["Account"]}},"/account/guests/{guestId}/permissions/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"},{"description":"Can be \"datapoint\" or \"group\"","enum":["datapoint","group"],"in":"query","name":"entityType","required":false,"type":"string"},{"description":"Can be \"w\" or \"r\"","enum":["r","w"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Optional id of the datapoint/group entity to filter by","format":"int64","in":"query","name":"entityId","required":false,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve count of the permissions for a guest","tags":["Account"]}},"/account/guests/{guestId}/{type}/permissions/patch":{"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"},{"description":"Can be \"datapoint\" or \"group\"","enum":["datapoint","group"],"in":"path","name":"type","required":true,"type":"string"},{"description":"The patch permission request","in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.PermissionPatchRequest"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Change the permission on a shared object","tags":["Account"]},"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the guest","format":"int64","in":"path","name":"guestId","required":true,"type":"integer"},{"description":"Can be \"datapoint\" or \"group\"","enum":["datapoint","group"],"in":"path","name":"type","required":true,"type":"string"},{"description":"The patch permission request","in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.PermissionPatchRequest"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Change the permission on a shared object","tags":["Account"]}},"/account/ipblacklist":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.IpBlacklistEntry]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve list of a ip to exclude from event tracking","tags":["Account"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The entry to add","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Create an ip blacklist entry","tags":["Account"]}},"/account/ipblacklist/{blacklistId}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the ip to delete","in":"path","name":"blacklistId","required":true,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete an ip blacklist entry","tags":["Account"]}},"/account/plan":{"get":{"consumes":[],"deprecated":false,"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Plan"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve current account plan","tags":["Account"]}},"/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"},{"description":"","in":"query","name":"onlyFavorites","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this customer for a timeframe","tags":["Aggregated"]}},"/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this customer for a timeframe grouped by some temporal entity (day/week/month)","tags":["Aggregated"]}},"/aggregated/summary/conversions":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of conversion (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about a subset of conversions for a timeframe with conversions data","tags":["Aggregated"]}},"/aggregated/summary/datapoints":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"Type of datapoint (\"tl\"/\"tp\")","enum":["tp","tl"],"in":"query","name":"type","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the datapoint marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Filter by this group id","format":"int64","in":"query","name":"groupId","required":false,"type":"integer"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about a subset of datapoints for a timeframe with datapoints data","tags":["Aggregated"]}},"/aggregated/summary/groups":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of group (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the group marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about a subset of groups for a timeframe with groups data","tags":["Aggregated"]}},"/clickstream":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Filter by this group id (mutually exclusive with \"datapoint\" and \"conversion\")","format":"int64","in":"query","name":"group","required":false,"type":"integer"},{"description":"Filter by this datapoint id (mutually exclusive with \"group\" and \"conversion\")","format":"int64","in":"query","name":"datapoint","required":false,"type":"integer"},{"description":"Filter by this conversion id (mutually exclusive with \"datapoint\" and \"group\")","format":"int64","in":"query","name":"conversion","required":false,"type":"integer"},{"default":50,"description":"Limit results to this number","format":"int32","in":"query","name":"pageSize","required":false,"type":"integer"},{"description":"Filter event type (\"spiders\"/\"uniques\"/\"nonuniques\"/\"conversions\")","enum":["","spiders","uniques","nonuniques","conversions"],"in":"query","name":"filter","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.ClickStream.Hit]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve the latest list of events of this account. Limited to last 100.","tags":["ClickStream"]}},"/conversions":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Status of conversion (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude conversions created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude conversions created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a list of conversions","tags":["Conversions"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The body of the conversion","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Conversions.Conversion"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create a conversion","tags":["Conversions"]}},"/conversions/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of conversion (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this customer for a timeframe related to a subset of conversions grouped by some temporal entity (day/week/month)","tags":["Conversions"]}},"/conversions/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Status of conversion (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude conversions created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude conversions created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a count of conversions","tags":["Conversions"]}},"/conversions/{conversionId}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Delete conversion specified by id","tags":["Conversions"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Conversions.Conversion"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve conversion specified by id","tags":["Conversions"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Updated body of the conversion","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Conversions.Conversion"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Update conversion specified by id","tags":["Conversions"]}},"/conversions/{conversionId}/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Filter by this tag name","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the datapoint marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this conversion for a timeframe","tags":["Conversions"]}},"/conversions/{conversionId}/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this conversion for a timeframe grouped by some temporal entity (day/week/month)","tags":["Conversions"]}},"/conversions/{conversionId}/datapoints":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Type of datapoint (\"tl\"/\"tp\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter by this tag name","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a list of datapoints connected to this conversion","tags":["Conversions"]}},"/conversions/{conversionId}/datapoints/batch/patch":{"put":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Patch requests","in":"body","name":"data","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.PatchBodyBatch"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Modify the association between a conversion and multiple datapoints","tags":["Conversions"]}},"/conversions/{conversionId}/datapoints/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Type of datapoint (\"tl\"/\"tp\")","in":"query","name":"type","required":false,"type":"string"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","in":"query","name":"status","required":false,"type":"string"},{"description":"Filter by this tag name","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a count of datapoints connected to this conversion","tags":["Conversions"]}},"/conversions/{conversionId}/datapoints/patch":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Patch request","in":"body","name":"data","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.ConversionPatchBody"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Modify the association between a conversion and a datapoint","tags":["Conversions"]}},"/conversions/{conversionId}/hits":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Offset where to start from (it's the lastKey field in the response object)","in":"query","name":"offset","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Filter event type (\"spiders\"/\"uniques\"/\"nonuniques\"/\"conversions\")","enum":["spiders","uniques","nonuniques","conversions"],"in":"query","name":"filter","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitListPage"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve the list of events related to this conversion.","tags":["Conversions"]}},"/conversions/{conversionId}/notes":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Patch requests","in":"body","name":"note","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.GenericTextPatch"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Fast patch the \"notes\" field of a conversion","tags":["Conversions"]}},"/conversions/{conversionId}/reports":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the conversion","format":"int64","in":"path","name":"conversionId","required":true,"type":"integer"},{"description":"Type of the report.","enum":["datapoints","groups","browsers","browsersfamilies","platforms","cities","countries","keywords","referrers","convparameters","destinations","languages","params"],"in":"query","name":"type","required":true,"type":"string"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","beginning","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Type of the event you want to filter this report with. By default no filter is applied.","enum":["clicks","views"],"in":"query","name":"hittype","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Tops.Top"}},"401":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a top report connected to this conversion","tags":["Conversions"]}},"/datapoints":{"get":{"consumes":[],"deprecated":false,"parameters":[{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the datapoints associated to the user","tags":["DataPoints"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The body of the datapoint","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create a datapoint","tags":["DataPoints"]}},"/datapoints/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"Type of datapoint (\"tl\"/\"tp\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the datapoint is marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this customer for a timeframe by groups","tags":["DataPoints"]}},"/datapoints/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Type of datapoint (\"tl\"/\"tp\")","enum":["tp","tl"],"in":"query","name":"type","required":true,"type":"string"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the datapoint is marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about all datapoints of this customer for a timeframe grouped by some temporal entity (day/week/month)","tags":["DataPoints"]}},"/datapoints/batch":{"delete":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"A json containing the datapoints to delete.","in":"body","name":"batch","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.DeleteBatch"}}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Delete multiple datapoints","tags":["DataPoints"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"A json containing the datapoints to update.","in":"body","name":"batch","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.DatapointsBatch"}}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Update multiple datapoints","tags":["DataPoints"]},"put":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"A json containing the datapoints to create.","in":"body","name":"batch","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.DatapointsBatch"}}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create multiple datapoints","tags":["DataPoints"]}},"/datapoints/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the datapoints associated to the user","tags":["DataPoints"]}},"/datapoints/{id}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Delete a datapoint","tags":["DataPoints"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Get a datapoint","tags":["DataPoints"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"The body of the datapoint","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Update a datapoint","tags":["DataPoints"]}},"/datapoints/{id}/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this datapoint for a timeframe","tags":["DataPoints"]}},"/datapoints/{id}/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this datapoint for a timeframe grouped by some temporal entity (day/week/month)","tags":["DataPoints"]}},"/datapoints/{id}/favourite":{"put":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Fast switch the \"favourite\" field of a datapoint","tags":["DataPoints"]}},"/datapoints/{id}/hits":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Offset where to start from (it's the lastKey field in the response object)","in":"query","name":"offset","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Filter event type (\"spiders\"/\"uniques\"/\"nonuniques\"/\"conversions\")","enum":["spiders","uniques","nonuniques","conversions"],"in":"query","name":"filter","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitListPage"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve the list of events related to this datapoint.","tags":["DataPoints"]}},"/datapoints/{id}/notes":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Patch requests","in":"body","name":"note","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.GenericTextPatch"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Fast patch the \"notes\" field of a datapoint","tags":["DataPoints"]}},"/datapoints/{id}/reports":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the datapoint","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Type of the report.","enum":["browsers","browsersfamilies","platforms","cities","countries","isps","ips","oss","ossfamilies","keywords","referrers","destinations","languages","params"],"in":"query","name":"type","required":true,"type":"string"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","beginning","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Tops.Top"}},"401":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a top report connected to this datapoint","tags":["DataPoints"]}},"/domains":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"default":"system","description":"Type of domain (\"system\"/\"go\"/\"personal\"/\"dedicated\"). If not specified default is \"system\"","enum":["system","go","personal","dedicated"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Filter domains with this anmen","in":"query","name":"name","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a list of domains","tags":["Domains"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The domain to create","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Domains.Domain"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Create a domain","tags":["Domains"]}},"/domains/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"default":"system","description":"Type of domain (\"system\"/\"go\"/\"personal\"/\"dedicated\"). If not specified default is \"system\"","enum":["system","go","personal","dedicated"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Filter domains with this anmen","in":"query","name":"name","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve count of domains","tags":["Domains"]}},"/domains/{id}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of domain","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete a domain","tags":["Domains"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of domain","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Domains.Domain"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Get a domain","tags":["Domains"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of domain","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"The domain to update","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Domains.Domain"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Update a domain","tags":["Domains"]}},"/groups":{"get":{"consumes":[],"deprecated":false,"parameters":[{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Status of the group","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude groups created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude groups created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"},{"description":"Write permission","in":"query","name":"write","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the groups associated to the user.","tags":["Groups"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The body of the group","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Groups.Group"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create a group","tags":["Groups"]}},"/groups/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"},{"description":"Status of group (\"deleted\"/\"active\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the group is marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this customer for a timeframe by groups","tags":["Groups"]}},"/groups/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of group (\"deleted\"/\"active\")","in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the group is marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["deleted","active"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about all groups of this customer for a timeframe grouped by some temporal entity (day/week/month)","tags":["Groups"]}},"/groups/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Status of the datapoint","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude groups created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude groups created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"},{"description":"Write permission","in":"query","name":"write","required":false,"type":"boolean"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the groups associated to the user.","tags":["Groups"]}},"/groups/{id}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Delete group specified by id","tags":["Groups"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Groups.Group"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Get a group","tags":["Groups"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"The body of the group","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Groups.Group"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Update a group","tags":["Groups"]}},"/groups/{id}/aggregated":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"If using \"yesterday\" or \"today\" timeframe you can ask for the hourly detail","in":"query","name":"hourly","required":false,"type":"boolean"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this group for a timeframe","tags":["Groups"]}},"/groups/{id}/aggregated/list":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"The temporal entity you want to group by (\"week\"/\"month\"). If unspecified is \"day\".","enum":["week","month"],"in":"query","name":"groupBy","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about this group for a timeframe grouped by some temporal entity (day/week/month)","tags":["Groups"]}},"/groups/{id}/aggregated/summary":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Filter by this group id","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["today","yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","last12months","lastyear","currentyear","beginning","custom"],"in":"query","name":"timeFrame","required":true,"type":"string"},{"description":"Type of datapoint (\"tl\"/\"tp\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Status of datapoint (\"deleted\"/\"active\"/\"paused\"/\"spam\")","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tag","required":false,"type":"string"},{"description":"Is the datapoint marked as favourite","in":"query","name":"favourite","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"default":0,"description":"Offset where to start from","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve statistics about a subset of datapoints for a timeframe with datapoints data","tags":["Groups"]}},"/groups/{id}/datapoints":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the datapoints associated to the user in this group.","tags":["Groups"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"The body of the datapoint","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create a datapoint in this group","tags":["Groups"]}},"/groups/{id}/datapoints/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the datapoints associated to the user in this group.","tags":["Groups"]}},"/groups/{id}/favourite":{"put":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Fast switch the \"favourite\" field of a group","tags":["Groups"]}},"/groups/{id}/hits":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Limit results to this number","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Offset where to start from (it's the lastKey field in the response object)","in":"query","name":"offset","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Filter event type (\"spiders\"/\"uniques\"/\"nonuniques\"/\"conversions\")","enum":["spiders","uniques","nonuniques","conversions"],"in":"query","name":"filter","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitListPage"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve the list of events related to this group.","tags":["Groups"]}},"/groups/{id}/notes":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Patch requests","in":"body","name":"note","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.GenericTextPatch"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Fast patch the \"notes\" field of a group","tags":["Groups"]}},"/groups/{id}/reports":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Type of the report.","enum":["browsers","browsersfamilies","platforms","cities","countries","isps","ips","oss","ossfamilies","keywords","referrers","destinations","languages","params"],"in":"query","name":"type","required":true,"type":"string"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","beginning","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Type of the event you want to filter this report with. By default no filter is applied.","enum":["clicks","views"],"in":"query","name":"hittype","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Tops.Top"}},"401":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a top report connected to this group","tags":["Groups"]}},"/hits":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Limit results to this number","format":"int32","in":"query","name":"limit","required":false,"type":"integer"},{"description":"Offset where to start from (it's the lastKey field in the response object)","in":"query","name":"offset","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"},{"description":"Filter event type (\"spiders\"/\"uniques\"/\"nonuniques\"/\"conversions\")","enum":["spiders","uniques","nonuniques","conversions"],"in":"query","name":"filter","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitListPage"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve the list of events related to this account.","tags":["Hits"]}},"/me":{"get":{"consumes":[],"deprecated":false,"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.User"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve current account data","tags":["Me"]}},"/me/plan":{"get":{"consumes":[],"deprecated":false,"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Accounting.Plan"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve current account plan","tags":["Me"]}},"/reports":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Type of the report.","enum":["browsers","browsersfamilies","platforms","cities","countries","isps","ips","oss","ossfamilies","keywords","referrers","destinations","languages","params"],"in":"query","name":"type","required":true,"type":"string"},{"description":"Timeframe of the request. See list at $timeframeList","enum":["yesterday","last7","last30","lastmonth","currentmonth","previousmonth","last90","last120","last180","beginning","custom"],"in":"query","name":"timeframe","required":true,"type":"string"},{"description":"Type of the event you want to filter this report with. By default no filter is applied.","in":"query","name":"hittype","required":false,"type":"string"},{"description":"Filter by this group id (mutually exclusive with \"datapoint\" and \"conversion\")","format":"int64","in":"query","name":"group","required":false,"type":"integer"},{"description":"Filter by this datapoint id (mutually exclusive with \"group\" and \"conversion\")","format":"int64","in":"query","name":"datapoint","required":false,"type":"integer"},{"description":"Filter by this conversion id (mutually exclusive with \"datapoint\" and \"group\")","format":"int64","in":"query","name":"conversion","required":false,"type":"integer"},{"description":"If using a \"custom\" timeFrame you can specify the starting day (YYYYMMDD)","in":"query","name":"fromDay","required":false,"type":"string"},{"description":"If using a \"custom\" timeFrame you can specify the ending day (YYYYMMDD)","in":"query","name":"toDay","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Tops.Top"}},"401":{"description":"Forbidden"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a top report","tags":["Reports"]}},"/retargeting":{"get":{"consumes":[],"deprecated":false,"parameters":[{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the retargeting scripts associated to the user","tags":["Retargeting"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The body of the retargeting script","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Retargeting.RetargetingScript"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Creates a retargeting script","tags":["Retargeting"]}},"/retargeting/count":{"get":{"consumes":[],"deprecated":false,"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve count of retargeting scripts","tags":["Retargeting"]}},"/retargeting/{id}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the retargeting script","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Deletes a retargeting script (and remove associations)","tags":["Retargeting"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"The id of the retargeting script","format":"int64","in":"path","name":"id","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Retargeting.RetargetingScript"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Get a retargeting script object","tags":["Retargeting"]},"post":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The id of the retargeting script","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"The body of the retargeting script","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Retargeting.RetargetingScript"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Updates a retargeting script","tags":["Retargeting"]}},"/retargeting/{id}/datapoints":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the retargeting script","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Field to sort by","in":"query","name":"sortBy","required":false,"type":"string"},{"description":"Direction of sort \"asc\" or \"desc\"","enum":["asc","desc"],"in":"query","name":"sortDirection","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the datapoints associated to the retargeting script.","tags":["Retargeting"]}},"/retargeting/{id}/datapoints/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the group","format":"int64","in":"path","name":"id","required":true,"type":"integer"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"A comma separated list of tags you want to filter with.","in":"query","name":"tags","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Filter fields by favourite status","in":"query","name":"onlyFavorites","required":false,"type":"boolean"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the datapoints associated to the retargeting script.","tags":["Retargeting"]}},"/tags":{"get":{"consumes":[],"deprecated":false,"parameters":[{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Name of the tag","in":"query","name":"name","required":false,"type":"string"},{"description":"Comma separated list of datapoints id to filter by","in":"query","name":"datapoints","required":false,"type":"string"},{"description":"Comma separated list of groups id to filter by","in":"query","name":"groups","required":false,"type":"string"},{"description":"Type of entity related to the tag","enum":["tp","tl","dp","gr"],"in":"query","name":"type","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the groups associated to the user filtered by this tag.","tags":["Tags"]},"post":{"consumes":["application/json","text/json","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"The body of the tag","in":"body","name":"value","required":true,"schema":{"$ref":"#/definitions/Api.Core.Dto.Tags.Tag"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Create a tag","tags":["Tags"]}},"/tags/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Name of the tag","in":"query","name":"name","required":false,"type":"string"},{"description":"Comma separated list of datapoints id to filter by","in":"query","name":"datapoints","required":false,"type":"string"},{"description":"Comma separated list of groups id to filter by","in":"query","name":"groups","required":false,"type":"string"},{"description":"Type of entity related to the tag","enum":["tp","tl","dp","gr"],"in":"query","name":"type","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/System.Object"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the groups associated to the user filtered by this tag.","tags":["Tags"]}},"/tags/{tagId}":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/System.Object"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete a tag","tags":["Tags"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Dto.Tags.Tag"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Retrieve a tag","tags":["Tags"]}},"/tags/{tagId}/datapoints":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete the association of this tag with all datapoints","tags":["Tags"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag.","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the datapoints associated to the user filtered by this tag","tags":["Tags"]}},"/tags/{tagId}/datapoints/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag.","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"description":"Type of the datapoint (\"tp\"/\"tl\")","enum":["tp","tl"],"in":"query","name":"type","required":false,"type":"string"},{"description":"Status of the datapoint","enum":["deleted","active","paused","spam"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude datapoints created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude datapoints created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the datapoints associated to the user filtered by this tag","tags":["Tags"]}},"/tags/{tagId}/datapoints/patch":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"description":"The body patch","in":"body","name":"data","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.PatchBody"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Associate/Deassociate a tag with a datapoint","tags":["Tags"]}},"/tags/{tagId}/groups":{"delete":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Delete the association of this tag with all groups","tags":["Tags"]},"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag.","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"default":0,"description":"Where to start when retrieving elements. Default is 0 if not specified.","format":"int32","in":"query","minLength":0,"name":"offset","required":false,"type":"integer"},{"default":20,"description":"Maximum elements to retrieve. Default to 20 if not specified.","format":"int32","in":"query","maxLength":0,"minLength":0,"name":"limit","required":false,"type":"integer"},{"description":"Status of the datapoint","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude groups created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude groups created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"List of all the groups associated to the user filtered by this tag.","tags":["Tags"]}},"/tags/{tagId}/groups/count":{"get":{"consumes":[],"deprecated":false,"parameters":[{"description":"Id of the tag.","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"description":"Status of the datapoint","enum":["deleted","active"],"in":"query","name":"status","required":false,"type":"string"},{"description":"Filter fields by this pattern","in":"query","name":"textSearch","required":false,"type":"string"},{"description":"Exclude groups created before this date (YYYYMMDD)","in":"query","name":"createdAfter","required":false,"type":"string"},{"description":"Exclude groups created after this date (YYYYMMDD)","in":"query","name":"createdBefore","required":false,"type":"string"}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.CountResponce"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Count the groups associated to the user filtered by this tag","tags":["Tags"]}},"/tags/{tagId}/groups/patch":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"description":"The body patch","in":"body","name":"data","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.PatchBody"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"404":{"description":"Not found"},"500":{"description":"Internal Server Error"}},"summary":"Associate/Deassociate a tag with a group","tags":["Tags"]}},"/tags/{tagId}/name":{"put":{"consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"deprecated":false,"parameters":[{"description":"Id of the tag","format":"int64","in":"path","name":"tagId","required":true,"type":"integer"},{"description":"The body patch","in":"body","name":"data","required":true,"schema":{"$ref":"#/definitions/Api.Core.Requests.GenericTextPatch"}}],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"}},"401":{"description":"Unauthorized"},"500":{"description":"Internal Server Error"}},"summary":"Fast patch a tag name","tags":["Tags"]}}},"definitions":{"Api.Core.Dto.Accounting.ConversionOptions":{"properties":{"hideComCost":{"type":"boolean"},"hideCost":{"type":"boolean"},"hideCount":{"type":"boolean"},"hideParams":{"type":"boolean"},"hideValue":{"type":"boolean"},"percentCommission":{"format":"int32","type":"integer"},"percentValue":{"format":"int32","type":"integer"}},"type":"object"},"Api.Core.Dto.Accounting.DomainWhitelistEntry":{"properties":{"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"Api.Core.Dto.Accounting.ExtendedGrants":{"properties":{"allowAllGrants":{"type":"boolean"},"allowGroupCreation":{"type":"boolean"}},"type":"object"},"Api.Core.Dto.Accounting.Guest":{"properties":{"apiKey":{"type":"string"},"conversionOptions":{"$ref":"#/definitions/Api.Core.Dto.Accounting.ConversionOptions"},"creationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"currentGrant":{"$ref":"#/definitions/Api.Core.Dto.Grants.Grant"},"dateFormat":{"type":"string"},"decimalSeparator":{"type":"string"},"email":{"type":"string"},"extendedGrants":{"$ref":"#/definitions/Api.Core.Dto.Accounting.ExtendedGrants"},"groupGrants":{"format":"int64","type":"integer"},"hitOptions":{"$ref":"#/definitions/Api.Core.Dto.Accounting.HitOptions"},"id":{"format":"int64","type":"integer"},"key":{"type":"string"},"language":{"type":"string"},"loginCount":{"format":"int32","type":"integer"},"name":{"type":"string"},"notes":{"type":"string"},"numberGroupSeparator":{"type":"string"},"password":{"type":"string"},"timeFormat":{"enum":["AmPm","H24"],"type":"string"},"timeZone":{"format":"int32","type":"integer"},"timeframeMinDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"timezonename":{"type":"string"},"tlGrants":{"format":"int64","type":"integer"},"tpGrants":{"format":"int64","type":"integer"},"userName":{"type":"string"}},"type":"object"},"Api.Core.Dto.Accounting.HitOptions":{"properties":{"hideReferrer":{"type":"boolean"}},"type":"object"},"Api.Core.Dto.Accounting.IpBlacklistEntry":{"properties":{"id":{"type":"string"},"ip":{"type":"string"}},"type":"object"},"Api.Core.Dto.Accounting.Plan":{"properties":{"allowedPersonalDomains":{"format":"int32","type":"integer"},"allowedPersonalUrls":{"format":"int32","type":"integer"},"billingPeriodEnd":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"billingPeriodStart":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"bonusMonthlyEvents":{"format":"int64","type":"integer"},"maximumDatapoints":{"format":"int64","type":"integer"},"maximumGuests":{"format":"int64","type":"integer"},"monthlyEvents":{"format":"int64","type":"integer"},"name":{"type":"string"},"price":{"format":"double","type":"number"},"profileId":{"format":"int64","type":"integer"},"recurring":{"type":"boolean"},"recurringPeriod":{"format":"int32","type":"integer"},"usedDatapoints":{"format":"int64","type":"integer"},"usedMonthlyEvents":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Dto.Accounting.User":{"properties":{"boGoVal":{"type":"string"},"bonusClicks":{"format":"int64","type":"integer"},"companyName":{"type":"string"},"companyRole":{"type":"string"},"email":{"type":"string"},"firstName":{"type":"string"},"lastName":{"type":"string"},"phone":{"type":"string"},"redirectOnly":{"type":"boolean"},"registrationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"timeframeMinDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"timezone":{"format":"int32","type":"integer"},"timezonename":{"type":"string"}},"type":"object"},"Api.Core.Dto.Aggregated.AggregatedResult":{"properties":{"activityDay":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"commissionsCost":{"format":"double","type":"number"},"conversionsCost":{"format":"double","type":"number"},"conversionsValue":{"format":"double","type":"number"},"convertedClicks":{"format":"int64","type":"integer"},"entityData":{"$ref":"#/definitions/System.Object"},"entityId":{"type":"string"},"fromDay":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"hourlyBreakDown":{"additionalProperties":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"},"type":"object"},"lastHitDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"spiderHitsCount":{"format":"int64","type":"integer"},"toDay":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"totalClicks":{"format":"int64","type":"integer"},"totalViews":{"format":"int64","type":"integer"},"uniqueClicks":{"format":"int64","type":"integer"},"uniqueConversions":{"format":"int64","type":"integer"},"uniqueViews":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Dto.Aggregated.AggregatedSummaryResult":{"properties":{"count":{"format":"int64","type":"integer"},"limit":{"format":"int32","type":"integer"},"offset":{"format":"int64","type":"integer"},"result":{"items":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"},"type":"array"}},"type":"object"},"Api.Core.Dto.ClickStream.Hit":{"properties":{"accessTime":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"browser":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitBrowserInfo"},"clientLanguage":{"type":"string"},"conversion1":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"conversion2":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"conversion3":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"conversion4":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"conversion5":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"conversions":{"items":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo"},"type":"array"},"entity":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitDatapointInfo"},"ip":{"type":"string"},"isProxy":{"type":"string"},"isSpider":{"type":"string"},"isUnique":{"type":"string"},"location":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitLocationInfo"},"org":{"type":"string"},"os":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitOsInfo"},"queryParams":{"type":"string"},"realDestinationUrl":{"type":"string"},"referer":{"type":"string"},"source":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.HitSource"},"type":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitBrowserInfo":{"properties":{"browserType":{"type":"string"},"familyId":{"format":"int64","type":"integer"},"familyName":{"type":"string"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitConversionInfo":{"properties":{"accessTime":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"comcost":{"format":"double","type":"number"},"cost":{"format":"double","type":"number"},"date":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"deleted":{"type":"boolean"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"},"parameter":{"type":"string"},"value":{"format":"double","type":"number"}},"type":"object"},"Api.Core.Dto.ClickStream.HitDatapointInfo":{"properties":{"creationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"datapointFavourite":{"type":"boolean"},"datapointId":{"format":"int64","type":"integer"},"datapointName":{"type":"string"},"datapointTitle":{"type":"string"},"datapointType":{"type":"string"},"destinationUrl":{"type":"string"},"groupId":{"format":"int64","type":"integer"},"groupName":{"type":"string"},"isABTest":{"type":"boolean"},"isPrivateShared":{"type":"boolean"},"isPublic":{"type":"boolean"},"notes":{"type":"string"},"status":{"enum":["Active","Paused","Abuse","Deleted"],"type":"string"},"tags":{"items":{"$ref":"#/definitions/Api.Core.Dto.Tags.Tag"},"type":"array"},"trackingCode":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitListPage":{"properties":{"hits":{"items":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.Hit"},"type":"array"},"lastKey":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitLocationInfo":{"properties":{"areacode":{"type":"string"},"city":{"type":"string"},"country":{"type":"string"},"latitude":{"format":"double","type":"number"},"longitude":{"format":"double","type":"number"},"metrocode":{"type":"string"},"organization":{"type":"string"},"postalcode":{"type":"string"},"region":{"type":"string"},"regionName":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitOsInfo":{"properties":{"familyId":{"format":"int64","type":"integer"},"familyName":{"type":"string"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"}},"type":"object"},"Api.Core.Dto.ClickStream.HitSource":{"properties":{"id":{"format":"int64","type":"integer"},"name":{"type":"string"},"param":{"type":"string"}},"type":"object"},"Api.Core.Dto.Conversions.Conversion":{"properties":{"code":{"type":"string"},"creationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"deleted":{"type":"boolean"},"description":{"type":"string"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"},"protocol":{"enum":["Http","Https"],"type":"string"},"value":{"format":"double","type":"number"}},"type":"object"},"Api.Core.Dto.Datapoints.BrowserBaseDestinationItem":{"properties":{"emailDestinationUrl":{"type":"string"},"mobileDestinationUrl":{"type":"string"},"spidersDestinationUrl":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.Datapoint":{"properties":{"creationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"encodeIp":{"type":"boolean"},"fifthConversionId":{"format":"int64","type":"integer"},"fifthConversionName":{"type":"string"},"firstConversionId":{"format":"int64","type":"integer"},"firstConversionName":{"type":"string"},"fourthConversionId":{"format":"int64","type":"integer"},"fourthConversionName":{"type":"string"},"groupId":{"format":"int64","type":"integer"},"groupName":{"type":"string"},"id":{"format":"int64","type":"integer"},"isPublic":{"type":"boolean"},"isSecured":{"type":"boolean"},"lightTracking":{"type":"boolean"},"name":{"type":"string"},"notes":{"type":"string"},"preferred":{"type":"boolean"},"redirectOnly":{"type":"boolean"},"secondConversionId":{"format":"int64","type":"integer"},"secondConversionName":{"type":"string"},"status":{"enum":["Active","Paused","Abuse","Deleted"],"type":"string"},"tags":{"items":{"$ref":"#/definitions/Api.Core.Dto.Tags.Tag"},"type":"array"},"thirdConversionId":{"format":"int64","type":"integer"},"thirdConversionName":{"type":"string"},"title":{"type":"string"},"trackingCode":{"type":"string"},"type":{"enum":["TrackingLink","TrackingPixel"],"type":"string"},"typeTL":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.TrackingLinkSpecifics"},"typeTP":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.TrackingPixelSpecifics"},"writePermited":{"type":"boolean"}},"type":"object"},"Api.Core.Dto.Datapoints.DatapointRetargetingInfo":{"properties":{"id":{"format":"int64","type":"integer"},"name":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.MultipleDestinationItem":{"properties":{"url":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.TrackingLinkSpecifics":{"properties":{"appendQuery":{"type":"boolean"},"browserDestinationItem":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.BrowserBaseDestinationItem"},"destinationMode":{"enum":["Simple","RandomDestination","DestinationByLanguage","SpilloverDestination","DynamicUrl","BrowserDestination","DestinationByNation","UniqueDestination","SequentialDestination","WeightedDestination"],"type":"string"},"domainId":{"format":"int32","type":"integer"},"encodeUrl":{"type":"boolean"},"expirationClicks":{"format":"int64","type":"integer"},"expirationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"firstUrl":{"type":"string"},"goDomainId":{"format":"int32","type":"integer"},"hideUrl":{"type":"boolean"},"hideUrlTitle":{"type":"string"},"isABTest":{"type":"boolean"},"password":{"type":"string"},"pauseAfterClicksExpiration":{"type":"boolean"},"pauseAfterDateExpiration":{"type":"boolean"},"randomDestinationItems":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem"},"type":"array"},"redirectType":{"enum":["PermanentRedirect","TemporaryRedirect"],"type":"string"},"referrerClean":{"enum":["None","Clean","Myself"],"type":"string"},"scripts":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.DatapointRetargetingInfo"},"type":"array"},"sequentialDestinationItems":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem"},"type":"array"},"spilloverDestinationItems":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem"},"type":"array"},"uniqueDestinationItem":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.UniqueDestinationItem"},"url":{"type":"string"},"urlAfterClicksExpiration":{"type":"string"},"urlAfterDateExpiration":{"type":"string"},"urlsByLanguage":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.UrlByLanguageItem"},"type":"array"},"urlsByNation":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.UrlByNationItem"},"type":"array"},"weightedDestinationItems":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.WeightedDestinationItem"},"type":"array"}},"type":"object"},"Api.Core.Dto.Datapoints.TrackingPixelSpecifics":{"properties":{"parameterNote":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.UniqueDestinationItem":{"properties":{"firstDestinationUrl":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.UrlByLanguageItem":{"properties":{"languageCode":{"type":"string"},"url":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.UrlByNationItem":{"properties":{"nation":{"type":"string"},"url":{"type":"string"}},"type":"object"},"Api.Core.Dto.Datapoints.WeightedDestinationItem":{"properties":{"url":{"type":"string"},"weight":{"format":"int32","type":"integer"}},"type":"object"},"Api.Core.Dto.Domains.Domain":{"properties":{"custom404":{"type":"string"},"customHomepage":{"type":"string"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"},"type":{"enum":["System","Go","Dedicated","Personal"],"type":"string"}},"type":"object"},"Api.Core.Dto.EntityUriLong":{"properties":{"id":{"format":"int64","type":"integer"},"uri":{"type":"string"}},"type":"object"},"Api.Core.Dto.Grants.Grant":{"properties":{"DatapointType":{"type":"string"},"Entity":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"},"EntityName":{"type":"string"},"EntityType":{"type":"string"},"Type":{"type":"string"}},"type":"object"},"Api.Core.Dto.Groups.Group":{"properties":{"creationDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"deleted":{"type":"boolean"},"id":{"format":"int64","type":"integer"},"isPublic":{"type":"boolean"},"name":{"type":"string"},"notes":{"type":"string"},"preferred":{"type":"boolean"},"redirectOnly":{"type":"boolean"},"tags":{"items":{"$ref":"#/definitions/Api.Core.Dto.Tags.Tag"},"type":"array"},"writePermited":{"type":"boolean"}},"type":"object"},"Api.Core.Dto.Retargeting.RetargetingScript":{"properties":{"id":{"format":"int64","type":"integer"},"name":{"type":"string"},"script":{"type":"string"}},"type":"object"},"Api.Core.Dto.Tags.Tag":{"properties":{"datapoints":{"items":{"format":"int64","type":"integer"},"type":"array"},"groups":{"items":{"format":"int64","type":"integer"},"type":"array"},"id":{"format":"int64","type":"integer"},"name":{"type":"string"}},"type":"object"},"Api.Core.Dto.Tops.Top":{"properties":{"createdAt":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"data":{"items":{"$ref":"#/definitions/Api.Core.Dto.Tops.TopItem"},"type":"array"},"key":{"type":"string"}},"type":"object"},"Api.Core.Dto.Tops.TopItem":{"properties":{"entityData":{"$ref":"#/definitions/System.Object"},"id":{"type":"string"},"lastHitDate":{"description":" (A date in \"YmdHis\" format)","example":"20120203120530","type":"string"},"spiderClicks":{"format":"int64","type":"integer"},"spiderHits":{"format":"int64","type":"integer"},"spiderViews":{"format":"int64","type":"integer"},"totalClicks":{"format":"int64","type":"integer"},"totalCommissionsCost":{"format":"double","type":"number"},"totalConversions":{"format":"int64","type":"integer"},"totalConversionsCost":{"format":"double","type":"number"},"totalConversionsValue":{"format":"double","type":"number"},"totalHits":{"format":"int64","type":"integer"},"totalViews":{"format":"int64","type":"integer"},"uniqueClicks":{"format":"int64","type":"integer"},"uniqueHits":{"format":"int64","type":"integer"},"uniqueViews":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Requests.ConversionPatchBody":{"properties":{"Action":{"type":"string"},"Id":{"format":"int64","type":"integer"},"ReplaceId":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Requests.DatapointsBatch":{"properties":{"List":{"items":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"},"type":"array"}},"type":"object"},"Api.Core.Requests.DeleteBatch":{"properties":{"Entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.EntityUriLong"},"type":"array"}},"type":"object"},"Api.Core.Requests.GenericTextPatch":{"properties":{"Text":{"type":"string"}},"type":"object"},"Api.Core.Requests.PatchBody":{"properties":{"Action":{"type":"string"},"Id":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Requests.PatchBodyBatch":{"properties":{"PatchRequests":{"items":{"$ref":"#/definitions/Api.Core.Requests.PatchBody"},"type":"array"}},"type":"object"},"Api.Core.Requests.PermissionPatchRequest":{"properties":{"Action":{"type":"string"},"Id":{"format":"int64","type":"integer"},"Verb":{"type":"string"}},"type":"object"},"Api.Core.Responses.CountResponce":{"properties":{"count":{"format":"int64","type":"integer"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.DomainWhitelistEntry]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.IpBlacklistEntry]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.Aggregated.AggregatedResult"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Dto.ClickStream.Hit]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.ClickStream.Hit"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Grants.Grant]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Dto.Grants.Grant"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]":{"properties":{"entities":{"items":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"},"type":"array"}},"type":"object"},"Api.Core.Responses.EntityUri[System.Int64]":{"properties":{"id":{"format":"int64","type":"integer"},"uri":{"type":"string"}},"type":"object"},"Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]":{"properties":{"entityData":{"$ref":"#/definitions/Api.Core.Dto.Datapoints.Datapoint"},"errors":{"items":{"$ref":"#/definitions/ClickMeter.Infrastructure.Validation.ValidationFailure"},"type":"array"},"result":{"$ref":"#/definitions/Api.Core.Responses.EntityUri[System.Int64]"},"status":{"type":"string"}},"type":"object"},"ClickMeter.Infrastructure.Validation.ValidationFailure":{"properties":{"code":{"$ref":"#/definitions/System.Object"},"errorMessage":{"type":"string"},"errorValue":{"$ref":"#/definitions/System.Object"},"property":{"type":"string"}},"type":"object"},"System.Object":{"properties":{},"type":"object"}}} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml deleted file mode 100644 index 0ce32b1a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml +++ /dev/null @@ -1,6461 +0,0 @@ -swagger: '2.0' -schemes: - - http - - https -host: 'apiv2.clickmeter.com:80' -info: - contact: - email: api@clickmeter.com - name: Api Support - url: 'http://www.clickmeter.com/api' - description: Api dashboard for ClickMeter API - title: ClickMeter - version: v2 - x-logo: - url: 'https://s3.amazonaws.com/clickmeter.com/Web/static/cmlogo.svg' - x-origin: - format: swagger - url: 'http://api.v2.clickmeter.com.s3.amazonaws.com/docs/api-docs-v2.json' - version: '2.0' - x-providerName: clickmeter.com -securityDefinitions: - api_key: - description: API Key Authentication - in: header - name: X-Clickmeter-AuthKey - type: apiKey -security: - - api_key: [] -paths: - /account: - get: - consumes: [] - deprecated: false - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.User' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve current account data - tags: - - Account - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.User' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.User' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Update current account data - tags: - - Account - /account/domainwhitelist: - get: - consumes: [] - deprecated: false - parameters: - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.DomainWhitelistEntry]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve list of a domains allowed to redirect in DDU mode - tags: - - Account - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The entry to add - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Create an domain entry - tags: - - Account - '/account/domainwhitelist/{whitelistId}': - delete: - consumes: [] - deprecated: false - parameters: - - description: The id of the domain to delete - in: path - name: whitelistId - required: true - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete an domain entry - tags: - - Account - /account/guests: - get: - consumes: [] - deprecated: false - parameters: - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve list of a guest - tags: - - Account - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Guest object to create - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Guest' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Guest' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Create a guest - tags: - - Account - /account/guests/count: - get: - consumes: [] - deprecated: false - parameters: - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve count of guests - tags: - - Account - '/account/guests/{guestId}': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete a guest - tags: - - Account - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Guest' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a guest - tags: - - Account - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - - description: Guest object with field updated - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Guest' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Guest' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Update a guest - tags: - - Account - '/account/guests/{guestId}/permissions': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - - description: 'Can be "datapoint" or "group"' - enum: - - datapoint - - group - in: query - name: entityType - required: false - type: string - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Can be "w" or "r"' - enum: - - r - - w - in: query - name: type - required: false - type: string - - description: Optional id of the datapoint/group entity to filter by - format: int64 - in: query - name: entityId - required: false - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Grants.Grant]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve permissions for a guest - tags: - - Account - '/account/guests/{guestId}/permissions/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - - description: 'Can be "datapoint" or "group"' - enum: - - datapoint - - group - in: query - name: entityType - required: false - type: string - - description: 'Can be "w" or "r"' - enum: - - r - - w - in: query - name: type - required: false - type: string - - description: Optional id of the datapoint/group entity to filter by - format: int64 - in: query - name: entityId - required: false - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve count of the permissions for a guest - tags: - - Account - '/account/guests/{guestId}/{type}/permissions/patch': - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - - description: 'Can be "datapoint" or "group"' - enum: - - datapoint - - group - in: path - name: type - required: true - type: string - - description: The patch permission request - in: body - name: body - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.PermissionPatchRequest' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Change the permission on a shared object - tags: - - Account - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the guest - format: int64 - in: path - name: guestId - required: true - type: integer - - description: 'Can be "datapoint" or "group"' - enum: - - datapoint - - group - in: path - name: type - required: true - type: string - - description: The patch permission request - in: body - name: body - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.PermissionPatchRequest' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Change the permission on a shared object - tags: - - Account - /account/ipblacklist: - get: - consumes: [] - deprecated: false - parameters: - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.IpBlacklistEntry]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve list of a ip to exclude from event tracking - tags: - - Account - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The entry to add - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Create an ip blacklist entry - tags: - - Account - '/account/ipblacklist/{blacklistId}': - delete: - consumes: [] - deprecated: false - parameters: - - description: The id of the ip to delete - in: path - name: blacklistId - required: true - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete an ip blacklist entry - tags: - - Account - /account/plan: - get: - consumes: [] - deprecated: false - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Plan' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve current account plan - tags: - - Account - /aggregated: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - - description: '' - in: query - name: onlyFavorites - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this customer for a timeframe - tags: - - Aggregated - /aggregated/list: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this customer for a timeframe grouped by some temporal entity (day/week/month) - tags: - - Aggregated - /aggregated/summary/conversions: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of conversion ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about a subset of conversions for a timeframe with conversions data - tags: - - Aggregated - /aggregated/summary/datapoints: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'Type of datapoint ("tl"/"tp")' - enum: - - tp - - tl - in: query - name: type - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the datapoint marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Filter by this group id - format: int64 - in: query - name: groupId - required: false - type: integer - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about a subset of datapoints for a timeframe with datapoints data - tags: - - Aggregated - /aggregated/summary/groups: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of group ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the group marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about a subset of groups for a timeframe with groups data - tags: - - Aggregated - /clickstream: - get: - consumes: [] - deprecated: false - parameters: - - description: 'Filter by this group id (mutually exclusive with "datapoint" and "conversion")' - format: int64 - in: query - name: group - required: false - type: integer - - description: 'Filter by this datapoint id (mutually exclusive with "group" and "conversion")' - format: int64 - in: query - name: datapoint - required: false - type: integer - - description: 'Filter by this conversion id (mutually exclusive with "datapoint" and "group")' - format: int64 - in: query - name: conversion - required: false - type: integer - - default: 50 - description: Limit results to this number - format: int32 - in: query - name: pageSize - required: false - type: integer - - description: 'Filter event type ("spiders"/"uniques"/"nonuniques"/"conversions")' - enum: - - '' - - spiders - - uniques - - nonuniques - - conversions - in: query - name: filter - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.ClickStream.Hit]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve the latest list of events of this account. Limited to last 100. - tags: - - ClickStream - /conversions: - get: - consumes: [] - deprecated: false - parameters: - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Status of conversion ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude conversions created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude conversions created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a list of conversions - tags: - - Conversions - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The body of the conversion - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Conversions.Conversion' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create a conversion - tags: - - Conversions - /conversions/aggregated/list: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of conversion ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this customer for a timeframe related to a subset of conversions grouped by some temporal entity (day/week/month) - tags: - - Conversions - /conversions/count: - get: - consumes: [] - deprecated: false - parameters: - - description: 'Status of conversion ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude conversions created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude conversions created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a count of conversions - tags: - - Conversions - '/conversions/{conversionId}': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Delete conversion specified by id - tags: - - Conversions - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Conversions.Conversion' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Retrieve conversion specified by id - tags: - - Conversions - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Updated body of the conversion - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Conversions.Conversion' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Update conversion specified by id - tags: - - Conversions - '/conversions/{conversionId}/aggregated': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: Filter by this tag name - in: query - name: tag - required: false - type: string - - description: Is the datapoint marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this conversion for a timeframe - tags: - - Conversions - '/conversions/{conversionId}/aggregated/list': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this conversion for a timeframe grouped by some temporal entity (day/week/month) - tags: - - Conversions - '/conversions/{conversionId}/datapoints': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Type of datapoint ("tl"/"tp")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: Filter by this tag name - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a list of datapoints connected to this conversion - tags: - - Conversions - '/conversions/{conversionId}/datapoints/batch/patch': - put: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Patch requests - in: body - name: data - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.PatchBodyBatch' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Modify the association between a conversion and multiple datapoints - tags: - - Conversions - '/conversions/{conversionId}/datapoints/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: 'Type of datapoint ("tl"/"tp")' - in: query - name: type - required: false - type: string - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - in: query - name: status - required: false - type: string - - description: Filter by this tag name - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a count of datapoints connected to this conversion - tags: - - Conversions - '/conversions/{conversionId}/datapoints/patch': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Patch request - in: body - name: data - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.ConversionPatchBody' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Modify the association between a conversion and a datapoint - tags: - - Conversions - '/conversions/{conversionId}/hits': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - custom - in: query - name: timeframe - required: true - type: string - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: "Offset where to start from (it's the lastKey field in the response object)" - in: query - name: offset - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Filter event type ("spiders"/"uniques"/"nonuniques"/"conversions")' - enum: - - spiders - - uniques - - nonuniques - - conversions - in: query - name: filter - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitListPage' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve the list of events related to this conversion. - tags: - - Conversions - '/conversions/{conversionId}/notes': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Patch requests - in: body - name: note - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.GenericTextPatch' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: 'Fast patch the "notes" field of a conversion' - tags: - - Conversions - '/conversions/{conversionId}/reports': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the conversion - format: int64 - in: path - name: conversionId - required: true - type: integer - - description: Type of the report. - enum: - - datapoints - - groups - - browsers - - browsersfamilies - - platforms - - cities - - countries - - keywords - - referrers - - convparameters - - destinations - - languages - - params - in: query - name: type - required: true - type: string - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - beginning - - custom - in: query - name: timeframe - required: true - type: string - - description: Type of the event you want to filter this report with. By default no filter is applied. - enum: - - clicks - - views - in: query - name: hittype - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Tops.Top' - '401': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: Retrieve a top report connected to this conversion - tags: - - Conversions - /datapoints: - get: - consumes: [] - deprecated: false - parameters: - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the datapoints associated to the user - tags: - - DataPoints - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The body of the datapoint - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create a datapoint - tags: - - DataPoints - /datapoints/aggregated: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'Type of datapoint ("tl"/"tp")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the datapoint is marked as favourite - in: query - name: favourite - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this customer for a timeframe by groups - tags: - - DataPoints - /datapoints/aggregated/list: - get: - consumes: [] - deprecated: false - parameters: - - description: 'Type of datapoint ("tl"/"tp")' - enum: - - tp - - tl - in: query - name: type - required: true - type: string - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the datapoint is marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about all datapoints of this customer for a timeframe grouped by some temporal entity (day/week/month) - tags: - - DataPoints - /datapoints/batch: - delete: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: A json containing the datapoints to delete. - in: body - name: batch - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.DeleteBatch' - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Delete multiple datapoints - tags: - - DataPoints - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: A json containing the datapoints to update. - in: body - name: batch - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.DatapointsBatch' - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Update multiple datapoints - tags: - - DataPoints - put: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: A json containing the datapoints to create. - in: body - name: batch - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.DatapointsBatch' - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create multiple datapoints - tags: - - DataPoints - /datapoints/count: - get: - consumes: [] - deprecated: false - parameters: - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the datapoints associated to the user - tags: - - DataPoints - '/datapoints/{id}': - delete: - consumes: [] - deprecated: false - parameters: - - description: The id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Delete a datapoint - tags: - - DataPoints - get: - consumes: [] - deprecated: false - parameters: - - description: The id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Get a datapoint - tags: - - DataPoints - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: The body of the datapoint - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Update a datapoint - tags: - - DataPoints - '/datapoints/{id}/aggregated': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this datapoint for a timeframe - tags: - - DataPoints - '/datapoints/{id}/aggregated/list': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this datapoint for a timeframe grouped by some temporal entity (day/week/month) - tags: - - DataPoints - '/datapoints/{id}/favourite': - put: - consumes: [] - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: 'Fast switch the "favourite" field of a datapoint' - tags: - - DataPoints - '/datapoints/{id}/hits': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - custom - in: query - name: timeframe - required: true - type: string - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: "Offset where to start from (it's the lastKey field in the response object)" - in: query - name: offset - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Filter event type ("spiders"/"uniques"/"nonuniques"/"conversions")' - enum: - - spiders - - uniques - - nonuniques - - conversions - in: query - name: filter - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitListPage' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve the list of events related to this datapoint. - tags: - - DataPoints - '/datapoints/{id}/notes': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: Patch requests - in: body - name: note - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.GenericTextPatch' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: 'Fast patch the "notes" field of a datapoint' - tags: - - DataPoints - '/datapoints/{id}/reports': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the datapoint - format: int64 - in: path - name: id - required: true - type: integer - - description: Type of the report. - enum: - - browsers - - browsersfamilies - - platforms - - cities - - countries - - isps - - ips - - oss - - ossfamilies - - keywords - - referrers - - destinations - - languages - - params - in: query - name: type - required: true - type: string - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - beginning - - custom - in: query - name: timeframe - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Tops.Top' - '401': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: Retrieve a top report connected to this datapoint - tags: - - DataPoints - /domains: - get: - consumes: [] - deprecated: false - parameters: - - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - default: system - description: 'Type of domain ("system"/"go"/"personal"/"dedicated"). If not specified default is "system"' - enum: - - system - - go - - personal - - dedicated - in: query - name: type - required: false - type: string - - description: Filter domains with this anmen - in: query - name: name - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a list of domains - tags: - - Domains - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The domain to create - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Domains.Domain' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Create a domain - tags: - - Domains - /domains/count: - get: - consumes: [] - deprecated: false - parameters: - - default: system - description: 'Type of domain ("system"/"go"/"personal"/"dedicated"). If not specified default is "system"' - enum: - - system - - go - - personal - - dedicated - in: query - name: type - required: false - type: string - - description: Filter domains with this anmen - in: query - name: name - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve count of domains - tags: - - Domains - '/domains/{id}': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of domain - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete a domain - tags: - - Domains - get: - consumes: [] - deprecated: false - parameters: - - description: Id of domain - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Domains.Domain' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Get a domain - tags: - - Domains - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of domain - format: int64 - in: path - name: id - required: true - type: integer - - description: The domain to update - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Domains.Domain' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Update a domain - tags: - - Domains - /groups: - get: - consumes: [] - deprecated: false - parameters: - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Status of the group - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude groups created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude groups created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - - description: Write permission - in: query - name: write - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the groups associated to the user. - tags: - - Groups - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The body of the group - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Groups.Group' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create a group - tags: - - Groups - /groups/aggregated: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - - description: 'Status of group ("deleted"/"active")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the group is marked as favourite - in: query - name: favourite - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this customer for a timeframe by groups - tags: - - Groups - /groups/aggregated/list: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of group ("deleted"/"active")' - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the group is marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - deleted - - active - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about all groups of this customer for a timeframe grouped by some temporal entity (day/week/month) - tags: - - Groups - /groups/count: - get: - consumes: [] - deprecated: false - parameters: - - description: Status of the datapoint - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude groups created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude groups created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - - description: Write permission - in: query - name: write - required: false - type: boolean - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the groups associated to the user. - tags: - - Groups - '/groups/{id}': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Delete group specified by id - tags: - - Groups - get: - consumes: [] - deprecated: false - parameters: - - description: The id of the group - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Groups.Group' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Get a group - tags: - - Groups - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: The body of the group - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Groups.Group' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Update a group - tags: - - Groups - '/groups/{id}/aggregated': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'If using "yesterday" or "today" timeframe you can ask for the hourly detail' - in: query - name: hourly - required: false - type: boolean - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this group for a timeframe - tags: - - Groups - '/groups/{id}/aggregated/list': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'The temporal entity you want to group by ("week"/"month"). If unspecified is "day".' - enum: - - week - - month - in: query - name: groupBy - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about this group for a timeframe grouped by some temporal entity (day/week/month) - tags: - - Groups - '/groups/{id}/aggregated/summary': - get: - consumes: [] - deprecated: false - parameters: - - description: Filter by this group id - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - today - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - last12months - - lastyear - - currentyear - - beginning - - custom - in: query - name: timeFrame - required: true - type: string - - description: 'Type of datapoint ("tl"/"tp")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Status of datapoint ("deleted"/"active"/"paused"/"spam")' - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tag - required: false - type: string - - description: Is the datapoint marked as favourite - in: query - name: favourite - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - default: 0 - description: Offset where to start from - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedSummaryResult' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve statistics about a subset of datapoints for a timeframe with datapoints data - tags: - - Groups - '/groups/{id}/datapoints': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the datapoints associated to the user in this group. - tags: - - Groups - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: The body of the datapoint - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create a datapoint in this group - tags: - - Groups - '/groups/{id}/datapoints/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the datapoints associated to the user in this group. - tags: - - Groups - '/groups/{id}/favourite': - put: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: 'Fast switch the "favourite" field of a group' - tags: - - Groups - '/groups/{id}/hits': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - custom - in: query - name: timeframe - required: true - type: string - - description: Limit results to this number - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: "Offset where to start from (it's the lastKey field in the response object)" - in: query - name: offset - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Filter event type ("spiders"/"uniques"/"nonuniques"/"conversions")' - enum: - - spiders - - uniques - - nonuniques - - conversions - in: query - name: filter - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitListPage' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve the list of events related to this group. - tags: - - Groups - '/groups/{id}/notes': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Patch requests - in: body - name: note - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.GenericTextPatch' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: 'Fast patch the "notes" field of a group' - tags: - - Groups - '/groups/{id}/reports': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Type of the report. - enum: - - browsers - - browsersfamilies - - platforms - - cities - - countries - - isps - - ips - - oss - - ossfamilies - - keywords - - referrers - - destinations - - languages - - params - in: query - name: type - required: true - type: string - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - beginning - - custom - in: query - name: timeframe - required: true - type: string - - description: Type of the event you want to filter this report with. By default no filter is applied. - enum: - - clicks - - views - in: query - name: hittype - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Tops.Top' - '401': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: Retrieve a top report connected to this group - tags: - - Groups - /hits: - get: - consumes: [] - deprecated: false - parameters: - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - custom - in: query - name: timeframe - required: true - type: string - - description: Limit results to this number - format: int32 - in: query - name: limit - required: false - type: integer - - description: "Offset where to start from (it's the lastKey field in the response object)" - in: query - name: offset - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - - description: 'Filter event type ("spiders"/"uniques"/"nonuniques"/"conversions")' - enum: - - spiders - - uniques - - nonuniques - - conversions - in: query - name: filter - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitListPage' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve the list of events related to this account. - tags: - - Hits - /me: - get: - consumes: [] - deprecated: false - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.User' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve current account data - tags: - - Me - /me/plan: - get: - consumes: [] - deprecated: false - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Accounting.Plan' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve current account plan - tags: - - Me - /reports: - get: - consumes: [] - deprecated: false - parameters: - - description: Type of the report. - enum: - - browsers - - browsersfamilies - - platforms - - cities - - countries - - isps - - ips - - oss - - ossfamilies - - keywords - - referrers - - destinations - - languages - - params - in: query - name: type - required: true - type: string - - description: Timeframe of the request. See list at $timeframeList - enum: - - yesterday - - last7 - - last30 - - lastmonth - - currentmonth - - previousmonth - - last90 - - last120 - - last180 - - beginning - - custom - in: query - name: timeframe - required: true - type: string - - description: Type of the event you want to filter this report with. By default no filter is applied. - in: query - name: hittype - required: false - type: string - - description: 'Filter by this group id (mutually exclusive with "datapoint" and "conversion")' - format: int64 - in: query - name: group - required: false - type: integer - - description: 'Filter by this datapoint id (mutually exclusive with "group" and "conversion")' - format: int64 - in: query - name: datapoint - required: false - type: integer - - description: 'Filter by this conversion id (mutually exclusive with "datapoint" and "group")' - format: int64 - in: query - name: conversion - required: false - type: integer - - description: 'If using a "custom" timeFrame you can specify the starting day (YYYYMMDD)' - in: query - name: fromDay - required: false - type: string - - description: 'If using a "custom" timeFrame you can specify the ending day (YYYYMMDD)' - in: query - name: toDay - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Tops.Top' - '401': - description: Forbidden - '404': - description: Not found - '500': - description: Internal Server Error - summary: Retrieve a top report - tags: - - Reports - /retargeting: - get: - consumes: [] - deprecated: false - parameters: - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the retargeting scripts associated to the user - tags: - - Retargeting - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The body of the retargeting script - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Retargeting.RetargetingScript' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Creates a retargeting script - tags: - - Retargeting - /retargeting/count: - get: - consumes: [] - deprecated: false - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve count of retargeting scripts - tags: - - Retargeting - '/retargeting/{id}': - delete: - consumes: [] - deprecated: false - parameters: - - description: The id of the retargeting script - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Deletes a retargeting script (and remove associations) - tags: - - Retargeting - get: - consumes: [] - deprecated: false - parameters: - - description: The id of the retargeting script - format: int64 - in: path - name: id - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Retargeting.RetargetingScript' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Get a retargeting script object - tags: - - Retargeting - post: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The id of the retargeting script - format: int64 - in: path - name: id - required: true - type: integer - - description: The body of the retargeting script - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Retargeting.RetargetingScript' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Updates a retargeting script - tags: - - Retargeting - '/retargeting/{id}/datapoints': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the retargeting script - format: int64 - in: path - name: id - required: true - type: integer - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Field to sort by - in: query - name: sortBy - required: false - type: string - - description: 'Direction of sort "asc" or "desc"' - enum: - - asc - - desc - in: query - name: sortDirection - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the datapoints associated to the retargeting script. - tags: - - Retargeting - '/retargeting/{id}/datapoints/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the group - format: int64 - in: path - name: id - required: true - type: integer - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: A comma separated list of tags you want to filter with. - in: query - name: tags - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Filter fields by favourite status - in: query - name: onlyFavorites - required: false - type: boolean - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the datapoints associated to the retargeting script. - tags: - - Retargeting - /tags: - get: - consumes: [] - deprecated: false - parameters: - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Name of the tag - in: query - name: name - required: false - type: string - - description: Comma separated list of datapoints id to filter by - in: query - name: datapoints - required: false - type: string - - description: Comma separated list of groups id to filter by - in: query - name: groups - required: false - type: string - - description: Type of entity related to the tag - enum: - - tp - - tl - - dp - - gr - in: query - name: type - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the groups associated to the user filtered by this tag. - tags: - - Tags - post: - consumes: - - application/json - - text/json - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: The body of the tag - in: body - name: value - required: true - schema: - $ref: '#/definitions/Api.Core.Dto.Tags.Tag' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Create a tag - tags: - - Tags - /tags/count: - get: - consumes: [] - deprecated: false - parameters: - - description: Name of the tag - in: query - name: name - required: false - type: string - - description: Comma separated list of datapoints id to filter by - in: query - name: datapoints - required: false - type: string - - description: Comma separated list of groups id to filter by - in: query - name: groups - required: false - type: string - - description: Type of entity related to the tag - enum: - - tp - - tl - - dp - - gr - in: query - name: type - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/System.Object' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the groups associated to the user filtered by this tag. - tags: - - Tags - '/tags/{tagId}': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/System.Object' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete a tag - tags: - - Tags - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Dto.Tags.Tag' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Retrieve a tag - tags: - - Tags - '/tags/{tagId}/datapoints': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete the association of this tag with all datapoints - tags: - - Tags - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag. - format: int64 - in: path - name: tagId - required: true - type: integer - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the datapoints associated to the user filtered by this tag - tags: - - Tags - '/tags/{tagId}/datapoints/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag. - format: int64 - in: path - name: tagId - required: true - type: integer - - description: 'Type of the datapoint ("tp"/"tl")' - enum: - - tp - - tl - in: query - name: type - required: false - type: string - - description: Status of the datapoint - enum: - - deleted - - active - - paused - - spam - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude datapoints created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude datapoints created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the datapoints associated to the user filtered by this tag - tags: - - Tags - '/tags/{tagId}/datapoints/patch': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - - description: The body patch - in: body - name: data - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.PatchBody' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Associate/Deassociate a tag with a datapoint - tags: - - Tags - '/tags/{tagId}/groups': - delete: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Delete the association of this tag with all groups - tags: - - Tags - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag. - format: int64 - in: path - name: tagId - required: true - type: integer - - default: 0 - description: Where to start when retrieving elements. Default is 0 if not specified. - format: int32 - in: query - minLength: 0 - name: offset - required: false - type: integer - - default: 20 - description: Maximum elements to retrieve. Default to 20 if not specified. - format: int32 - in: query - maxLength: 0 - minLength: 0 - name: limit - required: false - type: integer - - description: Status of the datapoint - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude groups created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude groups created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: List of all the groups associated to the user filtered by this tag. - tags: - - Tags - '/tags/{tagId}/groups/count': - get: - consumes: [] - deprecated: false - parameters: - - description: Id of the tag. - format: int64 - in: path - name: tagId - required: true - type: integer - - description: Status of the datapoint - enum: - - deleted - - active - in: query - name: status - required: false - type: string - - description: Filter fields by this pattern - in: query - name: textSearch - required: false - type: string - - description: Exclude groups created before this date (YYYYMMDD) - in: query - name: createdAfter - required: false - type: string - - description: Exclude groups created after this date (YYYYMMDD) - in: query - name: createdBefore - required: false - type: string - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.CountResponce' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Count the groups associated to the user filtered by this tag - tags: - - Tags - '/tags/{tagId}/groups/patch': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - - description: The body patch - in: body - name: data - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.PatchBody' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '404': - description: Not found - '500': - description: Internal Server Error - summary: Associate/Deassociate a tag with a group - tags: - - Tags - '/tags/{tagId}/name': - put: - consumes: - - application/json - - text/json - - application/xml - - text/xml - - application/x-www-form-urlencoded - deprecated: false - parameters: - - description: Id of the tag - format: int64 - in: path - name: tagId - required: true - type: integer - - description: The body patch - in: body - name: data - required: true - schema: - $ref: '#/definitions/Api.Core.Requests.GenericTextPatch' - produces: - - application/json - - text/json - - application/xml - - text/xml - responses: - '200': - description: '' - schema: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - '401': - description: Unauthorized - '500': - description: Internal Server Error - summary: Fast patch a tag name - tags: - - Tags -definitions: - Api.Core.Dto.Accounting.ConversionOptions: - properties: - hideComCost: - type: boolean - hideCost: - type: boolean - hideCount: - type: boolean - hideParams: - type: boolean - hideValue: - type: boolean - percentCommission: - format: int32 - type: integer - percentValue: - format: int32 - type: integer - type: object - Api.Core.Dto.Accounting.DomainWhitelistEntry: - properties: - id: - type: string - name: - type: string - type: object - Api.Core.Dto.Accounting.ExtendedGrants: - properties: - allowAllGrants: - type: boolean - allowGroupCreation: - type: boolean - type: object - Api.Core.Dto.Accounting.Guest: - properties: - apiKey: - type: string - conversionOptions: - $ref: '#/definitions/Api.Core.Dto.Accounting.ConversionOptions' - creationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - currentGrant: - $ref: '#/definitions/Api.Core.Dto.Grants.Grant' - dateFormat: - type: string - decimalSeparator: - type: string - email: - type: string - extendedGrants: - $ref: '#/definitions/Api.Core.Dto.Accounting.ExtendedGrants' - groupGrants: - format: int64 - type: integer - hitOptions: - $ref: '#/definitions/Api.Core.Dto.Accounting.HitOptions' - id: - format: int64 - type: integer - key: - type: string - language: - type: string - loginCount: - format: int32 - type: integer - name: - type: string - notes: - type: string - numberGroupSeparator: - type: string - password: - type: string - timeFormat: - enum: - - AmPm - - H24 - type: string - timeZone: - format: int32 - type: integer - timeframeMinDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - timezonename: - type: string - tlGrants: - format: int64 - type: integer - tpGrants: - format: int64 - type: integer - userName: - type: string - type: object - Api.Core.Dto.Accounting.HitOptions: - properties: - hideReferrer: - type: boolean - type: object - Api.Core.Dto.Accounting.IpBlacklistEntry: - properties: - id: - type: string - ip: - type: string - type: object - Api.Core.Dto.Accounting.Plan: - properties: - allowedPersonalDomains: - format: int32 - type: integer - allowedPersonalUrls: - format: int32 - type: integer - billingPeriodEnd: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - billingPeriodStart: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - bonusMonthlyEvents: - format: int64 - type: integer - maximumDatapoints: - format: int64 - type: integer - maximumGuests: - format: int64 - type: integer - monthlyEvents: - format: int64 - type: integer - name: - type: string - price: - format: double - type: number - profileId: - format: int64 - type: integer - recurring: - type: boolean - recurringPeriod: - format: int32 - type: integer - usedDatapoints: - format: int64 - type: integer - usedMonthlyEvents: - format: int64 - type: integer - type: object - Api.Core.Dto.Accounting.User: - properties: - boGoVal: - type: string - bonusClicks: - format: int64 - type: integer - companyName: - type: string - companyRole: - type: string - email: - type: string - firstName: - type: string - lastName: - type: string - phone: - type: string - redirectOnly: - type: boolean - registrationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - timeframeMinDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - timezone: - format: int32 - type: integer - timezonename: - type: string - type: object - Api.Core.Dto.Aggregated.AggregatedResult: - properties: - activityDay: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - commissionsCost: - format: double - type: number - conversionsCost: - format: double - type: number - conversionsValue: - format: double - type: number - convertedClicks: - format: int64 - type: integer - entityData: - $ref: '#/definitions/System.Object' - entityId: - type: string - fromDay: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - hourlyBreakDown: - additionalProperties: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - type: object - lastHitDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - spiderHitsCount: - format: int64 - type: integer - toDay: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - totalClicks: - format: int64 - type: integer - totalViews: - format: int64 - type: integer - uniqueClicks: - format: int64 - type: integer - uniqueConversions: - format: int64 - type: integer - uniqueViews: - format: int64 - type: integer - type: object - Api.Core.Dto.Aggregated.AggregatedSummaryResult: - properties: - count: - format: int64 - type: integer - limit: - format: int32 - type: integer - offset: - format: int64 - type: integer - result: - items: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - type: array - type: object - Api.Core.Dto.ClickStream.Hit: - properties: - accessTime: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - browser: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitBrowserInfo' - clientLanguage: - type: string - conversion1: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - conversion2: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - conversion3: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - conversion4: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - conversion5: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - conversions: - items: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitConversionInfo' - type: array - entity: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitDatapointInfo' - ip: - type: string - isProxy: - type: string - isSpider: - type: string - isUnique: - type: string - location: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitLocationInfo' - org: - type: string - os: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitOsInfo' - queryParams: - type: string - realDestinationUrl: - type: string - referer: - type: string - source: - $ref: '#/definitions/Api.Core.Dto.ClickStream.HitSource' - type: - type: string - type: object - Api.Core.Dto.ClickStream.HitBrowserInfo: - properties: - browserType: - type: string - familyId: - format: int64 - type: integer - familyName: - type: string - id: - format: int64 - type: integer - name: - type: string - type: object - Api.Core.Dto.ClickStream.HitConversionInfo: - properties: - accessTime: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - comcost: - format: double - type: number - cost: - format: double - type: number - date: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - deleted: - type: boolean - id: - format: int64 - type: integer - name: - type: string - parameter: - type: string - value: - format: double - type: number - type: object - Api.Core.Dto.ClickStream.HitDatapointInfo: - properties: - creationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - datapointFavourite: - type: boolean - datapointId: - format: int64 - type: integer - datapointName: - type: string - datapointTitle: - type: string - datapointType: - type: string - destinationUrl: - type: string - groupId: - format: int64 - type: integer - groupName: - type: string - isABTest: - type: boolean - isPrivateShared: - type: boolean - isPublic: - type: boolean - notes: - type: string - status: - enum: - - Active - - Paused - - Abuse - - Deleted - type: string - tags: - items: - $ref: '#/definitions/Api.Core.Dto.Tags.Tag' - type: array - trackingCode: - type: string - type: object - Api.Core.Dto.ClickStream.HitListPage: - properties: - hits: - items: - $ref: '#/definitions/Api.Core.Dto.ClickStream.Hit' - type: array - lastKey: - type: string - type: object - Api.Core.Dto.ClickStream.HitLocationInfo: - properties: - areacode: - type: string - city: - type: string - country: - type: string - latitude: - format: double - type: number - longitude: - format: double - type: number - metrocode: - type: string - organization: - type: string - postalcode: - type: string - region: - type: string - regionName: - type: string - type: object - Api.Core.Dto.ClickStream.HitOsInfo: - properties: - familyId: - format: int64 - type: integer - familyName: - type: string - id: - format: int64 - type: integer - name: - type: string - type: object - Api.Core.Dto.ClickStream.HitSource: - properties: - id: - format: int64 - type: integer - name: - type: string - param: - type: string - type: object - Api.Core.Dto.Conversions.Conversion: - properties: - code: - type: string - creationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - deleted: - type: boolean - description: - type: string - id: - format: int64 - type: integer - name: - type: string - protocol: - enum: - - Http - - Https - type: string - value: - format: double - type: number - type: object - Api.Core.Dto.Datapoints.BrowserBaseDestinationItem: - properties: - emailDestinationUrl: - type: string - mobileDestinationUrl: - type: string - spidersDestinationUrl: - type: string - type: object - Api.Core.Dto.Datapoints.Datapoint: - properties: - creationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - encodeIp: - type: boolean - fifthConversionId: - format: int64 - type: integer - fifthConversionName: - type: string - firstConversionId: - format: int64 - type: integer - firstConversionName: - type: string - fourthConversionId: - format: int64 - type: integer - fourthConversionName: - type: string - groupId: - format: int64 - type: integer - groupName: - type: string - id: - format: int64 - type: integer - isPublic: - type: boolean - isSecured: - type: boolean - lightTracking: - type: boolean - name: - type: string - notes: - type: string - preferred: - type: boolean - redirectOnly: - type: boolean - secondConversionId: - format: int64 - type: integer - secondConversionName: - type: string - status: - enum: - - Active - - Paused - - Abuse - - Deleted - type: string - tags: - items: - $ref: '#/definitions/Api.Core.Dto.Tags.Tag' - type: array - thirdConversionId: - format: int64 - type: integer - thirdConversionName: - type: string - title: - type: string - trackingCode: - type: string - type: - enum: - - TrackingLink - - TrackingPixel - type: string - typeTL: - $ref: '#/definitions/Api.Core.Dto.Datapoints.TrackingLinkSpecifics' - typeTP: - $ref: '#/definitions/Api.Core.Dto.Datapoints.TrackingPixelSpecifics' - writePermited: - type: boolean - type: object - Api.Core.Dto.Datapoints.DatapointRetargetingInfo: - properties: - id: - format: int64 - type: integer - name: - type: string - type: object - Api.Core.Dto.Datapoints.MultipleDestinationItem: - properties: - url: - type: string - type: object - Api.Core.Dto.Datapoints.TrackingLinkSpecifics: - properties: - appendQuery: - type: boolean - browserDestinationItem: - $ref: '#/definitions/Api.Core.Dto.Datapoints.BrowserBaseDestinationItem' - destinationMode: - enum: - - Simple - - RandomDestination - - DestinationByLanguage - - SpilloverDestination - - DynamicUrl - - BrowserDestination - - DestinationByNation - - UniqueDestination - - SequentialDestination - - WeightedDestination - type: string - domainId: - format: int32 - type: integer - encodeUrl: - type: boolean - expirationClicks: - format: int64 - type: integer - expirationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - firstUrl: - type: string - goDomainId: - format: int32 - type: integer - hideUrl: - type: boolean - hideUrlTitle: - type: string - isABTest: - type: boolean - password: - type: string - pauseAfterClicksExpiration: - type: boolean - pauseAfterDateExpiration: - type: boolean - randomDestinationItems: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem' - type: array - redirectType: - enum: - - PermanentRedirect - - TemporaryRedirect - type: string - referrerClean: - enum: - - None - - Clean - - Myself - type: string - scripts: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.DatapointRetargetingInfo' - type: array - sequentialDestinationItems: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem' - type: array - spilloverDestinationItems: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.MultipleDestinationItem' - type: array - uniqueDestinationItem: - $ref: '#/definitions/Api.Core.Dto.Datapoints.UniqueDestinationItem' - url: - type: string - urlAfterClicksExpiration: - type: string - urlAfterDateExpiration: - type: string - urlsByLanguage: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.UrlByLanguageItem' - type: array - urlsByNation: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.UrlByNationItem' - type: array - weightedDestinationItems: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.WeightedDestinationItem' - type: array - type: object - Api.Core.Dto.Datapoints.TrackingPixelSpecifics: - properties: - parameterNote: - type: string - type: object - Api.Core.Dto.Datapoints.UniqueDestinationItem: - properties: - firstDestinationUrl: - type: string - type: object - Api.Core.Dto.Datapoints.UrlByLanguageItem: - properties: - languageCode: - type: string - url: - type: string - type: object - Api.Core.Dto.Datapoints.UrlByNationItem: - properties: - nation: - type: string - url: - type: string - type: object - Api.Core.Dto.Datapoints.WeightedDestinationItem: - properties: - url: - type: string - weight: - format: int32 - type: integer - type: object - Api.Core.Dto.Domains.Domain: - properties: - custom404: - type: string - customHomepage: - type: string - id: - format: int64 - type: integer - name: - type: string - type: - enum: - - System - - Go - - Dedicated - - Personal - type: string - type: object - Api.Core.Dto.EntityUriLong: - properties: - id: - format: int64 - type: integer - uri: - type: string - type: object - Api.Core.Dto.Grants.Grant: - properties: - DatapointType: - type: string - Entity: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - EntityName: - type: string - EntityType: - type: string - Type: - type: string - type: object - Api.Core.Dto.Groups.Group: - properties: - creationDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - deleted: - type: boolean - id: - format: int64 - type: integer - isPublic: - type: boolean - name: - type: string - notes: - type: string - preferred: - type: boolean - redirectOnly: - type: boolean - tags: - items: - $ref: '#/definitions/Api.Core.Dto.Tags.Tag' - type: array - writePermited: - type: boolean - type: object - Api.Core.Dto.Retargeting.RetargetingScript: - properties: - id: - format: int64 - type: integer - name: - type: string - script: - type: string - type: object - Api.Core.Dto.Tags.Tag: - properties: - datapoints: - items: - format: int64 - type: integer - type: array - groups: - items: - format: int64 - type: integer - type: array - id: - format: int64 - type: integer - name: - type: string - type: object - Api.Core.Dto.Tops.Top: - properties: - createdAt: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - data: - items: - $ref: '#/definitions/Api.Core.Dto.Tops.TopItem' - type: array - key: - type: string - type: object - Api.Core.Dto.Tops.TopItem: - properties: - entityData: - $ref: '#/definitions/System.Object' - id: - type: string - lastHitDate: - description: ' (A date in "YmdHis" format)' - example: '20120203120530' - type: string - spiderClicks: - format: int64 - type: integer - spiderHits: - format: int64 - type: integer - spiderViews: - format: int64 - type: integer - totalClicks: - format: int64 - type: integer - totalCommissionsCost: - format: double - type: number - totalConversions: - format: int64 - type: integer - totalConversionsCost: - format: double - type: number - totalConversionsValue: - format: double - type: number - totalHits: - format: int64 - type: integer - totalViews: - format: int64 - type: integer - uniqueClicks: - format: int64 - type: integer - uniqueHits: - format: int64 - type: integer - uniqueViews: - format: int64 - type: integer - type: object - Api.Core.Requests.ConversionPatchBody: - properties: - Action: - type: string - Id: - format: int64 - type: integer - ReplaceId: - format: int64 - type: integer - type: object - Api.Core.Requests.DatapointsBatch: - properties: - List: - items: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - type: array - type: object - Api.Core.Requests.DeleteBatch: - properties: - Entities: - items: - $ref: '#/definitions/Api.Core.Dto.EntityUriLong' - type: array - type: object - Api.Core.Requests.GenericTextPatch: - properties: - Text: - type: string - type: object - Api.Core.Requests.PatchBody: - properties: - Action: - type: string - Id: - format: int64 - type: integer - type: object - Api.Core.Requests.PatchBodyBatch: - properties: - PatchRequests: - items: - $ref: '#/definitions/Api.Core.Requests.PatchBody' - type: array - type: object - Api.Core.Requests.PermissionPatchRequest: - properties: - Action: - type: string - Id: - format: int64 - type: integer - Verb: - type: string - type: object - Api.Core.Responses.CountResponce: - properties: - count: - format: int64 - type: integer - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.DomainWhitelistEntry]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Dto.Accounting.DomainWhitelistEntry' - type: array - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Accounting.IpBlacklistEntry]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Dto.Accounting.IpBlacklistEntry' - type: array - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Aggregated.AggregatedResult]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Dto.Aggregated.AggregatedResult' - type: array - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Dto.ClickStream.Hit]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Dto.ClickStream.Hit' - type: array - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Dto.Grants.Grant]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Dto.Grants.Grant' - type: array - type: object - 'Api.Core.Responses.EntitiesResponse[Api.Core.Responses.EntityUri[System.Int64]]': - properties: - entities: - items: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - type: array - type: object - 'Api.Core.Responses.EntityUri[System.Int64]': - properties: - id: - format: int64 - type: integer - uri: - type: string - type: object - 'Api.Core.Responses.ModifyBatchItemResponce[Api.Core.Dto.Datapoints.Datapoint,System.Int64]': - properties: - entityData: - $ref: '#/definitions/Api.Core.Dto.Datapoints.Datapoint' - errors: - items: - $ref: '#/definitions/ClickMeter.Infrastructure.Validation.ValidationFailure' - type: array - result: - $ref: '#/definitions/Api.Core.Responses.EntityUri[System.Int64]' - status: - type: string - type: object - ClickMeter.Infrastructure.Validation.ValidationFailure: - properties: - code: - $ref: '#/definitions/System.Object' - errorMessage: - type: string - errorValue: - $ref: '#/definitions/System.Object' - property: - type: string - type: object - System.Object: - properties: {} - type: object diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json deleted file mode 100644 index d636d458..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Swagger Petstore", - "contact": { - "name": "wordnik api team", - "url": "http://developer.wordnik.com" - }, - "license": { - "name": "Creative Commons 4.0 International", - "url": "http://creativecommons.org/licenses/by/4.0/" - } - }, - "host": "petstore.swagger.wordnik.com", - "basePath": "/api", - "schemes": [ - "http" - ], - "paths": { - "/pets": { - "get": { - "tags": [ "Pet Operations" ], - "summary": "finds pets in the system", - "responses": { - "200": { - "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref": "NotCorrectRef" - } - }, - "headers": { - "x-expires": { - "type": "string" - } - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "NotCorrectRef" - } - } - } - } - } - }, - "definitions": { - "Pet": { - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "tag": { - "type": "string" - } - } - }, - "Error": { - "required": [ - "code", - "message" - ], - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - } - } - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json deleted file mode 100644 index f3908d52..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "2.1.0", - "title": "Missing Item API" - }, - "host": "item.com", - "basePath": "/missing/ref", - "schemes": [ - "http" - ], - "paths": { - "/employees": { - "get": { - "operationId": "LIST-Employees", - "summary": "List Employee Types", - "responses": { - "200": { - "description": "", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/employees-output" - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json deleted file mode 100644 index 551449ee..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "input": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": "Continue On Error" - }, - "paths": { - "/todos": { - "get": { - "responses": { - "200": { - "description": "List Todos", - "schema": { - "type": "array", - "items": { - "$ref": "#/input/definitions/todo-full" - } - } - }, - "404": { - "$ref": "#/input/responses/404" - } - } - } - } - }, - "definitions": { - "todo-partial": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "completed": { - "type": "boolean" - } - } - }, - "todo-full": { - "allOf": [ - { - "$ref": "#/input/definitions/todo-partial" - }, - { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "completed_at": { - "type": "string" - }, - "created_at": { - "type": "string" - }, - "updated_at": { - "type": "string" - } - } - } - ] - } - } - }, - "expected": { - "swagger": "2.0", - "info": { - "title": "Continue On Error", - "version": "1.0" - }, - "paths": { - "/todos": { - "get": { - "responses": { - "200": { - "description": "List Todos", - "schema": { - "type": "array", - "items": { - "allOf": [ - { - "type": "object", - "properties": { - "completed": { - "type": "boolean" - }, - "name": { - "type": "string" - } - } - }, - { - "type": "object", - "properties": { - "completed_at": { - "type": "string" - }, - "created_at": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "updated_at": { - "type": "string" - } - } - } - ] - } - } - }, - "404": {} - } - } - } - }, - "definitions": { - "todo-full": { - "allOf": [ - { - "type": "object", - "properties": { - "completed": { - "type": "boolean" - }, - "name": { - "type": "string" - } - } - }, - { - "type": "object", - "properties": { - "completed_at": { - "type": "string" - }, - "created_at": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "updated_at": { - "type": "string" - } - } - } - ] - }, - "todo-partial": { - "type": "object", - "properties": { - "completed": { - "type": "boolean" - }, - "name": { - "type": "string" - } - } - } - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json deleted file mode 100644 index 5a2a9f3d..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json +++ /dev/null @@ -1,124 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "title": "Swagger Sample", - "description": "Sample API Playground.", - "version": "1.0.0" - }, - "basePath": "/v1", - "schemes": [ - "http" - ], - "consumes": [ - "application/vdn.sample.v1+json" - ], - "produces": [ - "application/vdn.sample.v1+json" - ], - "paths": { - "/books": { - "get": { - "summary": "List all books", - "operationId": "listBooks", - "tags": [ - "books" - ], - "responses": { - "200": { - "headers": { - "Link": { - "type": "string" - } - }, - "description": "An array of books", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Book" - } - } - }, - "default": { - "description": "generic error response", - "schema": { - "$ref": "#/definitions/Error" - } - } - } - } - } - }, - "definitions": { - "Store": { - "type": "object", - "properties": { - "title": { - "type": "string", - "example": "Book Shop" - }, - "categories": { - "type": "array", - "items": { - "$ref": "#/definitions/Category" - } - } - } - }, - "Category": { - "type": "object", - "properties": { - "title": { - "type": "string", - "example": "Drama" - }, - "books": { - "type": "array", - "items": { - "$ref": "#/definitions/Book" - } - } - } - }, - "Book": { - "type": "object", - "required": [ - "title", - "summary" - ], - "properties": { - "title": { - "type": "string", - "example": "Winnie the Pooh" - }, - "summary": { - "type": "string", - "example": "Famous children's book" - }, - "related_books": { - "type": "array", - "items": { - "$ref": "#/definitions/Book" - } - } - } - }, - "Error": { - "type": "object", - "readOnly": true, - "properties": { - "code": { - "type": "integer", - "format": "int64", - "example": 400 - }, - "message": { - "type": "string", - "example": "Unexpected error" - } - }, - "required": [ - "message" - ] - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/params.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/params.json deleted file mode 100644 index 76e7b418..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/params.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "parameters": { - "id": { - "type": "integer", - "format": "int64", - "in": "path", - "required": true - }, - "tag": { - "type": "string", - "in": "query", - "required": false - }, - "query": { - "$ref": "#/parameters/tag" - } - }, - "paths": { - "/cars/{id}": { - "parameters": [ - { "$ref": "#/parameters/id"} - ] - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json deleted file mode 100644 index e53a412e..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json +++ /dev/null @@ -1,127 +0,0 @@ -{ - "definitions": { - "car": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "make": { - "type": "string" - }, - "brand": { - "$ref": "#/definitions/brand" - } - } - }, - "tag": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "value": { - "type": "string" - } - } - }, - "brand": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - } - } - }, - "truck": { - "$ref": "#/definitions/car" - }, - "batch": { - "items": { - "$ref": "#/definitions/brand" - } - }, - "batch2": { - "items": [ - { - "$ref": "#/definitions/brand" - }, - { - "$ref": "#/definitions/tag" - } - ] - }, - "allofBoth": { - "allOf": [ - { - "$ref": "#/definitions/brand" - }, - { - "$ref": "#/definitions/tag" - } - ] - }, - "anyofBoth": { - "anyOf": [ - { - "$ref": "#/definitions/brand" - }, - { - "$ref": "#/definitions/tag" - } - ] - }, - "oneofBoth": { - "oneOf": [ - { - "$ref": "#/definitions/brand" - }, - { - "$ref": "#/definitions/tag" - } - ] - }, - "notSomething": { - "not": { - "$ref": "#/definitions/tag" - } - }, - "withAdditional": { - "additionalProperties": { - "$ref": "#/definitions/tag" - } - }, - "withPattern": { - "patternProperties": { - "^x-ab": { - "$ref": "#/definitions/tag" - } - } - }, - "withAdditionalItems": { - "additionalItems": { - "$ref": "#/definitions/tag" - } - }, - "deps": { - "dependencies": { - "something": { - "$ref": "#/definitions/tag" - } - } - }, - "defined": { - "definitions": { - "something": { - "$ref": "#/definitions/tag" - } - } - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json deleted file mode 100644 index fe885fd9..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json +++ /dev/null @@ -1,161 +0,0 @@ -{ - "definitions": { - "car": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "make": { - "type": "string" - }, - "brand": { - "items": { - "$ref": "#/definitions/brand" - } - } - } - }, - "tag": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "value": { - "type": "string" - } - } - }, - "brand": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - } - } - }, - "truck": { - "items": { - "$ref": "#/definitions/car" - } - }, - "batch": { - "items": { - "items": { - "$ref": "#/definitions/brand" - } - } - }, - "batch2": { - "items": [ - { - "items": { - "$ref": "#/definitions/brand" - } - }, - { - "items": { - "$ref": "#/definitions/tag" - } - } - ] - }, - "allofBoth": { - "allOf": [ - { - "items": { - "$ref": "#/definitions/brand" - } - }, - { - "items": { - "$ref": "#/definitions/tag" - } - } - ] - }, - "anyofBoth": { - "anyOf": [ - { - "items": { - "$ref": "#/definitions/brand" - } - }, - { - "items": { - "$ref": "#/definitions/tag" - } - } - ] - }, - "oneofBoth": { - "oneOf": [ - { - "items": { - "$ref": "#/definitions/brand" - } - }, - { - "items": { - "$ref": "#/definitions/tag" - } - } - ] - }, - "notSomething": { - "not": { - "items": { - "$ref": "#/definitions/tag" - } - } - }, - "withAdditional": { - "additionalProperties": { - "items": { - "$ref": "#/definitions/tag" - } - } - }, - "withPattern": { - "patternProperties": { - "^x-ab": { - "items": { - "$ref": "#/definitions/tag" - } - } - } - }, - "withAdditionalItems": { - "additionalItems": { - "items": { - "$ref": "#/definitions/tag" - } - } - }, - "deps": { - "dependencies": { - "something": { - "items": { - "$ref": "#/definitions/tag" - } - } - } - }, - "defined": { - "definitions": { - "something": { - "items": { - "$ref": "#/definitions/tag" - } - } - } - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json deleted file mode 100644 index f042fdd7..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "properties": { - "id": { - "format": "int64", - "readOnly": true, - "type": "integer" - }, - "title": { - "maxLength": 80, - "minLength": 2, - "type": "string" - } - }, - "required": [ - "title" - ], - "type": "object" -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json deleted file mode 100644 index 5c653bca..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "basePath": "/v1", - "consumes": [ - "application/json" - ], - "host": "item.api.local", - "info": { - "description": "Item API", - "title": "Item API", - "version": "1.0.0" - }, - "paths": { - "/item": { - "get": { - "operationId": "GetItem", - "responses": { - "200": { - "description": "item detail response", - "schema": { - "$ref": "item.json" - } - } - } - } - } - }, - "produces": [ - "application/json" - ], - "schemes": [ - "http" - ], - "security": [ - { - "key": [] - } - ], - "securityDefinitions": { - "key": { - "in": "header", - "name": "x-item-token", - "type": "apiKey" - } - }, - "swagger": "2.0" -} diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json deleted file mode 100644 index 8f8dbf6b..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type":"array", - "items": { - "type": "string" - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json deleted file mode 100644 index 169a0d70..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "string" -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/refed.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/refed.json deleted file mode 100644 index 142be8bb..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/refed.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Swagger Petstore", - "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - "termsOfService": "http://helloreverb.com/terms/", - "contact": { - "name": "Wordnik API Team" - }, - "license": { - "name": "MIT" - } - }, - "host": "petstore.swagger.wordnik.com", - "basePath": "/api", - "schemes": [ - "http" - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": { - "idParam": { - "name": "id", - "in": "path", - "description": "ID of pet to fetch", - "required": true, - "type": "integer", - "format": "int64" - } - }, - "responses": { - "petResponse": { - "description": "pet response", - "schema": { - "$ref": "#/definitions/pet" - } - } - }, - "paths": { - "/pets": { - "get": { - "description": "Returns all pets from the system that the user has access to", - "operationId": "findPets", - "produces": [ - "application/json", - "application/xml", - "text/xml", - "text/html" - ], - "parameters": [ - { - "name": "tags", - "in": "query", - "description": "tags to filter by", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv" - }, - { - "name": "limit", - "in": "query", - "description": "maximum number of results to return", - "required": false, - "type": "integer", - "format": "int32" - } - ], - "responses": { - "200": { - "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pet" - } - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - }, - "post": { - "description": "Creates a new pet in the store. Duplicates are allowed", - "operationId": "addPet", - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "pet", - "in": "body", - "description": "Pet to add to the store", - "required": true, - "schema": { - "$ref": "#/definitions/petInput" - } - } - ], - "responses": { - "200": { "$ref": "#/responses/petResponse" }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - } - }, - "/pets/{id}": { - "get": { - "description": "Returns a user based on a single ID, if the user does not have access to the pet", - "operationId": "findPetById", - "produces": [ - "application/json", - "application/xml", - "text/xml", - "text/html" - ], - "parameters": [ - { - "$ref": "#/parameters/idParam" - } - ], - "responses": { - "200": { - "$ref": "#/responses/petResponse" - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - }, - "delete": { - "description": "deletes a single pet based on the ID supplied", - "operationId": "deletePet", - "parameters": [ - { - "$ref": "#/parameters/idParam" - } - ], - "responses": { - "204": { - "description": "pet deleted" - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/errorModel" - } - } - } - } - } - }, - "definitions": { - "pet": { - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "tag": { - "type": "string" - } - } - }, - "petInput": { - "allOf": [ - { - "$ref": "pet" - }, - { - "required": [ - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - } - } - } - ] - }, - "errorModel": { - "required": [ - "code", - "message" - ], - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - } - } - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json deleted file mode 100644 index 43cabe85..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "id": "http://localhost:1234", - "items": { - "id": "deeper/", - "items": { - "$ref": "stringProp.json" - } - }, - "definitions": { - "bool": { - "$ref": "boolProp.json" - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json b/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json deleted file mode 100644 index 5d7a0056..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id": "http://localhost:1234", - "items": { - "id": "deeper/", - "items": { - "$ref": "arrayProp.json#/items" - } - } -} \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/header.go b/discovery/vendor/github.com/go-openapi/spec/header.go deleted file mode 100644 index 85c4d454..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/header.go +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "strings" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -type HeaderProps struct { - Description string `json:"description,omitempty"` -} - -// Header describes a header for a response of the API -// -// For more information: http://goo.gl/8us55a#headerObject -type Header struct { - CommonValidations - SimpleSchema - VendorExtensible - HeaderProps -} - -// ResponseHeader creates a new header instance for use in a response -func ResponseHeader() *Header { - return new(Header) -} - -// WithDescription sets the description on this response, allows for chaining -func (h *Header) WithDescription(description string) *Header { - h.Description = description - return h -} - -// Typed a fluent builder method for the type of parameter -func (h *Header) Typed(tpe, format string) *Header { - h.Type = tpe - h.Format = format - return h -} - -// CollectionOf a fluent builder method for an array item -func (h *Header) CollectionOf(items *Items, format string) *Header { - h.Type = "array" - h.Items = items - h.CollectionFormat = format - return h -} - -// WithDefault sets the default value on this item -func (h *Header) WithDefault(defaultValue interface{}) *Header { - h.Default = defaultValue - return h -} - -// WithMaxLength sets a max length value -func (h *Header) WithMaxLength(max int64) *Header { - h.MaxLength = &max - return h -} - -// WithMinLength sets a min length value -func (h *Header) WithMinLength(min int64) *Header { - h.MinLength = &min - return h -} - -// WithPattern sets a pattern value -func (h *Header) WithPattern(pattern string) *Header { - h.Pattern = pattern - return h -} - -// WithMultipleOf sets a multiple of value -func (h *Header) WithMultipleOf(number float64) *Header { - h.MultipleOf = &number - return h -} - -// WithMaximum sets a maximum number value -func (h *Header) WithMaximum(max float64, exclusive bool) *Header { - h.Maximum = &max - h.ExclusiveMaximum = exclusive - return h -} - -// WithMinimum sets a minimum number value -func (h *Header) WithMinimum(min float64, exclusive bool) *Header { - h.Minimum = &min - h.ExclusiveMinimum = exclusive - return h -} - -// WithEnum sets a the enum values (replace) -func (h *Header) WithEnum(values ...interface{}) *Header { - h.Enum = append([]interface{}{}, values...) - return h -} - -// WithMaxItems sets the max items -func (h *Header) WithMaxItems(size int64) *Header { - h.MaxItems = &size - return h -} - -// WithMinItems sets the min items -func (h *Header) WithMinItems(size int64) *Header { - h.MinItems = &size - return h -} - -// UniqueValues dictates that this array can only have unique items -func (h *Header) UniqueValues() *Header { - h.UniqueItems = true - return h -} - -// AllowDuplicates this array can have duplicates -func (h *Header) AllowDuplicates() *Header { - h.UniqueItems = false - return h -} - -// MarshalJSON marshal this to JSON -func (h Header) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(h.CommonValidations) - if err != nil { - return nil, err - } - b2, err := json.Marshal(h.SimpleSchema) - if err != nil { - return nil, err - } - b3, err := json.Marshal(h.HeaderProps) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2, b3), nil -} - -// UnmarshalJSON marshal this from JSON -func (h *Header) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &h.CommonValidations); err != nil { - return err - } - if err := json.Unmarshal(data, &h.SimpleSchema); err != nil { - return err - } - if err := json.Unmarshal(data, &h.VendorExtensible); err != nil { - return err - } - if err := json.Unmarshal(data, &h.HeaderProps); err != nil { - return err - } - return nil -} - -// JSONLookup look up a value by the json property name -func (p Header) JSONLookup(token string) (interface{}, error) { - if ex, ok := p.Extensions[token]; ok { - return &ex, nil - } - - r, _, err := jsonpointer.GetForToken(p.CommonValidations, token) - if err != nil && !strings.HasPrefix(err.Error(), "object has no field") { - return nil, err - } - if r != nil { - return r, nil - } - r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token) - if err != nil && !strings.HasPrefix(err.Error(), "object has no field") { - return nil, err - } - if r != nil { - return r, nil - } - r, _, err = jsonpointer.GetForToken(p.HeaderProps, token) - return r, err -} diff --git a/discovery/vendor/github.com/go-openapi/spec/info.go b/discovery/vendor/github.com/go-openapi/spec/info.go deleted file mode 100644 index fb8b7c4a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/info.go +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "strings" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// Extensions vendor specific extensions -type Extensions map[string]interface{} - -// Add adds a value to these extensions -func (e Extensions) Add(key string, value interface{}) { - realKey := strings.ToLower(key) - e[realKey] = value -} - -// GetString gets a string value from the extensions -func (e Extensions) GetString(key string) (string, bool) { - if v, ok := e[strings.ToLower(key)]; ok { - str, ok := v.(string) - return str, ok - } - return "", false -} - -// GetBool gets a string value from the extensions -func (e Extensions) GetBool(key string) (bool, bool) { - if v, ok := e[strings.ToLower(key)]; ok { - str, ok := v.(bool) - return str, ok - } - return false, false -} - -// GetStringSlice gets a string value from the extensions -func (e Extensions) GetStringSlice(key string) ([]string, bool) { - if v, ok := e[strings.ToLower(key)]; ok { - arr, ok := v.([]interface{}) - if !ok { - return nil, false - } - var strs []string - for _, iface := range arr { - str, ok := iface.(string) - if !ok { - return nil, false - } - strs = append(strs, str) - } - return strs, ok - } - return nil, false -} - -// VendorExtensible composition block. -type VendorExtensible struct { - Extensions Extensions -} - -// AddExtension adds an extension to this extensible object -func (v *VendorExtensible) AddExtension(key string, value interface{}) { - if value == nil { - return - } - if v.Extensions == nil { - v.Extensions = make(map[string]interface{}) - } - v.Extensions.Add(key, value) -} - -// MarshalJSON marshals the extensions to json -func (v VendorExtensible) MarshalJSON() ([]byte, error) { - toser := make(map[string]interface{}) - for k, v := range v.Extensions { - lk := strings.ToLower(k) - if strings.HasPrefix(lk, "x-") { - toser[k] = v - } - } - return json.Marshal(toser) -} - -// UnmarshalJSON for this extensible object -func (v *VendorExtensible) UnmarshalJSON(data []byte) error { - var d map[string]interface{} - if err := json.Unmarshal(data, &d); err != nil { - return err - } - for k, vv := range d { - lk := strings.ToLower(k) - if strings.HasPrefix(lk, "x-") { - if v.Extensions == nil { - v.Extensions = map[string]interface{}{} - } - v.Extensions[k] = vv - } - } - return nil -} - -// InfoProps the properties for an info definition -type InfoProps struct { - Description string `json:"description,omitempty"` - Title string `json:"title,omitempty"` - TermsOfService string `json:"termsOfService,omitempty"` - Contact *ContactInfo `json:"contact,omitempty"` - License *License `json:"license,omitempty"` - Version string `json:"version,omitempty"` -} - -// Info object provides metadata about the API. -// The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience. -// -// For more information: http://goo.gl/8us55a#infoObject -type Info struct { - VendorExtensible - InfoProps -} - -// JSONLookup look up a value by the json property name -func (i Info) JSONLookup(token string) (interface{}, error) { - if ex, ok := i.Extensions[token]; ok { - return &ex, nil - } - r, _, err := jsonpointer.GetForToken(i.InfoProps, token) - return r, err -} - -// MarshalJSON marshal this to JSON -func (i Info) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(i.InfoProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(i.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2), nil -} - -// UnmarshalJSON marshal this from JSON -func (i *Info) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &i.InfoProps); err != nil { - return err - } - if err := json.Unmarshal(data, &i.VendorExtensible); err != nil { - return err - } - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/items.go b/discovery/vendor/github.com/go-openapi/spec/items.go deleted file mode 100644 index 492423ef..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/items.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "strings" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -type SimpleSchema struct { - Type string `json:"type,omitempty"` - Format string `json:"format,omitempty"` - Items *Items `json:"items,omitempty"` - CollectionFormat string `json:"collectionFormat,omitempty"` - Default interface{} `json:"default,omitempty"` - Example interface{} `json:"example,omitempty"` -} - -func (s *SimpleSchema) TypeName() string { - if s.Format != "" { - return s.Format - } - return s.Type -} - -func (s *SimpleSchema) ItemsTypeName() string { - if s.Items == nil { - return "" - } - return s.Items.TypeName() -} - -type CommonValidations struct { - Maximum *float64 `json:"maximum,omitempty"` - ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` - Minimum *float64 `json:"minimum,omitempty"` - ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` - MaxLength *int64 `json:"maxLength,omitempty"` - MinLength *int64 `json:"minLength,omitempty"` - Pattern string `json:"pattern,omitempty"` - MaxItems *int64 `json:"maxItems,omitempty"` - MinItems *int64 `json:"minItems,omitempty"` - UniqueItems bool `json:"uniqueItems,omitempty"` - MultipleOf *float64 `json:"multipleOf,omitempty"` - Enum []interface{} `json:"enum,omitempty"` -} - -// Items a limited subset of JSON-Schema's items object. -// It is used by parameter definitions that are not located in "body". -// -// For more information: http://goo.gl/8us55a#items-object -type Items struct { - Refable - CommonValidations - SimpleSchema - VendorExtensible -} - -// NewItems creates a new instance of items -func NewItems() *Items { - return &Items{} -} - -// Typed a fluent builder method for the type of item -func (i *Items) Typed(tpe, format string) *Items { - i.Type = tpe - i.Format = format - return i -} - -// CollectionOf a fluent builder method for an array item -func (i *Items) CollectionOf(items *Items, format string) *Items { - i.Type = "array" - i.Items = items - i.CollectionFormat = format - return i -} - -// WithDefault sets the default value on this item -func (i *Items) WithDefault(defaultValue interface{}) *Items { - i.Default = defaultValue - return i -} - -// WithMaxLength sets a max length value -func (i *Items) WithMaxLength(max int64) *Items { - i.MaxLength = &max - return i -} - -// WithMinLength sets a min length value -func (i *Items) WithMinLength(min int64) *Items { - i.MinLength = &min - return i -} - -// WithPattern sets a pattern value -func (i *Items) WithPattern(pattern string) *Items { - i.Pattern = pattern - return i -} - -// WithMultipleOf sets a multiple of value -func (i *Items) WithMultipleOf(number float64) *Items { - i.MultipleOf = &number - return i -} - -// WithMaximum sets a maximum number value -func (i *Items) WithMaximum(max float64, exclusive bool) *Items { - i.Maximum = &max - i.ExclusiveMaximum = exclusive - return i -} - -// WithMinimum sets a minimum number value -func (i *Items) WithMinimum(min float64, exclusive bool) *Items { - i.Minimum = &min - i.ExclusiveMinimum = exclusive - return i -} - -// WithEnum sets a the enum values (replace) -func (i *Items) WithEnum(values ...interface{}) *Items { - i.Enum = append([]interface{}{}, values...) - return i -} - -// WithMaxItems sets the max items -func (i *Items) WithMaxItems(size int64) *Items { - i.MaxItems = &size - return i -} - -// WithMinItems sets the min items -func (i *Items) WithMinItems(size int64) *Items { - i.MinItems = &size - return i -} - -// UniqueValues dictates that this array can only have unique items -func (i *Items) UniqueValues() *Items { - i.UniqueItems = true - return i -} - -// AllowDuplicates this array can have duplicates -func (i *Items) AllowDuplicates() *Items { - i.UniqueItems = false - return i -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (i *Items) UnmarshalJSON(data []byte) error { - var validations CommonValidations - if err := json.Unmarshal(data, &validations); err != nil { - return err - } - var ref Refable - if err := json.Unmarshal(data, &ref); err != nil { - return err - } - var simpleSchema SimpleSchema - if err := json.Unmarshal(data, &simpleSchema); err != nil { - return err - } - var vendorExtensible VendorExtensible - if err := json.Unmarshal(data, &vendorExtensible); err != nil { - return err - } - i.Refable = ref - i.CommonValidations = validations - i.SimpleSchema = simpleSchema - i.VendorExtensible = vendorExtensible - return nil -} - -// MarshalJSON converts this items object to JSON -func (i Items) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(i.CommonValidations) - if err != nil { - return nil, err - } - b2, err := json.Marshal(i.SimpleSchema) - if err != nil { - return nil, err - } - b3, err := json.Marshal(i.Refable) - if err != nil { - return nil, err - } - b4, err := json.Marshal(i.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b4, b3, b1, b2), nil -} - -// JSONLookup look up a value by the json property name -func (p Items) JSONLookup(token string) (interface{}, error) { - if token == "$ref" { - return &p.Ref, nil - } - - r, _, err := jsonpointer.GetForToken(p.CommonValidations, token) - if err != nil && !strings.HasPrefix(err.Error(), "object has no field") { - return nil, err - } - if r != nil { - return r, nil - } - r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token) - return r, err -} diff --git a/discovery/vendor/github.com/go-openapi/spec/license.go b/discovery/vendor/github.com/go-openapi/spec/license.go deleted file mode 100644 index f20961b4..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/license.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -// License information for the exposed API. -// -// For more information: http://goo.gl/8us55a#licenseObject -type License struct { - Name string `json:"name,omitempty"` - URL string `json:"url,omitempty"` -} diff --git a/discovery/vendor/github.com/go-openapi/spec/operation.go b/discovery/vendor/github.com/go-openapi/spec/operation.go deleted file mode 100644 index e698f9e8..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/operation.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -type OperationProps struct { - Description string `json:"description,omitempty"` - Consumes []string `json:"consumes,omitempty"` - Produces []string `json:"produces,omitempty"` - Schemes []string `json:"schemes,omitempty"` // the scheme, when present must be from [http, https, ws, wss] - Tags []string `json:"tags,omitempty"` - Summary string `json:"summary,omitempty"` - ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` - ID string `json:"operationId,omitempty"` - Deprecated bool `json:"deprecated,omitempty"` - Security []map[string][]string `json:"security,omitempty"` //Special case, see MarshalJSON function - Parameters []Parameter `json:"parameters,omitempty"` - Responses *Responses `json:"responses,omitempty"` -} - -// MarshalJSON takes care of serializing operation properties to JSON -// -// We use a custom marhaller here to handle a special cases related -// the Security field. We need to preserve zero length slice -// while omiting the field when the value is nil/unset. -func (op OperationProps) MarshalJSON() ([]byte, error) { - type Alias OperationProps - if op.Security == nil { - return json.Marshal(&struct { - Security []map[string][]string `json:"security,omitempty"` - *Alias - }{ - Security: op.Security, - Alias: (*Alias)(&op), - }) - } - return json.Marshal(&struct { - Security []map[string][]string `json:"security"` - *Alias - }{ - Security: op.Security, - Alias: (*Alias)(&op), - }) -} - -// Operation describes a single API operation on a path. -// -// For more information: http://goo.gl/8us55a#operationObject -type Operation struct { - VendorExtensible - OperationProps -} - -// SuccessResponse gets a success response model -func (o *Operation) SuccessResponse() (*Response, int, bool) { - if o.Responses == nil { - return nil, 0, false - } - - for k, v := range o.Responses.StatusCodeResponses { - if k/100 == 2 { - return &v, k, true - } - } - - return o.Responses.Default, 0, false -} - -// JSONLookup look up a value by the json property name -func (o Operation) JSONLookup(token string) (interface{}, error) { - if ex, ok := o.Extensions[token]; ok { - return &ex, nil - } - r, _, err := jsonpointer.GetForToken(o.OperationProps, token) - return r, err -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (o *Operation) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &o.OperationProps); err != nil { - return err - } - if err := json.Unmarshal(data, &o.VendorExtensible); err != nil { - return err - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (o Operation) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(o.OperationProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(o.VendorExtensible) - if err != nil { - return nil, err - } - concated := swag.ConcatJSON(b1, b2) - return concated, nil -} - -// NewOperation creates a new operation instance. -// It expects an ID as parameter but not passing an ID is also valid. -func NewOperation(id string) *Operation { - op := new(Operation) - op.ID = id - return op -} - -// WithID sets the ID property on this operation, allows for chaining. -func (o *Operation) WithID(id string) *Operation { - o.ID = id - return o -} - -// WithDescription sets the description on this operation, allows for chaining -func (o *Operation) WithDescription(description string) *Operation { - o.Description = description - return o -} - -// WithSummary sets the summary on this operation, allows for chaining -func (o *Operation) WithSummary(summary string) *Operation { - o.Summary = summary - return o -} - -// WithExternalDocs sets/removes the external docs for/from this operation. -// When you pass empty strings as params the external documents will be removed. -// When you pass non-empty string as one value then those values will be used on the external docs object. -// So when you pass a non-empty description, you should also pass the url and vice versa. -func (o *Operation) WithExternalDocs(description, url string) *Operation { - if description == "" && url == "" { - o.ExternalDocs = nil - return o - } - - if o.ExternalDocs == nil { - o.ExternalDocs = &ExternalDocumentation{} - } - o.ExternalDocs.Description = description - o.ExternalDocs.URL = url - return o -} - -// Deprecate marks the operation as deprecated -func (o *Operation) Deprecate() *Operation { - o.Deprecated = true - return o -} - -// Undeprecate marks the operation as not deprected -func (o *Operation) Undeprecate() *Operation { - o.Deprecated = false - return o -} - -// WithConsumes adds media types for incoming body values -func (o *Operation) WithConsumes(mediaTypes ...string) *Operation { - o.Consumes = append(o.Consumes, mediaTypes...) - return o -} - -// WithProduces adds media types for outgoing body values -func (o *Operation) WithProduces(mediaTypes ...string) *Operation { - o.Produces = append(o.Produces, mediaTypes...) - return o -} - -// WithTags adds tags for this operation -func (o *Operation) WithTags(tags ...string) *Operation { - o.Tags = append(o.Tags, tags...) - return o -} - -// AddParam adds a parameter to this operation, when a parameter for that location -// and with that name already exists it will be replaced -func (o *Operation) AddParam(param *Parameter) *Operation { - if param == nil { - return o - } - - for i, p := range o.Parameters { - if p.Name == param.Name && p.In == param.In { - params := append(o.Parameters[:i], *param) - params = append(params, o.Parameters[i+1:]...) - o.Parameters = params - return o - } - } - - o.Parameters = append(o.Parameters, *param) - return o -} - -// RemoveParam removes a parameter from the operation -func (o *Operation) RemoveParam(name, in string) *Operation { - for i, p := range o.Parameters { - if p.Name == name && p.In == name { - o.Parameters = append(o.Parameters[:i], o.Parameters[i+1:]...) - return o - } - } - return o -} - -// SecuredWith adds a security scope to this operation. -func (o *Operation) SecuredWith(name string, scopes ...string) *Operation { - o.Security = append(o.Security, map[string][]string{name: scopes}) - return o -} - -// WithDefaultResponse adds a default response to the operation. -// Passing a nil value will remove the response -func (o *Operation) WithDefaultResponse(response *Response) *Operation { - return o.RespondsWith(0, response) -} - -// RespondsWith adds a status code response to the operation. -// When the code is 0 the value of the response will be used as default response value. -// When the value of the response is nil it will be removed from the operation -func (o *Operation) RespondsWith(code int, response *Response) *Operation { - if o.Responses == nil { - o.Responses = new(Responses) - } - if code == 0 { - o.Responses.Default = response - return o - } - if response == nil { - delete(o.Responses.StatusCodeResponses, code) - return o - } - if o.Responses.StatusCodeResponses == nil { - o.Responses.StatusCodeResponses = make(map[int]Response) - } - o.Responses.StatusCodeResponses[code] = *response - return o -} diff --git a/discovery/vendor/github.com/go-openapi/spec/parameter.go b/discovery/vendor/github.com/go-openapi/spec/parameter.go deleted file mode 100644 index 71aee1e8..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/parameter.go +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "strings" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// QueryParam creates a query parameter -func QueryParam(name string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "query"}} -} - -// HeaderParam creates a header parameter, this is always required by default -func HeaderParam(name string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "header", Required: true}} -} - -// PathParam creates a path parameter, this is always required -func PathParam(name string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "path", Required: true}} -} - -// BodyParam creates a body parameter -func BodyParam(name string, schema *Schema) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "body", Schema: schema}, SimpleSchema: SimpleSchema{Type: "object"}} -} - -// FormDataParam creates a body parameter -func FormDataParam(name string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "formData"}} -} - -// FileParam creates a body parameter -func FileParam(name string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name, In: "formData"}, SimpleSchema: SimpleSchema{Type: "file"}} -} - -// SimpleArrayParam creates a param for a simple array (string, int, date etc) -func SimpleArrayParam(name, tpe, fmt string) *Parameter { - return &Parameter{ParamProps: ParamProps{Name: name}, SimpleSchema: SimpleSchema{Type: "array", CollectionFormat: "csv", Items: &Items{SimpleSchema: SimpleSchema{Type: "string", Format: fmt}}}} -} - -// ParamRef creates a parameter that's a json reference -func ParamRef(uri string) *Parameter { - p := new(Parameter) - p.Ref = MustCreateRef(uri) - return p -} - -type ParamProps struct { - Description string `json:"description,omitempty"` - Name string `json:"name,omitempty"` - In string `json:"in,omitempty"` - Required bool `json:"required,omitempty"` - Schema *Schema `json:"schema,omitempty"` // when in == "body" - AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` // when in == "query" || "formData" -} - -// Parameter a unique parameter is defined by a combination of a [name](#parameterName) and [location](#parameterIn). -// -// There are five possible parameter types. -// * Path - Used together with [Path Templating](#pathTemplating), where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`. -// * Query - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`. -// * Header - Custom headers that are expected as part of the request. -// * Body - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be *one* body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only. Since Form parameters are also in the payload, body and form parameters cannot exist together for the same operation. -// * Form - Used to describe the payload of an HTTP request when either `application/x-www-form-urlencoded` or `multipart/form-data` are used as the content type of the request (in Swagger's definition, the [`consumes`](#operationConsumes) property of an operation). This is the only parameter type that can be used to send files, thus supporting the `file` type. Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation. Form parameters have a different format based on the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4): -// * `application/x-www-form-urlencoded` - Similar to the format of Query parameters but as a payload. For example, `foo=1&bar=swagger` - both `foo` and `bar` are form parameters. This is normally used for simple parameters that are being transferred. -// * `multipart/form-data` - each parameter takes a section in the payload with an internal header. For example, for the header `Content-Disposition: form-data; name="submit-name"` the name of the parameter is `submit-name`. This type of form parameters is more commonly used for file transfers. -// -// For more information: http://goo.gl/8us55a#parameterObject -type Parameter struct { - Refable - CommonValidations - SimpleSchema - VendorExtensible - ParamProps -} - -// JSONLookup look up a value by the json property name -func (p Parameter) JSONLookup(token string) (interface{}, error) { - if ex, ok := p.Extensions[token]; ok { - return &ex, nil - } - if token == "$ref" { - return &p.Ref, nil - } - - r, _, err := jsonpointer.GetForToken(p.CommonValidations, token) - if err != nil && !strings.HasPrefix(err.Error(), "object has no field") { - return nil, err - } - if r != nil { - return r, nil - } - r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token) - if err != nil && !strings.HasPrefix(err.Error(), "object has no field") { - return nil, err - } - if r != nil { - return r, nil - } - r, _, err = jsonpointer.GetForToken(p.ParamProps, token) - return r, err -} - -// WithDescription a fluent builder method for the description of the parameter -func (p *Parameter) WithDescription(description string) *Parameter { - p.Description = description - return p -} - -// Named a fluent builder method to override the name of the parameter -func (p *Parameter) Named(name string) *Parameter { - p.Name = name - return p -} - -// WithLocation a fluent builder method to override the location of the parameter -func (p *Parameter) WithLocation(in string) *Parameter { - p.In = in - return p -} - -// Typed a fluent builder method for the type of the parameter value -func (p *Parameter) Typed(tpe, format string) *Parameter { - p.Type = tpe - p.Format = format - return p -} - -// CollectionOf a fluent builder method for an array parameter -func (p *Parameter) CollectionOf(items *Items, format string) *Parameter { - p.Type = "array" - p.Items = items - p.CollectionFormat = format - return p -} - -// WithDefault sets the default value on this parameter -func (p *Parameter) WithDefault(defaultValue interface{}) *Parameter { - p.AsOptional() // with default implies optional - p.Default = defaultValue - return p -} - -// AllowsEmptyValues flags this parameter as being ok with empty values -func (p *Parameter) AllowsEmptyValues() *Parameter { - p.AllowEmptyValue = true - return p -} - -// NoEmptyValues flags this parameter as not liking empty values -func (p *Parameter) NoEmptyValues() *Parameter { - p.AllowEmptyValue = false - return p -} - -// AsOptional flags this parameter as optional -func (p *Parameter) AsOptional() *Parameter { - p.Required = false - return p -} - -// AsRequired flags this parameter as required -func (p *Parameter) AsRequired() *Parameter { - if p.Default != nil { // with a default required makes no sense - return p - } - p.Required = true - return p -} - -// WithMaxLength sets a max length value -func (p *Parameter) WithMaxLength(max int64) *Parameter { - p.MaxLength = &max - return p -} - -// WithMinLength sets a min length value -func (p *Parameter) WithMinLength(min int64) *Parameter { - p.MinLength = &min - return p -} - -// WithPattern sets a pattern value -func (p *Parameter) WithPattern(pattern string) *Parameter { - p.Pattern = pattern - return p -} - -// WithMultipleOf sets a multiple of value -func (p *Parameter) WithMultipleOf(number float64) *Parameter { - p.MultipleOf = &number - return p -} - -// WithMaximum sets a maximum number value -func (p *Parameter) WithMaximum(max float64, exclusive bool) *Parameter { - p.Maximum = &max - p.ExclusiveMaximum = exclusive - return p -} - -// WithMinimum sets a minimum number value -func (p *Parameter) WithMinimum(min float64, exclusive bool) *Parameter { - p.Minimum = &min - p.ExclusiveMinimum = exclusive - return p -} - -// WithEnum sets a the enum values (replace) -func (p *Parameter) WithEnum(values ...interface{}) *Parameter { - p.Enum = append([]interface{}{}, values...) - return p -} - -// WithMaxItems sets the max items -func (p *Parameter) WithMaxItems(size int64) *Parameter { - p.MaxItems = &size - return p -} - -// WithMinItems sets the min items -func (p *Parameter) WithMinItems(size int64) *Parameter { - p.MinItems = &size - return p -} - -// UniqueValues dictates that this array can only have unique items -func (p *Parameter) UniqueValues() *Parameter { - p.UniqueItems = true - return p -} - -// AllowDuplicates this array can have duplicates -func (p *Parameter) AllowDuplicates() *Parameter { - p.UniqueItems = false - return p -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (p *Parameter) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &p.CommonValidations); err != nil { - return err - } - if err := json.Unmarshal(data, &p.Refable); err != nil { - return err - } - if err := json.Unmarshal(data, &p.SimpleSchema); err != nil { - return err - } - if err := json.Unmarshal(data, &p.VendorExtensible); err != nil { - return err - } - if err := json.Unmarshal(data, &p.ParamProps); err != nil { - return err - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (p Parameter) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(p.CommonValidations) - if err != nil { - return nil, err - } - b2, err := json.Marshal(p.SimpleSchema) - if err != nil { - return nil, err - } - b3, err := json.Marshal(p.Refable) - if err != nil { - return nil, err - } - b4, err := json.Marshal(p.VendorExtensible) - if err != nil { - return nil, err - } - b5, err := json.Marshal(p.ParamProps) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b3, b1, b2, b4, b5), nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/path_item.go b/discovery/vendor/github.com/go-openapi/spec/path_item.go deleted file mode 100644 index 9ab3ec53..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/path_item.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// pathItemProps the path item specific properties -type PathItemProps struct { - Get *Operation `json:"get,omitempty"` - Put *Operation `json:"put,omitempty"` - Post *Operation `json:"post,omitempty"` - Delete *Operation `json:"delete,omitempty"` - Options *Operation `json:"options,omitempty"` - Head *Operation `json:"head,omitempty"` - Patch *Operation `json:"patch,omitempty"` - Parameters []Parameter `json:"parameters,omitempty"` -} - -// PathItem describes the operations available on a single path. -// A Path Item may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering). -// The path itself is still exposed to the documentation viewer but they will -// not know which operations and parameters are available. -// -// For more information: http://goo.gl/8us55a#pathItemObject -type PathItem struct { - Refable - VendorExtensible - PathItemProps -} - -// JSONLookup look up a value by the json property name -func (p PathItem) JSONLookup(token string) (interface{}, error) { - if ex, ok := p.Extensions[token]; ok { - return &ex, nil - } - if token == "$ref" { - return &p.Ref, nil - } - r, _, err := jsonpointer.GetForToken(p.PathItemProps, token) - return r, err -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (p *PathItem) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &p.Refable); err != nil { - return err - } - if err := json.Unmarshal(data, &p.VendorExtensible); err != nil { - return err - } - if err := json.Unmarshal(data, &p.PathItemProps); err != nil { - return err - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (p PathItem) MarshalJSON() ([]byte, error) { - b3, err := json.Marshal(p.Refable) - if err != nil { - return nil, err - } - b4, err := json.Marshal(p.VendorExtensible) - if err != nil { - return nil, err - } - b5, err := json.Marshal(p.PathItemProps) - if err != nil { - return nil, err - } - concated := swag.ConcatJSON(b3, b4, b5) - return concated, nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/paths.go b/discovery/vendor/github.com/go-openapi/spec/paths.go deleted file mode 100644 index 9dc82a29..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/paths.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "fmt" - "strings" - - "github.com/go-openapi/swag" -) - -// Paths holds the relative paths to the individual endpoints. -// The path is appended to the [`basePath`](http://goo.gl/8us55a#swaggerBasePath) in order -// to construct the full URL. -// The Paths may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering). -// -// For more information: http://goo.gl/8us55a#pathsObject -type Paths struct { - VendorExtensible - Paths map[string]PathItem `json:"-"` // custom serializer to flatten this, each entry must start with "/" -} - -// JSONLookup look up a value by the json property name -func (p Paths) JSONLookup(token string) (interface{}, error) { - if pi, ok := p.Paths[token]; ok { - return &pi, nil - } - if ex, ok := p.Extensions[token]; ok { - return &ex, nil - } - return nil, fmt.Errorf("object has no field %q", token) -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (p *Paths) UnmarshalJSON(data []byte) error { - var res map[string]json.RawMessage - if err := json.Unmarshal(data, &res); err != nil { - return err - } - for k, v := range res { - if strings.HasPrefix(strings.ToLower(k), "x-") { - if p.Extensions == nil { - p.Extensions = make(map[string]interface{}) - } - var d interface{} - if err := json.Unmarshal(v, &d); err != nil { - return err - } - p.Extensions[k] = d - } - if strings.HasPrefix(k, "/") { - if p.Paths == nil { - p.Paths = make(map[string]PathItem) - } - var pi PathItem - if err := json.Unmarshal(v, &pi); err != nil { - return err - } - p.Paths[k] = pi - } - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (p Paths) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(p.VendorExtensible) - if err != nil { - return nil, err - } - - pths := make(map[string]PathItem) - for k, v := range p.Paths { - if strings.HasPrefix(k, "/") { - pths[k] = v - } - } - b2, err := json.Marshal(pths) - if err != nil { - return nil, err - } - concated := swag.ConcatJSON(b1, b2) - return concated, nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/ref.go b/discovery/vendor/github.com/go-openapi/spec/ref.go deleted file mode 100644 index 4833b87e..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/ref.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "net/http" - "os" - "path/filepath" - - "github.com/go-openapi/jsonreference" -) - -// Refable is a struct for things that accept a $ref property -type Refable struct { - Ref Ref -} - -// MarshalJSON marshals the ref to json -func (r Refable) MarshalJSON() ([]byte, error) { - return r.Ref.MarshalJSON() -} - -// UnmarshalJSON unmarshalss the ref from json -func (r *Refable) UnmarshalJSON(d []byte) error { - return json.Unmarshal(d, &r.Ref) -} - -// Ref represents a json reference that is potentially resolved -type Ref struct { - jsonreference.Ref -} - -// RemoteURI gets the remote uri part of the ref -func (r *Ref) RemoteURI() string { - if r.String() == "" { - return r.String() - } - - u := *r.GetURL() - u.Fragment = "" - return u.String() -} - -// IsValidURI returns true when the url the ref points to can be found -func (r *Ref) IsValidURI(basepaths ...string) bool { - if r.String() == "" { - return true - } - - v := r.RemoteURI() - if v == "" { - return true - } - - if r.HasFullURL { - rr, err := http.Get(v) - if err != nil { - return false - } - - return rr.StatusCode/100 == 2 - } - - if !(r.HasFileScheme || r.HasFullFilePath || r.HasURLPathOnly) { - return false - } - - // check for local file - pth := v - if r.HasURLPathOnly { - base := "." - if len(basepaths) > 0 { - base = filepath.Dir(filepath.Join(basepaths...)) - } - p, e := filepath.Abs(filepath.ToSlash(filepath.Join(base, pth))) - if e != nil { - return false - } - pth = p - } - - fi, err := os.Stat(filepath.ToSlash(pth)) - if err != nil { - return false - } - - return !fi.IsDir() -} - -// Inherits creates a new reference from a parent and a child -// If the child cannot inherit from the parent, an error is returned -func (r *Ref) Inherits(child Ref) (*Ref, error) { - ref, err := r.Ref.Inherits(child.Ref) - if err != nil { - return nil, err - } - return &Ref{Ref: *ref}, nil -} - -// NewRef creates a new instance of a ref object -// returns an error when the reference uri is an invalid uri -func NewRef(refURI string) (Ref, error) { - ref, err := jsonreference.New(refURI) - if err != nil { - return Ref{}, err - } - return Ref{Ref: ref}, nil -} - -// MustCreateRef creates a ref object but panics when refURI is invalid. -// Use the NewRef method for a version that returns an error. -func MustCreateRef(refURI string) Ref { - return Ref{Ref: jsonreference.MustCreateRef(refURI)} -} - -// MarshalJSON marshals this ref into a JSON object -func (r Ref) MarshalJSON() ([]byte, error) { - str := r.String() - if str == "" { - if r.IsRoot() { - return []byte(`{"$ref":""}`), nil - } - return []byte("{}"), nil - } - v := map[string]interface{}{"$ref": str} - return json.Marshal(v) -} - -// UnmarshalJSON unmarshals this ref from a JSON object -func (r *Ref) UnmarshalJSON(d []byte) error { - var v map[string]interface{} - if err := json.Unmarshal(d, &v); err != nil { - return err - } - - if v == nil { - return nil - } - - if vv, ok := v["$ref"]; ok { - if str, ok := vv.(string); ok { - ref, err := jsonreference.New(str) - if err != nil { - return err - } - *r = Ref{Ref: ref} - } - } - - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/response.go b/discovery/vendor/github.com/go-openapi/spec/response.go deleted file mode 100644 index a32b039e..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/response.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// ResponseProps properties specific to a response -type ResponseProps struct { - Description string `json:"description,omitempty"` - Schema *Schema `json:"schema,omitempty"` - Headers map[string]Header `json:"headers,omitempty"` - Examples map[string]interface{} `json:"examples,omitempty"` -} - -// Response describes a single response from an API Operation. -// -// For more information: http://goo.gl/8us55a#responseObject -type Response struct { - Refable - ResponseProps - VendorExtensible -} - -// JSONLookup look up a value by the json property name -func (p Response) JSONLookup(token string) (interface{}, error) { - if ex, ok := p.Extensions[token]; ok { - return &ex, nil - } - if token == "$ref" { - return &p.Ref, nil - } - r, _, err := jsonpointer.GetForToken(p.ResponseProps, token) - return r, err -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (r *Response) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &r.ResponseProps); err != nil { - return err - } - if err := json.Unmarshal(data, &r.Refable); err != nil { - return err - } - if err := json.Unmarshal(data, &r.VendorExtensible); err != nil { - return err - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (r Response) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(r.ResponseProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(r.Refable) - if err != nil { - return nil, err - } - b3, err := json.Marshal(r.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2, b3), nil -} - -// NewResponse creates a new response instance -func NewResponse() *Response { - return new(Response) -} - -// ResponseRef creates a response as a json reference -func ResponseRef(url string) *Response { - resp := NewResponse() - resp.Ref = MustCreateRef(url) - return resp -} - -// WithDescription sets the description on this response, allows for chaining -func (r *Response) WithDescription(description string) *Response { - r.Description = description - return r -} - -// WithSchema sets the schema on this response, allows for chaining. -// Passing a nil argument removes the schema from this response -func (r *Response) WithSchema(schema *Schema) *Response { - r.Schema = schema - return r -} - -// AddHeader adds a header to this response -func (r *Response) AddHeader(name string, header *Header) *Response { - if header == nil { - return r.RemoveHeader(name) - } - if r.Headers == nil { - r.Headers = make(map[string]Header) - } - r.Headers[name] = *header - return r -} - -// RemoveHeader removes a header from this response -func (r *Response) RemoveHeader(name string) *Response { - delete(r.Headers, name) - return r -} - -// AddExample adds an example to this response -func (r *Response) AddExample(mediaType string, example interface{}) *Response { - if r.Examples == nil { - r.Examples = make(map[string]interface{}) - } - r.Examples[mediaType] = example - return r -} diff --git a/discovery/vendor/github.com/go-openapi/spec/responses.go b/discovery/vendor/github.com/go-openapi/spec/responses.go deleted file mode 100644 index 3ab06697..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/responses.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "fmt" - "reflect" - "strconv" - - "github.com/go-openapi/swag" -) - -// Responses is a container for the expected responses of an operation. -// The container maps a HTTP response code to the expected response. -// It is not expected from the documentation to necessarily cover all possible HTTP response codes, -// since they may not be known in advance. However, it is expected from the documentation to cover -// a successful operation response and any known errors. -// -// The `default` can be used a default response object for all HTTP codes that are not covered -// individually by the specification. -// -// The `Responses Object` MUST contain at least one response code, and it SHOULD be the response -// for a successful operation call. -// -// For more information: http://goo.gl/8us55a#responsesObject -type Responses struct { - VendorExtensible - ResponsesProps -} - -// JSONLookup implements an interface to customize json pointer lookup -func (r Responses) JSONLookup(token string) (interface{}, error) { - if token == "default" { - return r.Default, nil - } - if ex, ok := r.Extensions[token]; ok { - return &ex, nil - } - if i, err := strconv.Atoi(token); err == nil { - if scr, ok := r.StatusCodeResponses[i]; ok { - return scr, nil - } - } - return nil, fmt.Errorf("object has no field %q", token) -} - -// UnmarshalJSON hydrates this items instance with the data from JSON -func (r *Responses) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &r.ResponsesProps); err != nil { - return err - } - if err := json.Unmarshal(data, &r.VendorExtensible); err != nil { - return err - } - if reflect.DeepEqual(ResponsesProps{}, r.ResponsesProps) { - r.ResponsesProps = ResponsesProps{} - } - return nil -} - -// MarshalJSON converts this items object to JSON -func (r Responses) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(r.ResponsesProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(r.VendorExtensible) - if err != nil { - return nil, err - } - concated := swag.ConcatJSON(b1, b2) - return concated, nil -} - -type ResponsesProps struct { - Default *Response - StatusCodeResponses map[int]Response -} - -func (r ResponsesProps) MarshalJSON() ([]byte, error) { - toser := map[string]Response{} - if r.Default != nil { - toser["default"] = *r.Default - } - for k, v := range r.StatusCodeResponses { - toser[strconv.Itoa(k)] = v - } - return json.Marshal(toser) -} - -func (r *ResponsesProps) UnmarshalJSON(data []byte) error { - var res map[string]Response - if err := json.Unmarshal(data, &res); err != nil { - return nil - } - if v, ok := res["default"]; ok { - r.Default = &v - delete(res, "default") - } - for k, v := range res { - if nk, err := strconv.Atoi(k); err == nil { - if r.StatusCodeResponses == nil { - r.StatusCodeResponses = map[int]Response{} - } - r.StatusCodeResponses[nk] = v - } - } - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/schema.go b/discovery/vendor/github.com/go-openapi/spec/schema.go deleted file mode 100644 index 1cdcc163..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/schema.go +++ /dev/null @@ -1,628 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "fmt" - "net/url" - "strings" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// BooleanProperty creates a boolean property -func BooleanProperty() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"boolean"}}} -} - -// BoolProperty creates a boolean property -func BoolProperty() *Schema { return BooleanProperty() } - -// StringProperty creates a string property -func StringProperty() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}} -} - -// CharProperty creates a string property -func CharProperty() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}} -} - -// Float64Property creates a float64/double property -func Float64Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "double"}} -} - -// Float32Property creates a float32/float property -func Float32Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "float"}} -} - -// Int8Property creates an int8 property -func Int8Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int8"}} -} - -// Int16Property creates an int16 property -func Int16Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int16"}} -} - -// Int32Property creates an int32 property -func Int32Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int32"}} -} - -// Int64Property creates an int64 property -func Int64Property() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int64"}} -} - -// StrFmtProperty creates a property for the named string format -func StrFmtProperty(format string) *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: format}} -} - -// DateProperty creates a date property -func DateProperty() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date"}} -} - -// DateTimeProperty creates a date time property -func DateTimeProperty() *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date-time"}} -} - -// MapProperty creates a map property -func MapProperty(property *Schema) *Schema { - return &Schema{SchemaProps: SchemaProps{Type: []string{"object"}, AdditionalProperties: &SchemaOrBool{Allows: true, Schema: property}}} -} - -// RefProperty creates a ref property -func RefProperty(name string) *Schema { - return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}} -} - -// RefSchema creates a ref property -func RefSchema(name string) *Schema { - return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}} -} - -// ArrayProperty creates an array property -func ArrayProperty(items *Schema) *Schema { - if items == nil { - return &Schema{SchemaProps: SchemaProps{Type: []string{"array"}}} - } - return &Schema{SchemaProps: SchemaProps{Items: &SchemaOrArray{Schema: items}, Type: []string{"array"}}} -} - -// ComposedSchema creates a schema with allOf -func ComposedSchema(schemas ...Schema) *Schema { - s := new(Schema) - s.AllOf = schemas - return s -} - -// SchemaURL represents a schema url -type SchemaURL string - -// MarshalJSON marshal this to JSON -func (r SchemaURL) MarshalJSON() ([]byte, error) { - if r == "" { - return []byte("{}"), nil - } - v := map[string]interface{}{"$schema": string(r)} - return json.Marshal(v) -} - -// UnmarshalJSON unmarshal this from JSON -func (r *SchemaURL) UnmarshalJSON(data []byte) error { - var v map[string]interface{} - if err := json.Unmarshal(data, &v); err != nil { - return err - } - if v == nil { - return nil - } - if vv, ok := v["$schema"]; ok { - if str, ok := vv.(string); ok { - u, err := url.Parse(str) - if err != nil { - return err - } - - *r = SchemaURL(u.String()) - } - } - return nil -} - -// type ExtraSchemaProps map[string]interface{} - -// // JSONSchema represents a structure that is a json schema draft 04 -// type JSONSchema struct { -// SchemaProps -// ExtraSchemaProps -// } - -// // MarshalJSON marshal this to JSON -// func (s JSONSchema) MarshalJSON() ([]byte, error) { -// b1, err := json.Marshal(s.SchemaProps) -// if err != nil { -// return nil, err -// } -// b2, err := s.Ref.MarshalJSON() -// if err != nil { -// return nil, err -// } -// b3, err := s.Schema.MarshalJSON() -// if err != nil { -// return nil, err -// } -// b4, err := json.Marshal(s.ExtraSchemaProps) -// if err != nil { -// return nil, err -// } -// return swag.ConcatJSON(b1, b2, b3, b4), nil -// } - -// // UnmarshalJSON marshal this from JSON -// func (s *JSONSchema) UnmarshalJSON(data []byte) error { -// var sch JSONSchema -// if err := json.Unmarshal(data, &sch.SchemaProps); err != nil { -// return err -// } -// if err := json.Unmarshal(data, &sch.Ref); err != nil { -// return err -// } -// if err := json.Unmarshal(data, &sch.Schema); err != nil { -// return err -// } -// if err := json.Unmarshal(data, &sch.ExtraSchemaProps); err != nil { -// return err -// } -// *s = sch -// return nil -// } - -type SchemaProps struct { - ID string `json:"id,omitempty"` - Ref Ref `json:"-"` - Schema SchemaURL `json:"-"` - Description string `json:"description,omitempty"` - Type StringOrArray `json:"type,omitempty"` - Format string `json:"format,omitempty"` - Title string `json:"title,omitempty"` - Default interface{} `json:"default,omitempty"` - Maximum *float64 `json:"maximum,omitempty"` - ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` - Minimum *float64 `json:"minimum,omitempty"` - ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` - MaxLength *int64 `json:"maxLength,omitempty"` - MinLength *int64 `json:"minLength,omitempty"` - Pattern string `json:"pattern,omitempty"` - MaxItems *int64 `json:"maxItems,omitempty"` - MinItems *int64 `json:"minItems,omitempty"` - UniqueItems bool `json:"uniqueItems,omitempty"` - MultipleOf *float64 `json:"multipleOf,omitempty"` - Enum []interface{} `json:"enum,omitempty"` - MaxProperties *int64 `json:"maxProperties,omitempty"` - MinProperties *int64 `json:"minProperties,omitempty"` - Required []string `json:"required,omitempty"` - Items *SchemaOrArray `json:"items,omitempty"` - AllOf []Schema `json:"allOf,omitempty"` - OneOf []Schema `json:"oneOf,omitempty"` - AnyOf []Schema `json:"anyOf,omitempty"` - Not *Schema `json:"not,omitempty"` - Properties map[string]Schema `json:"properties,omitempty"` - AdditionalProperties *SchemaOrBool `json:"additionalProperties,omitempty"` - PatternProperties map[string]Schema `json:"patternProperties,omitempty"` - Dependencies Dependencies `json:"dependencies,omitempty"` - AdditionalItems *SchemaOrBool `json:"additionalItems,omitempty"` - Definitions Definitions `json:"definitions,omitempty"` -} - -type SwaggerSchemaProps struct { - Discriminator string `json:"discriminator,omitempty"` - ReadOnly bool `json:"readOnly,omitempty"` - XML *XMLObject `json:"xml,omitempty"` - ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` - Example interface{} `json:"example,omitempty"` -} - -// Schema the schema object allows the definition of input and output data types. -// These types can be objects, but also primitives and arrays. -// This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/) -// and uses a predefined subset of it. -// On top of this subset, there are extensions provided by this specification to allow for more complete documentation. -// -// For more information: http://goo.gl/8us55a#schemaObject -type Schema struct { - VendorExtensible - SchemaProps - SwaggerSchemaProps - ExtraProps map[string]interface{} `json:"-"` -} - -// JSONLookup implements an interface to customize json pointer lookup -func (s Schema) JSONLookup(token string) (interface{}, error) { - if ex, ok := s.Extensions[token]; ok { - return &ex, nil - } - - if ex, ok := s.ExtraProps[token]; ok { - return &ex, nil - } - - r, _, err := jsonpointer.GetForToken(s.SchemaProps, token) - if r != nil || (err != nil && !strings.HasPrefix(err.Error(), "object has no field")) { - return r, err - } - r, _, err = jsonpointer.GetForToken(s.SwaggerSchemaProps, token) - return r, err -} - -// WithID sets the id for this schema, allows for chaining -func (s *Schema) WithID(id string) *Schema { - s.ID = id - return s -} - -// WithTitle sets the title for this schema, allows for chaining -func (s *Schema) WithTitle(title string) *Schema { - s.Title = title - return s -} - -// WithDescription sets the description for this schema, allows for chaining -func (s *Schema) WithDescription(description string) *Schema { - s.Description = description - return s -} - -// WithProperties sets the properties for this schema -func (s *Schema) WithProperties(schemas map[string]Schema) *Schema { - s.Properties = schemas - return s -} - -// SetProperty sets a property on this schema -func (s *Schema) SetProperty(name string, schema Schema) *Schema { - if s.Properties == nil { - s.Properties = make(map[string]Schema) - } - s.Properties[name] = schema - return s -} - -// WithAllOf sets the all of property -func (s *Schema) WithAllOf(schemas ...Schema) *Schema { - s.AllOf = schemas - return s -} - -// WithMaxProperties sets the max number of properties an object can have -func (s *Schema) WithMaxProperties(max int64) *Schema { - s.MaxProperties = &max - return s -} - -// WithMinProperties sets the min number of properties an object must have -func (s *Schema) WithMinProperties(min int64) *Schema { - s.MinProperties = &min - return s -} - -// Typed sets the type of this schema for a single value item -func (s *Schema) Typed(tpe, format string) *Schema { - s.Type = []string{tpe} - s.Format = format - return s -} - -// AddType adds a type with potential format to the types for this schema -func (s *Schema) AddType(tpe, format string) *Schema { - s.Type = append(s.Type, tpe) - if format != "" { - s.Format = format - } - return s -} - -// CollectionOf a fluent builder method for an array parameter -func (s *Schema) CollectionOf(items Schema) *Schema { - s.Type = []string{"array"} - s.Items = &SchemaOrArray{Schema: &items} - return s -} - -// WithDefault sets the default value on this parameter -func (s *Schema) WithDefault(defaultValue interface{}) *Schema { - s.Default = defaultValue - return s -} - -// WithRequired flags this parameter as required -func (s *Schema) WithRequired(items ...string) *Schema { - s.Required = items - return s -} - -// AddRequired adds field names to the required properties array -func (s *Schema) AddRequired(items ...string) *Schema { - s.Required = append(s.Required, items...) - return s -} - -// WithMaxLength sets a max length value -func (s *Schema) WithMaxLength(max int64) *Schema { - s.MaxLength = &max - return s -} - -// WithMinLength sets a min length value -func (s *Schema) WithMinLength(min int64) *Schema { - s.MinLength = &min - return s -} - -// WithPattern sets a pattern value -func (s *Schema) WithPattern(pattern string) *Schema { - s.Pattern = pattern - return s -} - -// WithMultipleOf sets a multiple of value -func (s *Schema) WithMultipleOf(number float64) *Schema { - s.MultipleOf = &number - return s -} - -// WithMaximum sets a maximum number value -func (s *Schema) WithMaximum(max float64, exclusive bool) *Schema { - s.Maximum = &max - s.ExclusiveMaximum = exclusive - return s -} - -// WithMinimum sets a minimum number value -func (s *Schema) WithMinimum(min float64, exclusive bool) *Schema { - s.Minimum = &min - s.ExclusiveMinimum = exclusive - return s -} - -// WithEnum sets a the enum values (replace) -func (s *Schema) WithEnum(values ...interface{}) *Schema { - s.Enum = append([]interface{}{}, values...) - return s -} - -// WithMaxItems sets the max items -func (s *Schema) WithMaxItems(size int64) *Schema { - s.MaxItems = &size - return s -} - -// WithMinItems sets the min items -func (s *Schema) WithMinItems(size int64) *Schema { - s.MinItems = &size - return s -} - -// UniqueValues dictates that this array can only have unique items -func (s *Schema) UniqueValues() *Schema { - s.UniqueItems = true - return s -} - -// AllowDuplicates this array can have duplicates -func (s *Schema) AllowDuplicates() *Schema { - s.UniqueItems = false - return s -} - -// AddToAllOf adds a schema to the allOf property -func (s *Schema) AddToAllOf(schemas ...Schema) *Schema { - s.AllOf = append(s.AllOf, schemas...) - return s -} - -// WithDiscriminator sets the name of the discriminator field -func (s *Schema) WithDiscriminator(discriminator string) *Schema { - s.Discriminator = discriminator - return s -} - -// AsReadOnly flags this schema as readonly -func (s *Schema) AsReadOnly() *Schema { - s.ReadOnly = true - return s -} - -// AsWritable flags this schema as writeable (not read-only) -func (s *Schema) AsWritable() *Schema { - s.ReadOnly = false - return s -} - -// WithExample sets the example for this schema -func (s *Schema) WithExample(example interface{}) *Schema { - s.Example = example - return s -} - -// WithExternalDocs sets/removes the external docs for/from this schema. -// When you pass empty strings as params the external documents will be removed. -// When you pass non-empty string as one value then those values will be used on the external docs object. -// So when you pass a non-empty description, you should also pass the url and vice versa. -func (s *Schema) WithExternalDocs(description, url string) *Schema { - if description == "" && url == "" { - s.ExternalDocs = nil - return s - } - - if s.ExternalDocs == nil { - s.ExternalDocs = &ExternalDocumentation{} - } - s.ExternalDocs.Description = description - s.ExternalDocs.URL = url - return s -} - -// WithXMLName sets the xml name for the object -func (s *Schema) WithXMLName(name string) *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Name = name - return s -} - -// WithXMLNamespace sets the xml namespace for the object -func (s *Schema) WithXMLNamespace(namespace string) *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Namespace = namespace - return s -} - -// WithXMLPrefix sets the xml prefix for the object -func (s *Schema) WithXMLPrefix(prefix string) *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Prefix = prefix - return s -} - -// AsXMLAttribute flags this object as xml attribute -func (s *Schema) AsXMLAttribute() *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Attribute = true - return s -} - -// AsXMLElement flags this object as an xml node -func (s *Schema) AsXMLElement() *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Attribute = false - return s -} - -// AsWrappedXML flags this object as wrapped, this is mostly useful for array types -func (s *Schema) AsWrappedXML() *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Wrapped = true - return s -} - -// AsUnwrappedXML flags this object as an xml node -func (s *Schema) AsUnwrappedXML() *Schema { - if s.XML == nil { - s.XML = new(XMLObject) - } - s.XML.Wrapped = false - return s -} - -// MarshalJSON marshal this to JSON -func (s Schema) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(s.SchemaProps) - if err != nil { - return nil, fmt.Errorf("schema props %v", err) - } - b2, err := json.Marshal(s.VendorExtensible) - if err != nil { - return nil, fmt.Errorf("vendor props %v", err) - } - b3, err := s.Ref.MarshalJSON() - if err != nil { - return nil, fmt.Errorf("ref prop %v", err) - } - b4, err := s.Schema.MarshalJSON() - if err != nil { - return nil, fmt.Errorf("schema prop %v", err) - } - b5, err := json.Marshal(s.SwaggerSchemaProps) - if err != nil { - return nil, fmt.Errorf("common validations %v", err) - } - var b6 []byte - if s.ExtraProps != nil { - jj, err := json.Marshal(s.ExtraProps) - if err != nil { - return nil, fmt.Errorf("extra props %v", err) - } - b6 = jj - } - return swag.ConcatJSON(b1, b2, b3, b4, b5, b6), nil -} - -// UnmarshalJSON marshal this from JSON -func (s *Schema) UnmarshalJSON(data []byte) error { - var sch Schema - if err := json.Unmarshal(data, &sch.SchemaProps); err != nil { - return err - } - if err := json.Unmarshal(data, &sch.Ref); err != nil { - return err - } - if err := json.Unmarshal(data, &sch.Schema); err != nil { - return err - } - if err := json.Unmarshal(data, &sch.SwaggerSchemaProps); err != nil { - return err - } - - var d map[string]interface{} - if err := json.Unmarshal(data, &d); err != nil { - return err - } - - delete(d, "$ref") - delete(d, "$schema") - for _, pn := range swag.DefaultJSONNameProvider.GetJSONNames(s) { - delete(d, pn) - } - - for k, vv := range d { - lk := strings.ToLower(k) - if strings.HasPrefix(lk, "x-") { - if sch.Extensions == nil { - sch.Extensions = map[string]interface{}{} - } - sch.Extensions[k] = vv - continue - } - if sch.ExtraProps == nil { - sch.ExtraProps = map[string]interface{}{} - } - sch.ExtraProps[k] = vv - } - - *s = sch - - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json b/discovery/vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json deleted file mode 100644 index 85eb502a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json +++ /dev/null @@ -1,150 +0,0 @@ -{ - "id": "http://json-schema.org/draft-04/schema#", - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Core schema meta-schema", - "definitions": { - "schemaArray": { - "type": "array", - "minItems": 1, - "items": { "$ref": "#" } - }, - "positiveInteger": { - "type": "integer", - "minimum": 0 - }, - "positiveIntegerDefault0": { - "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ] - }, - "simpleTypes": { - "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ] - }, - "stringArray": { - "type": "array", - "items": { "type": "string" }, - "minItems": 1, - "uniqueItems": true - } - }, - "type": "object", - "properties": { - "id": { - "type": "string", - "format": "uri" - }, - "$schema": { - "type": "string", - "format": "uri" - }, - "title": { - "type": "string" - }, - "description": { - "type": "string" - }, - "default": {}, - "multipleOf": { - "type": "number", - "minimum": 0, - "exclusiveMinimum": true - }, - "maximum": { - "type": "number" - }, - "exclusiveMaximum": { - "type": "boolean", - "default": false - }, - "minimum": { - "type": "number" - }, - "exclusiveMinimum": { - "type": "boolean", - "default": false - }, - "maxLength": { "$ref": "#/definitions/positiveInteger" }, - "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" }, - "pattern": { - "type": "string", - "format": "regex" - }, - "additionalItems": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ], - "default": {} - }, - "items": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } - ], - "default": {} - }, - "maxItems": { "$ref": "#/definitions/positiveInteger" }, - "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" }, - "uniqueItems": { - "type": "boolean", - "default": false - }, - "maxProperties": { "$ref": "#/definitions/positiveInteger" }, - "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" }, - "required": { "$ref": "#/definitions/stringArray" }, - "additionalProperties": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ], - "default": {} - }, - "definitions": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "properties": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "patternProperties": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, - "dependencies": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/stringArray" } - ] - } - }, - "enum": { - "type": "array", - "minItems": 1, - "uniqueItems": true - }, - "type": { - "anyOf": [ - { "$ref": "#/definitions/simpleTypes" }, - { - "type": "array", - "items": { "$ref": "#/definitions/simpleTypes" }, - "minItems": 1, - "uniqueItems": true - } - ] - }, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" } - }, - "dependencies": { - "exclusiveMaximum": [ "maximum" ], - "exclusiveMinimum": [ "minimum" ] - }, - "default": {} -} diff --git a/discovery/vendor/github.com/go-openapi/spec/schemas/v2/README.md b/discovery/vendor/github.com/go-openapi/spec/schemas/v2/README.md deleted file mode 100644 index 32c1b929..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/schemas/v2/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Swagger 2.0 specification schema - -This folder contains the Swagger 2.0 specification schema files maintained here: - -https://github.com/reverb/swagger-spec/blob/master/schemas/v2.0 \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/spec/schemas/v2/schema.json b/discovery/vendor/github.com/go-openapi/spec/schemas/v2/schema.json deleted file mode 100644 index 4dfccd07..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/schemas/v2/schema.json +++ /dev/null @@ -1,1607 +0,0 @@ -{ - "title": "A JSON Schema for Swagger 2.0 API.", - "id": "http://swagger.io/v2/schema.json#", - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "required": [ - "swagger", - "info", - "paths" - ], - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "swagger": { - "type": "string", - "enum": [ - "2.0" - ], - "description": "The Swagger version of this document." - }, - "info": { - "$ref": "#/definitions/info" - }, - "host": { - "type": "string", - "pattern": "^[^{}/ :\\\\]+(?::\\d+)?$", - "description": "The host (name or ip) of the API. Example: 'swagger.io'" - }, - "basePath": { - "type": "string", - "pattern": "^/", - "description": "The base path to the API. Example: '/api'." - }, - "schemes": { - "$ref": "#/definitions/schemesList" - }, - "consumes": { - "description": "A list of MIME types accepted by the API.", - "allOf": [ - { - "$ref": "#/definitions/mediaTypeList" - } - ] - }, - "produces": { - "description": "A list of MIME types the API can produce.", - "allOf": [ - { - "$ref": "#/definitions/mediaTypeList" - } - ] - }, - "paths": { - "$ref": "#/definitions/paths" - }, - "definitions": { - "$ref": "#/definitions/definitions" - }, - "parameters": { - "$ref": "#/definitions/parameterDefinitions" - }, - "responses": { - "$ref": "#/definitions/responseDefinitions" - }, - "security": { - "$ref": "#/definitions/security" - }, - "securityDefinitions": { - "$ref": "#/definitions/securityDefinitions" - }, - "tags": { - "type": "array", - "items": { - "$ref": "#/definitions/tag" - }, - "uniqueItems": true - }, - "externalDocs": { - "$ref": "#/definitions/externalDocs" - } - }, - "definitions": { - "info": { - "type": "object", - "description": "General information about the API.", - "required": [ - "version", - "title" - ], - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "title": { - "type": "string", - "description": "A unique and precise title of the API." - }, - "version": { - "type": "string", - "description": "A semantic version number of the API." - }, - "description": { - "type": "string", - "description": "A longer description of the API. Should be different from the title. GitHub Flavored Markdown is allowed." - }, - "termsOfService": { - "type": "string", - "description": "The terms of service for the API." - }, - "contact": { - "$ref": "#/definitions/contact" - }, - "license": { - "$ref": "#/definitions/license" - } - } - }, - "contact": { - "type": "object", - "description": "Contact information for the owners of the API.", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "description": "The identifying name of the contact person/organization." - }, - "url": { - "type": "string", - "description": "The URL pointing to the contact information.", - "format": "uri" - }, - "email": { - "type": "string", - "description": "The email address of the contact person/organization.", - "format": "email" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "license": { - "type": "object", - "required": [ - "name" - ], - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "description": "The name of the license type. It's encouraged to use an OSI compatible license." - }, - "url": { - "type": "string", - "description": "The URL pointing to the license.", - "format": "uri" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "paths": { - "type": "object", - "description": "Relative paths to the individual endpoints. They must be relative to the 'basePath'.", - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - }, - "^/": { - "$ref": "#/definitions/pathItem" - } - }, - "additionalProperties": false - }, - "definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/schema" - }, - "description": "One or more JSON objects describing the schemas being consumed and produced by the API." - }, - "parameterDefinitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/parameter" - }, - "description": "One or more JSON representations for parameters" - }, - "responseDefinitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/response" - }, - "description": "One or more JSON representations for parameters" - }, - "externalDocs": { - "type": "object", - "additionalProperties": false, - "description": "information about external documentation", - "required": [ - "url" - ], - "properties": { - "description": { - "type": "string" - }, - "url": { - "type": "string", - "format": "uri" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "examples": { - "type": "object", - "additionalProperties": true - }, - "mimeType": { - "type": "string", - "description": "The MIME type of the HTTP message." - }, - "operation": { - "type": "object", - "required": [ - "responses" - ], - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "tags": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true - }, - "summary": { - "type": "string", - "description": "A brief summary of the operation." - }, - "description": { - "type": "string", - "description": "A longer description of the operation, GitHub Flavored Markdown is allowed." - }, - "externalDocs": { - "$ref": "#/definitions/externalDocs" - }, - "operationId": { - "type": "string", - "description": "A unique identifier of the operation." - }, - "produces": { - "description": "A list of MIME types the API can produce.", - "allOf": [ - { - "$ref": "#/definitions/mediaTypeList" - } - ] - }, - "consumes": { - "description": "A list of MIME types the API can consume.", - "allOf": [ - { - "$ref": "#/definitions/mediaTypeList" - } - ] - }, - "parameters": { - "$ref": "#/definitions/parametersList" - }, - "responses": { - "$ref": "#/definitions/responses" - }, - "schemes": { - "$ref": "#/definitions/schemesList" - }, - "deprecated": { - "type": "boolean", - "default": false - }, - "security": { - "$ref": "#/definitions/security" - } - } - }, - "pathItem": { - "type": "object", - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "$ref": { - "type": "string" - }, - "get": { - "$ref": "#/definitions/operation" - }, - "put": { - "$ref": "#/definitions/operation" - }, - "post": { - "$ref": "#/definitions/operation" - }, - "delete": { - "$ref": "#/definitions/operation" - }, - "options": { - "$ref": "#/definitions/operation" - }, - "head": { - "$ref": "#/definitions/operation" - }, - "patch": { - "$ref": "#/definitions/operation" - }, - "parameters": { - "$ref": "#/definitions/parametersList" - } - } - }, - "responses": { - "type": "object", - "description": "Response objects names can either be any valid HTTP status code or 'default'.", - "minProperties": 1, - "additionalProperties": false, - "patternProperties": { - "^([0-9]{3})$|^(default)$": { - "$ref": "#/definitions/responseValue" - }, - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "not": { - "type": "object", - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - } - }, - "responseValue": { - "oneOf": [ - { - "$ref": "#/definitions/response" - }, - { - "$ref": "#/definitions/jsonReference" - } - ] - }, - "response": { - "type": "object", - "required": [ - "description" - ], - "properties": { - "description": { - "type": "string" - }, - "schema": { - "oneOf": [ - { - "$ref": "#/definitions/schema" - }, - { - "$ref": "#/definitions/fileSchema" - } - ] - }, - "headers": { - "$ref": "#/definitions/headers" - }, - "examples": { - "$ref": "#/definitions/examples" - } - }, - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "headers": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/header" - } - }, - "header": { - "type": "object", - "additionalProperties": false, - "required": [ - "type" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "string", - "number", - "integer", - "boolean", - "array" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormat" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "vendorExtension": { - "description": "Any property starting with x- is valid.", - "additionalProperties": true, - "additionalItems": true - }, - "bodyParameter": { - "type": "object", - "required": [ - "name", - "in", - "schema" - ], - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "description": { - "type": "string", - "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." - }, - "name": { - "type": "string", - "description": "The name of the parameter." - }, - "in": { - "type": "string", - "description": "Determines the location of the parameter.", - "enum": [ - "body" - ] - }, - "required": { - "type": "boolean", - "description": "Determines whether or not this parameter is required or optional.", - "default": false - }, - "schema": { - "$ref": "#/definitions/schema" - } - }, - "additionalProperties": false - }, - "headerParameterSubSchema": { - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "required": { - "type": "boolean", - "description": "Determines whether or not this parameter is required or optional.", - "default": false - }, - "in": { - "type": "string", - "description": "Determines the location of the parameter.", - "enum": [ - "header" - ] - }, - "description": { - "type": "string", - "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." - }, - "name": { - "type": "string", - "description": "The name of the parameter." - }, - "type": { - "type": "string", - "enum": [ - "string", - "number", - "boolean", - "integer", - "array" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormat" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - } - } - }, - "queryParameterSubSchema": { - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "required": { - "type": "boolean", - "description": "Determines whether or not this parameter is required or optional.", - "default": false - }, - "in": { - "type": "string", - "description": "Determines the location of the parameter.", - "enum": [ - "query" - ] - }, - "description": { - "type": "string", - "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." - }, - "name": { - "type": "string", - "description": "The name of the parameter." - }, - "allowEmptyValue": { - "type": "boolean", - "default": false, - "description": "allows sending a parameter by name only or with an empty value." - }, - "type": { - "type": "string", - "enum": [ - "string", - "number", - "boolean", - "integer", - "array" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormatWithMulti" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - } - } - }, - "formDataParameterSubSchema": { - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "required": { - "type": "boolean", - "description": "Determines whether or not this parameter is required or optional.", - "default": false - }, - "in": { - "type": "string", - "description": "Determines the location of the parameter.", - "enum": [ - "formData" - ] - }, - "description": { - "type": "string", - "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." - }, - "name": { - "type": "string", - "description": "The name of the parameter." - }, - "allowEmptyValue": { - "type": "boolean", - "default": false, - "description": "allows sending a parameter by name only or with an empty value." - }, - "type": { - "type": "string", - "enum": [ - "string", - "number", - "boolean", - "integer", - "array", - "file" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormatWithMulti" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - } - } - }, - "pathParameterSubSchema": { - "additionalProperties": false, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "required": [ - "required" - ], - "properties": { - "required": { - "type": "boolean", - "enum": [ - true - ], - "description": "Determines whether or not this parameter is required or optional." - }, - "in": { - "type": "string", - "description": "Determines the location of the parameter.", - "enum": [ - "path" - ] - }, - "description": { - "type": "string", - "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." - }, - "name": { - "type": "string", - "description": "The name of the parameter." - }, - "type": { - "type": "string", - "enum": [ - "string", - "number", - "boolean", - "integer", - "array" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormat" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - } - } - }, - "nonBodyParameter": { - "type": "object", - "required": [ - "name", - "in", - "type" - ], - "oneOf": [ - { - "$ref": "#/definitions/headerParameterSubSchema" - }, - { - "$ref": "#/definitions/formDataParameterSubSchema" - }, - { - "$ref": "#/definitions/queryParameterSubSchema" - }, - { - "$ref": "#/definitions/pathParameterSubSchema" - } - ] - }, - "parameter": { - "oneOf": [ - { - "$ref": "#/definitions/bodyParameter" - }, - { - "$ref": "#/definitions/nonBodyParameter" - } - ] - }, - "schema": { - "type": "object", - "description": "A deterministic version of a JSON Schema object.", - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "properties": { - "$ref": { - "type": "string" - }, - "format": { - "type": "string" - }, - "title": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/title" - }, - "description": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/description" - }, - "default": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/default" - }, - "multipleOf": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf" - }, - "maximum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/maximum" - }, - "exclusiveMaximum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum" - }, - "minimum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/minimum" - }, - "exclusiveMinimum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum" - }, - "maxLength": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" - }, - "minLength": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" - }, - "pattern": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/pattern" - }, - "maxItems": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" - }, - "minItems": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" - }, - "uniqueItems": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/uniqueItems" - }, - "maxProperties": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" - }, - "minProperties": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" - }, - "required": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" - }, - "enum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/enum" - }, - "additionalProperties": { - "anyOf": [ - { - "$ref": "#/definitions/schema" - }, - { - "type": "boolean" - } - ], - "default": {} - }, - "type": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/type" - }, - "items": { - "anyOf": [ - { - "$ref": "#/definitions/schema" - }, - { - "type": "array", - "minItems": 1, - "items": { - "$ref": "#/definitions/schema" - } - } - ], - "default": {} - }, - "allOf": { - "type": "array", - "minItems": 1, - "items": { - "$ref": "#/definitions/schema" - } - }, - "properties": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/schema" - }, - "default": {} - }, - "discriminator": { - "type": "string" - }, - "readOnly": { - "type": "boolean", - "default": false - }, - "xml": { - "$ref": "#/definitions/xml" - }, - "externalDocs": { - "$ref": "#/definitions/externalDocs" - }, - "example": {} - }, - "additionalProperties": false - }, - "fileSchema": { - "type": "object", - "description": "A deterministic version of a JSON Schema object.", - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - }, - "required": [ - "type" - ], - "properties": { - "format": { - "type": "string" - }, - "title": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/title" - }, - "description": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/description" - }, - "default": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/default" - }, - "required": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" - }, - "type": { - "type": "string", - "enum": [ - "file" - ] - }, - "readOnly": { - "type": "boolean", - "default": false - }, - "externalDocs": { - "$ref": "#/definitions/externalDocs" - }, - "example": {} - }, - "additionalProperties": false - }, - "primitivesItems": { - "type": "object", - "additionalProperties": false, - "properties": { - "type": { - "type": "string", - "enum": [ - "string", - "number", - "integer", - "boolean", - "array" - ] - }, - "format": { - "type": "string" - }, - "items": { - "$ref": "#/definitions/primitivesItems" - }, - "collectionFormat": { - "$ref": "#/definitions/collectionFormat" - }, - "default": { - "$ref": "#/definitions/default" - }, - "maximum": { - "$ref": "#/definitions/maximum" - }, - "exclusiveMaximum": { - "$ref": "#/definitions/exclusiveMaximum" - }, - "minimum": { - "$ref": "#/definitions/minimum" - }, - "exclusiveMinimum": { - "$ref": "#/definitions/exclusiveMinimum" - }, - "maxLength": { - "$ref": "#/definitions/maxLength" - }, - "minLength": { - "$ref": "#/definitions/minLength" - }, - "pattern": { - "$ref": "#/definitions/pattern" - }, - "maxItems": { - "$ref": "#/definitions/maxItems" - }, - "minItems": { - "$ref": "#/definitions/minItems" - }, - "uniqueItems": { - "$ref": "#/definitions/uniqueItems" - }, - "enum": { - "$ref": "#/definitions/enum" - }, - "multipleOf": { - "$ref": "#/definitions/multipleOf" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "security": { - "type": "array", - "items": { - "$ref": "#/definitions/securityRequirement" - }, - "uniqueItems": true - }, - "securityRequirement": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true - } - }, - "xml": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string" - }, - "namespace": { - "type": "string" - }, - "prefix": { - "type": "string" - }, - "attribute": { - "type": "boolean", - "default": false - }, - "wrapped": { - "type": "boolean", - "default": false - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "tag": { - "type": "object", - "additionalProperties": false, - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - }, - "description": { - "type": "string" - }, - "externalDocs": { - "$ref": "#/definitions/externalDocs" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "securityDefinitions": { - "type": "object", - "additionalProperties": { - "oneOf": [ - { - "$ref": "#/definitions/basicAuthenticationSecurity" - }, - { - "$ref": "#/definitions/apiKeySecurity" - }, - { - "$ref": "#/definitions/oauth2ImplicitSecurity" - }, - { - "$ref": "#/definitions/oauth2PasswordSecurity" - }, - { - "$ref": "#/definitions/oauth2ApplicationSecurity" - }, - { - "$ref": "#/definitions/oauth2AccessCodeSecurity" - } - ] - } - }, - "basicAuthenticationSecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "basic" - ] - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "apiKeySecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "name", - "in" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "apiKey" - ] - }, - "name": { - "type": "string" - }, - "in": { - "type": "string", - "enum": [ - "header", - "query" - ] - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "oauth2ImplicitSecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "flow", - "authorizationUrl" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "oauth2" - ] - }, - "flow": { - "type": "string", - "enum": [ - "implicit" - ] - }, - "scopes": { - "$ref": "#/definitions/oauth2Scopes" - }, - "authorizationUrl": { - "type": "string", - "format": "uri" - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "oauth2PasswordSecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "flow", - "tokenUrl" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "oauth2" - ] - }, - "flow": { - "type": "string", - "enum": [ - "password" - ] - }, - "scopes": { - "$ref": "#/definitions/oauth2Scopes" - }, - "tokenUrl": { - "type": "string", - "format": "uri" - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "oauth2ApplicationSecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "flow", - "tokenUrl" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "oauth2" - ] - }, - "flow": { - "type": "string", - "enum": [ - "application" - ] - }, - "scopes": { - "$ref": "#/definitions/oauth2Scopes" - }, - "tokenUrl": { - "type": "string", - "format": "uri" - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "oauth2AccessCodeSecurity": { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "flow", - "authorizationUrl", - "tokenUrl" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "oauth2" - ] - }, - "flow": { - "type": "string", - "enum": [ - "accessCode" - ] - }, - "scopes": { - "$ref": "#/definitions/oauth2Scopes" - }, - "authorizationUrl": { - "type": "string", - "format": "uri" - }, - "tokenUrl": { - "type": "string", - "format": "uri" - }, - "description": { - "type": "string" - } - }, - "patternProperties": { - "^x-": { - "$ref": "#/definitions/vendorExtension" - } - } - }, - "oauth2Scopes": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "mediaTypeList": { - "type": "array", - "items": { - "$ref": "#/definitions/mimeType" - }, - "uniqueItems": true - }, - "parametersList": { - "type": "array", - "description": "The parameters needed to send a valid API call.", - "additionalItems": false, - "items": { - "oneOf": [ - { - "$ref": "#/definitions/parameter" - }, - { - "$ref": "#/definitions/jsonReference" - } - ] - }, - "uniqueItems": true - }, - "schemesList": { - "type": "array", - "description": "The transfer protocol of the API.", - "items": { - "type": "string", - "enum": [ - "http", - "https", - "ws", - "wss" - ] - }, - "uniqueItems": true - }, - "collectionFormat": { - "type": "string", - "enum": [ - "csv", - "ssv", - "tsv", - "pipes" - ], - "default": "csv" - }, - "collectionFormatWithMulti": { - "type": "string", - "enum": [ - "csv", - "ssv", - "tsv", - "pipes", - "multi" - ], - "default": "csv" - }, - "title": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/title" - }, - "description": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/description" - }, - "default": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/default" - }, - "multipleOf": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf" - }, - "maximum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/maximum" - }, - "exclusiveMaximum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum" - }, - "minimum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/minimum" - }, - "exclusiveMinimum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum" - }, - "maxLength": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" - }, - "minLength": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" - }, - "pattern": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/pattern" - }, - "maxItems": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" - }, - "minItems": { - "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" - }, - "uniqueItems": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/uniqueItems" - }, - "enum": { - "$ref": "http://json-schema.org/draft-04/schema#/properties/enum" - }, - "jsonReference": { - "type": "object", - "required": [ - "$ref" - ], - "additionalProperties": false, - "properties": { - "$ref": { - "type": "string" - } - } - } - } -} diff --git a/discovery/vendor/github.com/go-openapi/spec/security_scheme.go b/discovery/vendor/github.com/go-openapi/spec/security_scheme.go deleted file mode 100644 index 22d4f10a..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/security_scheme.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -const ( - basic = "basic" - apiKey = "apiKey" - oauth2 = "oauth2" - implicit = "implicit" - password = "password" - application = "application" - accessCode = "accessCode" -) - -// BasicAuth creates a basic auth security scheme -func BasicAuth() *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{Type: basic}} -} - -// APIKeyAuth creates an api key auth security scheme -func APIKeyAuth(fieldName, valueSource string) *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{Type: apiKey, Name: fieldName, In: valueSource}} -} - -// OAuth2Implicit creates an implicit flow oauth2 security scheme -func OAuth2Implicit(authorizationURL string) *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{ - Type: oauth2, - Flow: implicit, - AuthorizationURL: authorizationURL, - }} -} - -// OAuth2Password creates a password flow oauth2 security scheme -func OAuth2Password(tokenURL string) *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{ - Type: oauth2, - Flow: password, - TokenURL: tokenURL, - }} -} - -// OAuth2Application creates an application flow oauth2 security scheme -func OAuth2Application(tokenURL string) *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{ - Type: oauth2, - Flow: application, - TokenURL: tokenURL, - }} -} - -// OAuth2AccessToken creates an access token flow oauth2 security scheme -func OAuth2AccessToken(authorizationURL, tokenURL string) *SecurityScheme { - return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{ - Type: oauth2, - Flow: accessCode, - AuthorizationURL: authorizationURL, - TokenURL: tokenURL, - }} -} - -type SecuritySchemeProps struct { - Description string `json:"description,omitempty"` - Type string `json:"type"` - Name string `json:"name,omitempty"` // api key - In string `json:"in,omitempty"` // api key - Flow string `json:"flow,omitempty"` // oauth2 - AuthorizationURL string `json:"authorizationUrl,omitempty"` // oauth2 - TokenURL string `json:"tokenUrl,omitempty"` // oauth2 - Scopes map[string]string `json:"scopes,omitempty"` // oauth2 -} - -// AddScope adds a scope to this security scheme -func (s *SecuritySchemeProps) AddScope(scope, description string) { - if s.Scopes == nil { - s.Scopes = make(map[string]string) - } - s.Scopes[scope] = description -} - -// SecurityScheme allows the definition of a security scheme that can be used by the operations. -// Supported schemes are basic authentication, an API key (either as a header or as a query parameter) -// and OAuth2's common flows (implicit, password, application and access code). -// -// For more information: http://goo.gl/8us55a#securitySchemeObject -type SecurityScheme struct { - VendorExtensible - SecuritySchemeProps -} - -// JSONLookup implements an interface to customize json pointer lookup -func (s SecurityScheme) JSONLookup(token string) (interface{}, error) { - if ex, ok := s.Extensions[token]; ok { - return &ex, nil - } - - r, _, err := jsonpointer.GetForToken(s.SecuritySchemeProps, token) - return r, err -} - -// MarshalJSON marshal this to JSON -func (s SecurityScheme) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(s.SecuritySchemeProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(s.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2), nil -} - -// UnmarshalJSON marshal this from JSON -func (s *SecurityScheme) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &s.SecuritySchemeProps); err != nil { - return err - } - if err := json.Unmarshal(data, &s.VendorExtensible); err != nil { - return err - } - return nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/spec.go b/discovery/vendor/github.com/go-openapi/spec/spec.go deleted file mode 100644 index 0bb045bc..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/spec.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import "encoding/json" - -//go:generate curl -L --progress -o ./schemas/v2/schema.json http://swagger.io/v2/schema.json -//go:generate curl -L --progress -o ./schemas/jsonschema-draft-04.json http://json-schema.org/draft-04/schema -//go:generate go-bindata -pkg=spec -prefix=./schemas -ignore=.*\.md ./schemas/... -//go:generate perl -pi -e s,Json,JSON,g bindata.go - -const ( - // SwaggerSchemaURL the url for the swagger 2.0 schema to validate specs - SwaggerSchemaURL = "http://swagger.io/v2/schema.json#" - // JSONSchemaURL the url for the json schema schema - JSONSchemaURL = "http://json-schema.org/draft-04/schema#" -) - -var ( - jsonSchema *Schema - swaggerSchema *Schema -) - -func init() { - jsonSchema = MustLoadJSONSchemaDraft04() - swaggerSchema = MustLoadSwagger20Schema() -} - -// MustLoadJSONSchemaDraft04 panics when Swagger20Schema returns an error -func MustLoadJSONSchemaDraft04() *Schema { - d, e := JSONSchemaDraft04() - if e != nil { - panic(e) - } - return d -} - -// JSONSchemaDraft04 loads the json schema document for json shema draft04 -func JSONSchemaDraft04() (*Schema, error) { - b, err := Asset("jsonschema-draft-04.json") - if err != nil { - return nil, err - } - - schema := new(Schema) - if err := json.Unmarshal(b, schema); err != nil { - return nil, err - } - return schema, nil -} - -// MustLoadSwagger20Schema panics when Swagger20Schema returns an error -func MustLoadSwagger20Schema() *Schema { - d, e := Swagger20Schema() - if e != nil { - panic(e) - } - return d -} - -// Swagger20Schema loads the swagger 2.0 schema from the embedded assets -func Swagger20Schema() (*Schema, error) { - - b, err := Asset("v2/schema.json") - if err != nil { - return nil, err - } - - schema := new(Schema) - if err := json.Unmarshal(b, schema); err != nil { - return nil, err - } - return schema, nil -} diff --git a/discovery/vendor/github.com/go-openapi/spec/swagger.go b/discovery/vendor/github.com/go-openapi/spec/swagger.go deleted file mode 100644 index 23780c78..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/swagger.go +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - "fmt" - "strconv" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -// Swagger this is the root document object for the API specification. -// It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier) together into one document. -// -// For more information: http://goo.gl/8us55a#swagger-object- -type Swagger struct { - VendorExtensible - SwaggerProps -} - -// JSONLookup look up a value by the json property name -func (s Swagger) JSONLookup(token string) (interface{}, error) { - if ex, ok := s.Extensions[token]; ok { - return &ex, nil - } - r, _, err := jsonpointer.GetForToken(s.SwaggerProps, token) - return r, err -} - -// MarshalJSON marshals this swagger structure to json -func (s Swagger) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(s.SwaggerProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(s.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2), nil -} - -// UnmarshalJSON unmarshals a swagger spec from json -func (s *Swagger) UnmarshalJSON(data []byte) error { - var sw Swagger - if err := json.Unmarshal(data, &sw.SwaggerProps); err != nil { - return err - } - if err := json.Unmarshal(data, &sw.VendorExtensible); err != nil { - return err - } - *s = sw - return nil -} - -type SwaggerProps struct { - ID string `json:"id,omitempty"` - Consumes []string `json:"consumes,omitempty"` - Produces []string `json:"produces,omitempty"` - Schemes []string `json:"schemes,omitempty"` // the scheme, when present must be from [http, https, ws, wss] - Swagger string `json:"swagger,omitempty"` - Info *Info `json:"info,omitempty"` - Host string `json:"host,omitempty"` - BasePath string `json:"basePath,omitempty"` // must start with a leading "/" - Paths *Paths `json:"paths"` // required - Definitions Definitions `json:"definitions,omitempty"` - Parameters map[string]Parameter `json:"parameters,omitempty"` - Responses map[string]Response `json:"responses,omitempty"` - SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"` - Security []map[string][]string `json:"security,omitempty"` - Tags []Tag `json:"tags,omitempty"` - ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` -} - -// Dependencies represent a dependencies property -type Dependencies map[string]SchemaOrStringArray - -// SchemaOrBool represents a schema or boolean value, is biased towards true for the boolean property -type SchemaOrBool struct { - Allows bool - Schema *Schema -} - -// JSONLookup implements an interface to customize json pointer lookup -func (s SchemaOrBool) JSONLookup(token string) (interface{}, error) { - if token == "allows" { - return s.Allows, nil - } - r, _, err := jsonpointer.GetForToken(s.Schema, token) - return r, err -} - -var jsTrue = []byte("true") -var jsFalse = []byte("false") - -// MarshalJSON convert this object to JSON -func (s SchemaOrBool) MarshalJSON() ([]byte, error) { - if s.Schema != nil { - return json.Marshal(s.Schema) - } - - if s.Schema == nil && !s.Allows { - return jsFalse, nil - } - return jsTrue, nil -} - -// UnmarshalJSON converts this bool or schema object from a JSON structure -func (s *SchemaOrBool) UnmarshalJSON(data []byte) error { - var nw SchemaOrBool - if len(data) >= 4 { - if data[0] == '{' { - var sch Schema - if err := json.Unmarshal(data, &sch); err != nil { - return err - } - nw.Schema = &sch - } - nw.Allows = !(data[0] == 'f' && data[1] == 'a' && data[2] == 'l' && data[3] == 's' && data[4] == 'e') - } - *s = nw - return nil -} - -// SchemaOrStringArray represents a schema or a string array -type SchemaOrStringArray struct { - Schema *Schema - Property []string -} - -// JSONLookup implements an interface to customize json pointer lookup -func (s SchemaOrStringArray) JSONLookup(token string) (interface{}, error) { - r, _, err := jsonpointer.GetForToken(s.Schema, token) - return r, err -} - -// MarshalJSON converts this schema object or array into JSON structure -func (s SchemaOrStringArray) MarshalJSON() ([]byte, error) { - if len(s.Property) > 0 { - return json.Marshal(s.Property) - } - if s.Schema != nil { - return json.Marshal(s.Schema) - } - return []byte("null"), nil -} - -// UnmarshalJSON converts this schema object or array from a JSON structure -func (s *SchemaOrStringArray) UnmarshalJSON(data []byte) error { - var first byte - if len(data) > 1 { - first = data[0] - } - var nw SchemaOrStringArray - if first == '{' { - var sch Schema - if err := json.Unmarshal(data, &sch); err != nil { - return err - } - nw.Schema = &sch - } - if first == '[' { - if err := json.Unmarshal(data, &nw.Property); err != nil { - return err - } - } - *s = nw - return nil -} - -// Definitions contains the models explicitly defined in this spec -// An object to hold data types that can be consumed and produced by operations. -// These data types can be primitives, arrays or models. -// -// For more information: http://goo.gl/8us55a#definitionsObject -type Definitions map[string]Schema - -// SecurityDefinitions a declaration of the security schemes available to be used in the specification. -// This does not enforce the security schemes on the operations and only serves to provide -// the relevant details for each scheme. -// -// For more information: http://goo.gl/8us55a#securityDefinitionsObject -type SecurityDefinitions map[string]*SecurityScheme - -// StringOrArray represents a value that can either be a string -// or an array of strings. Mainly here for serialization purposes -type StringOrArray []string - -// Contains returns true when the value is contained in the slice -func (s StringOrArray) Contains(value string) bool { - for _, str := range s { - if str == value { - return true - } - } - return false -} - -// JSONLookup implements an interface to customize json pointer lookup -func (s SchemaOrArray) JSONLookup(token string) (interface{}, error) { - if _, err := strconv.Atoi(token); err == nil { - r, _, err := jsonpointer.GetForToken(s.Schemas, token) - return r, err - } - r, _, err := jsonpointer.GetForToken(s.Schema, token) - return r, err -} - -// UnmarshalJSON unmarshals this string or array object from a JSON array or JSON string -func (s *StringOrArray) UnmarshalJSON(data []byte) error { - var first byte - if len(data) > 1 { - first = data[0] - } - - if first == '[' { - var parsed []string - if err := json.Unmarshal(data, &parsed); err != nil { - return err - } - *s = StringOrArray(parsed) - return nil - } - - var single interface{} - if err := json.Unmarshal(data, &single); err != nil { - return err - } - if single == nil { - return nil - } - switch single.(type) { - case string: - *s = StringOrArray([]string{single.(string)}) - return nil - default: - return fmt.Errorf("only string or array is allowed, not %T", single) - } -} - -// MarshalJSON converts this string or array to a JSON array or JSON string -func (s StringOrArray) MarshalJSON() ([]byte, error) { - if len(s) == 1 { - return json.Marshal([]string(s)[0]) - } - return json.Marshal([]string(s)) -} - -// SchemaOrArray represents a value that can either be a Schema -// or an array of Schema. Mainly here for serialization purposes -type SchemaOrArray struct { - Schema *Schema - Schemas []Schema -} - -// Len returns the number of schemas in this property -func (s SchemaOrArray) Len() int { - if s.Schema != nil { - return 1 - } - return len(s.Schemas) -} - -// ContainsType returns true when one of the schemas is of the specified type -func (s *SchemaOrArray) ContainsType(name string) bool { - if s.Schema != nil { - return s.Schema.Type != nil && s.Schema.Type.Contains(name) - } - return false -} - -// MarshalJSON converts this schema object or array into JSON structure -func (s SchemaOrArray) MarshalJSON() ([]byte, error) { - if len(s.Schemas) > 0 { - return json.Marshal(s.Schemas) - } - return json.Marshal(s.Schema) -} - -// UnmarshalJSON converts this schema object or array from a JSON structure -func (s *SchemaOrArray) UnmarshalJSON(data []byte) error { - var nw SchemaOrArray - var first byte - if len(data) > 1 { - first = data[0] - } - if first == '{' { - var sch Schema - if err := json.Unmarshal(data, &sch); err != nil { - return err - } - nw.Schema = &sch - } - if first == '[' { - if err := json.Unmarshal(data, &nw.Schemas); err != nil { - return err - } - } - *s = nw - return nil -} - -// vim:set ft=go noet sts=2 sw=2 ts=2: diff --git a/discovery/vendor/github.com/go-openapi/spec/tag.go b/discovery/vendor/github.com/go-openapi/spec/tag.go deleted file mode 100644 index 97f55584..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/tag.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -import ( - "encoding/json" - - "github.com/go-openapi/jsonpointer" - "github.com/go-openapi/swag" -) - -type TagProps struct { - Description string `json:"description,omitempty"` - Name string `json:"name,omitempty"` - ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` -} - -// NewTag creates a new tag -func NewTag(name, description string, externalDocs *ExternalDocumentation) Tag { - return Tag{TagProps: TagProps{description, name, externalDocs}} -} - -// Tag allows adding meta data to a single tag that is used by the [Operation Object](http://goo.gl/8us55a#operationObject). -// It is not mandatory to have a Tag Object per tag used there. -// -// For more information: http://goo.gl/8us55a#tagObject -type Tag struct { - VendorExtensible - TagProps -} - -// JSONLookup implements an interface to customize json pointer lookup -func (t Tag) JSONLookup(token string) (interface{}, error) { - if ex, ok := t.Extensions[token]; ok { - return &ex, nil - } - - r, _, err := jsonpointer.GetForToken(t.TagProps, token) - return r, err -} - -// MarshalJSON marshal this to JSON -func (t Tag) MarshalJSON() ([]byte, error) { - b1, err := json.Marshal(t.TagProps) - if err != nil { - return nil, err - } - b2, err := json.Marshal(t.VendorExtensible) - if err != nil { - return nil, err - } - return swag.ConcatJSON(b1, b2), nil -} - -// UnmarshalJSON marshal this from JSON -func (t *Tag) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, &t.TagProps); err != nil { - return err - } - return json.Unmarshal(data, &t.VendorExtensible) -} diff --git a/discovery/vendor/github.com/go-openapi/spec/xml_object.go b/discovery/vendor/github.com/go-openapi/spec/xml_object.go deleted file mode 100644 index 945a4670..00000000 --- a/discovery/vendor/github.com/go-openapi/spec/xml_object.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 spec - -// XMLObject a metadata object that allows for more fine-tuned XML model definitions. -// -// For more information: http://goo.gl/8us55a#xmlObject -type XMLObject struct { - Name string `json:"name,omitempty"` - Namespace string `json:"namespace,omitempty"` - Prefix string `json:"prefix,omitempty"` - Attribute bool `json:"attribute,omitempty"` - Wrapped bool `json:"wrapped,omitempty"` -} - -// WithName sets the xml name for the object -func (x *XMLObject) WithName(name string) *XMLObject { - x.Name = name - return x -} - -// WithNamespace sets the xml namespace for the object -func (x *XMLObject) WithNamespace(namespace string) *XMLObject { - x.Namespace = namespace - return x -} - -// WithPrefix sets the xml prefix for the object -func (x *XMLObject) WithPrefix(prefix string) *XMLObject { - x.Prefix = prefix - return x -} - -// AsAttribute flags this object as xml attribute -func (x *XMLObject) AsAttribute() *XMLObject { - x.Attribute = true - return x -} - -// AsElement flags this object as an xml node -func (x *XMLObject) AsElement() *XMLObject { - x.Attribute = false - return x -} - -// AsWrapped flags this object as wrapped, this is mostly useful for array types -func (x *XMLObject) AsWrapped() *XMLObject { - x.Wrapped = true - return x -} - -// AsUnwrapped flags this object as an xml node -func (x *XMLObject) AsUnwrapped() *XMLObject { - x.Wrapped = false - return x -} diff --git a/discovery/vendor/github.com/go-openapi/swag/.editorconfig b/discovery/vendor/github.com/go-openapi/swag/.editorconfig deleted file mode 100644 index 3152da69..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/.editorconfig +++ /dev/null @@ -1,26 +0,0 @@ -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -end_of_line = lf -insert_final_newline = true -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true - -# Set default charset -[*.{js,py,go,scala,rb,java,html,css,less,sass,md}] -charset = utf-8 - -# Tab indentation (no size specified) -[*.go] -indent_style = tab - -[*.md] -trim_trailing_whitespace = false - -# Matches the exact files either package.json or .travis.yml -[{package.json,.travis.yml}] -indent_style = space -indent_size = 2 diff --git a/discovery/vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md b/discovery/vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md deleted file mode 100644 index 7dea4240..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md +++ /dev/null @@ -1,117 +0,0 @@ -## Contribution Guidelines - -### Pull requests are always welcome - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep go-swagger lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* go-swagger. - - -### Conventions - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Update the documentation when creating or modifying features. Test -your documentation changes for clarity, concision, and correctness, as -well as a clean documentation build. See ``docs/README.md`` for more -information on building the docs and how docs get released. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run `gofmt -s -w file.go` on each changed file before -committing your changes. Most editors have plugins that do this automatically. - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Pull requests must not contain commits from other users or branches. - -Commit messages must start with a capitalized and short summary (max. 50 -chars) written in the imperative, followed by an optional, more detailed -explanatory text which is separated from the summary by an empty line. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using `git rebase -i` and `git push -f`. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like `Closes #XXX` -or `Fixes #XXX`, which will automatically close the issue when merged. - -### Sign your work - -The sign-off is a simple line at the end of the explanation for the -patch, which certifies that you wrote it or otherwise have the right to -pass it on as an open-source patch. The rules are pretty simple: if you -can certify the below (from -[developercertificate.org](http://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -660 York Street, Suite 102, -San Francisco, CA 94110 USA - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -then you just add a line to every git commit message: - - Signed-off-by: Joe Smith - -using your real name (sorry, no pseudonyms or anonymous contributions.) - -You can add the sign off when creating the git commit via `git commit -s`. diff --git a/discovery/vendor/github.com/go-openapi/swag/.gitignore b/discovery/vendor/github.com/go-openapi/swag/.gitignore deleted file mode 100644 index 5862205e..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -secrets.yml -vendor -Godeps diff --git a/discovery/vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md b/discovery/vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md deleted file mode 100644 index 9322b065..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at ivan+abuse@flanders.co.nz. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/discovery/vendor/github.com/go-openapi/swag/LICENSE b/discovery/vendor/github.com/go-openapi/swag/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/discovery/vendor/github.com/go-openapi/swag/README.md b/discovery/vendor/github.com/go-openapi/swag/README.md deleted file mode 100644 index 5d43728e..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Swag [![Build Status](https://travis-ci.org/go-openapi/swag.svg?branch=master)](https://travis-ci.org/go-openapi/swag) [![codecov](https://codecov.io/gh/go-openapi/swag/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/swag) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) - -[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/swag/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/swag?status.svg)](http://godoc.org/github.com/go-openapi/swag) - -Contains a bunch of helper functions: - -* convert between value and pointers for builtins -* convert from string to builtin -* fast json concatenation -* search in path -* load from file or http -* name manglin \ No newline at end of file diff --git a/discovery/vendor/github.com/go-openapi/swag/convert.go b/discovery/vendor/github.com/go-openapi/swag/convert.go deleted file mode 100644 index 2bf5ecbb..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/convert.go +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "math" - "strconv" - "strings" -) - -// same as ECMA Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER -const ( - maxJSONFloat = float64(1<<53 - 1) // 9007199254740991.0 2^53 - 1 - minJSONFloat = -float64(1<<53 - 1) //-9007199254740991.0 -2^53 - 1 -) - -// IsFloat64AJSONInteger allow for integers [-2^53, 2^53-1] inclusive -func IsFloat64AJSONInteger(f float64) bool { - if math.IsNaN(f) || math.IsInf(f, 0) || f < minJSONFloat || f > maxJSONFloat { - return false - } - - return f == float64(int64(f)) || f == float64(uint64(f)) -} - -var evaluatesAsTrue = map[string]struct{}{ - "true": struct{}{}, - "1": struct{}{}, - "yes": struct{}{}, - "ok": struct{}{}, - "y": struct{}{}, - "on": struct{}{}, - "selected": struct{}{}, - "checked": struct{}{}, - "t": struct{}{}, - "enabled": struct{}{}, -} - -// ConvertBool turn a string into a boolean -func ConvertBool(str string) (bool, error) { - _, ok := evaluatesAsTrue[strings.ToLower(str)] - return ok, nil -} - -// ConvertFloat32 turn a string into a float32 -func ConvertFloat32(str string) (float32, error) { - f, err := strconv.ParseFloat(str, 32) - if err != nil { - return 0, err - } - return float32(f), nil -} - -// ConvertFloat64 turn a string into a float64 -func ConvertFloat64(str string) (float64, error) { - return strconv.ParseFloat(str, 64) -} - -// ConvertInt8 turn a string into int8 boolean -func ConvertInt8(str string) (int8, error) { - i, err := strconv.ParseInt(str, 10, 8) - if err != nil { - return 0, err - } - return int8(i), nil -} - -// ConvertInt16 turn a string into a int16 -func ConvertInt16(str string) (int16, error) { - i, err := strconv.ParseInt(str, 10, 16) - if err != nil { - return 0, err - } - return int16(i), nil -} - -// ConvertInt32 turn a string into a int32 -func ConvertInt32(str string) (int32, error) { - i, err := strconv.ParseInt(str, 10, 32) - if err != nil { - return 0, err - } - return int32(i), nil -} - -// ConvertInt64 turn a string into a int64 -func ConvertInt64(str string) (int64, error) { - return strconv.ParseInt(str, 10, 64) -} - -// ConvertUint8 turn a string into a uint8 -func ConvertUint8(str string) (uint8, error) { - i, err := strconv.ParseUint(str, 10, 8) - if err != nil { - return 0, err - } - return uint8(i), nil -} - -// ConvertUint16 turn a string into a uint16 -func ConvertUint16(str string) (uint16, error) { - i, err := strconv.ParseUint(str, 10, 16) - if err != nil { - return 0, err - } - return uint16(i), nil -} - -// ConvertUint32 turn a string into a uint32 -func ConvertUint32(str string) (uint32, error) { - i, err := strconv.ParseUint(str, 10, 32) - if err != nil { - return 0, err - } - return uint32(i), nil -} - -// ConvertUint64 turn a string into a uint64 -func ConvertUint64(str string) (uint64, error) { - return strconv.ParseUint(str, 10, 64) -} - -// FormatBool turns a boolean into a string -func FormatBool(value bool) string { - return strconv.FormatBool(value) -} - -// FormatFloat32 turns a float32 into a string -func FormatFloat32(value float32) string { - return strconv.FormatFloat(float64(value), 'f', -1, 32) -} - -// FormatFloat64 turns a float64 into a string -func FormatFloat64(value float64) string { - return strconv.FormatFloat(value, 'f', -1, 64) -} - -// FormatInt8 turns an int8 into a string -func FormatInt8(value int8) string { - return strconv.FormatInt(int64(value), 10) -} - -// FormatInt16 turns an int16 into a string -func FormatInt16(value int16) string { - return strconv.FormatInt(int64(value), 10) -} - -// FormatInt32 turns an int32 into a string -func FormatInt32(value int32) string { - return strconv.Itoa(int(value)) -} - -// FormatInt64 turns an int64 into a string -func FormatInt64(value int64) string { - return strconv.FormatInt(value, 10) -} - -// FormatUint8 turns an uint8 into a string -func FormatUint8(value uint8) string { - return strconv.FormatUint(uint64(value), 10) -} - -// FormatUint16 turns an uint16 into a string -func FormatUint16(value uint16) string { - return strconv.FormatUint(uint64(value), 10) -} - -// FormatUint32 turns an uint32 into a string -func FormatUint32(value uint32) string { - return strconv.FormatUint(uint64(value), 10) -} - -// FormatUint64 turns an uint64 into a string -func FormatUint64(value uint64) string { - return strconv.FormatUint(value, 10) -} diff --git a/discovery/vendor/github.com/go-openapi/swag/convert_types.go b/discovery/vendor/github.com/go-openapi/swag/convert_types.go deleted file mode 100644 index c95e4e78..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/convert_types.go +++ /dev/null @@ -1,595 +0,0 @@ -package swag - -import "time" - -// This file was taken from the aws go sdk - -// String returns a pointer to of the string value passed in. -func String(v string) *string { - return &v -} - -// StringValue returns the value of the string pointer passed in or -// "" if the pointer is nil. -func StringValue(v *string) string { - if v != nil { - return *v - } - return "" -} - -// StringSlice converts a slice of string values into a slice of -// string pointers -func StringSlice(src []string) []*string { - dst := make([]*string, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// StringValueSlice converts a slice of string pointers into a slice of -// string values -func StringValueSlice(src []*string) []string { - dst := make([]string, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// StringMap converts a string map of string values into a string -// map of string pointers -func StringMap(src map[string]string) map[string]*string { - dst := make(map[string]*string) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// StringValueMap converts a string map of string pointers into a string -// map of string values -func StringValueMap(src map[string]*string) map[string]string { - dst := make(map[string]string) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Bool returns a pointer to of the bool value passed in. -func Bool(v bool) *bool { - return &v -} - -// BoolValue returns the value of the bool pointer passed in or -// false if the pointer is nil. -func BoolValue(v *bool) bool { - if v != nil { - return *v - } - return false -} - -// BoolSlice converts a slice of bool values into a slice of -// bool pointers -func BoolSlice(src []bool) []*bool { - dst := make([]*bool, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// BoolValueSlice converts a slice of bool pointers into a slice of -// bool values -func BoolValueSlice(src []*bool) []bool { - dst := make([]bool, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// BoolMap converts a string map of bool values into a string -// map of bool pointers -func BoolMap(src map[string]bool) map[string]*bool { - dst := make(map[string]*bool) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// BoolValueMap converts a string map of bool pointers into a string -// map of bool values -func BoolValueMap(src map[string]*bool) map[string]bool { - dst := make(map[string]bool) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int returns a pointer to of the int value passed in. -func Int(v int) *int { - return &v -} - -// IntValue returns the value of the int pointer passed in or -// 0 if the pointer is nil. -func IntValue(v *int) int { - if v != nil { - return *v - } - return 0 -} - -// IntSlice converts a slice of int values into a slice of -// int pointers -func IntSlice(src []int) []*int { - dst := make([]*int, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// IntValueSlice converts a slice of int pointers into a slice of -// int values -func IntValueSlice(src []*int) []int { - dst := make([]int, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// IntMap converts a string map of int values into a string -// map of int pointers -func IntMap(src map[string]int) map[string]*int { - dst := make(map[string]*int) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// IntValueMap converts a string map of int pointers into a string -// map of int values -func IntValueMap(src map[string]*int) map[string]int { - dst := make(map[string]int) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int32 returns a pointer to of the int64 value passed in. -func Int32(v int32) *int32 { - return &v -} - -// Int32Value returns the value of the int64 pointer passed in or -// 0 if the pointer is nil. -func Int32Value(v *int32) int32 { - if v != nil { - return *v - } - return 0 -} - -// Int32Slice converts a slice of int64 values into a slice of -// int32 pointers -func Int32Slice(src []int32) []*int32 { - dst := make([]*int32, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int32ValueSlice converts a slice of int32 pointers into a slice of -// int32 values -func Int32ValueSlice(src []*int32) []int32 { - dst := make([]int32, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int32Map converts a string map of int32 values into a string -// map of int32 pointers -func Int32Map(src map[string]int32) map[string]*int32 { - dst := make(map[string]*int32) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int32ValueMap converts a string map of int32 pointers into a string -// map of int32 values -func Int32ValueMap(src map[string]*int32) map[string]int32 { - dst := make(map[string]int32) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int64 returns a pointer to of the int64 value passed in. -func Int64(v int64) *int64 { - return &v -} - -// Int64Value returns the value of the int64 pointer passed in or -// 0 if the pointer is nil. -func Int64Value(v *int64) int64 { - if v != nil { - return *v - } - return 0 -} - -// Int64Slice converts a slice of int64 values into a slice of -// int64 pointers -func Int64Slice(src []int64) []*int64 { - dst := make([]*int64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int64ValueSlice converts a slice of int64 pointers into a slice of -// int64 values -func Int64ValueSlice(src []*int64) []int64 { - dst := make([]int64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int64Map converts a string map of int64 values into a string -// map of int64 pointers -func Int64Map(src map[string]int64) map[string]*int64 { - dst := make(map[string]*int64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int64ValueMap converts a string map of int64 pointers into a string -// map of int64 values -func Int64ValueMap(src map[string]*int64) map[string]int64 { - dst := make(map[string]int64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint returns a pouinter to of the uint value passed in. -func Uint(v uint) *uint { - return &v -} - -// UintValue returns the value of the uint pouinter passed in or -// 0 if the pouinter is nil. -func UintValue(v *uint) uint { - if v != nil { - return *v - } - return 0 -} - -// UintSlice converts a slice of uint values uinto a slice of -// uint pouinters -func UintSlice(src []uint) []*uint { - dst := make([]*uint, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// UintValueSlice converts a slice of uint pouinters uinto a slice of -// uint values -func UintValueSlice(src []*uint) []uint { - dst := make([]uint, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// UintMap converts a string map of uint values uinto a string -// map of uint pouinters -func UintMap(src map[string]uint) map[string]*uint { - dst := make(map[string]*uint) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// UintValueMap converts a string map of uint pouinters uinto a string -// map of uint values -func UintValueMap(src map[string]*uint) map[string]uint { - dst := make(map[string]uint) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint32 returns a pouinter to of the uint64 value passed in. -func Uint32(v uint32) *uint32 { - return &v -} - -// Uint32Value returns the value of the uint64 pouinter passed in or -// 0 if the pouinter is nil. -func Uint32Value(v *uint32) uint32 { - if v != nil { - return *v - } - return 0 -} - -// Uint32Slice converts a slice of uint64 values uinto a slice of -// uint32 pouinters -func Uint32Slice(src []uint32) []*uint32 { - dst := make([]*uint32, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint32ValueSlice converts a slice of uint32 pouinters uinto a slice of -// uint32 values -func Uint32ValueSlice(src []*uint32) []uint32 { - dst := make([]uint32, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint32Map converts a string map of uint32 values uinto a string -// map of uint32 pouinters -func Uint32Map(src map[string]uint32) map[string]*uint32 { - dst := make(map[string]*uint32) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint32ValueMap converts a string map of uint32 pouinters uinto a string -// map of uint32 values -func Uint32ValueMap(src map[string]*uint32) map[string]uint32 { - dst := make(map[string]uint32) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint64 returns a pouinter to of the uint64 value passed in. -func Uint64(v uint64) *uint64 { - return &v -} - -// Uint64Value returns the value of the uint64 pouinter passed in or -// 0 if the pouinter is nil. -func Uint64Value(v *uint64) uint64 { - if v != nil { - return *v - } - return 0 -} - -// Uint64Slice converts a slice of uint64 values uinto a slice of -// uint64 pouinters -func Uint64Slice(src []uint64) []*uint64 { - dst := make([]*uint64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint64ValueSlice converts a slice of uint64 pouinters uinto a slice of -// uint64 values -func Uint64ValueSlice(src []*uint64) []uint64 { - dst := make([]uint64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint64Map converts a string map of uint64 values uinto a string -// map of uint64 pouinters -func Uint64Map(src map[string]uint64) map[string]*uint64 { - dst := make(map[string]*uint64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint64ValueMap converts a string map of uint64 pouinters uinto a string -// map of uint64 values -func Uint64ValueMap(src map[string]*uint64) map[string]uint64 { - dst := make(map[string]uint64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Float64 returns a pointer to of the float64 value passed in. -func Float64(v float64) *float64 { - return &v -} - -// Float64Value returns the value of the float64 pointer passed in or -// 0 if the pointer is nil. -func Float64Value(v *float64) float64 { - if v != nil { - return *v - } - return 0 -} - -// Float64Slice converts a slice of float64 values into a slice of -// float64 pointers -func Float64Slice(src []float64) []*float64 { - dst := make([]*float64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Float64ValueSlice converts a slice of float64 pointers into a slice of -// float64 values -func Float64ValueSlice(src []*float64) []float64 { - dst := make([]float64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Float64Map converts a string map of float64 values into a string -// map of float64 pointers -func Float64Map(src map[string]float64) map[string]*float64 { - dst := make(map[string]*float64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Float64ValueMap converts a string map of float64 pointers into a string -// map of float64 values -func Float64ValueMap(src map[string]*float64) map[string]float64 { - dst := make(map[string]float64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Time returns a pointer to of the time.Time value passed in. -func Time(v time.Time) *time.Time { - return &v -} - -// TimeValue returns the value of the time.Time pointer passed in or -// time.Time{} if the pointer is nil. -func TimeValue(v *time.Time) time.Time { - if v != nil { - return *v - } - return time.Time{} -} - -// TimeSlice converts a slice of time.Time values into a slice of -// time.Time pointers -func TimeSlice(src []time.Time) []*time.Time { - dst := make([]*time.Time, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// TimeValueSlice converts a slice of time.Time pointers into a slice of -// time.Time values -func TimeValueSlice(src []*time.Time) []time.Time { - dst := make([]time.Time, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// TimeMap converts a string map of time.Time values into a string -// map of time.Time pointers -func TimeMap(src map[string]time.Time) map[string]*time.Time { - dst := make(map[string]*time.Time) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// TimeValueMap converts a string map of time.Time pointers into a string -// map of time.Time values -func TimeValueMap(src map[string]*time.Time) map[string]time.Time { - dst := make(map[string]time.Time) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} diff --git a/discovery/vendor/github.com/go-openapi/swag/json.go b/discovery/vendor/github.com/go-openapi/swag/json.go deleted file mode 100644 index cb20a6a0..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/json.go +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "bytes" - "encoding/json" - "log" - "reflect" - "strings" - "sync" - - "github.com/mailru/easyjson/jlexer" - "github.com/mailru/easyjson/jwriter" -) - -// DefaultJSONNameProvider the default cache for types -var DefaultJSONNameProvider = NewNameProvider() - -const comma = byte(',') - -var closers = map[byte]byte{ - '{': '}', - '[': ']', -} - -type ejMarshaler interface { - MarshalEasyJSON(w *jwriter.Writer) -} - -type ejUnmarshaler interface { - UnmarshalEasyJSON(w *jlexer.Lexer) -} - -// WriteJSON writes json data, prefers finding an appropriate interface to short-circuit the marshaller -// so it takes the fastest option available. -func WriteJSON(data interface{}) ([]byte, error) { - if d, ok := data.(ejMarshaler); ok { - jw := new(jwriter.Writer) - d.MarshalEasyJSON(jw) - return jw.BuildBytes() - } - if d, ok := data.(json.Marshaler); ok { - return d.MarshalJSON() - } - return json.Marshal(data) -} - -// ReadJSON reads json data, prefers finding an appropriate interface to short-circuit the unmarshaller -// so it takes the fastes option available -func ReadJSON(data []byte, value interface{}) error { - if d, ok := value.(ejUnmarshaler); ok { - jl := &jlexer.Lexer{Data: data} - d.UnmarshalEasyJSON(jl) - return jl.Error() - } - if d, ok := value.(json.Unmarshaler); ok { - return d.UnmarshalJSON(data) - } - return json.Unmarshal(data, value) -} - -// DynamicJSONToStruct converts an untyped json structure into a struct -func DynamicJSONToStruct(data interface{}, target interface{}) error { - // TODO: convert straight to a json typed map (mergo + iterate?) - b, err := WriteJSON(data) - if err != nil { - return err - } - if err := ReadJSON(b, target); err != nil { - return err - } - return nil -} - -// ConcatJSON concatenates multiple json objects efficiently -func ConcatJSON(blobs ...[]byte) []byte { - if len(blobs) == 0 { - return nil - } - if len(blobs) == 1 { - return blobs[0] - } - - last := len(blobs) - 1 - var opening, closing byte - a := 0 - idx := 0 - buf := bytes.NewBuffer(nil) - - for i, b := range blobs { - if len(b) > 0 && opening == 0 { // is this an array or an object? - opening, closing = b[0], closers[b[0]] - } - - if opening != '{' && opening != '[' { - continue // don't know how to concatenate non container objects - } - - if len(b) < 3 { // yep empty but also the last one, so closing this thing - if i == last && a > 0 { - if err := buf.WriteByte(closing); err != nil { - log.Println(err) - } - } - continue - } - - idx = 0 - if a > 0 { // we need to join with a comma for everything beyond the first non-empty item - if err := buf.WriteByte(comma); err != nil { - log.Println(err) - } - idx = 1 // this is not the first or the last so we want to drop the leading bracket - } - - if i != last { // not the last one, strip brackets - if _, err := buf.Write(b[idx : len(b)-1]); err != nil { - log.Println(err) - } - } else { // last one, strip only the leading bracket - if _, err := buf.Write(b[idx:]); err != nil { - log.Println(err) - } - } - a++ - } - // somehow it ended up being empty, so provide a default value - if buf.Len() == 0 { - if err := buf.WriteByte(opening); err != nil { - log.Println(err) - } - if err := buf.WriteByte(closing); err != nil { - log.Println(err) - } - } - return buf.Bytes() -} - -// ToDynamicJSON turns an object into a properly JSON typed structure -func ToDynamicJSON(data interface{}) interface{} { - // TODO: convert straight to a json typed map (mergo + iterate?) - b, err := json.Marshal(data) - if err != nil { - log.Println(err) - } - var res interface{} - if err := json.Unmarshal(b, &res); err != nil { - log.Println(err) - } - return res -} - -// FromDynamicJSON turns an object into a properly JSON typed structure -func FromDynamicJSON(data, target interface{}) error { - b, err := json.Marshal(data) - if err != nil { - log.Println(err) - } - return json.Unmarshal(b, target) -} - -// NameProvider represents an object capabale of translating from go property names -// to json property names -// This type is thread-safe. -type NameProvider struct { - lock *sync.Mutex - index map[reflect.Type]nameIndex -} - -type nameIndex struct { - jsonNames map[string]string - goNames map[string]string -} - -// NewNameProvider creates a new name provider -func NewNameProvider() *NameProvider { - return &NameProvider{ - lock: &sync.Mutex{}, - index: make(map[reflect.Type]nameIndex), - } -} - -func buildnameIndex(tpe reflect.Type, idx, reverseIdx map[string]string) { - for i := 0; i < tpe.NumField(); i++ { - targetDes := tpe.Field(i) - - if targetDes.PkgPath != "" { // unexported - continue - } - - if targetDes.Anonymous { // walk embedded structures tree down first - buildnameIndex(targetDes.Type, idx, reverseIdx) - continue - } - - if tag := targetDes.Tag.Get("json"); tag != "" { - - parts := strings.Split(tag, ",") - if len(parts) == 0 { - continue - } - - nm := parts[0] - if nm == "-" { - continue - } - if nm == "" { // empty string means we want to use the Go name - nm = targetDes.Name - } - - idx[nm] = targetDes.Name - reverseIdx[targetDes.Name] = nm - } - } -} - -func newNameIndex(tpe reflect.Type) nameIndex { - var idx = make(map[string]string, tpe.NumField()) - var reverseIdx = make(map[string]string, tpe.NumField()) - - buildnameIndex(tpe, idx, reverseIdx) - return nameIndex{jsonNames: idx, goNames: reverseIdx} -} - -// GetJSONNames gets all the json property names for a type -func (n *NameProvider) GetJSONNames(subject interface{}) []string { - n.lock.Lock() - defer n.lock.Unlock() - tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() - names, ok := n.index[tpe] - if !ok { - names = n.makeNameIndex(tpe) - } - - var res []string - for k := range names.jsonNames { - res = append(res, k) - } - return res -} - -// GetJSONName gets the json name for a go property name -func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) { - tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() - return n.GetJSONNameForType(tpe, name) -} - -// GetJSONNameForType gets the json name for a go property name on a given type -func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool) { - n.lock.Lock() - defer n.lock.Unlock() - names, ok := n.index[tpe] - if !ok { - names = n.makeNameIndex(tpe) - } - nme, ok := names.goNames[name] - return nme, ok -} - -func (n *NameProvider) makeNameIndex(tpe reflect.Type) nameIndex { - names := newNameIndex(tpe) - n.index[tpe] = names - return names -} - -// GetGoName gets the go name for a json property name -func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) { - tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() - return n.GetGoNameForType(tpe, name) -} - -// GetGoNameForType gets the go name for a given type for a json property name -func (n *NameProvider) GetGoNameForType(tpe reflect.Type, name string) (string, bool) { - n.lock.Lock() - defer n.lock.Unlock() - names, ok := n.index[tpe] - if !ok { - names = n.makeNameIndex(tpe) - } - nme, ok := names.jsonNames[name] - return nme, ok -} diff --git a/discovery/vendor/github.com/go-openapi/swag/loading.go b/discovery/vendor/github.com/go-openapi/swag/loading.go deleted file mode 100644 index 62ed1e80..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/loading.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "fmt" - "io/ioutil" - "log" - "net/http" - "path/filepath" - "strings" - "time" -) - -// LoadHTTPTimeout the default timeout for load requests -var LoadHTTPTimeout = 30 * time.Second - -// LoadFromFileOrHTTP loads the bytes from a file or a remote http server based on the path passed in -func LoadFromFileOrHTTP(path string) ([]byte, error) { - return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(LoadHTTPTimeout))(path) -} - -// LoadFromFileOrHTTPWithTimeout loads the bytes from a file or a remote http server based on the path passed in -// timeout arg allows for per request overriding of the request timeout -func LoadFromFileOrHTTPWithTimeout(path string, timeout time.Duration) ([]byte, error) { - return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(timeout))(path) -} - -// LoadStrategy returns a loader function for a given path or uri -func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error) { - if strings.HasPrefix(path, "http") { - return remote - } - return func(pth string) ([]byte, error) { return local(filepath.FromSlash(pth)) } -} - -func loadHTTPBytes(timeout time.Duration) func(path string) ([]byte, error) { - return func(path string) ([]byte, error) { - client := &http.Client{Timeout: timeout} - req, err := http.NewRequest("GET", path, nil) - if err != nil { - return nil, err - } - resp, err := client.Do(req) - defer func() { - if resp != nil { - if e := resp.Body.Close(); e != nil { - log.Println(e) - } - } - }() - if err != nil { - return nil, err - } - - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("could not access document at %q [%s] ", path, resp.Status) - } - - return ioutil.ReadAll(resp.Body) - } -} diff --git a/discovery/vendor/github.com/go-openapi/swag/net.go b/discovery/vendor/github.com/go-openapi/swag/net.go deleted file mode 100644 index 8323fa37..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/net.go +++ /dev/null @@ -1,24 +0,0 @@ -package swag - -import ( - "net" - "strconv" -) - -// SplitHostPort splits a network address into a host and a port. -// The port is -1 when there is no port to be found -func SplitHostPort(addr string) (host string, port int, err error) { - h, p, err := net.SplitHostPort(addr) - if err != nil { - return "", -1, err - } - if p == "" { - return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr} - } - - pi, err := strconv.Atoi(p) - if err != nil { - return "", -1, err - } - return h, pi, nil -} diff --git a/discovery/vendor/github.com/go-openapi/swag/path.go b/discovery/vendor/github.com/go-openapi/swag/path.go deleted file mode 100644 index 941bd017..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/path.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "os" - "path/filepath" - "runtime" - "strings" -) - -const ( - // GOPATHKey represents the env key for gopath - GOPATHKey = "GOPATH" -) - -// FindInSearchPath finds a package in a provided lists of paths -func FindInSearchPath(searchPath, pkg string) string { - pathsList := filepath.SplitList(searchPath) - for _, path := range pathsList { - if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil { - if _, err := os.Stat(evaluatedPath); err == nil { - return evaluatedPath - } - } - } - return "" -} - -// FindInGoSearchPath finds a package in the $GOPATH:$GOROOT -func FindInGoSearchPath(pkg string) string { - return FindInSearchPath(FullGoSearchPath(), pkg) -} - -// FullGoSearchPath gets the search paths for finding packages -func FullGoSearchPath() string { - allPaths := os.Getenv(GOPATHKey) - if allPaths == "" { - allPaths = filepath.Join(os.Getenv("HOME"), "go") - } - if allPaths != "" { - allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":") - } else { - allPaths = runtime.GOROOT() - } - return allPaths -} diff --git a/discovery/vendor/github.com/go-openapi/swag/util.go b/discovery/vendor/github.com/go-openapi/swag/util.go deleted file mode 100644 index 0efb4173..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/util.go +++ /dev/null @@ -1,374 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "math" - "reflect" - "regexp" - "sort" - "strings" - "unicode" -) - -// Taken from https://github.com/golang/lint/blob/3390df4df2787994aea98de825b964ac7944b817/lint.go#L732-L769 -var commonInitialisms = map[string]bool{ - "ACL": true, - "API": true, - "ASCII": true, - "CPU": true, - "CSS": true, - "DNS": true, - "EOF": true, - "GUID": true, - "HTML": true, - "HTTPS": true, - "HTTP": true, - "ID": true, - "IP": true, - "JSON": true, - "LHS": true, - "OAI": true, - "QPS": true, - "RAM": true, - "RHS": true, - "RPC": true, - "SLA": true, - "SMTP": true, - "SQL": true, - "SSH": true, - "TCP": true, - "TLS": true, - "TTL": true, - "UDP": true, - "UI": true, - "UID": true, - "UUID": true, - "URI": true, - "URL": true, - "UTF8": true, - "VM": true, - "XML": true, - "XMPP": true, - "XSRF": true, - "XSS": true, -} -var initialisms []string - -func init() { - for k := range commonInitialisms { - initialisms = append(initialisms, k) - } - sort.Sort(sort.Reverse(byLength(initialisms))) -} - -// JoinByFormat joins a string array by a known format: -// ssv: space separated value -// tsv: tab separated value -// pipes: pipe (|) separated value -// csv: comma separated value (default) -func JoinByFormat(data []string, format string) []string { - if len(data) == 0 { - return data - } - var sep string - switch format { - case "ssv": - sep = " " - case "tsv": - sep = "\t" - case "pipes": - sep = "|" - case "multi": - return data - default: - sep = "," - } - return []string{strings.Join(data, sep)} -} - -// SplitByFormat splits a string by a known format: -// ssv: space separated value -// tsv: tab separated value -// pipes: pipe (|) separated value -// csv: comma separated value (default) -func SplitByFormat(data, format string) []string { - if data == "" { - return nil - } - var sep string - switch format { - case "ssv": - sep = " " - case "tsv": - sep = "\t" - case "pipes": - sep = "|" - case "multi": - return nil - default: - sep = "," - } - var result []string - for _, s := range strings.Split(data, sep) { - if ts := strings.TrimSpace(s); ts != "" { - result = append(result, ts) - } - } - return result -} - -type byLength []string - -func (s byLength) Len() int { - return len(s) -} -func (s byLength) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} -func (s byLength) Less(i, j int) bool { - return len(s[i]) < len(s[j]) -} - -// Prepares strings by splitting by caps, spaces, dashes, and underscore -func split(str string) (words []string) { - repl := strings.NewReplacer( - "@", "At ", - "&", "And ", - "|", "Pipe ", - "$", "Dollar ", - "!", "Bang ", - "-", " ", - "_", " ", - ) - - rex1 := regexp.MustCompile(`(\p{Lu})`) - rex2 := regexp.MustCompile(`(\pL|\pM|\pN|\p{Pc})+`) - - str = trim(str) - - // Convert dash and underscore to spaces - str = repl.Replace(str) - - // Split when uppercase is found (needed for Snake) - str = rex1.ReplaceAllString(str, " $1") - - // check if consecutive single char things make up an initialism - for _, k := range initialisms { - str = strings.Replace(str, rex1.ReplaceAllString(k, " $1"), " "+k, -1) - } - // Get the final list of words - words = rex2.FindAllString(str, -1) - - return -} - -// Removes leading whitespaces -func trim(str string) string { - return strings.Trim(str, " ") -} - -// Shortcut to strings.ToUpper() -func upper(str string) string { - return strings.ToUpper(trim(str)) -} - -// Shortcut to strings.ToLower() -func lower(str string) string { - return strings.ToLower(trim(str)) -} - -// Camelize an uppercased word -func Camelize(word string) (camelized string) { - for pos, ru := range word { - if pos > 0 { - camelized += string(unicode.ToLower(ru)) - } else { - camelized += string(unicode.ToUpper(ru)) - } - } - return -} - -// ToFileName lowercases and underscores a go type name -func ToFileName(name string) string { - var out []string - cml := trim(name) - - // Camelize any capital word preceding a reserved keyword ("initialism") - // thus, upper-cased words preceding a common initialism will get separated - // e.g: ELBHTTPLoadBalancer becomes elb_http_load_balancer - rexPrevious := regexp.MustCompile(`(?P\p{Lu}{2,})(?:HTTP|OAI)`) - cml = rexPrevious.ReplaceAllStringFunc(cml, func(match string) (replaceInMatch string) { - for _, m := range rexPrevious.FindAllStringSubmatch(match, -1) { // [ match submatch ] - if m[1] != "" { - replaceInMatch = strings.Replace(m[0], m[1], Camelize(m[1]), -1) - } - } - return - }) - - // Pre-camelize reserved keywords ("initialisms") to avoid unnecessary hyphenization - for _, k := range initialisms { - cml = strings.Replace(cml, k, Camelize(k), -1) - } - - // Camelize other capital words to avoid unnecessary hyphenization - rexCase := regexp.MustCompile(`(\p{Lu}{2,})`) - cml = rexCase.ReplaceAllStringFunc(cml, Camelize) - - // Final split with hyphens - for _, w := range split(cml) { - out = append(out, lower(w)) - } - return strings.Join(out, "_") -} - -// ToCommandName lowercases and underscores a go type name -func ToCommandName(name string) string { - var out []string - for _, w := range split(name) { - out = append(out, lower(w)) - } - return strings.Join(out, "-") -} - -// ToHumanNameLower represents a code name as a human series of words -func ToHumanNameLower(name string) string { - var out []string - for _, w := range split(name) { - if !commonInitialisms[upper(w)] { - out = append(out, lower(w)) - } else { - out = append(out, w) - } - } - return strings.Join(out, " ") -} - -// ToHumanNameTitle represents a code name as a human series of words with the first letters titleized -func ToHumanNameTitle(name string) string { - var out []string - for _, w := range split(name) { - uw := upper(w) - if !commonInitialisms[uw] { - out = append(out, upper(w[:1])+lower(w[1:])) - } else { - out = append(out, w) - } - } - return strings.Join(out, " ") -} - -// ToJSONName camelcases a name which can be underscored or pascal cased -func ToJSONName(name string) string { - var out []string - for i, w := range split(name) { - if i == 0 { - out = append(out, lower(w)) - continue - } - out = append(out, upper(w[:1])+lower(w[1:])) - } - return strings.Join(out, "") -} - -// ToVarName camelcases a name which can be underscored or pascal cased -func ToVarName(name string) string { - res := ToGoName(name) - if _, ok := commonInitialisms[res]; ok { - return lower(res) - } - if len(res) <= 1 { - return lower(res) - } - return lower(res[:1]) + res[1:] -} - -// ToGoName translates a swagger name which can be underscored or camel cased to a name that golint likes -func ToGoName(name string) string { - var out []string - for _, w := range split(name) { - uw := upper(w) - mod := int(math.Min(float64(len(uw)), 2)) - if !commonInitialisms[uw] && !commonInitialisms[uw[:len(uw)-mod]] { - uw = upper(w[:1]) + lower(w[1:]) - } - out = append(out, uw) - } - - result := strings.Join(out, "") - if len(result) > 0 { - ud := upper(result[:1]) - ru := []rune(ud) - if unicode.IsUpper(ru[0]) { - result = ud + result[1:] - } else { - result = "X" + ud + result[1:] - } - } - return result -} - -// ContainsStringsCI searches a slice of strings for a case-insensitive match -func ContainsStringsCI(coll []string, item string) bool { - for _, a := range coll { - if strings.EqualFold(a, item) { - return true - } - } - return false -} - -type zeroable interface { - IsZero() bool -} - -// IsZero returns true when the value passed into the function is a zero value. -// This allows for safer checking of interface values. -func IsZero(data interface{}) bool { - // check for things that have an IsZero method instead - if vv, ok := data.(zeroable); ok { - return vv.IsZero() - } - // continue with slightly more complex reflection - v := reflect.ValueOf(data) - switch v.Kind() { - case reflect.String: - return v.Len() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - return v.IsNil() - case reflect.Struct, reflect.Array: - return reflect.DeepEqual(data, reflect.Zero(v.Type()).Interface()) - case reflect.Invalid: - return true - } - return false -} - -// CommandLineOptionsGroup represents a group of user-defined command line options -type CommandLineOptionsGroup struct { - ShortDescription string - LongDescription string - Options interface{} -} diff --git a/discovery/vendor/github.com/go-openapi/swag/yaml.go b/discovery/vendor/github.com/go-openapi/swag/yaml.go deleted file mode 100644 index 26502f21..00000000 --- a/discovery/vendor/github.com/go-openapi/swag/yaml.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2015 go-swagger maintainers -// -// 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 swag - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - - "github.com/mailru/easyjson/jlexer" - "github.com/mailru/easyjson/jwriter" - - yaml "gopkg.in/yaml.v2" -) - -// YAMLMatcher matches yaml -func YAMLMatcher(path string) bool { - ext := filepath.Ext(path) - return ext == ".yaml" || ext == ".yml" -} - -// YAMLToJSON converts YAML unmarshaled data into json compatible data -func YAMLToJSON(data interface{}) (json.RawMessage, error) { - jm, err := transformData(data) - if err != nil { - return nil, err - } - b, err := WriteJSON(jm) - return json.RawMessage(b), err -} - -func BytesToYAMLDoc(data []byte) (interface{}, error) { - var canary map[interface{}]interface{} // validate this is an object and not a different type - if err := yaml.Unmarshal(data, &canary); err != nil { - return nil, err - } - - var document yaml.MapSlice // preserve order that is present in the document - if err := yaml.Unmarshal(data, &document); err != nil { - return nil, err - } - return document, nil -} - -type JSONMapSlice []JSONMapItem - -func (s JSONMapSlice) MarshalJSON() ([]byte, error) { - w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} - s.MarshalEasyJSON(w) - return w.BuildBytes() -} - -func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer) { - w.RawByte('{') - - ln := len(s) - last := ln - 1 - for i := 0; i < ln; i++ { - s[i].MarshalEasyJSON(w) - if i != last { // last item - w.RawByte(',') - } - } - - w.RawByte('}') -} - -func (s *JSONMapSlice) UnmarshalJSON(data []byte) error { - l := jlexer.Lexer{Data: data} - s.UnmarshalEasyJSON(&l) - return l.Error() -} -func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer) { - if in.IsNull() { - in.Skip() - return - } - - var result JSONMapSlice - in.Delim('{') - for !in.IsDelim('}') { - var mi JSONMapItem - mi.UnmarshalEasyJSON(in) - result = append(result, mi) - } - *s = result -} - -type JSONMapItem struct { - Key string - Value interface{} -} - -func (s JSONMapItem) MarshalJSON() ([]byte, error) { - w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} - s.MarshalEasyJSON(w) - return w.BuildBytes() -} - -func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) { - w.String(s.Key) - w.RawByte(':') - w.Raw(WriteJSON(s.Value)) -} - -func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) { - key := in.UnsafeString() - in.WantColon() - value := in.Interface() - in.WantComma() - s.Key = key - s.Value = value -} -func (s *JSONMapItem) UnmarshalJSON(data []byte) error { - l := jlexer.Lexer{Data: data} - s.UnmarshalEasyJSON(&l) - return l.Error() -} - -func transformData(input interface{}) (out interface{}, err error) { - switch in := input.(type) { - case yaml.MapSlice: - - o := make(JSONMapSlice, len(in)) - for i, mi := range in { - var nmi JSONMapItem - switch k := mi.Key.(type) { - case string: - nmi.Key = k - case int: - nmi.Key = strconv.Itoa(k) - default: - return nil, fmt.Errorf("types don't match expect map key string or int got: %T", mi.Key) - } - - v, err := transformData(mi.Value) - if err != nil { - return nil, err - } - nmi.Value = v - o[i] = nmi - } - return o, nil - case map[interface{}]interface{}: - o := make(JSONMapSlice, 0, len(in)) - for ke, va := range in { - var nmi JSONMapItem - switch k := ke.(type) { - case string: - nmi.Key = k - case int: - nmi.Key = strconv.Itoa(k) - default: - return nil, fmt.Errorf("types don't match expect map key string or int got: %T", ke) - } - - v, err := transformData(va) - if err != nil { - return nil, err - } - nmi.Value = v - o = append(o, nmi) - } - return o, nil - case []interface{}: - len1 := len(in) - o := make([]interface{}, len1) - for i := 0; i < len1; i++ { - o[i], err = transformData(in[i]) - if err != nil { - return nil, err - } - } - return o, nil - } - return input, nil -} - -// YAMLDoc loads a yaml document from either http or a file and converts it to json -func YAMLDoc(path string) (json.RawMessage, error) { - yamlDoc, err := YAMLData(path) - if err != nil { - return nil, err - } - - data, err := YAMLToJSON(yamlDoc) - if err != nil { - return nil, err - } - - return json.RawMessage(data), nil -} - -// YAMLData loads a yaml document from either http or a file -func YAMLData(path string) (interface{}, error) { - data, err := LoadFromFileOrHTTP(path) - if err != nil { - return nil, err - } - - return BytesToYAMLDoc(data) -} diff --git a/discovery/vendor/github.com/gogo/protobuf/.travis.yml b/discovery/vendor/github.com/gogo/protobuf/.travis.yml new file mode 100644 index 00000000..7f69fba0 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/.travis.yml @@ -0,0 +1,20 @@ +env: + - PROTOBUF_VERSION=2.6.1 + - PROTOBUF_VERSION=3.0.2 + - PROTOBUF_VERSION=3.4.0 + +before_install: + - ./install-protobuf.sh + - PATH=/home/travis/bin:$PATH protoc --version + +script: + - PATH=/home/travis/bin:$PATH make buildserverall + - echo $TRAVIS_GO_VERSION + - if [ "$TRAVIS_GO_VERSION" == 1.9 ] && [[ "$PROTOBUF_VERSION" == 3.4.0 ]]; then ! git status --porcelain | read || (git status; git diff; exit 1); fi + +language: go + +go: + - 1.8.3 + - 1.9 + diff --git a/discovery/vendor/github.com/gogo/protobuf/codec/codec_test.go b/discovery/vendor/github.com/gogo/protobuf/codec/codec_test.go new file mode 100644 index 00000000..de2c9bc4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/codec/codec_test.go @@ -0,0 +1,54 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package codec + +import ( + "github.com/gogo/protobuf/test" + "math/rand" + "testing" + "time" +) + +func TestCodec(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + in := test.NewPopulatedNinOptStruct(r, true) + c := New(r.Intn(1024)) + data, err := c.Marshal(in) + if err != nil { + t.Fatal(err) + } + out := &test.NinOptStruct{} + err = c.Unmarshal(data, out) + if err != nil { + t.Fatal(err) + } + if err := in.VerboseEqual(out); err != nil { + t.Fatal(err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/io/io_test.go b/discovery/vendor/github.com/gogo/protobuf/io/io_test.go new file mode 100644 index 00000000..0b74b310 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/io/io_test.go @@ -0,0 +1,221 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package io_test + +import ( + "bytes" + "encoding/binary" + "github.com/gogo/protobuf/io" + "github.com/gogo/protobuf/test" + goio "io" + "math/rand" + "testing" + "time" +) + +func iotest(writer io.WriteCloser, reader io.ReadCloser) error { + size := 1000 + msgs := make([]*test.NinOptNative, size) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for i := range msgs { + msgs[i] = test.NewPopulatedNinOptNative(r, true) + //issue 31 + if i == 5 { + msgs[i] = &test.NinOptNative{} + } + //issue 31 + if i == 999 { + msgs[i] = &test.NinOptNative{} + } + err := writer.WriteMsg(msgs[i]) + if err != nil { + return err + } + } + if err := writer.Close(); err != nil { + return err + } + i := 0 + for { + msg := &test.NinOptNative{} + if err := reader.ReadMsg(msg); err != nil { + if err == goio.EOF { + break + } + return err + } + if err := msg.VerboseEqual(msgs[i]); err != nil { + return err + } + i++ + } + if i != size { + panic("not enough messages read") + } + if err := reader.Close(); err != nil { + return err + } + return nil +} + +type buffer struct { + *bytes.Buffer + closed bool +} + +func (this *buffer) Close() error { + this.closed = true + return nil +} + +func newBuffer() *buffer { + return &buffer{bytes.NewBuffer(nil), false} +} + +func TestBigUint32Normal(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian) + reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestBigUint32MaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian) + reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestLittleUint32Normal(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian) + reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestLittleUint32MaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian) + reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestVarintNormal(t *testing.T) { + buf := newBuffer() + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestVarintNoClose(t *testing.T) { + buf := bytes.NewBuffer(nil) + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } +} + +//issue 32 +func TestVarintMaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestVarintError(t *testing.T) { + buf := newBuffer() + buf.Write([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}) + reader := io.NewDelimitedReader(buf, 1024*1024) + msg := &test.NinOptNative{} + err := reader.ReadMsg(msg) + if err == nil { + t.Fatalf("Expected error") + } +} + +func TestFull(t *testing.T) { + buf := newBuffer() + writer := io.NewFullWriter(buf) + reader := io.NewFullReader(buf, 1024*1024) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msgIn := test.NewPopulatedNinOptNative(r, true) + if err := writer.WriteMsg(msgIn); err != nil { + panic(err) + } + if err := writer.Close(); err != nil { + panic(err) + } + msgOut := &test.NinOptNative{} + if err := reader.ReadMsg(msgOut); err != nil { + panic(err) + } + if err := msgIn.VerboseEqual(msgOut); err != nil { + panic(err) + } + if err := reader.ReadMsg(msgOut); err != nil { + if err != goio.EOF { + panic(err) + } + } + if err := reader.Close(); err != nil { + panic(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/io/uint32_test.go b/discovery/vendor/github.com/gogo/protobuf/io/uint32_test.go new file mode 100644 index 00000000..d837e4a9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/io/uint32_test.go @@ -0,0 +1,38 @@ +package io_test + +import ( + "encoding/binary" + "io/ioutil" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/test" + example "github.com/gogo/protobuf/test/example" + + "github.com/gogo/protobuf/io" +) + +func BenchmarkUint32DelimWriterMarshaller(b *testing.B) { + w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msg := example.NewPopulatedA(r, true) + + for i := 0; i < b.N; i++ { + if err := w.WriteMsg(msg); err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkUint32DelimWriterFallback(b *testing.B) { + w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msg := test.NewPopulatedNinOptNative(r, true) + + for i := 0; i < b.N; i++ { + if err := w.WriteMsg(msg); err != nil { + b.Fatal(err) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go b/discovery/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go new file mode 100644 index 00000000..c4442704 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go @@ -0,0 +1,783 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package jsonpb + +import ( + "bytes" + "encoding/json" + "io" + "math" + "reflect" + "strings" + "testing" + + pb "github.com/gogo/protobuf/jsonpb/jsonpb_test_proto" + "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + "github.com/gogo/protobuf/types" +) + +var ( + marshaler = Marshaler{} + + marshalerAllOptions = Marshaler{ + Indent: " ", + } + + simpleObject = &pb.Simple{ + OInt32: proto.Int32(-32), + OInt64: proto.Int64(-6400000000), + OUint32: proto.Uint32(32), + OUint64: proto.Uint64(6400000000), + OSint32: proto.Int32(-13), + OSint64: proto.Int64(-2600000000), + OFloat: proto.Float32(3.14), + ODouble: proto.Float64(6.02214179e23), + OBool: proto.Bool(true), + OString: proto.String("hello \"there\""), + OBytes: []byte("beep boop"), + OCastBytes: pb.Bytes("wow"), + } + + simpleObjectJSON = `{` + + `"oBool":true,` + + `"oInt32":-32,` + + `"oInt64":"-6400000000",` + + `"oUint32":32,` + + `"oUint64":"6400000000",` + + `"oSint32":-13,` + + `"oSint64":"-2600000000",` + + `"oFloat":3.14,` + + `"oDouble":6.02214179e+23,` + + `"oString":"hello \"there\"",` + + `"oBytes":"YmVlcCBib29w",` + + `"oCastBytes":"d293"` + + `}` + + simpleObjectPrettyJSON = `{ + "oBool": true, + "oInt32": -32, + "oInt64": "-6400000000", + "oUint32": 32, + "oUint64": "6400000000", + "oSint32": -13, + "oSint64": "-2600000000", + "oFloat": 3.14, + "oDouble": 6.02214179e+23, + "oString": "hello \"there\"", + "oBytes": "YmVlcCBib29w", + "oCastBytes": "d293" +}` + + repeatsObject = &pb.Repeats{ + RBool: []bool{true, false, true}, + RInt32: []int32{-3, -4, -5}, + RInt64: []int64{-123456789, -987654321}, + RUint32: []uint32{1, 2, 3}, + RUint64: []uint64{6789012345, 3456789012}, + RSint32: []int32{-1, -2, -3}, + RSint64: []int64{-6789012345, -3456789012}, + RFloat: []float32{3.14, 6.28}, + RDouble: []float64{299792458 * 1e20, 6.62606957e-34}, + RString: []string{"happy", "days"}, + RBytes: [][]byte{[]byte("skittles"), []byte("m&m's")}, + } + + repeatsObjectJSON = `{` + + `"rBool":[true,false,true],` + + `"rInt32":[-3,-4,-5],` + + `"rInt64":["-123456789","-987654321"],` + + `"rUint32":[1,2,3],` + + `"rUint64":["6789012345","3456789012"],` + + `"rSint32":[-1,-2,-3],` + + `"rSint64":["-6789012345","-3456789012"],` + + `"rFloat":[3.14,6.28],` + + `"rDouble":[2.99792458e+28,6.62606957e-34],` + + `"rString":["happy","days"],` + + `"rBytes":["c2tpdHRsZXM=","bSZtJ3M="]` + + `}` + + repeatsObjectPrettyJSON = `{ + "rBool": [ + true, + false, + true + ], + "rInt32": [ + -3, + -4, + -5 + ], + "rInt64": [ + "-123456789", + "-987654321" + ], + "rUint32": [ + 1, + 2, + 3 + ], + "rUint64": [ + "6789012345", + "3456789012" + ], + "rSint32": [ + -1, + -2, + -3 + ], + "rSint64": [ + "-6789012345", + "-3456789012" + ], + "rFloat": [ + 3.14, + 6.28 + ], + "rDouble": [ + 2.99792458e+28, + 6.62606957e-34 + ], + "rString": [ + "happy", + "days" + ], + "rBytes": [ + "c2tpdHRsZXM=", + "bSZtJ3M=" + ] +}` + + innerSimple = &pb.Simple{OInt32: proto.Int32(-32)} + innerSimple2 = &pb.Simple{OInt64: proto.Int64(25)} + innerRepeats = &pb.Repeats{RString: []string{"roses", "red"}} + innerRepeats2 = &pb.Repeats{RString: []string{"violets", "blue"}} + complexObject = &pb.Widget{ + Color: pb.Widget_GREEN.Enum(), + RColor: []pb.Widget_Color{pb.Widget_RED, pb.Widget_GREEN, pb.Widget_BLUE}, + Simple: innerSimple, + RSimple: []*pb.Simple{innerSimple, innerSimple2}, + Repeats: innerRepeats, + RRepeats: []*pb.Repeats{innerRepeats, innerRepeats2}, + } + + complexObjectJSON = `{"color":"GREEN",` + + `"rColor":["RED","GREEN","BLUE"],` + + `"simple":{"oInt32":-32},` + + `"rSimple":[{"oInt32":-32},{"oInt64":"25"}],` + + `"repeats":{"rString":["roses","red"]},` + + `"rRepeats":[{"rString":["roses","red"]},{"rString":["violets","blue"]}]` + + `}` + + complexObjectPrettyJSON = `{ + "color": "GREEN", + "rColor": [ + "RED", + "GREEN", + "BLUE" + ], + "simple": { + "oInt32": -32 + }, + "rSimple": [ + { + "oInt32": -32 + }, + { + "oInt64": "25" + } + ], + "repeats": { + "rString": [ + "roses", + "red" + ] + }, + "rRepeats": [ + { + "rString": [ + "roses", + "red" + ] + }, + { + "rString": [ + "violets", + "blue" + ] + } + ] +}` + + colorPrettyJSON = `{ + "color": 2 +}` + + colorListPrettyJSON = `{ + "color": 1000, + "rColor": [ + "RED" + ] +}` + + nummyPrettyJSON = `{ + "nummy": { + "1": 2, + "3": 4 + } +}` + + objjyPrettyJSON = `{ + "objjy": { + "1": { + "dub": 1 + } + } +}` + realNumber = &pb.Real{Value: proto.Float64(3.14159265359)} + realNumberName = "Pi" + complexNumber = &pb.Complex{Imaginary: proto.Float64(0.5772156649)} + realNumberJSON = `{` + + `"value":3.14159265359,` + + `"[jsonpb.Complex.real_extension]":{"imaginary":0.5772156649},` + + `"[jsonpb.name]":"Pi"` + + `}` + + anySimple = &pb.KnownTypes{ + An: &types.Any{ + TypeUrl: "something.example.com/jsonpb.Simple", + Value: []byte{ + // &pb.Simple{OBool:true} + 1 << 3, 1, + }, + }, + } + anySimpleJSON = `{"an":{"@type":"something.example.com/jsonpb.Simple","oBool":true}}` + anySimplePrettyJSON = `{ + "an": { + "@type": "something.example.com/jsonpb.Simple", + "oBool": true + } +}` + + anyWellKnown = &pb.KnownTypes{ + An: &types.Any{ + TypeUrl: "type.googleapis.com/google.protobuf.Duration", + Value: []byte{ + // &durpb.Duration{Seconds: 1, Nanos: 212000000 } + 1 << 3, 1, // seconds + 2 << 3, 0x80, 0xba, 0x8b, 0x65, // nanos + }, + }, + } + anyWellKnownJSON = `{"an":{"@type":"type.googleapis.com/google.protobuf.Duration","value":"1.212s"}}` + anyWellKnownPrettyJSON = `{ + "an": { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } +}` + + nonFinites = &pb.NonFinites{ + FNan: proto.Float32(float32(math.NaN())), + FPinf: proto.Float32(float32(math.Inf(1))), + FNinf: proto.Float32(float32(math.Inf(-1))), + DNan: proto.Float64(float64(math.NaN())), + DPinf: proto.Float64(float64(math.Inf(1))), + DNinf: proto.Float64(float64(math.Inf(-1))), + } + nonFinitesJSON = `{` + + `"fNan":"NaN",` + + `"fPinf":"Infinity",` + + `"fNinf":"-Infinity",` + + `"dNan":"NaN",` + + `"dPinf":"Infinity",` + + `"dNinf":"-Infinity"` + + `}` +) + +func init() { + if err := proto.SetExtension(realNumber, pb.E_Name, &realNumberName); err != nil { + panic(err) + } + if err := proto.SetExtension(realNumber, pb.E_Complex_RealExtension, complexNumber); err != nil { + panic(err) + } +} + +var marshalingTests = []struct { + desc string + marshaler Marshaler + pb proto.Message + json string +}{ + {"simple flat object", marshaler, simpleObject, simpleObjectJSON}, + {"simple pretty object", marshalerAllOptions, simpleObject, simpleObjectPrettyJSON}, + {"non-finite floats fields object", marshaler, nonFinites, nonFinitesJSON}, + {"repeated fields flat object", marshaler, repeatsObject, repeatsObjectJSON}, + {"repeated fields pretty object", marshalerAllOptions, repeatsObject, repeatsObjectPrettyJSON}, + {"nested message/enum flat object", marshaler, complexObject, complexObjectJSON}, + {"nested message/enum pretty object", marshalerAllOptions, complexObject, complexObjectPrettyJSON}, + {"enum-string flat object", Marshaler{}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, `{"color":"BLUE"}`}, + {"enum-value pretty object", Marshaler{EnumsAsInts: true, Indent: " "}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, colorPrettyJSON}, + {"unknown enum value object", marshalerAllOptions, + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}, colorListPrettyJSON}, + {"repeated proto3 enum", Marshaler{}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":["PUNS","SLAPSTICK"]}`}, + {"repeated proto3 enum as int", Marshaler{EnumsAsInts: true}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":[1,2]}`}, + {"empty value", marshaler, &pb.Simple3{}, `{}`}, + {"empty value emitted", Marshaler{EmitDefaults: true}, &pb.Simple3{}, `{"dub":0}`}, + {"empty repeated emitted", Marshaler{EmitDefaults: true}, &pb.SimpleSlice3{}, `{"slices":[]}`}, + {"empty map emitted", Marshaler{EmitDefaults: true}, &pb.SimpleMap3{}, `{"stringy":{}}`}, + {"nested struct null", Marshaler{EmitDefaults: true}, &pb.SimpleNull3{}, `{"simple":null}`}, + {"map", marshaler, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`}, + {"map", marshalerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON}, + {"map", marshaler, + &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}, + `{"strry":{"\"one\"":"two","three":"four"}}`}, + {"map", marshaler, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, `{"objjy":{"1":{"dub":1}}}`}, + {"map", marshalerAllOptions, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, objjyPrettyJSON}, + {"map", marshaler, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}}, + `{"buggy":{"1234":"yup"}}`}, + {"map", marshaler, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`}, + // TODO: This is broken. + //{"map", marshaler, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":"ROMAN"}`}, + {"map", Marshaler{EnumsAsInts: true}, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":2}}`}, + {"map", marshaler, &pb.Mappy{S32Booly: map[int32]bool{1: true, 3: false, 10: true, 12: false}}, `{"s32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{S64Booly: map[int64]bool{1: true, 3: false, 10: true, 12: false}}, `{"s64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U32Booly: map[uint32]bool{1: true, 3: false, 10: true, 12: false}}, `{"u32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U64Booly: map[uint64]bool{1: true, 3: false, 10: true, 12: false}}, `{"u64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"proto2 map", marshaler, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}}, + `{"mInt64Str":{"213":"cat"}}`}, + {"proto2 map", marshaler, + &pb.Maps{MBoolSimple: map[bool]*pb.Simple{true: {OInt32: proto.Int32(1)}}}, + `{"mBoolSimple":{"true":{"oInt32":1}}}`}, + {"oneof, not set", marshaler, &pb.MsgWithOneof{}, `{}`}, + {"oneof, set", marshaler, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Title{Title: "Grand Poobah"}}, `{"title":"Grand Poobah"}`}, + {"force orig_name", Marshaler{OrigName: true}, &pb.Simple{OInt32: proto.Int32(4)}, + `{"o_int32":4}`}, + {"proto2 extension", marshaler, realNumber, realNumberJSON}, + {"Any with message", marshaler, anySimple, anySimpleJSON}, + {"Any with message and indent", marshalerAllOptions, anySimple, anySimplePrettyJSON}, + {"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON}, + {"Any with WKT and indent", marshalerAllOptions, anyWellKnown, anyWellKnownPrettyJSON}, + {"Duration", marshaler, &pb.KnownTypes{Dur: &types.Duration{Seconds: 3}}, `{"dur":"3.000s"}`}, + {"Struct", marshaler, &pb.KnownTypes{St: &types.Struct{ + Fields: map[string]*types.Value{ + "one": {Kind: &types.Value_StringValue{StringValue: "loneliest number"}}, + "two": {Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}, + }, + }}, `{"st":{"one":"loneliest number","two":null}}`}, + {"empty ListValue", marshaler, &pb.KnownTypes{Lv: &types.ListValue{}}, `{"lv":[]}`}, + {"basic ListValue", marshaler, &pb.KnownTypes{Lv: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_NullValue{}}, + {Kind: &types.Value_NumberValue{NumberValue: 3}}, + {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}, `{"lv":["x",null,3,true]}`}, + {"Timestamp", marshaler, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: 14e8, Nanos: 21e6}}, `{"ts":"2014-05-13T16:53:20.021Z"}`}, + {"number Value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NumberValue{NumberValue: 1}}}, `{"val":1}`}, + {"null Value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}}, `{"val":null}`}, + {"string number value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "9223372036854775807"}}}, `{"val":"9223372036854775807"}`}, + {"list of lists Value", marshaler, &pb.KnownTypes{Val: &types.Value{ + Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{{Kind: &types.Value_StringValue{StringValue: "y"}}}, + }}}, + {Kind: &types.Value_StringValue{StringValue: "z"}}, + }, + }}}, + }, + }}, + }}, `{"val":["x",[["y"],"z"]]}`}, + {"DoubleValue", marshaler, &pb.KnownTypes{Dbl: &types.DoubleValue{Value: 1.2}}, `{"dbl":1.2}`}, + {"FloatValue", marshaler, &pb.KnownTypes{Flt: &types.FloatValue{Value: 1.2}}, `{"flt":1.2}`}, + {"Int64Value", marshaler, &pb.KnownTypes{I64: &types.Int64Value{Value: -3}}, `{"i64":"-3"}`}, + {"UInt64Value", marshaler, &pb.KnownTypes{U64: &types.UInt64Value{Value: 3}}, `{"u64":"3"}`}, + {"Int32Value", marshaler, &pb.KnownTypes{I32: &types.Int32Value{Value: -4}}, `{"i32":-4}`}, + {"UInt32Value", marshaler, &pb.KnownTypes{U32: &types.UInt32Value{Value: 4}}, `{"u32":4}`}, + {"BoolValue", marshaler, &pb.KnownTypes{Bool: &types.BoolValue{Value: true}}, `{"bool":true}`}, + {"StringValue", marshaler, &pb.KnownTypes{Str: &types.StringValue{Value: "plush"}}, `{"str":"plush"}`}, + {"BytesValue", marshaler, &pb.KnownTypes{Bytes: &types.BytesValue{Value: []byte("wow")}}, `{"bytes":"d293"}`}, +} + +func TestMarshaling(t *testing.T) { + for _, tt := range marshalingTests { + json, err := tt.marshaler.MarshalToString(tt.pb) + if err != nil { + t.Errorf("%s: marshaling error: %v", tt.desc, err) + } else if tt.json != json { + t.Errorf("%s: got [%v] want [%v]", tt.desc, json, tt.json) + } + } +} + +func TestMarshalJSONPBMarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + msg := dynamicMessage{rawJson: rawJson} + str, err := new(Marshaler).MarshalToString(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling JSONPBMarshaler: %v", err) + } + if str != rawJson { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, rawJson) + } +} + +func TestMarshalAnyJSONPBMarshaler(t *testing.T) { + msg := dynamicMessage{rawJson: `{ "foo": "bar", "baz": [0, 1, 2, 3] }`} + a, err := types.MarshalAny(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling to Any: %v", err) + } + str, err := new(Marshaler).MarshalToString(a) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling Any to JSON: %v", err) + } + // after custom marshaling, it's round-tripped through JSON decoding/encoding already, + // so the keys are sorted, whitespace is compacted, and "@type" key has been added + expected := `{"@type":"type.googleapis.com/` + dynamicMessageName + `","baz":[0,1,2,3],"foo":"bar"}` + if str != expected { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, expected) + } +} + +var unmarshalingTests = []struct { + desc string + unmarshaler Unmarshaler + json string + pb proto.Message +}{ + {"simple flat object", Unmarshaler{}, simpleObjectJSON, simpleObject}, + {"simple pretty object", Unmarshaler{}, simpleObjectPrettyJSON, simpleObject}, + {"repeated fields flat object", Unmarshaler{}, repeatsObjectJSON, repeatsObject}, + {"repeated fields pretty object", Unmarshaler{}, repeatsObjectPrettyJSON, repeatsObject}, + {"nested message/enum flat object", Unmarshaler{}, complexObjectJSON, complexObject}, + {"nested message/enum pretty object", Unmarshaler{}, complexObjectPrettyJSON, complexObject}, + {"enum-string object", Unmarshaler{}, `{"color":"BLUE"}`, &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"enum-value object", Unmarshaler{}, "{\n \"color\": 2\n}", &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"unknown field with allowed option", Unmarshaler{AllowUnknownFields: true}, `{"unknown": "foo"}`, new(pb.Simple)}, + {"proto3 enum string", Unmarshaler{}, `{"hilarity":"PUNS"}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 enum value", Unmarshaler{}, `{"hilarity":1}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"unknown enum value object", + Unmarshaler{}, + "{\n \"color\": 1000,\n \"r_color\": [\n \"RED\"\n ]\n}", + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}}, + {"repeated proto3 enum", Unmarshaler{}, `{"rFunny":["PUNS","SLAPSTICK"]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as int", Unmarshaler{}, `{"rFunny":[1,2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as mix of strings and ints", Unmarshaler{}, `{"rFunny":["PUNS",2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"unquoted int64 object", Unmarshaler{}, `{"oInt64":-314}`, &pb.Simple{OInt64: proto.Int64(-314)}}, + {"unquoted uint64 object", Unmarshaler{}, `{"oUint64":123}`, &pb.Simple{OUint64: proto.Uint64(123)}}, + {"NaN", Unmarshaler{}, `{"oDouble":"NaN"}`, &pb.Simple{ODouble: proto.Float64(math.NaN())}}, + {"Inf", Unmarshaler{}, `{"oFloat":"Infinity"}`, &pb.Simple{OFloat: proto.Float32(float32(math.Inf(1)))}}, + {"-Inf", Unmarshaler{}, `{"oDouble":"-Infinity"}`, &pb.Simple{ODouble: proto.Float64(math.Inf(-1))}}, + {"map", Unmarshaler{}, `{"nummy":{"1":2,"3":4}}`, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}}, + {"map", Unmarshaler{}, `{"strry":{"\"one\"":"two","three":"four"}}`, &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}}, + {"map", Unmarshaler{}, `{"objjy":{"1":{"dub":1}}}`, &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}}, + {"proto2 extension", Unmarshaler{}, realNumberJSON, realNumber}, + // TODO does not work with go version 1.7, but works with go version 1.8 {"Any with message", Unmarshaler{}, anySimpleJSON, anySimple}, + // TODO does not work with go version 1.7, but works with go version 1.8 {"Any with message and indent", Unmarshaler{}, anySimplePrettyJSON, anySimple}, + {"Any with WKT", Unmarshaler{}, anyWellKnownJSON, anyWellKnown}, + {"Any with WKT and indent", Unmarshaler{}, anyWellKnownPrettyJSON, anyWellKnown}, + // TODO: This is broken. + //{"map", Unmarshaler{}, `{"enumy":{"XIV":"ROMAN"}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"map", Unmarshaler{}, `{"enumy":{"XIV":2}}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"oneof", Unmarshaler{}, `{"salary":31000}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Salary{Salary: 31000}}}, + {"oneof spec name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{Country: "Australia"}}}, + {"oneof orig_name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{Country: "Australia"}}}, + {"oneof spec name2", Unmarshaler{}, `{"homeAddress":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{HomeAddress: "Australia"}}}, + {"oneof orig_name2", Unmarshaler{}, `{"home_address":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{HomeAddress: "Australia"}}}, + {"orig_name input", Unmarshaler{}, `{"o_bool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + {"camelName input", Unmarshaler{}, `{"oBool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + {"Duration", Unmarshaler{}, `{"dur":"3.000s"}`, &pb.KnownTypes{Dur: &types.Duration{Seconds: 3}}}, + {"null Duration", Unmarshaler{}, `{"dur":null}`, &pb.KnownTypes{Dur: nil}}, + {"Timestamp", Unmarshaler{}, `{"ts":"2014-05-13T16:53:20.021Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: 14e8, Nanos: 21e6}}}, + {"PreEpochTimestamp", Unmarshaler{}, `{"ts":"1969-12-31T23:59:58.999999995Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: -2, Nanos: 999999995}}}, + {"ZeroTimeTimestamp", Unmarshaler{}, `{"ts":"0001-01-01T00:00:00Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: -62135596800, Nanos: 0}}}, + {"null Timestamp", Unmarshaler{}, `{"ts":null}`, &pb.KnownTypes{Ts: nil}}, + {"null Struct", Unmarshaler{}, `{"st": null}`, &pb.KnownTypes{St: nil}}, + {"empty Struct", Unmarshaler{}, `{"st": {}}`, &pb.KnownTypes{St: &types.Struct{}}}, + {"basic Struct", Unmarshaler{}, `{"st": {"a": "x", "b": null, "c": 3, "d": true}}`, &pb.KnownTypes{St: &types.Struct{Fields: map[string]*types.Value{ + "a": {Kind: &types.Value_StringValue{StringValue: "x"}}, + "b": {Kind: &types.Value_NullValue{}}, + "c": {Kind: &types.Value_NumberValue{NumberValue: 3}}, + "d": {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}}, + {"nested Struct", Unmarshaler{}, `{"st": {"a": {"b": 1, "c": [{"d": true}, "f"]}}}`, &pb.KnownTypes{St: &types.Struct{Fields: map[string]*types.Value{ + "a": {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{ + "b": {Kind: &types.Value_NumberValue{NumberValue: 1}}, + "c": {Kind: &types.Value_ListValue{ListValue: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{"d": {Kind: &types.Value_BoolValue{BoolValue: true}}}}}}, + {Kind: &types.Value_StringValue{StringValue: "f"}}, + }}}}, + }}}}, + }}}}, + {"null ListValue", Unmarshaler{}, `{"lv": null}`, &pb.KnownTypes{Lv: nil}}, + {"empty ListValue", Unmarshaler{}, `{"lv": []}`, &pb.KnownTypes{Lv: &types.ListValue{}}}, + {"basic ListValue", Unmarshaler{}, `{"lv": ["x", null, 3, true]}`, &pb.KnownTypes{Lv: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_NullValue{}}, + {Kind: &types.Value_NumberValue{NumberValue: 3}}, + {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}}, + {"number Value", Unmarshaler{}, `{"val":1}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NumberValue{NumberValue: 1}}}}, + {"null Value", Unmarshaler{}, `{"val":null}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}}}, + {"bool Value", Unmarshaler{}, `{"val":true}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_BoolValue{BoolValue: true}}}}, + {"string Value", Unmarshaler{}, `{"val":"x"}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "x"}}}}, + {"string number value", Unmarshaler{}, `{"val":"9223372036854775807"}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "9223372036854775807"}}}}, + {"list of lists Value", Unmarshaler{}, `{"val":["x", [["y"], "z"]]}`, &pb.KnownTypes{Val: &types.Value{ + Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{{Kind: &types.Value_StringValue{StringValue: "y"}}}, + }}}, + {Kind: &types.Value_StringValue{StringValue: "z"}}, + }, + }}}, + }, + }}}}}, + + {"DoubleValue", Unmarshaler{}, `{"dbl":1.2}`, &pb.KnownTypes{Dbl: &types.DoubleValue{Value: 1.2}}}, + {"FloatValue", Unmarshaler{}, `{"flt":1.2}`, &pb.KnownTypes{Flt: &types.FloatValue{Value: 1.2}}}, + {"Int64Value", Unmarshaler{}, `{"i64":"-3"}`, &pb.KnownTypes{I64: &types.Int64Value{Value: -3}}}, + {"UInt64Value", Unmarshaler{}, `{"u64":"3"}`, &pb.KnownTypes{U64: &types.UInt64Value{Value: 3}}}, + {"Int32Value", Unmarshaler{}, `{"i32":-4}`, &pb.KnownTypes{I32: &types.Int32Value{Value: -4}}}, + {"UInt32Value", Unmarshaler{}, `{"u32":4}`, &pb.KnownTypes{U32: &types.UInt32Value{Value: 4}}}, + {"BoolValue", Unmarshaler{}, `{"bool":true}`, &pb.KnownTypes{Bool: &types.BoolValue{Value: true}}}, + {"StringValue", Unmarshaler{}, `{"str":"plush"}`, &pb.KnownTypes{Str: &types.StringValue{Value: "plush"}}}, + {"BytesValue", Unmarshaler{}, `{"bytes":"d293"}`, &pb.KnownTypes{Bytes: &types.BytesValue{Value: []byte("wow")}}}, + // Ensure that `null` as a value ends up with a nil pointer instead of a [type]Value struct. + {"null DoubleValue", Unmarshaler{}, `{"dbl":null}`, &pb.KnownTypes{Dbl: nil}}, + {"null FloatValue", Unmarshaler{}, `{"flt":null}`, &pb.KnownTypes{Flt: nil}}, + {"null Int64Value", Unmarshaler{}, `{"i64":null}`, &pb.KnownTypes{I64: nil}}, + {"null UInt64Value", Unmarshaler{}, `{"u64":null}`, &pb.KnownTypes{U64: nil}}, + {"null Int32Value", Unmarshaler{}, `{"i32":null}`, &pb.KnownTypes{I32: nil}}, + {"null UInt32Value", Unmarshaler{}, `{"u32":null}`, &pb.KnownTypes{U32: nil}}, + {"null BoolValue", Unmarshaler{}, `{"bool":null}`, &pb.KnownTypes{Bool: nil}}, + {"null StringValue", Unmarshaler{}, `{"str":null}`, &pb.KnownTypes{Str: nil}}, + {"null BytesValue", Unmarshaler{}, `{"bytes":null}`, &pb.KnownTypes{Bytes: nil}}, +} + +func TestUnmarshaling(t *testing.T) { + for _, tt := range unmarshalingTests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.Unmarshal(strings.NewReader(tt.json), p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } +} + +func TestUnmarshalNullArray(t *testing.T) { + var repeats pb.Repeats + if err := UnmarshalString(`{"rBool":null}`, &repeats); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(repeats, pb.Repeats{}) { + t.Errorf("got non-nil fields in [%#v]", repeats) + } +} + +func TestUnmarshalNullObject(t *testing.T) { + var maps pb.Maps + if err := UnmarshalString(`{"mInt64Str":null}`, &maps); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(maps, pb.Maps{}) { + t.Errorf("got non-nil fields in [%#v]", maps) + } +} + +func TestUnmarshalNext(t *testing.T) { + // We only need to check against a few, not all of them. + tests := unmarshalingTests[:5] + + // Create a buffer with many concatenated JSON objects. + var b bytes.Buffer + for _, tt := range tests { + b.WriteString(tt.json) + } + + dec := json.NewDecoder(&b) + for _, tt := range tests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.UnmarshalNext(dec, p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } + + p := &pb.Simple{} + err := new(Unmarshaler).UnmarshalNext(dec, p) + if err != io.EOF { + t.Errorf("eof: got %v, expected io.EOF", err) + } +} + +var unmarshalingShouldError = []struct { + desc string + in string + pb proto.Message +}{ + {"a value", "666", new(pb.Simple)}, + {"gibberish", "{adskja123;l23=-=", new(pb.Simple)}, + {"unknown field", `{"unknown": "foo"}`, new(pb.Simple)}, + {"unknown enum name", `{"hilarity":"DAVE"}`, new(proto3pb.Message)}, +} + +func TestUnmarshalingBadInput(t *testing.T) { + for _, tt := range unmarshalingShouldError { + err := UnmarshalString(tt.in, tt.pb) + if err == nil { + t.Errorf("an error was expected when parsing %q instead of an object", tt.desc) + } + } +} + +func TestUnmarshalJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + var msg dynamicMessage + if err := Unmarshal(strings.NewReader(rawJson), &msg); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + if msg.rawJson != rawJson { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", msg.rawJson, rawJson) + } +} + +func TestUnmarshalAnyJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "@type": "blah.com/` + dynamicMessageName + `", "foo": "bar", "baz": [0, 1, 2, 3] }` + var got types.Any + if err := Unmarshal(strings.NewReader(rawJson), &got); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + + dm := &dynamicMessage{rawJson: `{"baz":[0,1,2,3],"foo":"bar"}`} + var want types.Any + if b, err := proto.Marshal(dm); err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } else { + want.TypeUrl = "blah.com/" + dynamicMessageName + want.Value = b + } + + if !proto.Equal(&got, &want) { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", got, want) + } +} + +const ( + dynamicMessageName = "google.protobuf.jsonpb.testing.dynamicMessage" +) + +func init() { + // we register the custom type below so that we can use it in Any types + proto.RegisterType((*dynamicMessage)(nil), dynamicMessageName) +} + +// dynamicMessage implements protobuf.Message but is not a normal generated message type. +// It provides implementations of JSONPBMarshaler and JSONPBUnmarshaler for JSON support. +type dynamicMessage struct { + rawJson string `protobuf:"bytes,1,opt,name=rawJson"` +} + +func (m *dynamicMessage) Reset() { + m.rawJson = "{}" +} + +func (m *dynamicMessage) String() string { + return m.rawJson +} + +func (m *dynamicMessage) ProtoMessage() { +} + +func (m *dynamicMessage) MarshalJSONPB(jm *Marshaler) ([]byte, error) { + return []byte(m.rawJson), nil +} + +func (m *dynamicMessage) UnmarshalJSONPB(jum *Unmarshaler, js []byte) error { + m.rawJson = string(js) + return nil +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/all_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/all_test.go new file mode 100644 index 00000000..b5f8709d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/all_test.go @@ -0,0 +1,2278 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "math" + "math/rand" + "reflect" + "runtime/debug" + "strings" + "testing" + "time" + + . "github.com/gogo/protobuf/proto" + . "github.com/gogo/protobuf/proto/testdata" +) + +var globalO *Buffer + +func old() *Buffer { + if globalO == nil { + globalO = NewBuffer(nil) + } + globalO.Reset() + return globalO +} + +func equalbytes(b1, b2 []byte, t *testing.T) { + if len(b1) != len(b2) { + t.Errorf("wrong lengths: 2*%d != %d", len(b1), len(b2)) + return + } + for i := 0; i < len(b1); i++ { + if b1[i] != b2[i] { + t.Errorf("bad byte[%d]:%x %x: %s %s", i, b1[i], b2[i], b1, b2) + } + } +} + +func initGoTestField() *GoTestField { + f := new(GoTestField) + f.Label = String("label") + f.Type = String("type") + return f +} + +// These are all structurally equivalent but the tag numbers differ. +// (It's remarkable that required, optional, and repeated all have +// 8 letters.) +func initGoTest_RequiredGroup() *GoTest_RequiredGroup { + return &GoTest_RequiredGroup{ + RequiredField: String("required"), + } +} + +func initGoTest_OptionalGroup() *GoTest_OptionalGroup { + return &GoTest_OptionalGroup{ + RequiredField: String("optional"), + } +} + +func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup { + return &GoTest_RepeatedGroup{ + RequiredField: String("repeated"), + } +} + +func initGoTest(setdefaults bool) *GoTest { + pb := new(GoTest) + if setdefaults { + pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted) + pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted) + pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted) + pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted) + pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted) + pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted) + pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted) + pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted) + pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted) + pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted) + pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted + pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted) + pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted) + } + + pb.Kind = GoTest_TIME.Enum() + pb.RequiredField = initGoTestField() + pb.F_BoolRequired = Bool(true) + pb.F_Int32Required = Int32(3) + pb.F_Int64Required = Int64(6) + pb.F_Fixed32Required = Uint32(32) + pb.F_Fixed64Required = Uint64(64) + pb.F_Uint32Required = Uint32(3232) + pb.F_Uint64Required = Uint64(6464) + pb.F_FloatRequired = Float32(3232) + pb.F_DoubleRequired = Float64(6464) + pb.F_StringRequired = String("string") + pb.F_BytesRequired = []byte("bytes") + pb.F_Sint32Required = Int32(-32) + pb.F_Sint64Required = Int64(-64) + pb.Requiredgroup = initGoTest_RequiredGroup() + + return pb +} + +func fail(msg string, b *bytes.Buffer, s string, t *testing.T) { + data := b.Bytes() + ld := len(data) + ls := len(s) / 2 + + fmt.Printf("fail %s ld=%d ls=%d\n", msg, ld, ls) + + // find the interesting spot - n + n := ls + if ld < ls { + n = ld + } + j := 0 + for i := 0; i < n; i++ { + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + if data[i] == bs { + continue + } + n = i + break + } + l := n - 10 + if l < 0 { + l = 0 + } + h := n + 10 + + // find the interesting spot - n + fmt.Printf("is[%d]:", l) + for i := l; i < h; i++ { + if i >= ld { + fmt.Printf(" --") + continue + } + fmt.Printf(" %.2x", data[i]) + } + fmt.Printf("\n") + + fmt.Printf("sb[%d]:", l) + for i := l; i < h; i++ { + if i >= ls { + fmt.Printf(" --") + continue + } + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + fmt.Printf(" %.2x", bs) + } + fmt.Printf("\n") + + t.Fail() + + // t.Errorf("%s: \ngood: %s\nbad: %x", msg, s, b.Bytes()) + // Print the output in a partially-decoded format; can + // be helpful when updating the test. It produces the output + // that is pasted, with minor edits, into the argument to verify(). + // data := b.Bytes() + // nesting := 0 + // for b.Len() > 0 { + // start := len(data) - b.Len() + // var u uint64 + // u, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // wire := u & 0x7 + // tag := u >> 3 + // switch wire { + // case WireVarint: + // v, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed32: + // v, err := DecodeFixed32(b) + // if err != nil { + // fmt.Printf("decode error on fixed32:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed64: + // v, err := DecodeFixed64(b) + // if err != nil { + // fmt.Printf("decode error on fixed64:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireBytes: + // nb, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // after_tag := len(data) - b.Len() + // str := make([]byte, nb) + // _, err = b.Read(str) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" \"%x\" // field %d, encoding %d (FIELD)\n", + // data[start:after_tag], str, tag, wire) + // case WireStartGroup: + // nesting++ + // fmt.Printf("\t\t\"%x\"\t\t// start group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // case WireEndGroup: + // fmt.Printf("\t\t\"%x\"\t\t// end group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // nesting-- + // default: + // fmt.Printf("unrecognized wire type %d\n", wire) + // return + // } + // } +} + +func hex(c uint8) uint8 { + if '0' <= c && c <= '9' { + return c - '0' + } + if 'a' <= c && c <= 'f' { + return 10 + c - 'a' + } + if 'A' <= c && c <= 'F' { + return 10 + c - 'A' + } + return 0 +} + +func equal(b []byte, s string, t *testing.T) bool { + if 2*len(b) != len(s) { + // fail(fmt.Sprintf("wrong lengths: 2*%d != %d", len(b), len(s)), b, s, t) + fmt.Printf("wrong lengths: 2*%d != %d\n", len(b), len(s)) + return false + } + for i, j := 0, 0; i < len(b); i, j = i+1, j+2 { + x := hex(s[j])*16 + hex(s[j+1]) + if b[i] != x { + // fail(fmt.Sprintf("bad byte[%d]:%x %x", i, b[i], x), b, s, t) + fmt.Printf("bad byte[%d]:%x %x", i, b[i], x) + return false + } + } + return true +} + +func overify(t *testing.T, pb *GoTest, expected string) { + o := old() + err := o.Marshal(pb) + if err != nil { + fmt.Printf("overify marshal-1 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 1", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = o.Unmarshal(pbd) + if err != nil { + t.Fatalf("overify unmarshal err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + o.Reset() + err = o.Marshal(pbd) + if err != nil { + t.Errorf("overify marshal-2 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 2", o.Bytes()) + t.Fatalf("string = %s", expected) + } +} + +// Simple tests for numeric encode/decode primitives (varint, etc.) +func TestNumericPrimitives(t *testing.T) { + for i := uint64(0); i < 1e6; i += 111 { + o := old() + if o.EncodeVarint(i) != nil { + t.Error("EncodeVarint") + break + } + x, e := o.DecodeVarint() + if e != nil { + t.Fatal("DecodeVarint") + } + if x != i { + t.Fatal("varint decode fail:", i, x) + } + + o = old() + if o.EncodeFixed32(i) != nil { + t.Fatal("encFixed32") + } + x, e = o.DecodeFixed32() + if e != nil { + t.Fatal("decFixed32") + } + if x != i { + t.Fatal("fixed32 decode fail:", i, x) + } + + o = old() + if o.EncodeFixed64(i*1234567) != nil { + t.Error("encFixed64") + break + } + x, e = o.DecodeFixed64() + if e != nil { + t.Error("decFixed64") + break + } + if x != i*1234567 { + t.Error("fixed64 decode fail:", i*1234567, x) + break + } + + o = old() + i32 := int32(i - 12345) + if o.EncodeZigzag32(uint64(i32)) != nil { + t.Fatal("EncodeZigzag32") + } + x, e = o.DecodeZigzag32() + if e != nil { + t.Fatal("DecodeZigzag32") + } + if x != uint64(uint32(i32)) { + t.Fatal("zigzag32 decode fail:", i32, x) + } + + o = old() + i64 := int64(i - 12345) + if o.EncodeZigzag64(uint64(i64)) != nil { + t.Fatal("EncodeZigzag64") + } + x, e = o.DecodeZigzag64() + if e != nil { + t.Fatal("DecodeZigzag64") + } + if x != uint64(i64) { + t.Fatal("zigzag64 decode fail:", i64, x) + } + } +} + +// fakeMarshaler is a simple struct implementing Marshaler and Message interfaces. +type fakeMarshaler struct { + b []byte + err error +} + +func (f *fakeMarshaler) Marshal() ([]byte, error) { return f.b, f.err } +func (f *fakeMarshaler) String() string { return fmt.Sprintf("Bytes: %v Error: %v", f.b, f.err) } +func (f *fakeMarshaler) ProtoMessage() {} +func (f *fakeMarshaler) Reset() {} + +type msgWithFakeMarshaler struct { + M *fakeMarshaler `protobuf:"bytes,1,opt,name=fake"` +} + +func (m *msgWithFakeMarshaler) String() string { return CompactTextString(m) } +func (m *msgWithFakeMarshaler) ProtoMessage() {} +func (m *msgWithFakeMarshaler) Reset() {} + +// Simple tests for proto messages that implement the Marshaler interface. +func TestMarshalerEncoding(t *testing.T) { + tests := []struct { + name string + m Message + want []byte + errType reflect.Type + }{ + { + name: "Marshaler that fails", + m: &fakeMarshaler{ + err: errors.New("some marshal err"), + b: []byte{5, 6, 7}, + }, + // Since the Marshal method returned bytes, they should be written to the + // buffer. (For efficiency, we assume that Marshal implementations are + // always correct w.r.t. RequiredNotSetError and output.) + want: []byte{5, 6, 7}, + errType: reflect.TypeOf(errors.New("some marshal err")), + }, + { + name: "Marshaler that fails with RequiredNotSetError", + m: &msgWithFakeMarshaler{ + M: &fakeMarshaler{ + err: &RequiredNotSetError{}, + b: []byte{5, 6, 7}, + }, + }, + // Since there's an error that can be continued after, + // the buffer should be written. + want: []byte{ + 10, 3, // for &msgWithFakeMarshaler + 5, 6, 7, // for &fakeMarshaler + }, + errType: reflect.TypeOf(&RequiredNotSetError{}), + }, + { + name: "Marshaler that succeeds", + m: &fakeMarshaler{ + b: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + want: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + } + for _, test := range tests { + b := NewBuffer(nil) + err := b.Marshal(test.m) + if reflect.TypeOf(err) != test.errType { + t.Errorf("%s: got err %T(%v) wanted %T", test.name, err, err, test.errType) + } + if !reflect.DeepEqual(test.want, b.Bytes()) { + t.Errorf("%s: got bytes %v wanted %v", test.name, b.Bytes(), test.want) + } + if size := Size(test.m); size != len(b.Bytes()) { + t.Errorf("%s: Size(_) = %v, but marshaled to %v bytes", test.name, size, len(b.Bytes())) + } + + m, mErr := Marshal(test.m) + if !bytes.Equal(b.Bytes(), m) { + t.Errorf("%s: Marshal returned %v, but (*Buffer).Marshal wrote %v", test.name, m, b.Bytes()) + } + if !reflect.DeepEqual(err, mErr) { + t.Errorf("%s: Marshal err = %q, but (*Buffer).Marshal returned %q", + test.name, fmt.Sprint(mErr), fmt.Sprint(err)) + } + } +} + +// Simple tests for bytes +func TestBytesPrimitives(t *testing.T) { + o := old() + bytes := []byte{'n', 'o', 'w', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 't', 'i', 'm', 'e'} + if o.EncodeRawBytes(bytes) != nil { + t.Error("EncodeRawBytes") + } + decb, e := o.DecodeRawBytes(false) + if e != nil { + t.Error("DecodeRawBytes") + } + equalbytes(bytes, decb, t) +} + +// Simple tests for strings +func TestStringPrimitives(t *testing.T) { + o := old() + s := "now is the time" + if o.EncodeStringBytes(s) != nil { + t.Error("enc_string") + } + decs, e := o.DecodeStringBytes() + if e != nil { + t.Error("dec_string") + } + if s != decs { + t.Error("string encode/decode fail:", s, decs) + } +} + +// Do we catch the "required bit not set" case? +func TestRequiredBit(t *testing.T) { + o := old() + pb := new(GoTest) + err := o.Marshal(pb) + if err == nil { + t.Error("did not catch missing required fields") + } else if strings.Index(err.Error(), "Kind") < 0 { + t.Error("wrong error type:", err) + } +} + +// Check that all fields are nil. +// Clearly silly, and a residue from a more interesting test with an earlier, +// different initialization property, but it once caught a compiler bug so +// it lives. +func checkInitialized(pb *GoTest, t *testing.T) { + if pb.F_BoolDefaulted != nil { + t.Error("New or Reset did not set boolean:", *pb.F_BoolDefaulted) + } + if pb.F_Int32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Int32Defaulted) + } + if pb.F_Int64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Int64Defaulted) + } + if pb.F_Fixed32Defaulted != nil { + t.Error("New or Reset did not set fixed32:", *pb.F_Fixed32Defaulted) + } + if pb.F_Fixed64Defaulted != nil { + t.Error("New or Reset did not set fixed64:", *pb.F_Fixed64Defaulted) + } + if pb.F_Uint32Defaulted != nil { + t.Error("New or Reset did not set uint32:", *pb.F_Uint32Defaulted) + } + if pb.F_Uint64Defaulted != nil { + t.Error("New or Reset did not set uint64:", *pb.F_Uint64Defaulted) + } + if pb.F_FloatDefaulted != nil { + t.Error("New or Reset did not set float:", *pb.F_FloatDefaulted) + } + if pb.F_DoubleDefaulted != nil { + t.Error("New or Reset did not set double:", *pb.F_DoubleDefaulted) + } + if pb.F_StringDefaulted != nil { + t.Error("New or Reset did not set string:", *pb.F_StringDefaulted) + } + if pb.F_BytesDefaulted != nil { + t.Error("New or Reset did not set bytes:", string(pb.F_BytesDefaulted)) + } + if pb.F_Sint32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Sint32Defaulted) + } + if pb.F_Sint64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Sint64Defaulted) + } +} + +// Does Reset() reset? +func TestReset(t *testing.T) { + pb := initGoTest(true) + // muck with some values + pb.F_BoolDefaulted = Bool(false) + pb.F_Int32Defaulted = Int32(237) + pb.F_Int64Defaulted = Int64(12346) + pb.F_Fixed32Defaulted = Uint32(32000) + pb.F_Fixed64Defaulted = Uint64(666) + pb.F_Uint32Defaulted = Uint32(323232) + pb.F_Uint64Defaulted = nil + pb.F_FloatDefaulted = nil + pb.F_DoubleDefaulted = Float64(0) + pb.F_StringDefaulted = String("gotcha") + pb.F_BytesDefaulted = []byte("asdfasdf") + pb.F_Sint32Defaulted = Int32(123) + pb.F_Sint64Defaulted = Int64(789) + pb.Reset() + checkInitialized(pb, t) +} + +// All required fields set, no defaults provided. +func TestEncodeDecode1(t *testing.T) { + pb := initGoTest(false) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 0x20 + "714000000000000000"+ // field 14, encoding 1, value 0x40 + "78a019"+ // field 15, encoding 0, value 0xca0 = 3232 + "8001c032"+ // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2, string "string" + "b304"+ // field 70, encoding 3, start group + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // field 70, encoding 4, end group + "aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f") // field 103, encoding 0, 0x7f zigzag64 +} + +// All required fields set, defaults provided. +func TestEncodeDecode2(t *testing.T) { + pb := initGoTest(true) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All default fields set to their default value by hand +func TestEncodeDecode3(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolDefaulted = Bool(true) + pb.F_Int32Defaulted = Int32(32) + pb.F_Int64Defaulted = Int64(64) + pb.F_Fixed32Defaulted = Uint32(320) + pb.F_Fixed64Defaulted = Uint64(640) + pb.F_Uint32Defaulted = Uint32(3200) + pb.F_Uint64Defaulted = Uint64(6400) + pb.F_FloatDefaulted = Float32(314159) + pb.F_DoubleDefaulted = Float64(271828) + pb.F_StringDefaulted = String("hello, \"world!\"\n") + pb.F_BytesDefaulted = []byte("Bignose") + pb.F_Sint32Defaulted = Int32(-32) + pb.F_Sint64Defaulted = Int64(-64) + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all non-defaulted optional fields have values. +func TestEncodeDecode4(t *testing.T) { + pb := initGoTest(true) + pb.Table = String("hello") + pb.Param = Int32(7) + pb.OptionalField = initGoTestField() + pb.F_BoolOptional = Bool(true) + pb.F_Int32Optional = Int32(32) + pb.F_Int64Optional = Int64(64) + pb.F_Fixed32Optional = Uint32(3232) + pb.F_Fixed64Optional = Uint64(6464) + pb.F_Uint32Optional = Uint32(323232) + pb.F_Uint64Optional = Uint64(646464) + pb.F_FloatOptional = Float32(32.) + pb.F_DoubleOptional = Float64(64.) + pb.F_StringOptional = String("hello") + pb.F_BytesOptional = []byte("Bignose") + pb.F_Sint32Optional = Int32(-32) + pb.F_Sint64Optional = Int64(-64) + pb.Optionalgroup = initGoTest_OptionalGroup() + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello" + "1807"+ // field 3, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "f00101"+ // field 30, encoding 0, value 1 + "f80120"+ // field 31, encoding 0, value 32 + "800240"+ // field 32, encoding 0, value 64 + "8d02a00c0000"+ // field 33, encoding 5, value 3232 + "91024019000000000000"+ // field 34, encoding 1, value 6464 + "9802a0dd13"+ // field 35, encoding 0, value 323232 + "a002c0ba27"+ // field 36, encoding 0, value 646464 + "ad0200000042"+ // field 37, encoding 5, value 32.0 + "b1020000000000005040"+ // field 38, encoding 1, value 64.0 + "ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "d305"+ // start group field 90 level 1 + "da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional" + "d405"+ // end group field 90 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose" + "f0123f"+ // field 302, encoding 0, value 63 + "f8127f"+ // field 303, encoding 0, value 127 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestEncodeDecode5(t *testing.T) { + pb := initGoTest(true) + pb.RepeatedField = []*GoTestField{initGoTestField(), initGoTestField()} + pb.F_BoolRepeated = []bool{false, true} + pb.F_Int32Repeated = []int32{32, 33} + pb.F_Int64Repeated = []int64{64, 65} + pb.F_Fixed32Repeated = []uint32{3232, 3333} + pb.F_Fixed64Repeated = []uint64{6464, 6565} + pb.F_Uint32Repeated = []uint32{323232, 333333} + pb.F_Uint64Repeated = []uint64{646464, 656565} + pb.F_FloatRepeated = []float32{32., 33.} + pb.F_DoubleRepeated = []float64{64., 65.} + pb.F_StringRepeated = []string{"hello", "sailor"} + pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")} + pb.F_Sint32Repeated = []int32{32, -32} + pb.F_Sint64Repeated = []int64{64, -64} + pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "a00100"+ // field 20, encoding 0, value 0 + "a00101"+ // field 20, encoding 0, value 1 + "a80120"+ // field 21, encoding 0, value 32 + "a80121"+ // field 21, encoding 0, value 33 + "b00140"+ // field 22, encoding 0, value 64 + "b00141"+ // field 22, encoding 0, value 65 + "bd01a00c0000"+ // field 23, encoding 5, value 3232 + "bd01050d0000"+ // field 23, encoding 5, value 3333 + "c1014019000000000000"+ // field 24, encoding 1, value 6464 + "c101a519000000000000"+ // field 24, encoding 1, value 6565 + "c801a0dd13"+ // field 25, encoding 0, value 323232 + "c80195ac14"+ // field 25, encoding 0, value 333333 + "d001c0ba27"+ // field 26, encoding 0, value 646464 + "d001b58928"+ // field 26, encoding 0, value 656565 + "dd0100000042"+ // field 27, encoding 5, value 32.0 + "dd0100000442"+ // field 27, encoding 5, value 33.0 + "e1010000000000005040"+ // field 28, encoding 1, value 64.0 + "e1010000000000405040"+ // field 28, encoding 1, value 65.0 + "ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello" + "ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ca0c03"+"626967"+ // field 201, encoding 2, string "big" + "ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose" + "d00c40"+ // field 202, encoding 0, value 32 + "d00c3f"+ // field 202, encoding 0, value -32 + "d80c8001"+ // field 203, encoding 0, value 64 + "d80c7f"+ // field 203, encoding 0, value -64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, all packed repeated fields given two values. +func TestEncodeDecode6(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolRepeatedPacked = []bool{false, true} + pb.F_Int32RepeatedPacked = []int32{32, 33} + pb.F_Int64RepeatedPacked = []int64{64, 65} + pb.F_Fixed32RepeatedPacked = []uint32{3232, 3333} + pb.F_Fixed64RepeatedPacked = []uint64{6464, 6565} + pb.F_Uint32RepeatedPacked = []uint32{323232, 333333} + pb.F_Uint64RepeatedPacked = []uint64{646464, 656565} + pb.F_FloatRepeatedPacked = []float32{32., 33.} + pb.F_DoubleRepeatedPacked = []float64{64., 65.} + pb.F_Sint32RepeatedPacked = []int32{32, -32} + pb.F_Sint64RepeatedPacked = []int64{64, -64} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1 + "9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33 + "a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65 + "aa0308"+ // field 53, encoding 2, 8 bytes + "a00c0000050d0000"+ // value 3232, value 3333 + "b20310"+ // field 54, encoding 2, 16 bytes + "4019000000000000a519000000000000"+ // value 6464, value 6565 + "ba0306"+ // field 55, encoding 2, 6 bytes + "a0dd1395ac14"+ // value 323232, value 333333 + "c20306"+ // field 56, encoding 2, 6 bytes + "c0ba27b58928"+ // value 646464, value 656565 + "ca0308"+ // field 57, encoding 2, 8 bytes + "0000004200000442"+ // value 32.0, value 33.0 + "d20310"+ // field 58, encoding 2, 16 bytes + "00000000000050400000000000405040"+ // value 64.0, value 65.0 + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "b21f02"+ // field 502, encoding 2, 2 bytes + "403f"+ // value 32, value -32 + "ba1f03"+ // field 503, encoding 2, 3 bytes + "80017f") // value 64, value -64 +} + +// Test that we can encode empty bytes fields. +func TestEncodeDecodeBytes1(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRequired = []byte{} + pb.F_BytesRepeated = [][]byte{{}} + pb.F_BytesOptional = []byte{} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 { + t.Error("required empty bytes field is incorrect") + } + if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil { + t.Error("repeated empty bytes field is incorrect") + } + if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 { + t.Error("optional empty bytes field is incorrect") + } +} + +// Test that we encode nil-valued fields of a repeated bytes field correctly. +// Since entries in a repeated field cannot be nil, nil must mean empty value. +func TestEncodeDecodeBytes2(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRepeated = [][]byte{nil} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil { + t.Error("Unexpected value for repeated bytes field") + } +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestSkippingUnrecognizedFields(t *testing.T) { + o := old() + pb := initGoTestField() + + // Marshal it normally. + o.Marshal(pb) + + // Now new a GoSkipTest record. + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + // Marshal it into same buffer. + o.Marshal(skip) + + pbd := new(GoTestField) + o.Unmarshal(pbd) + + // The __unrecognized field should be a marshaling of GoSkipTest + skipd := new(GoSkipTest) + + o.SetBuf(pbd.XXX_unrecognized) + o.Unmarshal(skipd) + + if *skipd.SkipInt32 != *skip.SkipInt32 { + t.Error("skip int32", skipd.SkipInt32) + } + if *skipd.SkipFixed32 != *skip.SkipFixed32 { + t.Error("skip fixed32", skipd.SkipFixed32) + } + if *skipd.SkipFixed64 != *skip.SkipFixed64 { + t.Error("skip fixed64", skipd.SkipFixed64) + } + if *skipd.SkipString != *skip.SkipString { + t.Error("skip string", *skipd.SkipString) + } + if *skipd.Skipgroup.GroupInt32 != *skip.Skipgroup.GroupInt32 { + t.Error("skip group int32", skipd.Skipgroup.GroupInt32) + } + if *skipd.Skipgroup.GroupString != *skip.Skipgroup.GroupString { + t.Error("skip group string", *skipd.Skipgroup.GroupString) + } +} + +// Check that unrecognized fields of a submessage are preserved. +func TestSubmessageUnrecognizedFields(t *testing.T) { + nm := &NewMessage{ + Nested: &NewMessage_Nested{ + Name: String("Nigel"), + FoodGroup: String("carbs"), + }, + } + b, err := Marshal(nm) + if err != nil { + t.Fatalf("Marshal of NewMessage: %v", err) + } + + // Unmarshal into an OldMessage. + om := new(OldMessage) + if err = Unmarshal(b, om); err != nil { + t.Fatalf("Unmarshal to OldMessage: %v", err) + } + exp := &OldMessage{ + Nested: &OldMessage_Nested{ + Name: String("Nigel"), + // normal protocol buffer users should not do this + XXX_unrecognized: []byte("\x12\x05carbs"), + }, + } + if !Equal(om, exp) { + t.Errorf("om = %v, want %v", om, exp) + } + + // Clone the OldMessage. + om = Clone(om).(*OldMessage) + if !Equal(om, exp) { + t.Errorf("Clone(om) = %v, want %v", om, exp) + } + + // Marshal the OldMessage, then unmarshal it into an empty NewMessage. + if b, err = Marshal(om); err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + t.Logf("Marshal(%v) -> %q", om, b) + nm2 := new(NewMessage) + if err := Unmarshal(b, nm2); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + if !Equal(nm, nm2) { + t.Errorf("NewMessage round-trip: %v => %v", nm, nm2) + } +} + +// Check that an int32 field can be upgraded to an int64 field. +func TestNegativeInt32(t *testing.T) { + om := &OldMessage{ + Num: Int32(-1), + } + b, err := Marshal(om) + if err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + + // Check the size. It should be 11 bytes; + // 1 for the field/wire type, and 10 for the negative number. + if len(b) != 11 { + t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b) + } + + // Unmarshal into a NewMessage. + nm := new(NewMessage) + if err := Unmarshal(b, nm); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + want := &NewMessage{ + Num: Int64(-1), + } + if !Equal(nm, want) { + t.Errorf("nm = %v, want %v", nm, want) + } +} + +// Check that we can grow an array (repeated field) to have many elements. +// This test doesn't depend only on our encoding; for variety, it makes sure +// we create, encode, and decode the correct contents explicitly. It's therefore +// a bit messier. +// This test also uses (and hence tests) the Marshal/Unmarshal functions +// instead of the methods. +func TestBigRepeated(t *testing.T) { + pb := initGoTest(true) + + // Create the arrays + const N = 50 // Internally the library starts much smaller. + pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N) + pb.F_Sint64Repeated = make([]int64, N) + pb.F_Sint32Repeated = make([]int32, N) + pb.F_BytesRepeated = make([][]byte, N) + pb.F_StringRepeated = make([]string, N) + pb.F_DoubleRepeated = make([]float64, N) + pb.F_FloatRepeated = make([]float32, N) + pb.F_Uint64Repeated = make([]uint64, N) + pb.F_Uint32Repeated = make([]uint32, N) + pb.F_Fixed64Repeated = make([]uint64, N) + pb.F_Fixed32Repeated = make([]uint32, N) + pb.F_Int64Repeated = make([]int64, N) + pb.F_Int32Repeated = make([]int32, N) + pb.F_BoolRepeated = make([]bool, N) + pb.RepeatedField = make([]*GoTestField, N) + + // Fill in the arrays with checkable values. + igtf := initGoTestField() + igtrg := initGoTest_RepeatedGroup() + for i := 0; i < N; i++ { + pb.Repeatedgroup[i] = igtrg + pb.F_Sint64Repeated[i] = int64(i) + pb.F_Sint32Repeated[i] = int32(i) + s := fmt.Sprint(i) + pb.F_BytesRepeated[i] = []byte(s) + pb.F_StringRepeated[i] = s + pb.F_DoubleRepeated[i] = float64(i) + pb.F_FloatRepeated[i] = float32(i) + pb.F_Uint64Repeated[i] = uint64(i) + pb.F_Uint32Repeated[i] = uint32(i) + pb.F_Fixed64Repeated[i] = uint64(i) + pb.F_Fixed32Repeated[i] = uint32(i) + pb.F_Int64Repeated[i] = int64(i) + pb.F_Int32Repeated[i] = int32(i) + pb.F_BoolRepeated[i] = i%2 == 0 + pb.RepeatedField[i] = igtf + } + + // Marshal. + buf, _ := Marshal(pb) + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + Unmarshal(buf, pbd) + + // Check the checkable values + for i := uint64(0); i < N; i++ { + if pbd.Repeatedgroup[i] == nil { // TODO: more checking? + t.Error("pbd.Repeatedgroup bad") + } + var x uint64 + x = uint64(pbd.F_Sint64Repeated[i]) + if x != i { + t.Error("pbd.F_Sint64Repeated bad", x, i) + } + x = uint64(pbd.F_Sint32Repeated[i]) + if x != i { + t.Error("pbd.F_Sint32Repeated bad", x, i) + } + s := fmt.Sprint(i) + equalbytes(pbd.F_BytesRepeated[i], []byte(s), t) + if pbd.F_StringRepeated[i] != s { + t.Error("pbd.F_Sint32Repeated bad", pbd.F_StringRepeated[i], i) + } + x = uint64(pbd.F_DoubleRepeated[i]) + if x != i { + t.Error("pbd.F_DoubleRepeated bad", x, i) + } + x = uint64(pbd.F_FloatRepeated[i]) + if x != i { + t.Error("pbd.F_FloatRepeated bad", x, i) + } + x = pbd.F_Uint64Repeated[i] + if x != i { + t.Error("pbd.F_Uint64Repeated bad", x, i) + } + x = uint64(pbd.F_Uint32Repeated[i]) + if x != i { + t.Error("pbd.F_Uint32Repeated bad", x, i) + } + x = pbd.F_Fixed64Repeated[i] + if x != i { + t.Error("pbd.F_Fixed64Repeated bad", x, i) + } + x = uint64(pbd.F_Fixed32Repeated[i]) + if x != i { + t.Error("pbd.F_Fixed32Repeated bad", x, i) + } + x = uint64(pbd.F_Int64Repeated[i]) + if x != i { + t.Error("pbd.F_Int64Repeated bad", x, i) + } + x = uint64(pbd.F_Int32Repeated[i]) + if x != i { + t.Error("pbd.F_Int32Repeated bad", x, i) + } + if pbd.F_BoolRepeated[i] != (i%2 == 0) { + t.Error("pbd.F_BoolRepeated bad", x, i) + } + if pbd.RepeatedField[i] == nil { // TODO: more checking? + t.Error("pbd.RepeatedField bad") + } + } +} + +// Verify we give a useful message when decoding to the wrong structure type. +func TestTypeMismatch(t *testing.T) { + pb1 := initGoTest(true) + + // Marshal + o := old() + o.Marshal(pb1) + + // Now Unmarshal it to the wrong type. + pb2 := initGoTestField() + err := o.Unmarshal(pb2) + if err == nil { + t.Error("expected error, got no error") + } else if !strings.Contains(err.Error(), "bad wiretype") { + t.Error("expected bad wiretype error, got", err) + } +} + +func encodeDecode(t *testing.T, in, out Message, msg string) { + buf, err := Marshal(in) + if err != nil { + t.Fatalf("failed marshaling %v: %v", msg, err) + } + if err := Unmarshal(buf, out); err != nil { + t.Fatalf("failed unmarshaling %v: %v", msg, err) + } +} + +func TestPackedNonPackedDecoderSwitching(t *testing.T) { + np, p := new(NonPackedTest), new(PackedTest) + + // non-packed -> packed + np.A = []int32{0, 1, 1, 2, 3, 5} + encodeDecode(t, np, p, "non-packed -> packed") + if !reflect.DeepEqual(np.A, p.B) { + t.Errorf("failed non-packed -> packed; np.A=%+v, p.B=%+v", np.A, p.B) + } + + // packed -> non-packed + np.Reset() + p.B = []int32{3, 1, 4, 1, 5, 9} + encodeDecode(t, p, np, "packed -> non-packed") + if !reflect.DeepEqual(p.B, np.A) { + t.Errorf("failed packed -> non-packed; p.B=%+v, np.A=%+v", p.B, np.A) + } +} + +func TestProto1RepeatedGroup(t *testing.T) { + pb := &MessageList{ + Message: []*MessageList_Message{ + { + Name: String("blah"), + Count: Int32(7), + }, + // NOTE: pb.Message[1] is a nil + nil, + }, + } + + o := old() + err := o.Marshal(pb) + if err == nil || !strings.Contains(err.Error(), "repeated field Message has nil") { + t.Fatalf("unexpected or no error when marshaling: %v", err) + } +} + +// Test that enums work. Checks for a bug introduced by making enums +// named types instead of int32: newInt32FromUint64 would crash with +// a type mismatch in reflect.PointTo. +func TestEnum(t *testing.T) { + pb := new(GoEnum) + pb.Foo = FOO_FOO1.Enum() + o := old() + if err := o.Marshal(pb); err != nil { + t.Fatal("error encoding enum:", err) + } + pb1 := new(GoEnum) + if err := o.Unmarshal(pb1); err != nil { + t.Fatal("error decoding enum:", err) + } + if *pb1.Foo != FOO_FOO1 { + t.Error("expected 7 but got ", *pb1.Foo) + } +} + +// Enum types have String methods. Check that enum fields can be printed. +// We don't care what the value actually is, just as long as it doesn't crash. +func TestPrintingNilEnumFields(t *testing.T) { + pb := new(GoEnum) + _ = fmt.Sprintf("%+v", pb) +} + +// Verify that absent required fields cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcement(t *testing.T) { + pb := new(GoTestField) + _, err := Marshal(pb) + if err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Label") { + t.Errorf("marshal: bad error type: %v", err) + } + + // A slightly sneaky, yet valid, proto. It encodes the same required field twice, + // so simply counting the required fields is insufficient. + // field 1, encoding 2, value "hi" + buf := []byte("\x0A\x02hi\x0A\x02hi") + err = Unmarshal(buf, pb) + if err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +// Verify that absent required fields in groups cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcementGroups(t *testing.T) { + pb := &GoTestRequiredGroupField{Group: &GoTestRequiredGroupField_Group{}} + if _, err := Marshal(pb); err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.Field") { + t.Errorf("marshal: bad error type: %v", err) + } + + buf := []byte{11, 12} + if err := Unmarshal(buf, pb); err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +func TestTypedNilMarshal(t *testing.T) { + // A typed nil should return ErrNil and not crash. + { + var m *GoEnum + if _, err := Marshal(m); err != ErrNil { + t.Errorf("Marshal(%#v): got %v, want ErrNil", m, err) + } + } + + { + m := &Communique{Union: &Communique_Msg{Msg: nil}} + if _, err := Marshal(m); err == nil || err == ErrNil { + t.Errorf("Marshal(%#v): got %v, want errOneofHasNil", m, err) + } + } +} + +// A type that implements the Marshaler interface, but is not nillable. +type nonNillableInt uint64 + +func (nni nonNillableInt) Marshal() ([]byte, error) { + return EncodeVarint(uint64(nni)), nil +} + +type NNIMessage struct { + nni nonNillableInt +} + +func (*NNIMessage) Reset() {} +func (*NNIMessage) String() string { return "" } +func (*NNIMessage) ProtoMessage() {} + +// A type that implements the Marshaler interface and is nillable. +type nillableMessage struct { + x uint64 +} + +func (nm *nillableMessage) Marshal() ([]byte, error) { + return EncodeVarint(nm.x), nil +} + +type NMMessage struct { + nm *nillableMessage +} + +func (*NMMessage) Reset() {} +func (*NMMessage) String() string { return "" } +func (*NMMessage) ProtoMessage() {} + +// Verify a type that uses the Marshaler interface, but has a nil pointer. +func TestNilMarshaler(t *testing.T) { + // Try a struct with a Marshaler field that is nil. + // It should be directly marshable. + nmm := new(NMMessage) + if _, err := Marshal(nmm); err != nil { + t.Error("unexpected error marshaling nmm: ", err) + } + + // Try a struct with a Marshaler field that is not nillable. + nnim := new(NNIMessage) + nnim.nni = 7 + var _ Marshaler = nnim.nni // verify it is truly a Marshaler + if _, err := Marshal(nnim); err != nil { + t.Error("unexpected error marshaling nnim: ", err) + } +} + +func TestAllSetDefaults(t *testing.T) { + // Exercise SetDefaults with all scalar field types. + m := &Defaults{ + // NaN != NaN, so override that here. + F_Nan: Float32(1.7), + } + expected := &Defaults{ + F_Bool: Bool(true), + F_Int32: Int32(32), + F_Int64: Int64(64), + F_Fixed32: Uint32(320), + F_Fixed64: Uint64(640), + F_Uint32: Uint32(3200), + F_Uint64: Uint64(6400), + F_Float: Float32(314159), + F_Double: Float64(271828), + F_String: String(`hello, "world!"` + "\n"), + F_Bytes: []byte("Bignose"), + F_Sint32: Int32(-32), + F_Sint64: Int64(-64), + F_Enum: Defaults_GREEN.Enum(), + F_Pinf: Float32(float32(math.Inf(1))), + F_Ninf: Float32(float32(math.Inf(-1))), + F_Nan: Float32(1.7), + StrZero: String(""), + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("SetDefaults failed\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithSetField(t *testing.T) { + // Check that a set value is not overridden. + m := &Defaults{ + F_Int32: Int32(12), + } + SetDefaults(m) + if v := m.GetF_Int32(); v != 12 { + t.Errorf("m.FInt32 = %v, want 12", v) + } +} + +func TestSetDefaultsWithSubMessage(t *testing.T) { + m := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + }, + } + expected := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + Port: Int32(4000), + }, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithRepeatedSubMessage(t *testing.T) { + m := &MyMessage{ + RepInner: []*InnerMessage{{}}, + } + expected := &MyMessage{ + RepInner: []*InnerMessage{{ + Port: Int32(4000), + }}, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultWithRepeatedNonMessage(t *testing.T) { + m := &MyMessage{ + Pet: []string{"turtle", "wombat"}, + } + expected := Clone(m) + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestMaximumTagNumber(t *testing.T) { + m := &MaxTag{ + LastField: String("natural goat essence"), + } + buf, err := Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal failed: %v", err) + } + m2 := new(MaxTag) + if err := Unmarshal(buf, m2); err != nil { + t.Fatalf("proto.Unmarshal failed: %v", err) + } + if got, want := m2.GetLastField(), *m.LastField; got != want { + t.Errorf("got %q, want %q", got, want) + } +} + +func TestJSON(t *testing.T) { + m := &MyMessage{ + Count: Int32(4), + Pet: []string{"bunny", "kitty"}, + Inner: &InnerMessage{ + Host: String("cauchy"), + }, + Bikeshed: MyMessage_GREEN.Enum(), + } + const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}` + + b, err := json.Marshal(m) + if err != nil { + t.Fatalf("json.Marshal failed: %v", err) + } + s := string(b) + if s != expected { + t.Errorf("got %s\nwant %s", s, expected) + } + + received := new(MyMessage) + if err := json.Unmarshal(b, received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } + + // Test unmarshalling of JSON with symbolic enum name. + const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}` + received.Reset() + if err := json.Unmarshal([]byte(old), received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } +} + +func TestBadWireType(t *testing.T) { + b := []byte{7<<3 | 6} // field 7, wire type 6 + pb := new(OtherMessage) + if err := Unmarshal(b, pb); err == nil { + t.Errorf("Unmarshal did not fail") + } else if !strings.Contains(err.Error(), "unknown wire type") { + t.Errorf("wrong error: %v", err) + } +} + +func TestBytesWithInvalidLength(t *testing.T) { + // If a byte sequence has an invalid (negative) length, Unmarshal should not panic. + b := []byte{2<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0} + Unmarshal(b, new(MyMessage)) +} + +func TestLengthOverflow(t *testing.T) { + // Overflowing a length should not panic. + b := []byte{2<<3 | WireBytes, 1, 1, 3<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01} + Unmarshal(b, new(MyMessage)) +} + +func TestVarintOverflow(t *testing.T) { + // Overflowing a 64-bit length should not be allowed. + b := []byte{1<<3 | WireVarint, 0x01, 3<<3 | WireBytes, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01} + if err := Unmarshal(b, new(MyMessage)); err == nil { + t.Fatalf("Overflowed uint64 length without error") + } +} + +func TestUnmarshalFuzz(t *testing.T) { + const N = 1000 + seed := time.Now().UnixNano() + t.Logf("RNG seed is %d", seed) + rng := rand.New(rand.NewSource(seed)) + buf := make([]byte, 20) + for i := 0; i < N; i++ { + for j := range buf { + buf[j] = byte(rng.Intn(256)) + } + fuzzUnmarshal(t, buf) + } +} + +func TestMergeMessages(t *testing.T) { + pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}} + data, err := Marshal(pb) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + pb1 := new(MessageList) + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("first Unmarshal: %v", err) + } + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("second Unmarshal: %v", err) + } + if len(pb1.Message) != 1 { + t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message)) + } + + pb2 := new(MessageList) + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("first UnmarshalMerge: %v", err) + } + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("second UnmarshalMerge: %v", err) + } + if len(pb2.Message) != 2 { + t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message)) + } +} + +func TestExtensionMarshalOrder(t *testing.T) { + m := &MyMessage{Count: Int(123)} + if err := SetExtension(m, E_Ext_More, &Ext{Data: String("alpha")}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Text, String("aleph")); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Number, Int32(1)); err != nil { + t.Fatalf("SetExtension: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + var orig []byte + for i := 0; i < 100; i++ { + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if i == 0 { + orig = b + continue + } + if !bytes.Equal(b, orig) { + t.Errorf("Bytes differ on attempt #%d", i) + } + } +} + +// Many extensions, because small maps might not iterate differently on each iteration. +var exts = []*ExtensionDesc{ + E_X201, + E_X202, + E_X203, + E_X204, + E_X205, + E_X206, + E_X207, + E_X208, + E_X209, + E_X210, + E_X211, + E_X212, + E_X213, + E_X214, + E_X215, + E_X216, + E_X217, + E_X218, + E_X219, + E_X220, + E_X221, + E_X222, + E_X223, + E_X224, + E_X225, + E_X226, + E_X227, + E_X228, + E_X229, + E_X230, + E_X231, + E_X232, + E_X233, + E_X234, + E_X235, + E_X236, + E_X237, + E_X238, + E_X239, + E_X240, + E_X241, + E_X242, + E_X243, + E_X244, + E_X245, + E_X246, + E_X247, + E_X248, + E_X249, + E_X250, +} + +func TestMessageSetMarshalOrder(t *testing.T) { + m := &MyMessageSet{} + for _, x := range exts { + if err := SetExtension(m, x, &Empty{}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + } + + buf, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + for i := 0; i < 10; i++ { + b1, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if !bytes.Equal(b1, buf) { + t.Errorf("Bytes differ on re-Marshal #%d", i) + } + + m2 := &MyMessageSet{} + if err = Unmarshal(buf, m2); err != nil { + t.Errorf("Unmarshal: %v", err) + } + b2, err := Marshal(m2) + if err != nil { + t.Errorf("re-Marshal: %v", err) + } + if !bytes.Equal(b2, buf) { + t.Errorf("Bytes differ on round-trip #%d", i) + } + } +} + +func TestUnmarshalMergesMessages(t *testing.T) { + // If a nested message occurs twice in the input, + // the fields should be merged when decoding. + a := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("polhode"), + Port: Int32(1234), + }, + } + aData, err := Marshal(a) + if err != nil { + t.Fatalf("Marshal(a): %v", err) + } + b := &OtherMessage{ + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Connected: Bool(true), + }, + } + bData, err := Marshal(b) + if err != nil { + t.Fatalf("Marshal(b): %v", err) + } + want := &OtherMessage{ + Key: Int64(123), + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Port: Int32(1234), + Connected: Bool(true), + }, + } + got := new(OtherMessage) + if err := Unmarshal(append(aData, bData...), got); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + if !Equal(got, want) { + t.Errorf("\n got %v\nwant %v", got, want) + } +} + +func TestEncodingSizes(t *testing.T) { + tests := []struct { + m Message + n int + }{ + {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6}, + {&Defaults{F_Int32: Int32(math.MinInt32)}, 11}, + {&Defaults{F_Uint32: Uint32(uint32(math.MaxInt32) + 1)}, 6}, + {&Defaults{F_Uint32: Uint32(math.MaxUint32)}, 6}, + } + for _, test := range tests { + b, err := Marshal(test.m) + if err != nil { + t.Errorf("Marshal(%v): %v", test.m, err) + continue + } + if len(b) != test.n { + t.Errorf("Marshal(%v) yielded %d bytes, want %d bytes", test.m, len(b), test.n) + } + } +} + +func TestRequiredNotSetError(t *testing.T) { + pb := initGoTest(false) + pb.RequiredField.Label = nil + pb.F_Int32Required = nil + pb.F_Int64Required = nil + + expected := "0807" + // field 1, encoding 0, value 7 + "2206" + "120474797065" + // field 4, encoding 2 (GoTestField) + "5001" + // field 10, encoding 0, value 1 + "6d20000000" + // field 13, encoding 5, value 0x20 + "714000000000000000" + // field 14, encoding 1, value 0x40 + "78a019" + // field 15, encoding 0, value 0xca0 = 3232 + "8001c032" + // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45" + // field 17, encoding 5, value 3232.0 + "9101000000000040b940" + // field 18, encoding 1, value 6464.0 + "9a0106" + "737472696e67" + // field 19, encoding 2, string "string" + "b304" + // field 70, encoding 3, start group + "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required" + "b404" + // field 70, encoding 4, end group + "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes" + "b0063f" + // field 102, encoding 0, 0x3f zigzag32 + "b8067f" // field 103, encoding 0, 0x7f zigzag64 + + o := old() + mbytes, err := Marshal(pb) + if _, ok := err.(*RequiredNotSetError); !ok { + fmt.Printf("marshal-1 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("expected = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-1 wrong err msg: %v", err) + } + if !equal(mbytes, expected, t) { + o.DebugPrint("neq 1", mbytes) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = Unmarshal(mbytes, pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Fatalf("unmarshal err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 { + t.Errorf("unmarshal wrong err msg: %v", err) + } + mbytes, err = Marshal(pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-2 wrong err msg: %v", err) + } + if !equal(mbytes, expected, t) { + o.DebugPrint("neq 2", mbytes) + t.Fatalf("string = %s", expected) + } +} + +func fuzzUnmarshal(t *testing.T, data []byte) { + defer func() { + if e := recover(); e != nil { + t.Errorf("These bytes caused a panic: %+v", data) + t.Logf("Stack:\n%s", debug.Stack()) + t.FailNow() + } + }() + + pb := new(MyMessage) + Unmarshal(data, pb) +} + +func TestMapFieldMarshal(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // b should be the concatenation of these three byte sequences in some order. + parts := []string{ + "\n\a\b\x01\x12\x03Rob", + "\n\a\b\x04\x12\x03Ian", + "\n\b\b\x08\x12\x04Dave", + } + ok := false + for i := range parts { + for j := range parts { + if j == i { + continue + } + for k := range parts { + if k == i || k == j { + continue + } + try := parts[i] + parts[j] + parts[k] + if bytes.Equal(b, []byte(try)) { + ok = true + break + } + } + } + } + if !ok { + t.Fatalf("Incorrect Marshal output.\n got %q\nwant %q (or a permutation of that)", b, parts[0]+parts[1]+parts[2]) + } + t.Logf("FYI b: %q", b) + + (new(Buffer)).DebugPrint("Dump of b", b) +} + +func TestMapFieldRoundTrips(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + MsgMapping: map[int64]*FloatingPoint{ + 0x7001: {F: Float64(2.0)}, + }, + ByteMapping: map[bool][]byte{ + false: []byte("that's not right!"), + true: []byte("aye, 'tis true!"), + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("FYI b: %q", b) + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + for _, pair := range [][2]interface{}{ + {m.NameMapping, m2.NameMapping}, + {m.MsgMapping, m2.MsgMapping}, + {m.ByteMapping, m2.ByteMapping}, + } { + if !reflect.DeepEqual(pair[0], pair[1]) { + t.Errorf("Map did not survive a round trip.\ninitial: %v\n final: %v", pair[0], pair[1]) + } + } +} + +func TestMapFieldWithNil(t *testing.T) { + m1 := &MessageWithMap{ + MsgMapping: map[int64]*FloatingPoint{ + 1: nil, + }, + } + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.MsgMapping[1]; !ok { + t.Error("msg_mapping[1] not present") + } else if v != nil { + t.Errorf("msg_mapping[1] not nil: %v", v) + } +} + +func TestMapFieldWithNilBytes(t *testing.T) { + m1 := &MessageWithMap{ + ByteMapping: map[bool][]byte{ + false: {}, + true: nil, + }, + } + n := Size(m1) + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if n != len(b) { + t.Errorf("Size(m1) = %d; want len(Marshal(m1)) = %d", n, len(b)) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.ByteMapping[false]; !ok { + t.Error("byte_mapping[false] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[false] not empty: %#v", v) + } + if v, ok := m2.ByteMapping[true]; !ok { + t.Error("byte_mapping[true] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[true] not empty: %#v", v) + } +} + +func TestDecodeMapFieldMissingKey(t *testing.T) { + b := []byte{ + 0x0A, 0x03, // message, tag 1 (name_mapping), of length 3 bytes + // no key + 0x12, 0x01, 0x6D, // string value of length 1 byte, value "m" + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing key: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{0: "m"}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no key was not as expected. got: %v, want %v", got, want) + } +} + +func TestDecodeMapFieldMissingValue(t *testing.T) { + b := []byte{ + 0x0A, 0x02, // message, tag 1 (name_mapping), of length 2 bytes + 0x08, 0x01, // varint key, value 1 + // no value + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing value: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{1: ""}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no value was not as expected. got: %v, want %v", got, want) + } +} + +func TestOneof(t *testing.T) { + m := &Communique{} + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal of empty message with oneof: %v", err) + } + if len(b) != 0 { + t.Errorf("Marshal of empty message yielded too many bytes: %v", b) + } + + m = &Communique{ + Union: &Communique_Name{Name: "Barry"}, + } + + // Round-trip. + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof: %v", err) + } + if len(b) != 7 { // name tag/wire (1) + name len (1) + name (5) + t.Errorf("Incorrect marshal of message with oneof: %v", b) + } + m.Reset() + if err = Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof: %v", err) + } + if x, ok := m.Union.(*Communique_Name); !ok || x.Name != "Barry" { + t.Errorf("After round trip, Union = %+v", m.Union) + } + if name := m.GetName(); name != "Barry" { + t.Errorf("After round trip, GetName = %q, want %q", name, "Barry") + } + + // Let's try with a message in the oneof. + m.Union = &Communique_Msg{Msg: &Strings{StringField: String("deep deep string")}} + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof set to message: %v", err) + } + if len(b) != 20 { // msg tag/wire (1) + msg len (1) + msg (1 + 1 + 16) + t.Errorf("Incorrect marshal of message with oneof set to message: %v", b) + } + m.Reset() + if err := Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof set to message: %v", err) + } + ss, ok := m.Union.(*Communique_Msg) + if !ok || ss.Msg.GetStringField() != "deep deep string" { + t.Errorf("After round trip with oneof set to message, Union = %+v", m.Union) + } +} + +func TestInefficientPackedBool(t *testing.T) { + // https://github.com/golang/protobuf/issues/76 + inp := []byte{ + 0x12, 0x02, // 0x12 = 2<<3|2; 2 bytes + // Usually a bool should take a single byte, + // but it is permitted to be any varint. + 0xb9, 0x30, + } + if err := Unmarshal(inp, new(MoreRepeated)); err != nil { + t.Error(err) + } +} + +// Benchmarks + +func testMsg() *GoTest { + pb := initGoTest(true) + const N = 1000 // Internally the library starts much smaller. + pb.F_Int32Repeated = make([]int32, N) + pb.F_DoubleRepeated = make([]float64, N) + for i := 0; i < N; i++ { + pb.F_Int32Repeated[i] = int32(i) + pb.F_DoubleRepeated[i] = float64(i) + } + return pb +} + +func bytesMsg() *GoTest { + pb := initGoTest(true) + buf := make([]byte, 4000) + for i := range buf { + buf[i] = byte(i) + } + pb.F_BytesDefaulted = buf + return pb +} + +func benchmarkMarshal(b *testing.B, pb Message, marshal func(Message) ([]byte, error)) { + d, _ := marshal(pb) + b.SetBytes(int64(len(d))) + b.ResetTimer() + for i := 0; i < b.N; i++ { + marshal(pb) + } +} + +func benchmarkBufferMarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + p.Reset() + err := p.Marshal(pb0) + return p.Bytes(), err + }) +} + +func benchmarkSize(b *testing.B, pb Message) { + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + Size(pb) + return nil, nil + }) +} + +func newOf(pb Message) Message { + in := reflect.ValueOf(pb) + if in.IsNil() { + return pb + } + return reflect.New(in.Type().Elem()).Interface().(Message) +} + +func benchmarkUnmarshal(b *testing.B, pb Message, unmarshal func([]byte, Message) error) { + d, _ := Marshal(pb) + b.SetBytes(int64(len(d))) + pbd := newOf(pb) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + unmarshal(d, pbd) + } +} + +func benchmarkBufferUnmarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkUnmarshal(b, pb, func(d []byte, pb0 Message) error { + p.SetBuf(d) + return p.Unmarshal(pb0) + }) +} + +// Benchmark{Marshal,BufferMarshal,Size,Unmarshal,BufferUnmarshal}{,Bytes} + +func BenchmarkMarshal(b *testing.B) { + benchmarkMarshal(b, testMsg(), Marshal) +} + +func BenchmarkBufferMarshal(b *testing.B) { + benchmarkBufferMarshal(b, testMsg()) +} + +func BenchmarkSize(b *testing.B) { + benchmarkSize(b, testMsg()) +} + +func BenchmarkUnmarshal(b *testing.B) { + benchmarkUnmarshal(b, testMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshal(b *testing.B) { + benchmarkBufferUnmarshal(b, testMsg()) +} + +func BenchmarkMarshalBytes(b *testing.B) { + benchmarkMarshal(b, bytesMsg(), Marshal) +} + +func BenchmarkBufferMarshalBytes(b *testing.B) { + benchmarkBufferMarshal(b, bytesMsg()) +} + +func BenchmarkSizeBytes(b *testing.B) { + benchmarkSize(b, bytesMsg()) +} + +func BenchmarkUnmarshalBytes(b *testing.B) { + benchmarkUnmarshal(b, bytesMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshalBytes(b *testing.B) { + benchmarkBufferUnmarshal(b, bytesMsg()) +} + +func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) { + b.StopTimer() + pb := initGoTestField() + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + pbd := new(GoTestField) + p := NewBuffer(nil) + p.Marshal(pb) + p.Marshal(skip) + p2 := NewBuffer(nil) + + b.StartTimer() + for i := 0; i < b.N; i++ { + p2.SetBuf(p.Bytes()) + p2.Unmarshal(pbd) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/any_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/any_test.go new file mode 100644 index 00000000..f098d828 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/any_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "strings" + "testing" + + "github.com/gogo/protobuf/proto" + + pb "github.com/gogo/protobuf/proto/proto3_proto" + testpb "github.com/gogo/protobuf/proto/testdata" + "github.com/gogo/protobuf/types" +) + +var ( + expandedMarshaler = proto.TextMarshaler{ExpandAny: true} + expandedCompactMarshaler = proto.TextMarshaler{Compact: true, ExpandAny: true} +) + +// anyEqual reports whether two messages which may be google.protobuf.Any or may +// contain google.protobuf.Any fields are equal. We can't use proto.Equal for +// comparison, because semantically equivalent messages may be marshaled to +// binary in different tag order. Instead, trust that TextMarshaler with +// ExpandAny option works and compare the text marshaling results. +func anyEqual(got, want proto.Message) bool { + // if messages are proto.Equal, no need to marshal. + if proto.Equal(got, want) { + return true + } + g := expandedMarshaler.Text(got) + w := expandedMarshaler.Text(want) + return g == w +} + +type golden struct { + m proto.Message + t, c string +} + +var goldenMessages = makeGolden() + +func makeGolden() []golden { + nested := &pb.Nested{Bunny: "Monty"} + nb, err := proto.Marshal(nested) + if err != nil { + panic(err) + } + m1 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m2 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "http://[::1]/type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m3 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: `type.googleapis.com/"/` + proto.MessageName(nested), Value: nb}, + } + m4 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/a/path/" + proto.MessageName(nested), Value: nb}, + } + m5 := &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb} + + any1 := &testpb.MyMessage{Count: proto.Int32(47), Name: proto.String("David")} + proto.SetExtension(any1, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("foo")}) + proto.SetExtension(any1, testpb.E_Ext_Text, proto.String("bar")) + any1b, err := proto.Marshal(any1) + if err != nil { + panic(err) + } + any2 := &testpb.MyMessage{Count: proto.Int32(42), Bikeshed: testpb.MyMessage_GREEN.Enum(), RepBytes: [][]byte{[]byte("roboto")}} + proto.SetExtension(any2, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("baz")}) + any2b, err := proto.Marshal(any2) + if err != nil { + panic(err) + } + m6 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + ManyThings: []*types.Any{ + {TypeUrl: "type.googleapis.com/" + proto.MessageName(any2), Value: any2b}, + {TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + }, + } + + const ( + m1Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m2Golden = ` +name: "David" +result_count: 47 +anything: < + ["http://[::1]/type.googleapis.com/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m3Golden = ` +name: "David" +result_count: 47 +anything: < + ["type.googleapis.com/\"/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m4Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m5Golden = ` +[type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" +> +` + m6Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 42 + bikeshed: GREEN + rep_bytes: "roboto" + [testdata.Ext.more]: < + data: "baz" + > + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +` + ) + return []golden{ + {m1, strings.TrimSpace(m1Golden) + "\n", strings.TrimSpace(compact(m1Golden)) + " "}, + {m2, strings.TrimSpace(m2Golden) + "\n", strings.TrimSpace(compact(m2Golden)) + " "}, + {m3, strings.TrimSpace(m3Golden) + "\n", strings.TrimSpace(compact(m3Golden)) + " "}, + {m4, strings.TrimSpace(m4Golden) + "\n", strings.TrimSpace(compact(m4Golden)) + " "}, + {m5, strings.TrimSpace(m5Golden) + "\n", strings.TrimSpace(compact(m5Golden)) + " "}, + {m6, strings.TrimSpace(m6Golden) + "\n", strings.TrimSpace(compact(m6Golden)) + " "}, + } +} + +func TestMarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + if got, want := expandedMarshaler.Text(tt.m), tt.t; got != want { + t.Errorf("message %v: got:\n%s\nwant:\n%s", tt.m, got, want) + } + if got, want := expandedCompactMarshaler.Text(tt.m), tt.c; got != want { + t.Errorf("message %v: got:\n`%s`\nwant:\n`%s`", tt.m, got, want) + } + } +} + +func TestUnmarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + want := tt.m + got := proto.Clone(tt.m) + got.Reset() + if err := proto.UnmarshalText(tt.t, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.t, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.t, got, want) + } + got.Reset() + if err := proto.UnmarshalText(tt.c, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.c, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.c, got, want) + } + } +} + +func TestMarshalUnknownAny(t *testing.T) { + m := &pb.Message{ + Anything: &types.Any{ + TypeUrl: "foo", + Value: []byte("bar"), + }, + } + want := `anything: < + type_url: "foo" + value: "bar" +> +` + got := expandedMarshaler.Text(m) + if got != want { + t.Errorf("got\n`%s`\nwant\n`%s`", got, want) + } +} + +func TestAmbiguousAny(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + type_url: "ttt/proto3_proto.Nested" + value: "\n\x05Monty" + `, pb) + t.Logf("result: %v (error: %v)", expandedMarshaler.Text(pb), err) + if err != nil { + t.Errorf("failed to parse ambiguous Any message: %v", err) + } +} + +func TestUnmarshalOverwriteAny(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 7: Any message unpacked multiple times, or "type_url" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} + +func TestUnmarshalAnyMixAndMatch(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + value: "\n\x05Monty" + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 5: Any message unpacked multiple times, or "value" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/clone_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/clone_test.go new file mode 100644 index 00000000..1a16eb55 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/clone_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2011 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +var cloneTestMessage = &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, +} + +func init() { + ext := &pb.Ext{ + Data: proto.String("extension"), + } + if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil { + panic("SetExtension: " + err.Error()) + } +} + +func TestClone(t *testing.T) { + m := proto.Clone(cloneTestMessage).(*pb.MyMessage) + if !proto.Equal(m, cloneTestMessage) { + t.Errorf("Clone(%v) = %v", cloneTestMessage, m) + } + + // Verify it was a deep copy. + *m.Inner.Port++ + if proto.Equal(m, cloneTestMessage) { + t.Error("Mutating clone changed the original") + } + // Byte fields and repeated fields should be copied. + if &m.Pet[0] == &cloneTestMessage.Pet[0] { + t.Error("Pet: repeated field not copied") + } + if &m.Others[0] == &cloneTestMessage.Others[0] { + t.Error("Others: repeated field not copied") + } + if &m.Others[0].Value[0] == &cloneTestMessage.Others[0].Value[0] { + t.Error("Others[0].Value: bytes field not copied") + } + if &m.RepBytes[0] == &cloneTestMessage.RepBytes[0] { + t.Error("RepBytes: repeated field not copied") + } + if &m.RepBytes[0][0] == &cloneTestMessage.RepBytes[0][0] { + t.Error("RepBytes[0]: bytes field not copied") + } +} + +func TestCloneNil(t *testing.T) { + var m *pb.MyMessage + if c := proto.Clone(m); !proto.Equal(m, c) { + t.Errorf("Clone(%v) = %v", m, c) + } +} + +var mergeTests = []struct { + src, dst, want proto.Message +}{ + { + src: &pb.MyMessage{ + Count: proto.Int32(42), + }, + dst: &pb.MyMessage{ + Name: proto.String("Dave"), + }, + want: &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + }, + }, + { + src: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + }, + Pet: []string{"horsey"}, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + }, + dst: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + { + // Explicitly test a src=nil field + Inner: nil, + }, + }, + }, + want: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty", "horsey"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + {}, + { + Value: []byte("some bytes"), + }, + }, + }, + }, + { + src: &pb.MyMessage{ + RepBytes: [][]byte{[]byte("wow")}, + }, + dst: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham")}, + }, + want: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, + }, + }, + // Check that a scalar bytes field replaces rather than appends. + { + src: &pb.OtherMessage{Value: []byte("foo")}, + dst: &pb.OtherMessage{Value: []byte("bar")}, + want: &pb.OtherMessage{Value: []byte("foo")}, + }, + { + src: &pb.MessageWithMap{ + NameMapping: map[int32]string{6: "Nigel"}, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: {F: proto.Float64(2.0)}, + 0x4002: { + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + dst: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Bruce", // should be overwritten + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4002: { + F: proto.Float64(3.0), + Exact: proto.Bool(true), + }, // the entire message should be overwritten + }, + }, + want: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Nigel", + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: {F: proto.Float64(2.0)}, + 0x4002: { + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + }, + // proto3 shouldn't merge zero values, + // in the same way that proto2 shouldn't merge nils. + { + src: &proto3pb.Message{ + Name: "Aaron", + Data: []byte(""), // zero value, but not nil + }, + dst: &proto3pb.Message{ + HeightInCm: 176, + Data: []byte("texas!"), + }, + want: &proto3pb.Message{ + Name: "Aaron", + HeightInCm: 176, + Data: []byte("texas!"), + }, + }, + // Oneof fields should merge by assignment. + { + src: &pb.Communique{ + Union: &pb.Communique_Number{Number: 41}, + }, + dst: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Number{Number: 41}, + }, + }, + // Oneof nil is the same as not set. + { + src: &pb.Communique{}, + dst: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + }, + { + src: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Cute: true}, // replace + "kay_b": {Bunny: "rabbit"}, // insert + }, + }, + dst: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Bunny: "lost"}, // replaced + "kay_c": {Bunny: "bunny"}, // keep + }, + }, + want: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Cute: true}, + "kay_b": {Bunny: "rabbit"}, + "kay_c": {Bunny: "bunny"}, + }, + }, + }, +} + +func TestMerge(t *testing.T) { + for _, m := range mergeTests { + got := proto.Clone(m.dst) + proto.Merge(got, m.src) + if !proto.Equal(got, m.want) { + t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/decode_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/decode_test.go new file mode 100644 index 00000000..64d4decd --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/decode_test.go @@ -0,0 +1,262 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// +build go1.7 + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + tpb "github.com/gogo/protobuf/proto/proto3_proto" +) + +var ( + bytesBlackhole []byte + msgBlackhole = new(tpb.Message) +) + +// Disabled this Benchmark because it is using features (b.Run) from go1.7 and gogoprotobuf still have compatibility with go1.5 +// BenchmarkVarint32ArraySmall shows the performance on an array of small int32 fields (1 and +// 2 bytes long). +// func BenchmarkVarint32ArraySmall(b *testing.B) { +// for i := uint(1); i <= 10; i++ { +// dist := genInt32Dist([7]int{0, 3, 1}, 1<unmarshal. +} + +func TestMarshalUnmarshalRepeatedExtension(t *testing.T) { + // Add a repeated extension to the result. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + // Marshal message with a repeated extension. + msg1 := new(pb.OtherMessage) + err := proto.SetExtension(msg1, pb.E_RComplex, test.ext) + if err != nil { + t.Fatalf("[%s] Error setting extension: %v", test.name, err) + } + b, err := proto.Marshal(msg1) + if err != nil { + t.Fatalf("[%s] Error marshaling message: %v", test.name, err) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err = proto.Unmarshal(b, msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_RComplex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.([]*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(ext, test.ext) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %v want: %v\n", test.name, ext, test.ext) + } + } +} + +func TestUnmarshalRepeatingNonRepeatedExtension(t *testing.T) { + // We may see multiple instances of the same extension in the wire + // format. For example, the proto compiler may encode custom options in + // this way. Here, we verify that we merge the extensions together. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + var buf bytes.Buffer + var want pb.ComplexExtension + + // Generate a serialized representation of a repeated extension + // by catenating bytes together. + for i, e := range test.ext { + // Merge to create the wanted proto. + proto.Merge(&want, e) + + // serialize the message + msg := new(pb.OtherMessage) + err := proto.SetExtension(msg, pb.E_Complex, e) + if err != nil { + t.Fatalf("[%s] Error setting extension %d: %v", test.name, i, err) + } + b, err := proto.Marshal(msg) + if err != nil { + t.Fatalf("[%s] Error marshaling message %d: %v", test.name, i, err) + } + buf.Write(b) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err := proto.Unmarshal(buf.Bytes(), msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_Complex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.(*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(*ext, want) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %v want: %v\n", test.name, ext, want) + } + } +} + +func TestClearAllExtensions(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + m := &pb.MyMessage{} + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + if !proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got false, want true", proto.MarshalTextString(m)) + } + proto.ClearAllExtensions(m) + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } +} + +func TestMarshalRace(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + + m := &pb.MyMessage{Count: proto.Int32(4)} + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + + errChan := make(chan error, 3) + for n := 3; n > 0; n-- { + go func() { + _, err := proto.Marshal(m) + errChan <- err + }() + } + for i := 0; i < 3; i++ { + err := <-errChan + if err != nil { + t.Fatal(err) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/map_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/map_test.go new file mode 100644 index 00000000..18b946d0 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/map_test.go @@ -0,0 +1,46 @@ +package proto_test + +import ( + "fmt" + "testing" + + "github.com/gogo/protobuf/proto" + ppb "github.com/gogo/protobuf/proto/proto3_proto" +) + +func marshalled() []byte { + m := &ppb.IntMaps{} + for i := 0; i < 1000; i++ { + m.Maps = append(m.Maps, &ppb.IntMap{ + Rtt: map[int32]int32{1: 2}, + }) + } + b, err := proto.Marshal(m) + if err != nil { + panic(fmt.Sprintf("Can't marshal %+v: %v", m, err)) + } + return b +} + +func BenchmarkConcurrentMapUnmarshal(b *testing.B) { + in := marshalled() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } + }) +} + +func BenchmarkSequentialMapUnmarshal(b *testing.B) { + in := marshalled() + b.ResetTimer() + for i := 0; i < b.N; i++ { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/message_set_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/message_set_test.go new file mode 100644 index 00000000..353a3ea7 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/message_set_test.go @@ -0,0 +1,66 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "bytes" + "testing" +) + +func TestUnmarshalMessageSetWithDuplicate(t *testing.T) { + // Check that a repeated message set entry will be concatenated. + in := &messageSet{ + Item: []*_MessageSet_Item{ + {TypeId: Int32(12345), Message: []byte("hoo")}, + {TypeId: Int32(12345), Message: []byte("hah")}, + }, + } + b, err := Marshal(in) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("Marshaled bytes: %q", b) + + var extensions XXX_InternalExtensions + if err := UnmarshalMessageSet(b, &extensions); err != nil { + t.Fatalf("UnmarshalMessageSet: %v", err) + } + ext, ok := extensions.p.extensionMap[12345] + if !ok { + t.Fatalf("Didn't retrieve extension 12345; map is %v", extensions.p.extensionMap) + } + // Skip wire type/field number and length varints. + got := skipVarint(skipVarint(ext.enc)) + if want := []byte("hoohah"); !bytes.Equal(got, want) { + t.Errorf("Combined extension is %q, want %q", got, want) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/proto3_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/proto3_test.go new file mode 100644 index 00000000..75b66c17 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/proto3_test.go @@ -0,0 +1,135 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + pb "github.com/gogo/protobuf/proto/proto3_proto" + tpb "github.com/gogo/protobuf/proto/testdata" +) + +func TestProto3ZeroValues(t *testing.T) { + tests := []struct { + desc string + m proto.Message + }{ + {"zero message", &pb.Message{}}, + {"empty bytes field", &pb.Message{Data: []byte{}}}, + } + for _, test := range tests { + b, err := proto.Marshal(test.m) + if err != nil { + t.Errorf("%s: proto.Marshal: %v", test.desc, err) + continue + } + if len(b) > 0 { + t.Errorf("%s: Encoding is non-empty: %q", test.desc, b) + } + } +} + +func TestRoundTripProto3(t *testing.T) { + m := &pb.Message{ + Name: "David", // (2 | 1<<3): 0x0a 0x05 "David" + Hilarity: pb.Message_PUNS, // (0 | 2<<3): 0x10 0x01 + HeightInCm: 178, // (0 | 3<<3): 0x18 0xb2 0x01 + Data: []byte("roboto"), // (2 | 4<<3): 0x20 0x06 "roboto" + ResultCount: 47, // (0 | 7<<3): 0x38 0x2f + TrueScotsman: true, // (0 | 8<<3): 0x40 0x01 + Score: 8.1, // (5 | 9<<3): 0x4d <8.1> + + Key: []uint64{1, 0xdeadbeef}, + Nested: &pb.Nested{ + Bunny: "Monty", + }, + } + t.Logf(" m: %v", m) + + b, err := proto.Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal: %v", err) + } + t.Logf(" b: %q", b) + + m2 := new(pb.Message) + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatalf("proto.Unmarshal: %v", err) + } + t.Logf("m2: %v", m2) + + if !proto.Equal(m, m2) { + t.Errorf("proto.Equal returned false:\n m: %v\nm2: %v", m, m2) + } +} + +func TestGettersForBasicTypesExist(t *testing.T) { + var m pb.Message + if got := m.GetNested().GetBunny(); got != "" { + t.Errorf("m.GetNested().GetBunny() = %q, want empty string", got) + } + if got := m.GetNested().GetCute(); got { + t.Errorf("m.GetNested().GetCute() = %t, want false", got) + } +} + +func TestProto3SetDefaults(t *testing.T) { + in := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: new(tpb.SubDefaults), + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": new(tpb.SubDefaults), + }, + } + + got := proto.Clone(in).(*pb.Message) + proto.SetDefaults(got) + + // There are no defaults in proto3. Everything should be the zero value, but + // we need to remember to set defaults for nested proto2 messages. + want := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: &tpb.SubDefaults{N: proto.Int64(7)}, + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": {N: proto.Int64(7)}, + }, + } + + if !proto.Equal(got, want) { + t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/size2_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/size2_test.go new file mode 100644 index 00000000..a2729c39 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/size2_test.go @@ -0,0 +1,63 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "testing" +) + +// This is a separate file and package from size_test.go because that one uses +// generated messages and thus may not be in package proto without having a circular +// dependency, whereas this file tests unexported details of size.go. + +func TestVarintSize(t *testing.T) { + // Check the edge cases carefully. + testCases := []struct { + n uint64 + size int + }{ + {0, 1}, + {1, 1}, + {127, 1}, + {128, 2}, + {16383, 2}, + {16384, 3}, + {1<<63 - 1, 9}, + {1 << 63, 10}, + } + for _, tc := range testCases { + size := sizeVarint(tc.n) + if size != tc.size { + t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/size_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/size_test.go new file mode 100644 index 00000000..0a6c1772 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/size_test.go @@ -0,0 +1,164 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "log" + "strings" + "testing" + + . "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)} + +// messageWithExtension2 is in equal_test.go. +var messageWithExtension3 = &pb.MyMessage{Count: Int32(8)} + +func init() { + if err := SetExtension(messageWithExtension1, pb.E_Ext_More, &pb.Ext{Data: String("Abbott")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + if err := SetExtension(messageWithExtension3, pb.E_Ext_More, &pb.Ext{Data: String("Costello")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + + // Force messageWithExtension3 to have the extension encoded. + Marshal(messageWithExtension3) + +} + +var SizeTests = []struct { + desc string + pb Message +}{ + {"empty", &pb.OtherMessage{}}, + // Basic types. + {"bool", &pb.Defaults{F_Bool: Bool(true)}}, + {"int32", &pb.Defaults{F_Int32: Int32(12)}}, + {"negative int32", &pb.Defaults{F_Int32: Int32(-1)}}, + {"small int64", &pb.Defaults{F_Int64: Int64(1)}}, + {"big int64", &pb.Defaults{F_Int64: Int64(1 << 20)}}, + {"negative int64", &pb.Defaults{F_Int64: Int64(-1)}}, + {"fixed32", &pb.Defaults{F_Fixed32: Uint32(71)}}, + {"fixed64", &pb.Defaults{F_Fixed64: Uint64(72)}}, + {"uint32", &pb.Defaults{F_Uint32: Uint32(123)}}, + {"uint64", &pb.Defaults{F_Uint64: Uint64(124)}}, + {"float", &pb.Defaults{F_Float: Float32(12.6)}}, + {"double", &pb.Defaults{F_Double: Float64(13.9)}}, + {"string", &pb.Defaults{F_String: String("niles")}}, + {"bytes", &pb.Defaults{F_Bytes: []byte("wowsa")}}, + {"bytes, empty", &pb.Defaults{F_Bytes: []byte{}}}, + {"sint32", &pb.Defaults{F_Sint32: Int32(65)}}, + {"sint64", &pb.Defaults{F_Sint64: Int64(67)}}, + {"enum", &pb.Defaults{F_Enum: pb.Defaults_BLUE.Enum()}}, + // Repeated. + {"empty repeated bool", &pb.MoreRepeated{Bools: []bool{}}}, + {"repeated bool", &pb.MoreRepeated{Bools: []bool{false, true, true, false}}}, + {"packed repeated bool", &pb.MoreRepeated{BoolsPacked: []bool{false, true, true, false, true, true, true}}}, + {"repeated int32", &pb.MoreRepeated{Ints: []int32{1, 12203, 1729, -1}}}, + {"repeated int32 packed", &pb.MoreRepeated{IntsPacked: []int32{1, 12203, 1729}}}, + {"repeated int64 packed", &pb.MoreRepeated{Int64SPacked: []int64{ + // Need enough large numbers to verify that the header is counting the number of bytes + // for the field, not the number of elements. + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + }}}, + {"repeated string", &pb.MoreRepeated{Strings: []string{"r", "ken", "gri"}}}, + {"repeated fixed", &pb.MoreRepeated{Fixeds: []uint32{1, 2, 3, 4}}}, + // Nested. + {"nested", &pb.OldMessage{Nested: &pb.OldMessage_Nested{Name: String("whatever")}}}, + {"group", &pb.GroupOld{G: &pb.GroupOld_G{X: Int32(12345)}}}, + // Other things. + {"unrecognized", &pb.MoreRepeated{XXX_unrecognized: []byte{13<<3 | 0, 4}}}, + {"extension (unencoded)", messageWithExtension1}, + {"extension (encoded)", messageWithExtension3}, + // proto3 message + {"proto3 empty", &proto3pb.Message{}}, + {"proto3 bool", &proto3pb.Message{TrueScotsman: true}}, + {"proto3 int64", &proto3pb.Message{ResultCount: 1}}, + {"proto3 uint32", &proto3pb.Message{HeightInCm: 123}}, + {"proto3 float", &proto3pb.Message{Score: 12.6}}, + {"proto3 string", &proto3pb.Message{Name: "Snezana"}}, + {"proto3 bytes", &proto3pb.Message{Data: []byte("wowsa")}}, + {"proto3 bytes, empty", &proto3pb.Message{Data: []byte{}}}, + {"proto3 enum", &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 map field with empty bytes", &proto3pb.MessageWithMap{ByteMapping: map[bool][]byte{false: {}}}}, + + {"map field", &pb.MessageWithMap{NameMapping: map[int32]string{1: "Rob", 7: "Andrew"}}}, + {"map field with message", &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{0x7001: {F: Float64(2.0)}}}}, + {"map field with bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: []byte("this time for sure")}}}, + {"map field with empty bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: {}}}}, + + {"map field with big entry", &pb.MessageWithMap{NameMapping: map[int32]string{8: strings.Repeat("x", 125)}}}, + {"map field with big key and val", &pb.MessageWithMap{StrToStr: map[string]string{strings.Repeat("x", 70): strings.Repeat("y", 70)}}}, + {"map field with big numeric key", &pb.MessageWithMap{NameMapping: map[int32]string{0xf00d: "om nom nom"}}}, + + {"oneof not set", &pb.Oneof{}}, + {"oneof bool", &pb.Oneof{Union: &pb.Oneof_F_Bool{F_Bool: true}}}, + {"oneof zero int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 0}}}, + {"oneof big int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 1 << 20}}}, + {"oneof int64", &pb.Oneof{Union: &pb.Oneof_F_Int64{F_Int64: 42}}}, + {"oneof fixed32", &pb.Oneof{Union: &pb.Oneof_F_Fixed32{F_Fixed32: 43}}}, + {"oneof fixed64", &pb.Oneof{Union: &pb.Oneof_F_Fixed64{F_Fixed64: 44}}}, + {"oneof uint32", &pb.Oneof{Union: &pb.Oneof_F_Uint32{F_Uint32: 45}}}, + {"oneof uint64", &pb.Oneof{Union: &pb.Oneof_F_Uint64{F_Uint64: 46}}}, + {"oneof float", &pb.Oneof{Union: &pb.Oneof_F_Float{F_Float: 47.1}}}, + {"oneof double", &pb.Oneof{Union: &pb.Oneof_F_Double{F_Double: 48.9}}}, + {"oneof string", &pb.Oneof{Union: &pb.Oneof_F_String{F_String: "Rhythmic Fman"}}}, + {"oneof bytes", &pb.Oneof{Union: &pb.Oneof_F_Bytes{F_Bytes: []byte("let go")}}}, + {"oneof sint32", &pb.Oneof{Union: &pb.Oneof_F_Sint32{F_Sint32: 50}}}, + {"oneof sint64", &pb.Oneof{Union: &pb.Oneof_F_Sint64{F_Sint64: 51}}}, + {"oneof enum", &pb.Oneof{Union: &pb.Oneof_F_Enum{F_Enum: pb.MyMessage_BLUE}}}, + {"message for oneof", &pb.GoTestField{Label: String("k"), Type: String("v")}}, + {"oneof message", &pb.Oneof{Union: &pb.Oneof_F_Message{F_Message: &pb.GoTestField{Label: String("k"), Type: String("v")}}}}, + {"oneof group", &pb.Oneof{Union: &pb.Oneof_FGroup{FGroup: &pb.Oneof_F_Group{X: Int32(52)}}}}, + {"oneof largest tag", &pb.Oneof{Union: &pb.Oneof_F_Largest_Tag{F_Largest_Tag: 1}}}, + {"multiple oneofs", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 1}, Tormato: &pb.Oneof_Value{Value: 2}}}, +} + +func TestSize(t *testing.T) { + for _, tc := range SizeTests { + size := Size(tc.pb) + b, err := Marshal(tc.pb) + if err != nil { + t.Errorf("%v: Marshal failed: %v", tc.desc, err) + continue + } + if size != len(b) { + t.Errorf("%v: Size(%v) = %d, want %d", tc.desc, tc.pb, size, len(b)) + t.Logf("%v: bytes: %#v", tc.desc, b) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go new file mode 100644 index 00000000..8e845153 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go @@ -0,0 +1,86 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Verify that the compiler output for test.proto is unchanged. + +package testdata + +import ( + "crypto/sha1" + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "testing" +) + +// sum returns in string form (for easy comparison) the SHA-1 hash of the named file. +func sum(t *testing.T, name string) string { + data, err := ioutil.ReadFile(name) + if err != nil { + t.Fatal(err) + } + t.Logf("sum(%q): length is %d", name, len(data)) + hash := sha1.New() + _, err = hash.Write(data) + if err != nil { + t.Fatal(err) + } + return fmt.Sprintf("% x", hash.Sum(nil)) +} + +func run(t *testing.T, name string, args ...string) { + cmd := exec.Command(name, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + t.Fatal(err) + } +} + +func TestGolden(t *testing.T) { + // Compute the original checksum. + goldenSum := sum(t, "test.pb.go") + // Run the proto compiler. + run(t, "protoc", "--gogo_out="+os.TempDir(), "test.proto") + newFile := filepath.Join(os.TempDir(), "test.pb.go") + defer os.Remove(newFile) + // Compute the new checksum. + newSum := sum(t, newFile) + // Verify + if newSum != goldenSum { + run(t, "diff", "-u", "test.pb.go", newFile) + t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/text_parser_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/text_parser_test.go new file mode 100644 index 00000000..9a3a447c --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/text_parser_test.go @@ -0,0 +1,673 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "math" + "reflect" + "testing" + + . "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + . "github.com/gogo/protobuf/proto/testdata" +) + +type UnmarshalTextTest struct { + in string + err string // if "", no error expected + out *MyMessage +} + +func buildExtStructTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_More, &Ext{ + Data: String("Hello, world!"), + }) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtDataTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_Text, String("Hello, world!")) + SetExtension(msg, E_Ext_Number, Int32(1729)) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtRepStringTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + if err := SetExtension(msg, E_Greeting, []string{"bula", "hola"}); err != nil { + panic(err) + } + return UnmarshalTextTest{in: text, out: msg} +} + +var unMarshalTextTests = []UnmarshalTextTest{ + // Basic + { + in: " count:42\n name:\"Dave\" ", + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + }, + }, + + // Empty quoted string + { + in: `count:42 name:""`, + out: &MyMessage{ + Count: Int32(42), + Name: String(""), + }, + }, + + // Quoted string concatenation with double quotes + { + in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenation with single quotes + { + in: "count:42 name: 'My name is '\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenations with mixed quotes + { + in: "count:42 name: 'My name is '\n\"elsewhere\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + { + in: "count:42 name: \"My name is \"\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string with escaped apostrophe + { + in: `count:42 name: "HOLIDAY - New Year\'s Day"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("HOLIDAY - New Year's Day"), + }, + }, + + // Quoted string with single quote + { + in: `count:42 name: 'Roger "The Ramster" Ramjet'`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`Roger "The Ramster" Ramjet`), + }, + }, + + // Quoted string with all the accepted special characters from the C++ test + { + in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"), + }, + }, + + // Quoted string with quoted backslash + { + in: `count:42 name: "\\'xyz"`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`\'xyz`), + }, + }, + + // Quoted string with UTF-8 bytes. + { + in: "count:42 name: '\303\277\302\201\xAB'", + out: &MyMessage{ + Count: Int32(42), + Name: String("\303\277\302\201\xAB"), + }, + }, + + // Bad quoted string + { + in: `inner: < host: "\0" >` + "\n", + err: `line 1.15: invalid quoted string "\0": \0 requires 2 following digits`, + }, + + // Number too large for int64 + { + in: "count: 1 others { key: 123456789012345678901 }", + err: "line 1.23: invalid int64: 123456789012345678901", + }, + + // Number too large for int32 + { + in: "count: 1234567890123", + err: "line 1.7: invalid int32: 1234567890123", + }, + + // Number in hexadecimal + { + in: "count: 0x2beef", + out: &MyMessage{ + Count: Int32(0x2beef), + }, + }, + + // Number in octal + { + in: "count: 024601", + out: &MyMessage{ + Count: Int32(024601), + }, + }, + + // Floating point number with "f" suffix + { + in: "count: 4 others:< weight: 17.0f >", + out: &MyMessage{ + Count: Int32(4), + Others: []*OtherMessage{ + { + Weight: Float32(17), + }, + }, + }, + }, + + // Floating point positive infinity + { + in: "count: 4 bigfloat: inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(1)), + }, + }, + + // Floating point negative infinity + { + in: "count: 4 bigfloat: -inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(-1)), + }, + }, + + // Number too large for float32 + { + in: "others:< weight: 12345678901234567890123456789012345678901234567890 >", + err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890", + }, + + // Number posing as a quoted string + { + in: `inner: < host: 12 >` + "\n", + err: `line 1.15: invalid string: 12`, + }, + + // Quoted string posing as int32 + { + in: `count: "12"`, + err: `line 1.7: invalid int32: "12"`, + }, + + // Quoted string posing a float32 + { + in: `others:< weight: "17.4" >`, + err: `line 1.17: invalid float32: "17.4"`, + }, + + // Enum + { + in: `count:42 bikeshed: BLUE`, + out: &MyMessage{ + Count: Int32(42), + Bikeshed: MyMessage_BLUE.Enum(), + }, + }, + + // Repeated field + { + in: `count:42 pet: "horsey" pet:"bunny"`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated field with list notation + { + in: `count:42 pet: ["horsey", "bunny"]`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated message with/without colon and <>/{} + { + in: `count:42 others:{} others{} others:<> others:{}`, + out: &MyMessage{ + Count: Int32(42), + Others: []*OtherMessage{ + {}, + {}, + {}, + {}, + }, + }, + }, + + // Missing colon for inner message + { + in: `count:42 inner < host: "cauchy.syd" >`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("cauchy.syd"), + }, + }, + }, + + // Missing colon for string field + { + in: `name "Dave"`, + err: `line 1.5: expected ':', found "\"Dave\""`, + }, + + // Missing colon for int32 field + { + in: `count 42`, + err: `line 1.6: expected ':', found "42"`, + }, + + // Missing required field + { + in: `name: "Pawel"`, + err: `proto: required field "testdata.MyMessage.count" not set`, + out: &MyMessage{ + Name: String("Pawel"), + }, + }, + + // Missing required field in a required submessage + { + in: `count: 42 we_must_go_deeper < leo_finally_won_an_oscar <> >`, + err: `proto: required field "testdata.InnerMessage.host" not set`, + out: &MyMessage{ + Count: Int32(42), + WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}}, + }, + }, + + // Repeated non-repeated field + { + in: `name: "Rob" name: "Russ"`, + err: `line 1.12: non-repeated field "name" was repeated`, + }, + + // Group + { + in: `count: 17 SomeGroup { group_field: 12 }`, + out: &MyMessage{ + Count: Int32(17), + Somegroup: &MyMessage_SomeGroup{ + GroupField: Int32(12), + }, + }, + }, + + // Semicolon between fields + { + in: `count:3;name:"Calvin"`, + out: &MyMessage{ + Count: Int32(3), + Name: String("Calvin"), + }, + }, + // Comma between fields + { + in: `count:4,name:"Ezekiel"`, + out: &MyMessage{ + Count: Int32(4), + Name: String("Ezekiel"), + }, + }, + + // Boolean false + { + in: `count:42 inner { host: "example.com" connected: false }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean true + { + in: `count:42 inner { host: "example.com" connected: true }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean 0 + { + in: `count:42 inner { host: "example.com" connected: 0 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean 1 + { + in: `count:42 inner { host: "example.com" connected: 1 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean f + { + in: `count:42 inner { host: "example.com" connected: f }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean t + { + in: `count:42 inner { host: "example.com" connected: t }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean False + { + in: `count:42 inner { host: "example.com" connected: False }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean True + { + in: `count:42 inner { host: "example.com" connected: True }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + + // Extension + buildExtStructTest(`count: 42 [testdata.Ext.more]:`), + buildExtStructTest(`count: 42 [testdata.Ext.more] {data:"Hello, world!"}`), + buildExtDataTest(`count: 42 [testdata.Ext.text]:"Hello, world!" [testdata.Ext.number]:1729`), + buildExtRepStringTest(`count: 42 [testdata.greeting]:"bula" [testdata.greeting]:"hola"`), + + // Big all-in-one + { + in: "count:42 # Meaning\n" + + `name:"Dave" ` + + `quote:"\"I didn't want to go.\"" ` + + `pet:"bunny" ` + + `pet:"kitty" ` + + `pet:"horsey" ` + + `inner:<` + + ` host:"footrest.syd" ` + + ` port:7001 ` + + ` connected:true ` + + `> ` + + `others:<` + + ` key:3735928559 ` + + ` value:"\x01A\a\f" ` + + `> ` + + `others:<` + + " weight:58.9 # Atomic weight of Co\n" + + ` inner:<` + + ` host:"lesha.mtv" ` + + ` port:8002 ` + + ` >` + + `>`, + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + Quote: String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &InnerMessage{ + Host: String("footrest.syd"), + Port: Int32(7001), + Connected: Bool(true), + }, + Others: []*OtherMessage{ + { + Key: Int64(3735928559), + Value: []byte{0x1, 'A', '\a', '\f'}, + }, + { + Weight: Float32(58.9), + Inner: &InnerMessage{ + Host: String("lesha.mtv"), + Port: Int32(8002), + }, + }, + }, + }, + }, +} + +func TestUnmarshalText(t *testing.T) { + for i, test := range unMarshalTextTests { + pb := new(MyMessage) + err := UnmarshalText(test.in, pb) + if test.err == "" { + // We don't expect failure. + if err != nil { + t.Errorf("Test %d: Unexpected error: %v", i, err) + } else if !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } else { + // We do expect failure. + if err == nil { + t.Errorf("Test %d: Didn't get expected error: %v", i, test.err) + } else if err.Error() != test.err { + t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v", + i, err.Error(), test.err) + } else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } + } +} + +func TestUnmarshalTextCustomMessage(t *testing.T) { + msg := &textMessage{} + if err := UnmarshalText("custom", msg); err != nil { + t.Errorf("Unexpected error from custom unmarshal: %v", err) + } + if UnmarshalText("not custom", msg) == nil { + t.Errorf("Didn't get expected error from custom unmarshal") + } +} + +// Regression test; this caused a panic. +func TestRepeatedEnum(t *testing.T) { + pb := new(RepeatedEnum) + if err := UnmarshalText("color: RED", pb); err != nil { + t.Fatal(err) + } + exp := &RepeatedEnum{ + Color: []RepeatedEnum_Color{RepeatedEnum_RED}, + } + if !Equal(pb, exp) { + t.Errorf("Incorrect populated \nHave: %v\nWant: %v", pb, exp) + } +} + +func TestProto3TextParsing(t *testing.T) { + m := new(proto3pb.Message) + const in = `name: "Wallace" true_scotsman: true` + want := &proto3pb.Message{ + Name: "Wallace", + TrueScotsman: true, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestMapParsing(t *testing.T) { + m := new(MessageWithMap) + const in = `name_mapping: name_mapping:` + + `msg_mapping:,>` + // separating commas are okay + `msg_mapping>` + // no colon after "value" + `msg_mapping:>` + // omitted key + `msg_mapping:` + // omitted value + `byte_mapping:` + + `byte_mapping:<>` // omitted key and value + want := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Beatles", + 1234: "Feist", + }, + MsgMapping: map[int64]*FloatingPoint{ + -4: {F: Float64(2.0)}, + -2: {F: Float64(4.0)}, + 0: {F: Float64(5.0)}, + 1: nil, + }, + ByteMapping: map[bool][]byte{ + false: nil, + true: []byte("so be it"), + }, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestOneofParsing(t *testing.T) { + const in = `name:"Shrek"` + m := new(Communique) + want := &Communique{Union: &Communique_Name{Name: "Shrek"}} + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } + + const inOverwrite = `name:"Shrek" number:42` + m = new(Communique) + testErr := "line 1.13: field 'number' would overwrite already parsed oneof 'Union'" + if err := UnmarshalText(inOverwrite, m); err == nil { + t.Errorf("TestOneofParsing: Didn't get expected error: %v", testErr) + } else if err.Error() != testErr { + t.Errorf("TestOneofParsing: Incorrect error.\nHave: %v\nWant: %v", + err.Error(), testErr) + } + +} + +var benchInput string + +func init() { + benchInput = "count: 4\n" + for i := 0; i < 1000; i++ { + benchInput += "pet: \"fido\"\n" + } + + // Check it is valid input. + pb := new(MyMessage) + err := UnmarshalText(benchInput, pb) + if err != nil { + panic("Bad benchmark input: " + err.Error()) + } +} + +func BenchmarkUnmarshalText(b *testing.B) { + pb := new(MyMessage) + for i := 0; i < b.N; i++ { + UnmarshalText(benchInput, pb) + } + b.SetBytes(int64(len(benchInput))) +} diff --git a/discovery/vendor/github.com/gogo/protobuf/proto/text_test.go b/discovery/vendor/github.com/gogo/protobuf/proto/text_test.go new file mode 100644 index 00000000..27df6cb9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/proto/text_test.go @@ -0,0 +1,474 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "errors" + "io/ioutil" + "math" + "strings" + "testing" + + "github.com/gogo/protobuf/proto" + + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +// textMessage implements the methods that allow it to marshal and unmarshal +// itself as text. +type textMessage struct { +} + +func (*textMessage) MarshalText() ([]byte, error) { + return []byte("custom"), nil +} + +func (*textMessage) UnmarshalText(bytes []byte) error { + if string(bytes) != "custom" { + return errors.New("expected 'custom'") + } + return nil +} + +func (*textMessage) Reset() {} +func (*textMessage) String() string { return "" } +func (*textMessage) ProtoMessage() {} + +func newTestMessage() *pb.MyMessage { + msg := &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Quote: proto.String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("footrest.syd"), + Port: proto.Int32(7001), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(0xdeadbeef), + Value: []byte{1, 65, 7, 12}, + }, + { + Weight: proto.Float32(6.022), + Inner: &pb.InnerMessage{ + Host: proto.String("lesha.mtv"), + Port: proto.Int32(8002), + }, + }, + }, + Bikeshed: pb.MyMessage_BLUE.Enum(), + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(8), + }, + // One normally wouldn't do this. + // This is an undeclared tag 13, as a varint (wire type 0) with value 4. + XXX_unrecognized: []byte{13<<3 | 0, 4}, + } + ext := &pb.Ext{ + Data: proto.String("Big gobs for big rats"), + } + if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil { + panic(err) + } + greetings := []string{"adg", "easy", "cow"} + if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil { + panic(err) + } + + // Add an unknown extension. We marshal a pb.Ext, and fake the ID. + b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")}) + if err != nil { + panic(err) + } + b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...) + proto.SetRawExtension(msg, 201, b) + + // Extensions can be plain fields, too, so let's test that. + b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19) + proto.SetRawExtension(msg, 202, b) + + return msg +} + +const text = `count: 42 +name: "Dave" +quote: "\"I didn't want to go.\"" +pet: "bunny" +pet: "kitty" +pet: "horsey" +inner: < + host: "footrest.syd" + port: 7001 + connected: true +> +others: < + key: 3735928559 + value: "\001A\007\014" +> +others: < + weight: 6.022 + inner: < + host: "lesha.mtv" + port: 8002 + > +> +bikeshed: BLUE +SomeGroup { + group_field: 8 +} +/* 2 unknown bytes */ +13: 4 +[testdata.Ext.more]: < + data: "Big gobs for big rats" +> +[testdata.greeting]: "adg" +[testdata.greeting]: "easy" +[testdata.greeting]: "cow" +/* 13 unknown bytes */ +201: "\t3G skiing" +/* 3 unknown bytes */ +202: 19 +` + +func TestMarshalText(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, newTestMessage()); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != text { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, text) + } +} + +func TestMarshalTextCustomMessage(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, &textMessage{}); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != "custom" { + t.Errorf("Got %q, expected %q", s, "custom") + } +} +func TestMarshalTextNil(t *testing.T) { + want := "" + tests := []proto.Message{nil, (*pb.MyMessage)(nil)} + for i, test := range tests { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, test); err != nil { + t.Fatal(err) + } + if got := buf.String(); got != want { + t.Errorf("%d: got %q want %q", i, got, want) + } + } +} + +func TestMarshalTextUnknownEnum(t *testing.T) { + // The Color enum only specifies values 0-2. + m := &pb.MyMessage{Bikeshed: pb.MyMessage_Color(3).Enum()} + got := m.String() + const want = `bikeshed:3 ` + if got != want { + t.Errorf("\n got %q\nwant %q", got, want) + } +} + +func TestTextOneof(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&pb.Communique{}, ``}, + // scalar field + {&pb.Communique{Union: &pb.Communique_Number{Number: 4}}, `number:4`}, + // message field + {&pb.Communique{Union: &pb.Communique_Msg{ + Msg: &pb.Strings{StringField: proto.String("why hello!")}, + }}, `msg:`}, + // bad oneof (should not panic) + {&pb.Communique{Union: &pb.Communique_Msg{Msg: nil}}, `msg:/* nil */`}, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} + +func BenchmarkMarshalTextBuffered(b *testing.B) { + buf := new(bytes.Buffer) + m := newTestMessage() + for i := 0; i < b.N; i++ { + buf.Reset() + proto.MarshalText(buf, m) + } +} + +func BenchmarkMarshalTextUnbuffered(b *testing.B) { + w := ioutil.Discard + m := newTestMessage() + for i := 0; i < b.N; i++ { + proto.MarshalText(w, m) + } +} + +func compact(src string) string { + // s/[ \n]+/ /g; s/ $//; + dst := make([]byte, len(src)) + space, comment := false, false + j := 0 + for i := 0; i < len(src); i++ { + if strings.HasPrefix(src[i:], "/*") { + comment = true + i++ + continue + } + if comment && strings.HasPrefix(src[i:], "*/") { + comment = false + i++ + continue + } + if comment { + continue + } + c := src[i] + if c == ' ' || c == '\n' { + space = true + continue + } + if j > 0 && (dst[j-1] == ':' || dst[j-1] == '<' || dst[j-1] == '{') { + space = false + } + if c == '{' { + space = false + } + if space { + dst[j] = ' ' + j++ + space = false + } + dst[j] = c + j++ + } + if space { + dst[j] = ' ' + j++ + } + return string(dst[0:j]) +} + +var compactText = compact(text) + +func TestCompactText(t *testing.T) { + s := proto.CompactTextString(newTestMessage()) + if s != compactText { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v\n===\n", s, compactText) + } +} + +func TestStringEscaping(t *testing.T) { + testCases := []struct { + in *pb.Strings + out string + }{ + { + // Test data from C++ test (TextFormatTest.StringEscape). + // Single divergence: we don't escape apostrophes. + &pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")}, + "string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n", + }, + { + // Test data from the same C++ test. + &pb.Strings{StringField: proto.String("\350\260\267\346\255\214")}, + "string_field: \"\\350\\260\\267\\346\\255\\214\"\n", + }, + { + // Some UTF-8. + &pb.Strings{StringField: proto.String("\x00\x01\xff\x81")}, + `string_field: "\000\001\377\201"` + "\n", + }, + } + + for i, tc := range testCases { + var buf bytes.Buffer + if err := proto.MarshalText(&buf, tc.in); err != nil { + t.Errorf("proto.MarsalText: %v", err) + continue + } + s := buf.String() + if s != tc.out { + t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out) + continue + } + + // Check round-trip. + pbStrings := new(pb.Strings) + if err := proto.UnmarshalText(s, pbStrings); err != nil { + t.Errorf("#%d: UnmarshalText: %v", i, err) + continue + } + if !proto.Equal(pbStrings, tc.in) { + t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pbStrings) + } + } +} + +// A limitedWriter accepts some output before it fails. +// This is a proxy for something like a nearly-full or imminently-failing disk, +// or a network connection that is about to die. +type limitedWriter struct { + b bytes.Buffer + limit int +} + +var outOfSpace = errors.New("proto: insufficient space") + +func (w *limitedWriter) Write(p []byte) (n int, err error) { + var avail = w.limit - w.b.Len() + if avail <= 0 { + return 0, outOfSpace + } + if len(p) <= avail { + return w.b.Write(p) + } + n, _ = w.b.Write(p[:avail]) + return n, outOfSpace +} + +func TestMarshalTextFailing(t *testing.T) { + // Try lots of different sizes to exercise more error code-paths. + for lim := 0; lim < len(text); lim++ { + buf := new(limitedWriter) + buf.limit = lim + err := proto.MarshalText(buf, newTestMessage()) + // We expect a certain error, but also some partial results in the buffer. + if err != outOfSpace { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", err, outOfSpace) + } + s := buf.b.String() + x := text[:buf.limit] + if s != x { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, x) + } + } +} + +func TestFloats(t *testing.T) { + tests := []struct { + f float64 + want string + }{ + {0, "0"}, + {4.7, "4.7"}, + {math.Inf(1), "inf"}, + {math.Inf(-1), "-inf"}, + {math.NaN(), "nan"}, + } + for _, test := range tests { + msg := &pb.FloatingPoint{F: &test.f} + got := strings.TrimSpace(msg.String()) + want := `f:` + test.want + if got != want { + t.Errorf("f=%f: got %q, want %q", test.f, got, want) + } + } +} + +func TestRepeatedNilText(t *testing.T) { + m := &pb.MessageList{ + Message: []*pb.MessageList_Message{ + nil, + { + Name: proto.String("Horse"), + }, + nil, + }, + } + want := `Message +Message { + name: "Horse" +} +Message +` + if s := proto.MarshalTextString(m); s != want { + t.Errorf(" got: %s\nwant: %s", s, want) + } +} + +func TestProto3Text(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&proto3pb.Message{}, ``}, + // zero message except for an empty byte slice + {&proto3pb.Message{Data: []byte{}}, ``}, + // trivial case + {&proto3pb.Message{Name: "Rob", HeightInCm: 175}, `name:"Rob" height_in_cm:175`}, + // empty map + {&pb.MessageWithMap{}, ``}, + // non-empty map; map format is the same as a repeated struct, + // and they are sorted by key (numerically for numeric keys). + { + &pb.MessageWithMap{NameMapping: map[int32]string{ + -1: "Negatory", + 7: "Lucky", + 1234: "Feist", + 6345789: "Otis", + }}, + `name_mapping: ` + + `name_mapping: ` + + `name_mapping: ` + + `name_mapping:`, + }, + // map with nil value; not well-defined, but we shouldn't crash + { + &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{7: nil}}, + `msg_mapping:`, + }, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go new file mode 100644 index 00000000..d4248b48 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go @@ -0,0 +1,31 @@ +package descriptor_test + +import ( + "fmt" + "testing" + + tpb "github.com/gogo/protobuf/proto/testdata" + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestMessage(t *testing.T) { + var msg *descriptor.DescriptorProto + fd, md := descriptor.ForMessage(msg) + if pkg, want := fd.GetPackage(), "google.protobuf"; pkg != want { + t.Errorf("descriptor.ForMessage(%T).GetPackage() = %q; want %q", msg, pkg, want) + } + if name, want := md.GetName(), "DescriptorProto"; name != want { + t.Fatalf("descriptor.ForMessage(%T).GetName() = %q; want %q", msg, name, want) + } +} + +func Example_Options() { + var msg *tpb.MyMessageSet + _, md := descriptor.ForMessage(msg) + if md.GetOptions().GetMessageSetWireFormat() { + fmt.Printf("%v uses option message_set_wire_format.\n", md.GetName()) + } + + // Output: + // MyMessageSet uses option message_set_wire_format. +} diff --git a/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go new file mode 100644 index 00000000..fde3b046 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go @@ -0,0 +1,85 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2013 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package generator + +import ( + "testing" + + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestCamelCase(t *testing.T) { + tests := []struct { + in, want string + }{ + {"one", "One"}, + {"one_two", "OneTwo"}, + {"_my_field_name_2", "XMyFieldName_2"}, + {"Something_Capped", "Something_Capped"}, + {"my_Name", "My_Name"}, + {"OneTwo", "OneTwo"}, + {"_", "X"}, + {"_a_", "XA_"}, + } + for _, tc := range tests { + if got := CamelCase(tc.in); got != tc.want { + t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) + } + } +} + +func TestGoPackageOption(t *testing.T) { + tests := []struct { + in string + impPath, pkg string + ok bool + }{ + {"", "", "", false}, + {"foo", "", "foo", true}, + {"github.com/golang/bar", "github.com/golang/bar", "bar", true}, + {"github.com/golang/bar;baz", "github.com/golang/bar", "baz", true}, + } + for _, tc := range tests { + d := &FileDescriptor{ + FileDescriptorProto: &descriptor.FileDescriptorProto{ + Options: &descriptor.FileOptions{ + GoPackage: &tc.in, + }, + }, + } + impPath, pkg, ok := d.goPackageOption() + if impPath != tc.impPath || pkg != tc.pkg || ok != tc.ok { + t.Errorf("go_package = %q => (%q, %q, %t), want (%q, %q, %t)", tc.in, + impPath, pkg, ok, tc.impPath, tc.pkg, tc.ok) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go new file mode 100644 index 00000000..86e9c118 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go @@ -0,0 +1,210 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Test that we can use protocol buffers that use extensions. + +package testdata + +/* + +import ( + "bytes" + "regexp" + "testing" + + "github.com/golang/protobuf/proto" + base "extension_base.pb" + user "extension_user.pb" +) + +func TestSingleFieldExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(178), + } + + // Use extension within scope of another type. + vol := proto.Uint32(11) + err := proto.SetExtension(bm, user.E_LoudMessage_Volume, vol) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Decoded message didn't contain extension.") + } + vol_out, err := proto.GetExtension(bm_new, user.E_LoudMessage_Volume) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if v := vol_out.(*uint32); *v != *vol { + t.Errorf("vol_out = %v, expected %v", *v, *vol) + } + proto.ClearExtension(bm_new, user.E_LoudMessage_Volume) + if proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + // Use extension that is itself a message. + um := &user.UserMessage{ + Name: proto.String("Dave"), + Rank: proto.String("Major"), + } + err := proto.SetExtension(bm, user.E_LoginMessage_UserMessage, um) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Decoded message didn't contain extension.") + } + um_out, err := proto.GetExtension(bm_new, user.E_LoginMessage_UserMessage) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if n := um_out.(*user.UserMessage).Name; *n != *um.Name { + t.Errorf("um_out.Name = %q, expected %q", *n, *um.Name) + } + if r := um_out.(*user.UserMessage).Rank; *r != *um.Rank { + t.Errorf("um_out.Rank = %q, expected %q", *r, *um.Rank) + } + proto.ClearExtension(bm_new, user.E_LoginMessage_UserMessage) + if proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Failed clearing extension.") + } +} + +func TestTopLevelExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + width := proto.Int32(17) + err := proto.SetExtension(bm, user.E_Width, width) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Decoded message didn't contain extension.") + } + width_out, err := proto.GetExtension(bm_new, user.E_Width) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if w := width_out.(*int32); *w != *width { + t.Errorf("width_out = %v, expected %v", *w, *width) + } + proto.ClearExtension(bm_new, user.E_Width) + if proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageSetWireFormat(t *testing.T) { + osm := new(base.OldStyleMessage) + osp := &user.OldStyleParcel{ + Name: proto.String("Dave"), + Height: proto.Int32(178), + } + + err := proto.SetExtension(osm, user.E_OldStyleParcel_MessageSetExtension, osp) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + + buf, err := proto.Marshal(osm) + if err != nil { + t.Fatal("Failed encoding message:", err) + } + + // Data generated from Python implementation. + expected := []byte{ + 11, 16, 209, 15, 26, 9, 10, 4, 68, 97, 118, 101, 16, 178, 1, 12, + } + + if !bytes.Equal(expected, buf) { + t.Errorf("Encoding mismatch.\nwant %+v\n got %+v", expected, buf) + } + + // Check that it is restored correctly. + osm = new(base.OldStyleMessage) + if err := proto.Unmarshal(buf, osm); err != nil { + t.Fatal("Failed decoding message:", err) + } + osp_out, err := proto.GetExtension(osm, user.E_OldStyleParcel_MessageSetExtension) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + osp = osp_out.(*user.OldStyleParcel) + if *osp.Name != "Dave" || *osp.Height != 178 { + t.Errorf("Retrieved extension from decoded message is not correct: %+v", osp) + } +} + +func main() { + // simpler than rigging up gotest + testing.Main(regexp.MatchString, []testing.InternalTest{ + {"TestSingleFieldExtension", TestSingleFieldExtension}, + {"TestMessageExtension", TestMessageExtension}, + {"TestTopLevelExtension", TestTopLevelExtension}, + }, + []testing.InternalBenchmark{}, + []testing.InternalExample{}) +} + +*/ diff --git a/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go new file mode 100644 index 00000000..271d9639 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go @@ -0,0 +1,46 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// A simple binary to link together the protocol buffers in this test. + +package testdata + +import ( + "testing" + + mytestpb "./my_test" + multipb "github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi" +) + +func TestLink(t *testing.T) { + _ = &multipb.Multi1{} + _ = &mytestpb.Request{} +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go b/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go new file mode 100644 index 00000000..c99b7cad --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package asym + +import ( + "testing" +) + +func TestAsym(t *testing.T) { + m := &M{[]MyType{{}, {}}, nil} + if err := m.VerboseEqual(m); err != nil { + t.Fatalf("should be equal: %v", err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go new file mode 100644 index 00000000..7dade1a4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go @@ -0,0 +1,185 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: asym.proto + +/* +Package asym is a generated protocol buffer package. + +It is generated from these files: + asym.proto + +It has these top-level messages: + M + MyType +*/ +package asym + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &M{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &M{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &M{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/bug_test.go b/discovery/vendor/github.com/gogo/protobuf/test/bug_test.go new file mode 100644 index 00000000..53f720e9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go new file mode 100644 index 00000000..13154119 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go @@ -0,0 +1,512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/both/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go new file mode 100644 index 00000000..f0d1837c --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go @@ -0,0 +1,512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go new file mode 100644 index 00000000..866799fa --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go @@ -0,0 +1,456 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/neither/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go new file mode 100644 index 00000000..3d271b42 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go @@ -0,0 +1,456 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go new file mode 100644 index 00000000..e7f3ea31 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go @@ -0,0 +1,456 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go new file mode 100644 index 00000000..7aa705cb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go @@ -0,0 +1,512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/both/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go new file mode 100644 index 00000000..2b720ef2 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go @@ -0,0 +1,512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go new file mode 100644 index 00000000..4d30be3e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go @@ -0,0 +1,456 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go new file mode 100644 index 00000000..53f720e9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go new file mode 100644 index 00000000..036f3ec9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go @@ -0,0 +1,17950 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/both/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomDashMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOrBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestADeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndDeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNilMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTimerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyExtendableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOtherExtenableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinitionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedScopeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomContainerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNoExtensionsMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInner_InnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNodeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go new file mode 100644 index 00000000..53f720e9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go new file mode 100644 index 00000000..96844e0d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go @@ -0,0 +1,17950 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomDashMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOrBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestADeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndDeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNilMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTimerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyExtendableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOtherExtenableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinitionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedScopeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomContainerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNoExtensionsMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInner_InnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNodeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go new file mode 100644 index 00000000..53f720e9 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go new file mode 100644 index 00000000..0365b87f --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go @@ -0,0 +1,16046 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/custom/custom_test.go b/discovery/vendor/github.com/gogo/protobuf/test/custom/custom_test.go new file mode 100644 index 00000000..d4fe7bd4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/custom/custom_test.go @@ -0,0 +1,43 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package custom + +import ( + "testing" +) + +func TestUint128(t *testing.T) { + var uint128a = Uint128{0, 1} + buf := make([]byte, 16) + PutLittleEndianUint128(buf, 0, uint128a) + uint128b := GetLittleEndianUint128(buf, 0) + if !uint128a.Equal(uint128b) { + t.Fatalf("%v != %v", uint128a, uint128b) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go b/discovery/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go new file mode 100644 index 00000000..2e29d2a0 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go @@ -0,0 +1,34 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package custombytesnonstruct + +import testing "testing" + +func TestCustomBytesNonStruct(t *testing.T) { +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go b/discovery/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go new file mode 100644 index 00000000..6266b21b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go @@ -0,0 +1,48 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package dashfilename + +import ( + "os" + "os/exec" + "testing" +) + +//Issue 16 : https://github.com/gogo/protobuf/issues/detail?id=16 +func TestDashFilename(t *testing.T) { + name := "dash-filename" + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto") + data, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("err = %v: %s", err, string(data)) + } + if err := os.Remove(name + ".pb.go"); err != nil { + panic(err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/data/datapb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/data/datapb_test.go new file mode 100644 index 00000000..4fcd9eb4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/data/datapb_test.go @@ -0,0 +1,262 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: data.proto + +/* +Package data is a generated protocol buffer package. + +It is generated from these files: + data.proto + +It has these top-level messages: + MyMessage +*/ +package data + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMyMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMyMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MyMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MyMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go b/discovery/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go new file mode 100644 index 00000000..522ce9c1 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go @@ -0,0 +1,68 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package defaultcheck + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func testDefaultConflict(t *testing.T, name string) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove(name + ".pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestNullableDefault(t *testing.T) { + testDefaultConflict(t, "nc") +} + +func TestNullableExtension(t *testing.T) { + testDefaultConflict(t, "nx") +} + +func TestNullableEnum(t *testing.T) { + testDefaultConflict(t, "ne") +} + +func TestFaceDefault(t *testing.T) { + testDefaultConflict(t, "df") +} + +func TestNoGettersDefault(t *testing.T) { + testDefaultConflict(t, "dg") +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go b/discovery/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go new file mode 100644 index 00000000..94e0e257 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go @@ -0,0 +1,119 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package embedconflict + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func TestEmbedConflict(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ec.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("ec.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestEmbedMarshaler(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "em.proto") + data, err := cmd.CombinedOutput() + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + if !strings.Contains(dataStr, "WARNING: found non-") || !strings.Contains(dataStr, "unsafe_marshaler") { + t.Errorf("Expected WARNING: found non-[marshaler unsafe_marshaler] C with embedded marshaler D") + } + if err = os.Remove("em.pb.go"); err != nil { + t.Error(err) + } +} + +func TestEmbedExtend(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ee.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("ee.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestCustomName(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "en.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("en.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestRepeatedEmbed(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "er.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("er.pb.go"); err != nil { + t.Error(err) + } + } + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + warning := "ERROR: found repeated embedded field B in message A" + if !strings.Contains(dataStr, warning) { + t.Errorf("Expected " + warning) + } +} + +func TestTakesTooLongToDebug(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "eb.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("eb.pb.go"); err != nil { + t.Error(err) + } + } + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + warning := "ERROR: found embedded bytes field" + if !strings.Contains(dataStr, warning) { + t.Errorf("Expected " + warning) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go b/discovery/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go new file mode 100644 index 00000000..19e12c21 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package empty + +import ( + "testing" +) + +func TestEmpty(t *testing.T) { + +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go new file mode 100644 index 00000000..8f2ad83d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go @@ -0,0 +1,238 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumdecl.proto + +/* +Package enumdecl is a generated protocol buffer package. + +It is generated from these files: + enumdecl.proto + +It has these top-level messages: + Message +*/ +package enumdecl + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go new file mode 100644 index 00000000..06760206 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go @@ -0,0 +1,238 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumdeclall.proto + +/* +Package enumdeclall is a generated protocol buffer package. + +It is generated from these files: + enumdeclall.proto + +It has these top-level messages: + Message +*/ +package enumdeclall + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go new file mode 100644 index 00000000..06101d48 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go @@ -0,0 +1,450 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumstringer.proto + +/* +Package enumstringer is a generated protocol buffer package. + +It is generated from these files: + enumstringer.proto + +It has these top-level messages: + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum +*/ +package enumstringer + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/example/example_test.go b/discovery/vendor/github.com/gogo/protobuf/test/example/example_test.go new file mode 100644 index 00000000..34f4c436 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/example/example_test.go @@ -0,0 +1,35 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import "testing" + +func TestGetterExists(t *testing.T) { + _ = (&CastType{}).GetInt32() +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go new file mode 100644 index 00000000..10a63c23 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go @@ -0,0 +1,1671 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: example.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + example.proto + +It has these top-level messages: + A + B + C + U + E + R + CastType +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*A, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedA(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedA(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &A{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkBProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*B, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedB(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedB(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &B{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*C, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedC(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedC(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &C{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*U, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedU(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedU(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &U{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestEProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkEProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*E, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedE(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkEProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedE(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &E{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*R, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedR(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedR(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &R{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CastType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CastType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &B{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &B{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &C{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &C{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &U{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &U{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &E{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &E{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &R{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &R{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CastType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CastType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestExampleDescription(t *testing.T) { + ExampleDescription() +} +func TestAVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestEVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &E{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &R{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CastType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestRGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkASize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*A, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedA(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkBSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*B, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedB(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*C, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedC(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*U, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedU(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestESize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkESize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*E, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedE(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*R, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedR(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CastType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestEStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestRStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCastTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, true) + v := p.GetValue() + msg := &U{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/extension_test.go b/discovery/vendor/github.com/gogo/protobuf/test/extension_test.go new file mode 100644 index 00000000..54046d4d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/extension_test.go @@ -0,0 +1,164 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "github.com/gogo/protobuf/proto" + "math" + math_rand "math/rand" + "testing" + "time" +) + +//func SetRawExtension(base extendableProto, id int32, b []byte) { +//func HasExtension(pb extendableProto, extension *ExtensionDesc) bool { +//func ClearExtension(pb extendableProto, extension *ExtensionDesc) { +//func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) { +//func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) { +//func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error { + +type extendable interface { + proto.Message + ExtensionRangeArray() []proto.ExtensionRange +} + +func check(t *testing.T, m extendable, fieldA float64, ext *proto.ExtensionDesc) { + if !proto.HasExtension(m, ext) { + t.Fatalf("expected extension to be set") + } + fieldA2Interface, err := proto.GetExtension(m, ext) + if err != nil { + panic(err) + } + fieldA2 := fieldA2Interface.(*float64) + if fieldA != *fieldA2 { + t.Fatalf("Expected %f got %f", fieldA, *fieldA2) + } + fieldA3Interface, err := proto.GetUnsafeExtension(m, ext.Field) + if err != nil { + panic(err) + } + fieldA3 := fieldA3Interface.(*float64) + if fieldA != *fieldA3 { + t.Fatalf("Expected %f got %f", fieldA, *fieldA3) + } + proto.ClearExtension(m, ext) + if proto.HasExtension(m, ext) { + t.Fatalf("expected extension to be cleared") + } +} + +var fieldA float64 +var fieldABytes []byte +var extr = math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + +func init() { + fieldA = float64(1.1) + fieldABits := math.Float64bits(fieldA) + x := uint64(uint32(100)<<3 | uint32(proto.WireFixed64)) + fieldABytes = encodeVarintPopulateThetest(nil, x) + fieldABytes = append(fieldABytes, uint8(fieldABits)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>8)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>16)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>24)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>32)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>40)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>48)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>56)) +} + +func TestExtensionsMyExtendable(t *testing.T) { + m := NewPopulatedMyExtendable(extr, false) + err := proto.SetExtension(m, E_FieldA, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA) + proto.SetRawExtension(m, 100, fieldABytes) + check(t, m, fieldA, E_FieldA) +} + +func TestExtensionsNoExtensionsMapSetExtension(t *testing.T) { + m := NewPopulatedNoExtensionsMap(extr, false) + err := proto.SetExtension(m, E_FieldA1, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA1) +} + +func TestExtensionsNoExtensionsMapSetRawExtension(t *testing.T) { + m := NewPopulatedNoExtensionsMap(extr, false) + proto.SetRawExtension(m, 100, fieldABytes) + check(t, m, fieldA, E_FieldA1) +} + +func TestUnsafeExtension(t *testing.T) { + m := NewPopulatedMyExtendable(extr, false) + err := proto.SetUnsafeExtension(m, E_FieldA.Field, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA) +} + +//See another version of this test in proto/extensions_test.go +func TestGetExtensionStability(t *testing.T) { + check := func(m *NoExtensionsMap) bool { + ext1, err := proto.GetExtension(m, E_FieldB1) + if err != nil { + t.Fatalf("GetExtension() failed: %s", err) + } + ext2, err := proto.GetExtension(m, E_FieldB1) + if err != nil { + t.Fatalf("GetExtension() failed: %s", err) + } + return ext1.(*NinOptNative).Equal(ext2) + } + msg := &NoExtensionsMap{Field1: proto.Int64(2)} + ext0 := &NinOptNative{Field1: proto.Float64(1)} + if err := proto.SetExtension(msg, E_FieldB1, ext0); err != nil { + t.Fatalf("Could not set ext1: %s", ext0) + } + if !check(msg) { + t.Errorf("GetExtension() not stable before marshaling") + } + bb, err := proto.Marshal(msg) + if err != nil { + t.Fatalf("Marshal() failed: %s", err) + } + msg1 := &NoExtensionsMap{} + err = proto.Unmarshal(bb, msg1) + if err != nil { + t.Fatalf("Unmarshal() failed: %s", err) + } + if !check(msg1) { + t.Errorf("GetExtension() not stable after unmarshaling") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go new file mode 100644 index 00000000..01ff6615 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go @@ -0,0 +1,245 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: file.dot.proto + +/* +Package filedotname is a generated protocol buffer package. + +It is generated from these files: + file.dot.proto + +It has these top-level messages: + M +*/ +package filedotname + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*M, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedM(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedM(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &M{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &M{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &M{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFileDotDescription(t *testing.T) { + FileDotDescription() +} +func TestMVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &M{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*M, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedM(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go b/discovery/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go new file mode 100644 index 00000000..81c8793e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go @@ -0,0 +1,136 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package fuzztests + +import ( + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestFuzzUnrecognized(t *testing.T) { + msg := &Nil{} + input := []byte{0x8, 0xaf, 0x81, 0xc9, 0xb3, 0x97, 0xd1, 0xb5, 0xc2, 0x4f, 0x1a, 0x4a, 0x52, 0x48, 0x4e, 0x44, 0x65, 0x51, 0x4b, 0x46, 0x44, 0x33, 0x5a, 0x44, 0x72, 0x38, 0x58, 0x4c, 0x58, 0x70, 0x59, 0x45, 0x71, 0x45, 0x4f, 0x6d, 0x45, 0x4d, 0x54, 0x59, 0x4c, 0x6b, 0x55, 0x7a, 0x6f, 0x6b, 0x5a, 0x69, 0x56, 0x64, 0x46, 0x45, 0x56, 0x4d, 0x70, 0x6a, 0x39, 0x7a, 0x4b, 0x43, 0x4d, 0x6d, 0x76, 0x63, 0x46, 0x4f, 0x31, 0x4a, 0x5a, 0x6b, 0x66, 0x4a, 0x75, 0x51, 0x38, 0x54, 0x54, 0x30, 0x53, 0x61, 0x36, 0x6e, 0x4f, 0x6b, 0x35, 0x54, 0x95, 0x0, 0x0, 0x0, 0x0, 0x12, 0x38, 0x52, 0x36, 0x66, 0x76, 0x41, 0x74, 0x73, 0x7a, 0x39, 0x43, 0x6a, 0x4f, 0x64, 0x59, 0x77, 0x33, 0x30, 0x36, 0x58, 0x75, 0x65, 0x46, 0x4b, 0x46, 0x55, 0x56, 0x71, 0x6d, 0x49, 0x73, 0x4a, 0x4b, 0x78, 0x76, 0x41, 0x65, 0x42, 0x61, 0x5a, 0x30, 0x41, 0x37, 0x45, 0x76, 0x72, 0x31, 0x30, 0x4e, 0x78, 0x6d, 0x33, 0x63, 0x65, 0x66, 0x6b, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatal("expected error") + } +} + +func DisabledTestFuzzPackedIsNotIdempotent(t *testing.T) { + msg := &NinRepPackedNative{} + //original := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51, 0x71, 0x44, 0x65, 0x6f, 0x53, 0x30, 0x44, 0x6a, 0x58, 0x7a, 0x1b, 0x65, 0x62, 0x9c, 0x95, 0xc5, 0x41, 0xcb, 0x48, 0xa, 0x47, 0xf6, 0xd8, 0xd2, 0xd5, 0x8d, 0x6, 0x69, 0x8f, 0xbe, 0x7c, 0xf3, 0xe9, 0x79, 0x3c, 0xca, 0x6, 0x5b} + input := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatal("expected error") + } +} + +func DisabledTestFuzzFieldOrder(t *testing.T) { + msg := &NinOptStruct{} + input := []byte{0x52, 0x57, 0x52, 0x6a, 0x33, 0x56, 0x43, 0x76, 0x32, 0x54, 0x49, 0x4a, 0x55, 0x66, 0x39, 0x52, 0x32, 0x32, 0x73, 0x69, 0x4f, 0x67, 0x66, 0x79, 0x4b, 0x79, 0x5a, 0x55, 0x42, 0x53, 0x38, 0x68, 0x6c, 0x46, 0x79, 0x6b, 0x54, 0x43, 0x63, 0x66, 0x30, 0x6a, 0x33, 0x35, 0x33, 0x7a, 0x41, 0x66, 0x68, 0x57, 0x61, 0x78, 0x51, 0x37, 0x76, 0x52, 0x78, 0x34, 0x56, 0x43, 0x54, 0x31, 0x73, 0x6a, 0x77, 0x63, 0x45, 0x62, 0x62, 0x67, 0x34, 0x6f, 0x64, 0x35, 0x6c, 0x41, 0x45, 0x50, 0x64, 0x6f, 0x46, 0x38, 0x41, 0x4b, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err != nil { + t.Fatal(err) + } +} + +func TestFuzzSint64Overflow(t *testing.T) { + msg := &NinOptNative{} + //original := []byte{0x9, 0x65, 0xb4, 0xfd, 0xbc, 0x5, 0xc7, 0xee, 0x3f, 0x15, 0x48, 0xec, 0x67, 0x3f, 0x18, 0xca, 0xa4, 0xe0, 0xa9, 0x5, 0x20, 0x8e, 0xb7, 0x9f, 0xf5, 0xcf, 0xe9, 0xea, 0xad, 0xfd, 0x1, 0x28, 0xc9, 0xf1, 0xbc, 0x88, 0xc, 0x30, 0xeb, 0x99, 0xbd, 0xa8, 0xe, 0x38, 0xc0, 0xd4, 0xb7, 0xba, 0x7, 0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16, 0x9d, 0x59, 0xf9, 0x31, 0xe0, 0x99, 0x0, 0x0, 0x0, 0x0, 0x61, 0x59, 0x5b, 0xb5, 0x57, 0x56, 0x93, 0x70, 0xde, 0x68, 0x0, 0x72, 0x40, 0x64, 0x5a, 0x5a, 0x61, 0x57, 0x78, 0x68, 0x53, 0x65, 0x66, 0x67, 0x38, 0x38, 0x61, 0x48, 0x44, 0x32, 0x6c, 0x36, 0x50, 0x31, 0x4d, 0x43, 0x39, 0x31, 0x6d, 0x37, 0x34, 0x32, 0x48, 0x6b, 0x4d, 0x70, 0x31, 0x45, 0x73, 0x48, 0x71, 0x4a, 0x69, 0x37, 0x56, 0x53, 0x44, 0x6b, 0x48, 0x45, 0x50, 0x4b, 0x7a, 0x52, 0x49, 0x4c, 0x50, 0x69, 0x44, 0x72, 0x42, 0x56, 0x50, 0x78, 0x62, 0x56, 0x55, 0x7a, 0x5b, 0xb3, 0x6c, 0x59, 0x4c, 0xf1, 0x31, 0xeb, 0xb6, 0x25, 0x1a, 0x26, 0x67, 0x66, 0x97, 0x79, 0xb8, 0x37, 0x8, 0xe1, 0x32, 0x45, 0x6e, 0x6, 0x90, 0x4f, 0xde, 0x26, 0x7a, 0xc6, 0x29, 0x65, 0x4a, 0x69, 0xa7, 0x21, 0xfb, 0x42, 0xda, 0x43, 0x89, 0x27, 0x70, 0x71, 0xde, 0x66, 0xa4, 0x75, 0x2b, 0x5c, 0x96, 0x9f, 0x25, 0x3b, 0xc1, 0x64, 0x14, 0x4, 0x60, 0x8c, 0x58, 0x7e, 0xa1, 0x59, 0x7b, 0x47, 0x18, 0xc, 0x5b, 0x18, 0x63, 0x9, 0xb4, 0xc9, 0x7, 0xf9, 0xae, 0x33, 0xae, 0x2, 0x4a, 0x8b, 0x34, 0x92, 0x40, 0xb, 0xd7, 0x80, 0x60, 0xdb, 0x44, 0x5} + input := []byte{0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16} + if err := proto.Unmarshal(input, msg); err != nil { + return + } +} + +func DisabledTestFuzzOverrideField(t *testing.T) { + msg := &NinOptNative{} + //original := []byte{0x9, 0x73, 0x78, 0x5a, 0xf2, 0xb4, 0x66, 0xe8, 0x3f, 0x15, 0x71, 0xdc, 0x4, 0x3f, 0x18, 0xe5, 0x8e, 0xab, 0xdb, 0x3, 0x20, 0xbe, 0xed, 0xe6, 0xc0, 0xb9, 0xb8, 0xa7, 0xb5, 0x12, 0x28, 0xcb, 0x8c, 0x91, 0xef, 0xc, 0x30, 0x9a, 0xc1, 0xc3, 0xc0, 0xf, 0x38, 0xe8, 0x9b, 0xf0, 0xca, 0x5, 0x40, 0xd2, 0xd7, 0xdd, 0xa3, 0xea, 0xab, 0xec, 0xc2, 0xaa, 0x1, 0x4d, 0xc9, 0x15, 0x0, 0xea, 0x55, 0x72, 0x3e, 0x92, 0xa8, 0x59, 0x3e, 0x87, 0x7d, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x61, 0xca, 0xe7, 0xdb, 0x57, 0xa1, 0xb6, 0x41, 0xf4, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea, 0x82, 0x1, 0x23, 0xed, 0x7a, 0x3, 0x78, 0xee, 0x56, 0x46, 0xd0, 0xe1, 0x17, 0x18, 0x30, 0x9d, 0x2f, 0xac, 0x1c, 0xa, 0x30, 0xa9, 0x8d, 0x10, 0xed, 0xb5, 0x44, 0x36, 0x5e, 0x84, 0x73, 0x5d, 0x38, 0x51, 0x2b, 0x6e, 0xc6, 0xb5} + input := []byte{0x4d, 0xc9, 0x15, 0x0, 0xea, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea} + if err := proto.Unmarshal(input, msg); err != nil { + panic(err) + } + output, err := proto.Marshal(msg) + if err != nil { + t.Fatal(err) + } + if len(input) != len(output) { + t.Logf("%#v", msg) + msg2 := &NinOptNative{} + if err := proto.Unmarshal(output, msg2); err == nil { + t.Logf("%#v", msg2) + } + t.Errorf("expected %#v got %#v", input, output) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzBadWireType(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd30000'0000") + input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0x30, 0x27, 0x30, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected bad wiretype for Field4 error got %#v", msg) + } else { + t.Log(err) + } +} + +func TestFuzzIntegerOverflow(t *testing.T) { + msg := &Nil{} + //input := []byte("\x1500000\x8b\x9b\xa3\xa8\xb6\xe1\xe1\xfe\u061c0") + input := []byte{0x15, 0x30, 0x30, 0x30, 0x30, 0x30, 0x8b, 0x9b, 0xa3, 0xa8, 0xb6, 0xe1, 0xe1, 0xfe, 0xd8, 0x9c, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected integer overflow error %#v", msg) + } else { + t.Log(err) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzUnexpectedEOF(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x16000000000000000000" + "00\xb90") + input := []byte{0x6a, 0x16, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xb9, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected unexpected eof error got %#v", msg) + } else { + t.Log(err) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzCantSkipWireType(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd3000\xa80\xa7000") + input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0xa8, 0x30, 0xa7, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected cant skip wiretype error got %#v", msg) + } else { + t.Log(err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go new file mode 100644 index 00000000..fa0436a2 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go @@ -0,0 +1,540 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: group.proto + +/* +Package group is a generated protocol buffer package. + +It is generated from these files: + group.proto + +It has these top-level messages: + Groups1 + Groups2 +*/ +package group + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestGroups1Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups1_GProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1_G{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups2Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups2_GProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2_G{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups1JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups1_GJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1_G{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups2JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups2_GJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2_G{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups1ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Groups1{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Groups1{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1_GProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Groups1_G{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1_GProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Groups1_G{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Groups2{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Groups2{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2_GProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Groups2_G{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2_GProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Groups2_G{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroupDescription(t *testing.T) { + GroupDescription() +} +func TestGroups1VerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups1{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups1_GVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups1_G{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups2VerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups2{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups2_GVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups2_G{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups1GoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups1_GGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups2GoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups2_GGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups1Stringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups1_GStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups2Stringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups2_GStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go b/discovery/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go new file mode 100644 index 00000000..8bdcc623 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go @@ -0,0 +1,34 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package importdedup + +import testing "testing" + +func TestImportDedup(t *testing.T) { +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go new file mode 100644 index 00000000..7977184c --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go @@ -0,0 +1,154 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: index.proto + +/* +Package index is a generated protocol buffer package. + +It is generated from these files: + index.proto + +It has these top-level messages: + IndexQuery +*/ +package index + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestIndexQueryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestIndexQueryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIndexQueryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &IndexQuery{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &IndexQuery{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQuerySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go new file mode 100644 index 00000000..408dfbd5 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go @@ -0,0 +1,155 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: indeximport.proto + +/* +Package indeximport is a generated protocol buffer package. + +It is generated from these files: + indeximport.proto + +It has these top-level messages: + IndexQueries +*/ +package indeximport + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/test/indeximport-issue72/index" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestIndexQueriesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestIndexQueriesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIndexQueriesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &IndexQueries{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &IndexQueries{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go b/discovery/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go new file mode 100644 index 00000000..d769a284 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go @@ -0,0 +1,47 @@ +package int64support + +import ( + "encoding/json" + "testing" +) + +func TestMarshaler(t *testing.T) { + n := int64(1) + b, err := json.Marshal(&Object{&n}) + if err != nil { + t.Fatal(err) + } + const expected = "{\"optional_number\":1}" + if string(b) != expected { + t.Fatalf("expected '%s' instead of '%s'", expected, string(b)) + } + + b, err = json.Marshal(new(Object)) + if err != nil { + t.Fatal(err) + } + const expected2 = "{}" + if string(b) != expected2 { + t.Fatalf("expected '%s' instead of '%s'", expected2, string(b)) + } +} + +func TestUnmarshaler(t *testing.T) { + o := new(Object) + err := json.Unmarshal(([]byte)("{\"optional_number\": 1}"), o) + if err != nil { + t.Fatal(err) + } + if n := o.GetOptionalNumber(); n != 1 { + t.Fatalf("expected 1 instead of %d", n) + } + + o = new(Object) + err = json.Unmarshal(([]byte)("{}"), o) + if err != nil { + t.Fatal(err) + } + if o.OptionalNumber != nil { + t.Fatalf("expected nil OptionalNumber instead of %d", *o.OptionalNumber) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go new file mode 100644 index 00000000..f940dfeb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go @@ -0,0 +1,262 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: object.proto + +/* +Package int64support is a generated protocol buffer package. + +It is generated from these files: + object.proto + +It has these top-level messages: + Object +*/ +package int64support + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestObjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestObjectMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkObjectProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Object, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkObjectProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedObject(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Object{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestObjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Object{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Object{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Object{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestObjectGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestObjectSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkObjectSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Object, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go new file mode 100644 index 00000000..9cbecd78 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go @@ -0,0 +1,657 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue260.proto + +/* +Package issue260 is a generated protocol buffer package. + +It is generated from these files: + issue260.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package issue260 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go new file mode 100644 index 00000000..6fee7370 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go @@ -0,0 +1,123 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: events.proto + +/* +Package events is a generated protocol buffer package. + +It is generated from these files: + events.proto + +It has these top-level messages: + Subtype +*/ +package events + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/test/issue312" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubtypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subtype{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubtypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subtype{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubtypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subtype{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubtypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subtype{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubtypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubtype(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go new file mode 100644 index 00000000..f2953aba --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go @@ -0,0 +1,168 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue322.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + issue322.proto + +It has these top-level messages: + OneofTest +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestOneofTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOneofTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go new file mode 100644 index 00000000..76de576e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go @@ -0,0 +1,208 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue330.proto + +/* +Package issue330 is a generated protocol buffer package. + +It is generated from these files: + issue330.proto + +It has these top-level messages: + Object +*/ +package issue330 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestObjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestObjectMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkObjectProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Object, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkObjectProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedObject(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Object{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestObjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Object{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Object{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkObjectSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Object, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go new file mode 100644 index 00000000..a9fbde48 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue34 + +import ( + "bytes" + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestZeroLengthOptionalBytes(t *testing.T) { + roundtrip := func(f *Foo) *Foo { + data, err := proto.Marshal(f) + if err != nil { + panic(err) + } + newF := &Foo{} + err = proto.Unmarshal(data, newF) + if err != nil { + panic(err) + } + return newF + } + + f := &Foo{} + roundtrippedF := roundtrip(f) + if roundtrippedF.Bar != nil { + t.Fatalf("should be nil") + } + + f.Bar = []byte{} + roundtrippedF = roundtrip(f) + if roundtrippedF.Bar == nil { + t.Fatalf("should not be nil") + } + if len(roundtrippedF.Bar) != 0 { + t.Fatalf("should be empty") + } +} + +func TestRepeatedOptional(t *testing.T) { + repeated := &FooWithRepeated{Bar: [][]byte{[]byte("a"), []byte("b")}} + data, err := proto.Marshal(repeated) + if err != nil { + panic(err) + } + optional := &Foo{} + err = proto.Unmarshal(data, optional) + if err != nil { + panic(err) + } + + if !bytes.Equal(optional.Bar, []byte("b")) { + t.Fatalf("should return the last entry") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go new file mode 100644 index 00000000..571731c7 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go @@ -0,0 +1,56 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue42 + +import ( + "bytes" + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestIssue42Order(t *testing.T) { + unordered := NewPopulatedUnorderedFields(math_rand.New(math_rand.NewSource(time.Now().UnixNano())), false) + udata, err := proto.Marshal(unordered) + if err != nil { + t.Fatal(err) + } + ordered := &OrderedFields{} + if err = proto.Unmarshal(udata, ordered); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(ordered) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(udata, data) { + t.Fatalf("expected data to be marshaled in the same order, please sort fields before marshaling") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go new file mode 100644 index 00000000..93b4a56d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go @@ -0,0 +1,107 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: proto.proto + +/* +Package proto is a generated protocol buffer package. + +It is generated from these files: + proto.proto + +It has these top-level messages: + Foo +*/ +package proto + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto1 "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto1.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFooProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFooJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFooProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFooProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go b/discovery/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go new file mode 100644 index 00000000..ec255877 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go @@ -0,0 +1,36 @@ +package jsonpb_gogo + +import ( + "testing" + + "github.com/gogo/protobuf/jsonpb" +) + +// customFieldMessage implements protobuf.Message but is not a normal generated message type. +type customFieldMessage struct { + someField string //this is not a proto field +} + +func (m *customFieldMessage) Reset() { + m.someField = "hello" +} + +func (m *customFieldMessage) String() string { + return m.someField +} + +func (m *customFieldMessage) ProtoMessage() { +} + +func TestUnmarshalWithJSONPBUnmarshaler(t *testing.T) { + rawJson := `{}` + marshaler := &jsonpb.Marshaler{} + msg := &customFieldMessage{someField: "Ignore me"} + str, err := marshaler.MarshalToString(msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } + if str != rawJson { + t.Errorf("marshaled JSON was incorrect: got %s, wanted %s", str, rawJson) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go new file mode 100644 index 00000000..9998ead1 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go new file mode 100644 index 00000000..8db981eb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go @@ -0,0 +1,565 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/both/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go new file mode 100644 index 00000000..9998ead1 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go new file mode 100644 index 00000000..b1dfdf59 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go @@ -0,0 +1,565 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go new file mode 100644 index 00000000..9998ead1 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go new file mode 100644 index 00000000..d696b0a0 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go @@ -0,0 +1,481 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/neither/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go new file mode 100644 index 00000000..9998ead1 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go new file mode 100644 index 00000000..28c8b969 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go @@ -0,0 +1,481 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go new file mode 100644 index 00000000..488bc86b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go new file mode 100644 index 00000000..6d57605a --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go @@ -0,0 +1,990 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/both/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go new file mode 100644 index 00000000..488bc86b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go new file mode 100644 index 00000000..b509fc6e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go @@ -0,0 +1,990 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go new file mode 100644 index 00000000..488bc86b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go new file mode 100644 index 00000000..d76554d2 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go @@ -0,0 +1,878 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/neither/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go new file mode 100644 index 00000000..488bc86b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go new file mode 100644 index 00000000..0ebb4c62 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go @@ -0,0 +1,878 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go b/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go new file mode 100644 index 00000000..45a8eac5 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go @@ -0,0 +1,61 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package moredefaults + +import ( + "testing" + + test "github.com/gogo/protobuf/test/example" +) + +func TestDefaults(t *testing.T) { + b := MoreDefaultsB{} + aa := test.A{} + a := &MoreDefaultsA{} + b2 := a.GetB2() + a2 := a.GetA2() + if a.GetField1() != 1234 { + t.Fatalf("Field1 wrong") + } + if a.GetField2() != 0 { + t.Fatalf("Field2 wrong") + } + if a.GetB1() != nil { + t.Fatalf("B1 wrong") + } + if b2.GetField1() != b.GetField1() { + t.Fatalf("B2 wrong") + } + if a.GetA1() != nil { + t.Fatalf("A1 wrong") + } + if a2.GetNumber() != aa.GetNumber() { + t.Fatalf("A2 wrong") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go new file mode 100644 index 00000000..52ff94a8 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go @@ -0,0 +1,186 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: md.proto + +/* +Package moredefaults is a generated protocol buffer package. + +It is generated from these files: + md.proto + +It has these top-level messages: + MoreDefaultsB + MoreDefaultsA +*/ +package moredefaults + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/example" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMoreDefaultsBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsB{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMoreDefaultsAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsA{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMoreDefaultsBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsB{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMoreDefaultsAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsA{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMoreDefaultsBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MoreDefaultsB{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MoreDefaultsB{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MoreDefaultsA{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MoreDefaultsA{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go b/discovery/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go new file mode 100644 index 00000000..3318a29c --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go @@ -0,0 +1,38 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package nopackage + +import ( + "testing" +) + +func TestNoPackage(t *testing.T) { + //should compile + _ = (&M{}).Marshal +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go new file mode 100644 index 00000000..6339c578 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go @@ -0,0 +1,742 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/both/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go new file mode 100644 index 00000000..4275224b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go @@ -0,0 +1,742 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go new file mode 100644 index 00000000..e6aba811 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go @@ -0,0 +1,630 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/neither/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go new file mode 100644 index 00000000..8eb38a9a --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go @@ -0,0 +1,630 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go new file mode 100644 index 00000000..4957a3ee --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go @@ -0,0 +1,388 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/both/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go new file mode 100644 index 00000000..e3549d79 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go @@ -0,0 +1,388 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go new file mode 100644 index 00000000..632e8b12 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go @@ -0,0 +1,332 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/neither/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go new file mode 100644 index 00000000..262a5381 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go @@ -0,0 +1,332 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go new file mode 100644 index 00000000..f22e0a90 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go @@ -0,0 +1,185 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: oneofembed.proto + +/* +Package proto is a generated protocol buffer package. + +It is generated from these files: + oneofembed.proto + +It has these top-level messages: + Foo + Bar +*/ +package proto + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto1 "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto1.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFooProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBarProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBar(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Bar{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFooJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBarJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Bar{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFooProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFooProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Foo{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBarProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Bar{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBarProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Bar{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/packed/packed_test.go b/discovery/vendor/github.com/gogo/protobuf/test/packed/packed_test.go new file mode 100644 index 00000000..ea66292c --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/packed/packed_test.go @@ -0,0 +1,328 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package packed + +import ( + "bytes" + "fmt" + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + "time" + "unsafe" +) + +/* +https://github.com/gogo/protobuf/issues/detail?id=21 +https://developers.google.com/protocol-buffers/docs/proto#options +In 2.3.0 and later, this change is safe, as parsers for packable fields will always accept both formats, +*/ +func TestSafeIssue21(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedNinRepNative(popr, true) + data1, err := proto.Marshal(msg1) + if err != nil { + t.Fatal(err) + } + packedmsg := &NinRepPackedNative{} + err = proto.Unmarshal(data1, packedmsg) + if err != nil { + t.Fatal(err) + } + if len(packedmsg.XXX_unrecognized) != 0 { + t.Fatalf("packed msg unmarshaled unrecognized fields, even though there aren't any") + } + if err := VerboseEqual(msg1, packedmsg); err != nil { + t.Fatalf("%v", err) + } +} + +func TestUnsafeIssue21(t *testing.T) { + var bigendian uint32 = 0x01020304 + if *(*byte)(unsafe.Pointer(&bigendian)) == 1 { + t.Skip("unsafe does not work on big endian architectures") + } + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedNinRepNativeUnsafe(popr, true) + data1, err := proto.Marshal(msg1) + if err != nil { + t.Fatal(err) + } + packedmsg := &NinRepPackedNativeUnsafe{} + err = proto.Unmarshal(data1, packedmsg) + if err != nil { + t.Fatal(err) + } + if len(packedmsg.XXX_unrecognized) != 0 { + t.Fatalf("packed msg unmarshaled unrecognized fields, even though there aren't any") + } + if err := VerboseEqualUnsafe(msg1, packedmsg); err != nil { + t.Fatalf("%v", err) + } +} + +func VerboseEqual(this *NinRepNative, that *NinRepPackedNative) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } else if this == nil { + return fmt.Errorf("that != nil && this == nil") + } + + if len(this.Field1) != len(that.Field1) { + return fmt.Errorf("Field1 this(%v) Not Equal that(%v)", len(this.Field1), len(that.Field1)) + } + for i := range this.Field1 { + if this.Field1[i] != that.Field1[i] { + return fmt.Errorf("Field1 this[%v](%v) Not Equal that[%v](%v)", i, this.Field1[i], i, that.Field1[i]) + } + } + if len(this.Field2) != len(that.Field2) { + return fmt.Errorf("Field2 this(%v) Not Equal that(%v)", len(this.Field2), len(that.Field2)) + } + for i := range this.Field2 { + if this.Field2[i] != that.Field2[i] { + return fmt.Errorf("Field2 this[%v](%v) Not Equal that[%v](%v)", i, this.Field2[i], i, that.Field2[i]) + } + } + if len(this.Field3) != len(that.Field3) { + return fmt.Errorf("Field3 this(%v) Not Equal that(%v)", len(this.Field3), len(that.Field3)) + } + for i := range this.Field3 { + if this.Field3[i] != that.Field3[i] { + return fmt.Errorf("Field3 this[%v](%v) Not Equal that[%v](%v)", i, this.Field3[i], i, that.Field3[i]) + } + } + if len(this.Field4) != len(that.Field4) { + return fmt.Errorf("Field4 this(%v) Not Equal that(%v)", len(this.Field4), len(that.Field4)) + } + for i := range this.Field4 { + if this.Field4[i] != that.Field4[i] { + return fmt.Errorf("Field4 this[%v](%v) Not Equal that[%v](%v)", i, this.Field4[i], i, that.Field4[i]) + } + } + if len(this.Field5) != len(that.Field5) { + return fmt.Errorf("Field5 this(%v) Not Equal that(%v)", len(this.Field5), len(that.Field5)) + } + for i := range this.Field5 { + if this.Field5[i] != that.Field5[i] { + return fmt.Errorf("Field5 this[%v](%v) Not Equal that[%v](%v)", i, this.Field5[i], i, that.Field5[i]) + } + } + if len(this.Field6) != len(that.Field6) { + return fmt.Errorf("Field6 this(%v) Not Equal that(%v)", len(this.Field6), len(that.Field6)) + } + for i := range this.Field6 { + if this.Field6[i] != that.Field6[i] { + return fmt.Errorf("Field6 this[%v](%v) Not Equal that[%v](%v)", i, this.Field6[i], i, that.Field6[i]) + } + } + if len(this.Field7) != len(that.Field7) { + return fmt.Errorf("Field7 this(%v) Not Equal that(%v)", len(this.Field7), len(that.Field7)) + } + for i := range this.Field7 { + if this.Field7[i] != that.Field7[i] { + return fmt.Errorf("Field7 this[%v](%v) Not Equal that[%v](%v)", i, this.Field7[i], i, that.Field7[i]) + } + } + if len(this.Field8) != len(that.Field8) { + return fmt.Errorf("Field8 this(%v) Not Equal that(%v)", len(this.Field8), len(that.Field8)) + } + for i := range this.Field8 { + if this.Field8[i] != that.Field8[i] { + return fmt.Errorf("Field8 this[%v](%v) Not Equal that[%v](%v)", i, this.Field8[i], i, that.Field8[i]) + } + } + if len(this.Field9) != len(that.Field9) { + return fmt.Errorf("Field9 this(%v) Not Equal that(%v)", len(this.Field9), len(that.Field9)) + } + for i := range this.Field9 { + if this.Field9[i] != that.Field9[i] { + return fmt.Errorf("Field9 this[%v](%v) Not Equal that[%v](%v)", i, this.Field9[i], i, that.Field9[i]) + } + } + if len(this.Field10) != len(that.Field10) { + return fmt.Errorf("Field10 this(%v) Not Equal that(%v)", len(this.Field10), len(that.Field10)) + } + for i := range this.Field10 { + if this.Field10[i] != that.Field10[i] { + return fmt.Errorf("Field10 this[%v](%v) Not Equal that[%v](%v)", i, this.Field10[i], i, that.Field10[i]) + } + } + if len(this.Field11) != len(that.Field11) { + return fmt.Errorf("Field11 this(%v) Not Equal that(%v)", len(this.Field11), len(that.Field11)) + } + for i := range this.Field11 { + if this.Field11[i] != that.Field11[i] { + return fmt.Errorf("Field11 this[%v](%v) Not Equal that[%v](%v)", i, this.Field11[i], i, that.Field11[i]) + } + } + if len(this.Field12) != len(that.Field12) { + return fmt.Errorf("Field12 this(%v) Not Equal that(%v)", len(this.Field12), len(that.Field12)) + } + for i := range this.Field12 { + if this.Field12[i] != that.Field12[i] { + return fmt.Errorf("Field12 this[%v](%v) Not Equal that[%v](%v)", i, this.Field12[i], i, that.Field12[i]) + } + } + if len(this.Field13) != len(that.Field13) { + return fmt.Errorf("Field13 this(%v) Not Equal that(%v)", len(this.Field13), len(that.Field13)) + } + for i := range this.Field13 { + if this.Field13[i] != that.Field13[i] { + return fmt.Errorf("Field13 this[%v](%v) Not Equal that[%v](%v)", i, this.Field13[i], i, that.Field13[i]) + } + } + if !bytes.Equal(this.XXX_unrecognized, that.XXX_unrecognized) { + return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that.XXX_unrecognized) + } + return nil +} + +func VerboseEqualUnsafe(this *NinRepNativeUnsafe, that *NinRepPackedNativeUnsafe) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } else if this == nil { + return fmt.Errorf("that != nil && this == nil") + } + + if len(this.Field1) != len(that.Field1) { + return fmt.Errorf("Field1 this(%v) Not Equal that(%v)", len(this.Field1), len(that.Field1)) + } + for i := range this.Field1 { + if this.Field1[i] != that.Field1[i] { + return fmt.Errorf("Field1 this[%v](%v) Not Equal that[%v](%v)", i, this.Field1[i], i, that.Field1[i]) + } + } + if len(this.Field2) != len(that.Field2) { + return fmt.Errorf("Field2 this(%v) Not Equal that(%v)", len(this.Field2), len(that.Field2)) + } + for i := range this.Field2 { + if this.Field2[i] != that.Field2[i] { + return fmt.Errorf("Field2 this[%v](%v) Not Equal that[%v](%v)", i, this.Field2[i], i, that.Field2[i]) + } + } + if len(this.Field3) != len(that.Field3) { + return fmt.Errorf("Field3 this(%v) Not Equal that(%v)", len(this.Field3), len(that.Field3)) + } + for i := range this.Field3 { + if this.Field3[i] != that.Field3[i] { + return fmt.Errorf("Field3 this[%v](%v) Not Equal that[%v](%v)", i, this.Field3[i], i, that.Field3[i]) + } + } + if len(this.Field4) != len(that.Field4) { + return fmt.Errorf("Field4 this(%v) Not Equal that(%v)", len(this.Field4), len(that.Field4)) + } + for i := range this.Field4 { + if this.Field4[i] != that.Field4[i] { + return fmt.Errorf("Field4 this[%v](%v) Not Equal that[%v](%v)", i, this.Field4[i], i, that.Field4[i]) + } + } + if len(this.Field5) != len(that.Field5) { + return fmt.Errorf("Field5 this(%v) Not Equal that(%v)", len(this.Field5), len(that.Field5)) + } + for i := range this.Field5 { + if this.Field5[i] != that.Field5[i] { + return fmt.Errorf("Field5 this[%v](%v) Not Equal that[%v](%v)", i, this.Field5[i], i, that.Field5[i]) + } + } + if len(this.Field6) != len(that.Field6) { + return fmt.Errorf("Field6 this(%v) Not Equal that(%v)", len(this.Field6), len(that.Field6)) + } + for i := range this.Field6 { + if this.Field6[i] != that.Field6[i] { + return fmt.Errorf("Field6 this[%v](%v) Not Equal that[%v](%v)", i, this.Field6[i], i, that.Field6[i]) + } + } + if len(this.Field7) != len(that.Field7) { + return fmt.Errorf("Field7 this(%v) Not Equal that(%v)", len(this.Field7), len(that.Field7)) + } + for i := range this.Field7 { + if this.Field7[i] != that.Field7[i] { + return fmt.Errorf("Field7 this[%v](%v) Not Equal that[%v](%v)", i, this.Field7[i], i, that.Field7[i]) + } + } + if len(this.Field8) != len(that.Field8) { + return fmt.Errorf("Field8 this(%v) Not Equal that(%v)", len(this.Field8), len(that.Field8)) + } + for i := range this.Field8 { + if this.Field8[i] != that.Field8[i] { + return fmt.Errorf("Field8 this[%v](%v) Not Equal that[%v](%v)", i, this.Field8[i], i, that.Field8[i]) + } + } + if len(this.Field9) != len(that.Field9) { + return fmt.Errorf("Field9 this(%v) Not Equal that(%v)", len(this.Field9), len(that.Field9)) + } + for i := range this.Field9 { + if this.Field9[i] != that.Field9[i] { + return fmt.Errorf("Field9 this[%v](%v) Not Equal that[%v](%v)", i, this.Field9[i], i, that.Field9[i]) + } + } + if len(this.Field10) != len(that.Field10) { + return fmt.Errorf("Field10 this(%v) Not Equal that(%v)", len(this.Field10), len(that.Field10)) + } + for i := range this.Field10 { + if this.Field10[i] != that.Field10[i] { + return fmt.Errorf("Field10 this[%v](%v) Not Equal that[%v](%v)", i, this.Field10[i], i, that.Field10[i]) + } + } + if len(this.Field11) != len(that.Field11) { + return fmt.Errorf("Field11 this(%v) Not Equal that(%v)", len(this.Field11), len(that.Field11)) + } + for i := range this.Field11 { + if this.Field11[i] != that.Field11[i] { + return fmt.Errorf("Field11 this[%v](%v) Not Equal that[%v](%v)", i, this.Field11[i], i, that.Field11[i]) + } + } + if len(this.Field12) != len(that.Field12) { + return fmt.Errorf("Field12 this(%v) Not Equal that(%v)", len(this.Field12), len(that.Field12)) + } + for i := range this.Field12 { + if this.Field12[i] != that.Field12[i] { + return fmt.Errorf("Field12 this[%v](%v) Not Equal that[%v](%v)", i, this.Field12[i], i, that.Field12[i]) + } + } + if len(this.Field13) != len(that.Field13) { + return fmt.Errorf("Field13 this(%v) Not Equal that(%v)", len(this.Field13), len(that.Field13)) + } + for i := range this.Field13 { + if this.Field13[i] != that.Field13[i] { + return fmt.Errorf("Field13 this[%v](%v) Not Equal that[%v](%v)", i, this.Field13[i], i, that.Field13[i]) + } + } + if !bytes.Equal(this.XXX_unrecognized, that.XXX_unrecognized) { + return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that.XXX_unrecognized) + } + return nil +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go b/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go new file mode 100644 index 00000000..1a6d4676 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package protosize + +// We expect that Size field will have no suffix and ProtoSize will be present +var ( + _ = SizeMessage{}.Size + _ = (&SizeMessage{}).GetSize + + _ = (&SizeMessage{}).ProtoSize +) diff --git a/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go new file mode 100644 index 00000000..b980628a --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go @@ -0,0 +1,154 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: protosize.proto + +/* +Package protosize is a generated protocol buffer package. + +It is generated from these files: + protosize.proto + +It has these top-level messages: + SizeMessage +*/ +package protosize + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSizeMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSizeMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + size := p.ProtoSize() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSizeMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.ProtoSize() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go new file mode 100644 index 00000000..b9c26375 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go @@ -0,0 +1,181 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package required + +import ( + "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/test" + "math/rand" + "reflect" + "strconv" + "testing" + "time" +) + +func TestMarshalToErrorsWhenRequiredFieldIsNotPresent(t *testing.T) { + data := RequiredExample{} + buf, err := proto.Marshal(&data) + if err == nil { + t.Fatalf("err == nil; was %v instead", err) + } + if err.Error() != `proto: required field "theRequiredString" not set` { + t.Fatalf(`err.Error() != "proto: required field "theRequiredString" not set"; was "%s" instead`, err.Error()) + } + if len(buf) != 0 { + t.Fatalf(`len(buf) != 0; was %d instead`, len(buf)) + } +} + +func TestMarshalToSucceedsWhenRequiredFieldIsPresent(t *testing.T) { + data := RequiredExample{ + TheRequiredString: proto.String("present"), + } + buf, err := proto.Marshal(&data) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } + if len(buf) == 0 { + t.Fatalf(`len(buf) == 0; expected nonzero`) + } +} + +func TestUnmarshalErrorsWhenRequiredFieldIsNotPresent(t *testing.T) { + missingRequiredField := []byte{0x12, 0x8, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c} + data := RequiredExample{} + err := proto.Unmarshal(missingRequiredField, &data) + if err == nil { + t.Fatalf("err == nil; was %v instead", err) + } + if err.Error() != `proto: required field "theRequiredString" not set` { + t.Fatalf(`err.Error() != "proto: required field "theRequiredString" not set"; was "%s" instead`, err.Error()) + } +} + +func TestUnmarshalSucceedsWhenRequiredIsNotPresent(t *testing.T) { + dataOut := RequiredExample{ + TheRequiredString: proto.String("present"), + } + encodedMessage, err := proto.Marshal(&dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := RequiredExample{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } +} + +func TestUnmarshalPopulatedOptionalFieldsAsRequiredSucceeds(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := test.NewPopulatedNidOptNative(r, true) + encodedMessage, err := proto.Marshal(dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := NidOptNative{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } +} + +func TestUnmarshalPartiallyPopulatedOptionalFieldsFails(t *testing.T) { + // Fill in all fields, then randomly remove one. + dataOut := &test.NinOptNative{ + Field1: proto.Float64(0), + Field2: proto.Float32(0), + Field3: proto.Int32(0), + Field4: proto.Int64(0), + Field5: proto.Uint32(0), + Field6: proto.Uint64(0), + Field7: proto.Int32(0), + Field8: proto.Int64(0), + Field9: proto.Uint32(0), + Field10: proto.Int32(0), + Field11: proto.Uint64(0), + Field12: proto.Int64(0), + Field13: proto.Bool(false), + Field14: proto.String("0"), + Field15: []byte("0"), + } + r := rand.New(rand.NewSource(time.Now().UnixNano())) + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := NidOptNative{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } +} + +func TestMarshalFailsWithoutAllFieldsSet(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := NewPopulatedNinOptNative(r, true) + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } + if len(encodedMessage) > 0 { + t.Fatalf("Got some bytes from marshal, expected none.") + } +} + +func TestMissingFieldsOnRepeatedNestedTypes(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := &NestedNinOptNative{ + NestedNinOpts: []*NinOptNative{ + NewPopulatedNinOptNative(r, true), + NewPopulatedNinOptNative(r, true), + NewPopulatedNinOptNative(r, true), + }, + } + middle := dataOut.GetNestedNinOpts()[1] + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(middle).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } + if len(encodedMessage) > 0 { + t.Fatalf("Got some bytes from marshal, expected none.") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go b/discovery/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go new file mode 100644 index 00000000..907b923f --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go @@ -0,0 +1,48 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package sizerconflict + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func TestSizerConflict(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:./", "sizerconflict.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("sizerconflict.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go new file mode 100644 index 00000000..59d7928d --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go @@ -0,0 +1,154 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sizeunderscore.proto + +/* +Package sizeunderscore is a generated protocol buffer package. + +It is generated from these files: + sizeunderscore.proto + +It has these top-level messages: + SizeMessage +*/ +package sizeunderscore + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSizeMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSizeMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSizeMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &SizeMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go b/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go new file mode 100644 index 00000000..fd1181ff --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go @@ -0,0 +1,31 @@ +package stdtypes + +import ( + "io/ioutil" + "sync" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestConcurrentTextMarshal(t *testing.T) { + // Verify that there are no race conditions when calling + // TextMarshaler.Marshal on a protobuf message that contains a StdDuration + + std := StdTypes{} + var wg sync.WaitGroup + + tm := proto.TextMarshaler{} + + for i := 0; i < 2; i++ { + wg.Add(1) + go func() { + defer wg.Done() + err := tm.Marshal(ioutil.Discard, &std) + if err != nil { + t.Fatal(err) + } + }() + } + wg.Wait() +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go new file mode 100644 index 00000000..c8b24774 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go @@ -0,0 +1,808 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stdtypes.proto + +/* +Package stdtypes is a generated protocol buffer package. + +It is generated from these files: + stdtypes.proto + +It has these top-level messages: + StdTypes + RepStdTypes + MapStdTypes + OneofStdTypes +*/ +package stdtypes + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestRepStdTypesGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapStdTypesGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOneofStdTypesGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/tags/tags_test.go b/discovery/vendor/github.com/gogo/protobuf/test/tags/tags_test.go new file mode 100644 index 00000000..460273e4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/tags/tags_test.go @@ -0,0 +1,119 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package tags + +import ( + "bytes" + "encoding/json" + "encoding/xml" + math_rand "math/rand" + "testing" + "time" +) + +type MyJson struct { + MyField1 string + MyField2 string +} + +func NewPopulatedMyJson(r randyTags) *MyJson { + this := &MyJson{} + if r.Intn(10) != 0 { + this.MyField1 = randStringTags(r) + } + if r.Intn(10) != 0 { + this.MyField2 = randStringTags(r) + } + return this +} + +func TestJson(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedMyJson(popr) + data, err := json.Marshal(msg1) + if err != nil { + panic(err) + } + outside := &Outside{} + err = json.Unmarshal(data, outside) + if err != nil { + panic(err) + } + if outside.GetField1() != msg1.MyField1 { + t.Fatalf("proto field1 %s != %s", outside.GetField1(), msg1.MyField1) + } + if outside.GetField2() != msg1.MyField2 { + t.Fatalf("proto field2 %s != %s", outside.GetField2(), msg1.MyField2) + } + data2, err := json.Marshal(outside) + if err != nil { + panic(err) + } + msg2 := &MyJson{} + err = json.Unmarshal(data2, msg2) + if err != nil { + panic(err) + } + if msg2.MyField1 != msg1.MyField1 { + t.Fatalf("proto field1 %s != %s", msg2.MyField1, msg1.MyField1) + } + if msg2.MyField2 != msg1.MyField2 { + t.Fatalf("proto field2 %s != %s", msg2.MyField2, msg1.MyField2) + } +} + +func TestXml(t *testing.T) { + s := "Field1Value" + field1 := "Field1Value" + field2 := "Field2Value" + msg1 := &Outside{} + err := xml.Unmarshal([]byte(s), msg1) + if err != nil { + panic(err) + } + msg2 := &Outside{ + Inside: &Inside{ + Field1: &field1, + }, + Field2: &field2, + } + if msg1.GetField1() != msg2.GetField1() { + t.Fatalf("field1 expected %s got %s", msg2.GetField1(), msg1.GetField1()) + } + if err != nil { + panic(err) + } + data, err := xml.Marshal(msg2) + if err != nil { + panic(err) + } + if !bytes.Equal(data, []byte(s)) { + t.Fatalf("expected %s got %s", s, string(data)) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go new file mode 100644 index 00000000..bb7eb6bb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go new file mode 100644 index 00000000..34e8261a --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go @@ -0,0 +1,2424 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/both/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageWithMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUint128PairMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMap_NestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNotPackedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go new file mode 100644 index 00000000..bb7eb6bb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go new file mode 100644 index 00000000..8a631fd4 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go @@ -0,0 +1,2424 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageWithMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUint128PairMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMap_NestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNotPackedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go new file mode 100644 index 00000000..bb7eb6bb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go new file mode 100644 index 00000000..bd72e483 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go @@ -0,0 +1,2144 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/neither/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go new file mode 100644 index 00000000..bb7eb6bb --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go new file mode 100644 index 00000000..22fd5f40 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go @@ -0,0 +1,2144 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Message{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/thetestpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/thetestpb_test.go new file mode 100644 index 00000000..bfb54dd7 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/thetestpb_test.go @@ -0,0 +1,16046 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Node{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go new file mode 100644 index 00000000..0bc43610 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go @@ -0,0 +1,656 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: typedecl.proto + +/* +Package typedecl is a generated protocol buffer package. + +It is generated from these files: + typedecl.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package typedecl + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go new file mode 100644 index 00000000..043f43f0 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go @@ -0,0 +1,656 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: typedeclall.proto + +/* +Package typedeclall is a generated protocol buffer package. + +It is generated from these files: + typedeclall.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package typedeclall + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go b/discovery/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go new file mode 100644 index 00000000..bea4cae7 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go @@ -0,0 +1,7 @@ +package typedeclimport + +import "testing" + +func Test(t *testing.T) { + // No need to do anything, if this test runs, it means it works +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go new file mode 100644 index 00000000..7d24f58e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go new file mode 100644 index 00000000..54252b68 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go @@ -0,0 +1,1985 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/both/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKnownTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go new file mode 100644 index 00000000..7d24f58e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go new file mode 100644 index 00000000..dfcb314e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go @@ -0,0 +1,1985 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKnownTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go new file mode 100644 index 00000000..7d24f58e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go new file mode 100644 index 00000000..8c695caa --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go @@ -0,0 +1,1733 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/neither/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go new file mode 100644 index 00000000..7d24f58e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go new file mode 100644 index 00000000..153a8651 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go @@ -0,0 +1,1733 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go new file mode 100644 index 00000000..b842ef9b --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go @@ -0,0 +1,99 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unmarshalmerge + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + "time" +) + +func TestUnmarshalMerge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, true) + if p.GetSub() == nil { + p.Sub = &Sub{SubNumber: proto.Int64(12345)} + } + data, err := proto.Marshal(p) + if err != nil { + t.Fatal(err) + } + s := &Sub{} + b := &Big{ + Sub: s, + } + err = proto.UnmarshalMerge(data, b) + if err != nil { + t.Fatal(err) + } + if s.GetSubNumber() != p.GetSub().GetSubNumber() { + t.Fatalf("should have unmarshaled subnumber into sub") + } +} + +func TestUnsafeUnmarshalMerge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, true) + if p.GetSub() == nil { + p.Sub = &Sub{SubNumber: proto.Int64(12345)} + } + data, err := proto.Marshal(p) + if err != nil { + t.Fatal(err) + } + s := &Sub{} + b := &BigUnsafe{ + Sub: s, + } + err = proto.UnmarshalMerge(data, b) + if err != nil { + t.Fatal(err) + } + + if s.GetSubNumber() != p.GetSub().GetSubNumber() { + t.Fatalf("should have unmarshaled subnumber into sub") + } +} + +func TestInt64Merge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, true) + p2 := NewPopulatedIntMerge(popr, true) + data, err := proto.Marshal(p2) + if err != nil { + t.Fatal(err) + } + if err := proto.UnmarshalMerge(data, p); err != nil { + t.Fatal(err) + } + if !p.Equal(p2) { + t.Fatalf("exptected %#v but got %#v", p2, p) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go new file mode 100644 index 00000000..0600eaca --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go @@ -0,0 +1,704 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unmarshalmerge.proto + +/* +Package unmarshalmerge is a generated protocol buffer package. + +It is generated from these files: + unmarshalmerge.proto + +It has these top-level messages: + Big + BigUnsafe + Sub + IntMerge +*/ +package unmarshalmerge + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import unsafe "unsafe" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestBigProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBig(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Big{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkBigProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Big, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedBig(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBigProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedBig(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Big{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBigUnsafeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BigUnsafe{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkBigUnsafeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*BigUnsafe, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedBigUnsafe(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBigUnsafeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedBigUnsafe(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &BigUnsafe{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestSubProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSub(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Sub{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkSubProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*Sub, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedSub(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkSubProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedSub(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Sub{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestIntMergeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IntMerge{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkIntMergeProtoMarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + pops := make([]*IntMerge, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedIntMerge(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkIntMergeProtoUnmarshal(b *testing.B) { + popr := math_rand.New(math_rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedIntMerge(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &IntMerge{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBigJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Big{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBigUnsafeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BigUnsafe{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Sub{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIntMergeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IntMerge{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBigProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Big{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Big{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigUnsafeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &BigUnsafe{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigUnsafeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &BigUnsafe{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &Sub{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &Sub{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIntMergeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &IntMerge{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIntMergeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &IntMerge{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Big{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBigUnsafeVerboseEqual(t *testing.T) { + var bigendian uint32 = 0x01020304 + if *(*byte)(unsafe.Pointer(&bigendian)) == 1 { + t.Skip("unsafe does not work on big endian architectures") + } + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &BigUnsafe{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Sub{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestIntMergeVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &IntMerge{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBigGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBigUnsafeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestIntMergeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBigStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBigUnsafeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSubStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestIntMergeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go new file mode 100644 index 00000000..16751014 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go @@ -0,0 +1,200 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unrecognized + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestNewOld(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + newer := NewPopulatedA(popr, true) + data1, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + older := &OldA{} + if err = proto.Unmarshal(data1, older); err != nil { + panic(err) + } + data2, err := proto.Marshal(older) + if err != nil { + panic(err) + } + bluer := &A{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := newer.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err) + } +} + +func TestOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldA(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &A{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldA{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } +} + +func TestOldNewOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldA(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &A{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldA{} + if err = proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err = older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } + + data3, err := proto.Marshal(bluer) + if err != nil { + panic(err) + } + purple := &A{} + if err = proto.Unmarshal(data3, purple); err != nil { + panic(err) + } + data4, err := proto.Marshal(purple) + if err != nil { + panic(err) + } + magenta := &OldA{} + if err := proto.Unmarshal(data4, magenta); err != nil { + panic(err) + } + if err := older.VerboseEqual(magenta); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err) + } +} + +func TestOldUToU(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldU(popr, true) + // need optional field to be always initialized, to check it's lost in this test + older.Field1 = proto.String(randStringUnrecognized(popr)) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + + newer := &U{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + + older2 := &OldU{} + if err := proto.Unmarshal(data2, older2); err != nil { + panic(err) + } + + // check that Field1 is lost + if older2.Field1 != nil { + t.Fatalf("field must be lost, but it's not, older: %#v, older2: %#v", older, older2) + } + + // now restore Field1 and messages should be equal now + older2.Field1 = older.Field1 + if err := older.VerboseEqual(older2); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, older2, err) + } +} + +func TestOldUnoM(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldUnoM(popr, true) + // need optional field to be always initialized, to check it's lost in this test + older.Field1 = proto.String(randStringUnrecognized(popr)) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + + newer := &UnoM{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + + older2 := &OldUnoM{} + if err := proto.Unmarshal(data2, older2); err != nil { + panic(err) + } + + // check that Field1 is lost + if older2.Field1 != nil { + t.Fatalf("field must be lost, but it's not, older: %#v, older2: %#v", older, older2) + } + + // now restore Field1 and messages should be equal now + older2.Field1 = older.Field1 + if err := older.VerboseEqual(older2); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, older2, err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go new file mode 100644 index 00000000..a979c791 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go @@ -0,0 +1,1881 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unrecognized.proto + +/* +Package unrecognized is a generated protocol buffer package. + +It is generated from these files: + unrecognized.proto + +It has these top-level messages: + A + B + D + C + U + UnoM + OldA + OldB + OldC + OldU + OldUnoM +*/ +package unrecognized + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnoM{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldUnoM{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnoMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnoM{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldUnoMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldUnoM{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &B{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &B{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &D{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &D{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &C{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &C{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &U{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &U{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &UnoM{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &UnoM{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldA{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldA{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldB{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldB{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldC{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldC{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldU{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldU{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldUnoM{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldUnoM{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedDescription(t *testing.T) { + UnrecognizedDescription() +} +func TestAVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &B{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &D{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &C{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &U{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnoMVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnoM{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldAVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldA{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldBVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldB{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldCVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldC{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldUVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldU{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldUnoMVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldUnoM{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnoMGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldAGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldBGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldCGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldUGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldUnoMGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestDSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnoMStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldAStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldBStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldCStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldUStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldUnoMStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go new file mode 100644 index 00000000..893cb5de --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go @@ -0,0 +1,128 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unrecognizedgroup + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestNewOld(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + newer := NewPopulatedNewNoGroup(popr, true) + data1, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + older := &OldWithGroup{} + if err = proto.Unmarshal(data1, older); err != nil { + panic(err) + } + data2, err := proto.Marshal(older) + if err != nil { + panic(err) + } + bluer := &NewNoGroup{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := newer.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err) + } +} + +func TestOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldWithGroup(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &NewNoGroup{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldWithGroup{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } +} + +func TestOldNewOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldWithGroup(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &NewNoGroup{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldWithGroup{} + if err = proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err = older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } + + data3, err := proto.Marshal(bluer) + if err != nil { + panic(err) + } + purple := &NewNoGroup{} + if err = proto.Unmarshal(data3, purple); err != nil { + panic(err) + } + data4, err := proto.Marshal(purple) + if err != nil { + panic(err) + } + magenta := &OldWithGroup{} + if err := proto.Unmarshal(data4, magenta); err != nil { + panic(err) + } + if err := older.VerboseEqual(magenta); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go b/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go new file mode 100644 index 00000000..7aa89dee --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go @@ -0,0 +1,767 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unrecognizedgroup.proto + +/* +Package unrecognizedgroup is a generated protocol buffer package. + +It is generated from these files: + unrecognizedgroup.proto + +It has these top-level messages: + NewNoGroup + A + OldWithGroup +*/ +package unrecognizedgroup + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNewNoGroupProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNewNoGroupMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldWithGroup_Group1Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group1{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldWithGroup_Group2Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group2{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNewNoGroupJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroupJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroup_Group1JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group1{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroup_Group2JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group2{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNewNoGroupProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NewNoGroup{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNewNoGroupProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NewNoGroup{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &A{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldWithGroup{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldWithGroup{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group1ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldWithGroup_Group1{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group1ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldWithGroup_Group1{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group2ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &OldWithGroup_Group2{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group2ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &OldWithGroup_Group2{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedgroupDescription(t *testing.T) { + UnrecognizedgroupDescription() +} +func TestNewNoGroupVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NewNoGroup{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroupVerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroup_Group1VerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup_Group1{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroup_Group2VerboseEqual(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup_Group2{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNewNoGroupGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroupGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroup_Group1GoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroup_Group2GoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNewNoGroupSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestNewNoGroupStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroupStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroup_Group1Stringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroup_Group2Stringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/discovery/vendor/github.com/gogo/protobuf/test/uuid_test.go b/discovery/vendor/github.com/gogo/protobuf/test/uuid_test.go new file mode 100644 index 00000000..5f3b7280 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/test/uuid_test.go @@ -0,0 +1,51 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestBugUuid(t *testing.T) { + u := &CustomContainer{CustomStruct: NidOptCustom{Id: Uuid{}}} + data, err := proto.Marshal(u) + if err != nil { + panic(err) + } + u2 := &CustomContainer{} + err = proto.Unmarshal(data, u2) + if err != nil { + panic(err) + } + t.Logf("%+v", u2) + if u2.CustomStruct.Id != nil { + t.Fatalf("should be nil") + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/types/any_test.go b/discovery/vendor/github.com/gogo/protobuf/types/any_test.go new file mode 100644 index 00000000..14679a24 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/types/any_test.go @@ -0,0 +1,112 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + pb "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestMarshalUnmarshal(t *testing.T) { + orig := &Any{Value: []byte("test")} + + packed, err := MarshalAny(orig) + if err != nil { + t.Errorf("MarshalAny(%+v): got: _, %v exp: _, nil", orig, err) + } + + unpacked := &Any{} + err = UnmarshalAny(packed, unpacked) + if err != nil || !proto.Equal(unpacked, orig) { + t.Errorf("got: %v, %+v; want nil, %+v", err, unpacked, orig) + } +} + +func TestIs(t *testing.T) { + a, err := MarshalAny(&pb.FileDescriptorProto{}) + if err != nil { + t.Fatal(err) + } + if Is(a, &pb.DescriptorProto{}) { + t.Error("FileDescriptorProto is not a DescriptorProto, but Is says it is") + } + if !Is(a, &pb.FileDescriptorProto{}) { + t.Error("FileDescriptorProto is indeed a FileDescriptorProto, but Is says it is not") + } +} + +func TestIsDifferentUrlPrefixes(t *testing.T) { + m := &pb.FileDescriptorProto{} + a := &Any{TypeUrl: "foo/bar/" + proto.MessageName(m)} + if !Is(a, m) { + t.Errorf("message with type url %q didn't satisfy Is for type %q", a.TypeUrl, proto.MessageName(m)) + } +} + +func TestUnmarshalDynamic(t *testing.T) { + want := &pb.FileDescriptorProto{Name: proto.String("foo")} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + var got DynamicAny + if err := UnmarshalAny(a, &got); err != nil { + t.Fatal(err) + } + if !proto.Equal(got.Message, want) { + t.Errorf("invalid result from UnmarshalAny, got %q want %q", got.Message, want) + } +} + +func TestEmpty(t *testing.T) { + want := &pb.FileDescriptorProto{} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + got, err := EmptyAny(a) + if err != nil { + t.Fatal(err) + } + if !proto.Equal(got, want) { + t.Errorf("unequal empty message, got %q, want %q", got, want) + } + + // that's a valid type_url for a message which shouldn't be linked into this + // test binary. We want an error. + a.TypeUrl = "type.googleapis.com/google.protobuf.TestAny" + if _, err := EmptyAny(a); err == nil { + t.Errorf("got no error for an attempt to create a message of type %q, which shouldn't be linked in", a.TypeUrl) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/types/duration_test.go b/discovery/vendor/github.com/gogo/protobuf/types/duration_test.go new file mode 100644 index 00000000..7f2bcb42 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/types/duration_test.go @@ -0,0 +1,120 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "math" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +const ( + minGoSeconds = math.MinInt64 / int64(1e9) + maxGoSeconds = math.MaxInt64 / int64(1e9) +) + +var durationTests = []struct { + proto *Duration + isValid bool + inRange bool + dur time.Duration +}{ + // The zero duration. + {&Duration{Seconds: 0, Nanos: 0}, true, true, 0}, + // Some ordinary non-zero durations. + {&Duration{Seconds: 100, Nanos: 0}, true, true, 100 * time.Second}, + {&Duration{Seconds: -100, Nanos: 0}, true, true, -100 * time.Second}, + {&Duration{Seconds: 100, Nanos: 987}, true, true, 100*time.Second + 987}, + {&Duration{Seconds: -100, Nanos: -987}, true, true, -(100*time.Second + 987)}, + // The largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, true, math.MaxInt64}, + // The smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, true, math.MinInt64}, + {nil, false, false, 0}, + {&Duration{Seconds: -100, Nanos: 987}, false, false, 0}, + {&Duration{Seconds: 100, Nanos: -987}, false, false, 0}, + {&Duration{Seconds: math.MinInt64, Nanos: 0}, false, false, 0}, + {&Duration{Seconds: math.MaxInt64, Nanos: 0}, false, false, 0}, + // The largest valid duration. + {&Duration{Seconds: maxSeconds, Nanos: 1e9 - 1}, true, false, 0}, + // The smallest valid duration. + {&Duration{Seconds: minSeconds, Nanos: -(1e9 - 1)}, true, false, 0}, + // The smallest invalid duration above the valid range. + {&Duration{Seconds: maxSeconds + 1, Nanos: 0}, false, false, 0}, + // The largest invalid duration below the valid range. + {&Duration{Seconds: minSeconds - 1, Nanos: -(1e9 - 1)}, false, false, 0}, + // One nanosecond past the largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64-1e9*maxGoSeconds) + 1}, true, false, 0}, + // One nanosecond past the smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64-1e9*minGoSeconds) - 1}, true, false, 0}, + // One second past the largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds + 1, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, false, 0}, + // One second past the smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds - 1, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, false, 0}, +} + +func TestValidateDuration(t *testing.T) { + for _, test := range durationTests { + err := validateDuration(test.proto) + gotValid := (err == nil) + if gotValid != test.isValid { + t.Errorf("validateDuration(%v) = %t, want %t", test.proto, gotValid, test.isValid) + } + } +} + +func TestDurationFromProto(t *testing.T) { + for _, test := range durationTests { + got, err := DurationFromProto(test.proto) + gotOK := (err == nil) + wantOK := test.isValid && test.inRange + if gotOK != wantOK { + t.Errorf("DurationFromProto(%v) ok = %t, want %t", test.proto, gotOK, wantOK) + } + if err == nil && got != test.dur { + t.Errorf("DurationFromProto(%v) = %v, want %v", test.proto, got, test.dur) + } + } +} + +func TestDurationProto(t *testing.T) { + for _, test := range durationTests { + if test.isValid && test.inRange { + got := DurationProto(test.dur) + if !proto.Equal(got, test.proto) { + t.Errorf("DurationProto(%v) = %v, want %v", test.dur, got, test.proto) + } + } + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/types/timestamp_test.go b/discovery/vendor/github.com/gogo/protobuf/types/timestamp_test.go new file mode 100644 index 00000000..6af8631e --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/types/timestamp_test.go @@ -0,0 +1,152 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "math" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +var tests = []struct { + ts *Timestamp + valid bool + t time.Time +}{ + // The timestamp representing the Unix epoch date. + {&Timestamp{Seconds: 0, Nanos: 0}, true, utcDate(1970, 1, 1)}, + // The smallest representable timestamp. + {&Timestamp{Seconds: math.MinInt64, Nanos: math.MinInt32}, false, + time.Unix(math.MinInt64, math.MinInt32).UTC()}, + // The smallest representable timestamp with non-negative nanos. + {&Timestamp{Seconds: math.MinInt64, Nanos: 0}, false, time.Unix(math.MinInt64, 0).UTC()}, + // The earliest valid timestamp. + {&Timestamp{Seconds: minValidSeconds, Nanos: 0}, true, utcDate(1, 1, 1)}, + //"0001-01-01T00:00:00Z"}, + // The largest representable timestamp. + {&Timestamp{Seconds: math.MaxInt64, Nanos: math.MaxInt32}, false, + time.Unix(math.MaxInt64, math.MaxInt32).UTC()}, + // The largest representable timestamp with nanos in range. + {&Timestamp{Seconds: math.MaxInt64, Nanos: 1e9 - 1}, false, + time.Unix(math.MaxInt64, 1e9-1).UTC()}, + // The largest valid timestamp. + {&Timestamp{Seconds: maxValidSeconds - 1, Nanos: 1e9 - 1}, true, + time.Date(9999, 12, 31, 23, 59, 59, 1e9-1, time.UTC)}, + // The smallest invalid timestamp that is larger than the valid range. + {&Timestamp{Seconds: maxValidSeconds, Nanos: 0}, false, time.Unix(maxValidSeconds, 0).UTC()}, + // A date before the epoch. + {&Timestamp{Seconds: -281836800, Nanos: 0}, true, utcDate(1961, 1, 26)}, + // A date after the epoch. + {&Timestamp{Seconds: 1296000000, Nanos: 0}, true, utcDate(2011, 1, 26)}, + // A date after the epoch, in the middle of the day. + {&Timestamp{Seconds: 1296012345, Nanos: 940483}, true, + time.Date(2011, 1, 26, 3, 25, 45, 940483, time.UTC)}, +} + +func TestValidateTimestamp(t *testing.T) { + for _, s := range tests { + got := validateTimestamp(s.ts) + if (got == nil) != s.valid { + t.Errorf("validateTimestamp(%v) = %v, want %v", s.ts, got, s.valid) + } + } +} + +func TestTimestampFromProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampFromProto(s.ts) + if (err == nil) != s.valid { + t.Errorf("TimestampFromProto(%v) error = %v, but valid = %t", s.ts, err, s.valid) + } else if s.valid && got != s.t { + t.Errorf("TimestampFromProto(%v) = %v, want %v", s.ts, got, s.t) + } + } + // Special case: a nil TimestampFromProto is an error, but returns the 0 Unix time. + got, err := TimestampFromProto(nil) + want := time.Unix(0, 0).UTC() + if got != want { + t.Errorf("TimestampFromProto(nil) = %v, want %v", got, want) + } + if err == nil { + t.Errorf("TimestampFromProto(nil) error = nil, expected error") + } +} + +func TestTimestampProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampProto(s.t) + if (err == nil) != s.valid { + t.Errorf("TimestampProto(%v) error = %v, but valid = %t", s.t, err, s.valid) + } else if s.valid && !proto.Equal(got, s.ts) { + t.Errorf("TimestampProto(%v) = %v, want %v", s.t, got, s.ts) + } + } + // No corresponding special case here: no time.Time results in a nil Timestamp. +} + +func TestTimestampString(t *testing.T) { + for _, test := range []struct { + ts *Timestamp + want string + }{ + // Not much testing needed because presumably time.Format is + // well-tested. + {&Timestamp{Seconds: 0, Nanos: 0}, "1970-01-01T00:00:00Z"}, + {&Timestamp{Seconds: minValidSeconds - 1, Nanos: 0}, "(timestamp: &types.Timestamp{Seconds: -62135596801,\nNanos: 0,\n} before 0001-01-01)"}, + } { + got := TimestampString(test.ts) + if got != test.want { + t.Errorf("TimestampString(%v) = %q, want %q", test.ts, got, test.want) + } + } +} + +func utcDate(year, month, day int) time.Time { + return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) +} + +func TestTimestampNow(t *testing.T) { + // Bracket the expected time. + before := time.Now() + ts := TimestampNow() + after := time.Now() + + tm, err := TimestampFromProto(ts) + if err != nil { + t.Errorf("between %v and %v\nTimestampNow() = %v\nwhich is invalid (%v)", before, after, ts, err) + } + if tm.Before(before) || tm.After(after) { + t.Errorf("between %v and %v\nTimestamp(TimestampNow()) = %v", before, after, tm) + } +} diff --git a/discovery/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go b/discovery/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go new file mode 100644 index 00000000..a0e5b824 --- /dev/null +++ b/discovery/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go @@ -0,0 +1,93 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + fast "github.com/gogo/protobuf/vanity/test/fast" + faster "github.com/gogo/protobuf/vanity/test/faster" + slick "github.com/gogo/protobuf/vanity/test/slick" + "testing" +) + +func TestFast(t *testing.T) { + _ = (&fast.A{}).Marshal + _ = (&fast.A{}).MarshalTo + _ = (&fast.A{}).Unmarshal + _ = (&fast.A{}).Size + + _ = (&fast.B{}).Marshal + _ = (&fast.B{}).MarshalTo + _ = (&fast.B{}).Unmarshal + _ = (&fast.B{}).Size +} + +func TestFaster(t *testing.T) { + _ = (&faster.A{}).Marshal + _ = (&faster.A{}).MarshalTo + _ = (&faster.A{}).Unmarshal + _ = (&faster.A{}).Size + + _ = (&faster.A{}).Strings == "" + + _ = (&faster.B{}).Marshal + _ = (&faster.B{}).MarshalTo + _ = (&faster.B{}).Unmarshal + _ = (&faster.B{}).Size + + _ = (&faster.B{}).String_ == nil + _ = (&faster.B{}).Int64 == 0 + _ = (&faster.B{}).Int32 == nil + if (&faster.B{}).GetInt32() != 1234 { + t.Fatalf("expected default") + } +} + +func TestSlick(t *testing.T) { + _ = (&slick.A{}).Marshal + _ = (&slick.A{}).MarshalTo + _ = (&slick.A{}).Unmarshal + _ = (&slick.A{}).Size + + _ = (&slick.A{}).Strings == "" + + _ = (&slick.A{}).GoString + _ = (&slick.A{}).String + + _ = (&slick.B{}).Marshal + _ = (&slick.B{}).MarshalTo + _ = (&slick.B{}).Unmarshal + _ = (&slick.B{}).Size + + _ = (&slick.B{}).String_ == nil + _ = (&slick.B{}).Int64 == 0 + _ = (&slick.B{}).Int32 == nil + if (&slick.B{}).GetInt32() != 1234 { + t.Fatalf("expected default") + } +} diff --git a/discovery/vendor/github.com/golang/glog/glog_test.go b/discovery/vendor/github.com/golang/glog/glog_test.go new file mode 100644 index 00000000..0fb376e1 --- /dev/null +++ b/discovery/vendor/github.com/golang/glog/glog_test.go @@ -0,0 +1,415 @@ +// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/ +// +// Copyright 2013 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 glog + +import ( + "bytes" + "fmt" + stdLog "log" + "path/filepath" + "runtime" + "strconv" + "strings" + "testing" + "time" +) + +// Test that shortHostname works as advertised. +func TestShortHostname(t *testing.T) { + for hostname, expect := range map[string]string{ + "": "", + "host": "host", + "host.google.com": "host", + } { + if got := shortHostname(hostname); expect != got { + t.Errorf("shortHostname(%q): expected %q, got %q", hostname, expect, got) + } + } +} + +// flushBuffer wraps a bytes.Buffer to satisfy flushSyncWriter. +type flushBuffer struct { + bytes.Buffer +} + +func (f *flushBuffer) Flush() error { + return nil +} + +func (f *flushBuffer) Sync() error { + return nil +} + +// swap sets the log writers and returns the old array. +func (l *loggingT) swap(writers [numSeverity]flushSyncWriter) (old [numSeverity]flushSyncWriter) { + l.mu.Lock() + defer l.mu.Unlock() + old = l.file + for i, w := range writers { + logging.file[i] = w + } + return +} + +// newBuffers sets the log writers to all new byte buffers and returns the old array. +func (l *loggingT) newBuffers() [numSeverity]flushSyncWriter { + return l.swap([numSeverity]flushSyncWriter{new(flushBuffer), new(flushBuffer), new(flushBuffer), new(flushBuffer)}) +} + +// contents returns the specified log value as a string. +func contents(s severity) string { + return logging.file[s].(*flushBuffer).String() +} + +// contains reports whether the string is contained in the log. +func contains(s severity, str string, t *testing.T) bool { + return strings.Contains(contents(s), str) +} + +// setFlags configures the logging flags how the test expects them. +func setFlags() { + logging.toStderr = false +} + +// Test that Info works as advertised. +func TestInfo(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + Info("test") + if !contains(infoLog, "I", t) { + t.Errorf("Info has wrong character: %q", contents(infoLog)) + } + if !contains(infoLog, "test", t) { + t.Error("Info failed") + } +} + +func TestInfoDepth(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + + f := func() { InfoDepth(1, "depth-test1") } + + // The next three lines must stay together + _, _, wantLine, _ := runtime.Caller(0) + InfoDepth(0, "depth-test0") + f() + + msgs := strings.Split(strings.TrimSuffix(contents(infoLog), "\n"), "\n") + if len(msgs) != 2 { + t.Fatalf("Got %d lines, expected 2", len(msgs)) + } + + for i, m := range msgs { + if !strings.HasPrefix(m, "I") { + t.Errorf("InfoDepth[%d] has wrong character: %q", i, m) + } + w := fmt.Sprintf("depth-test%d", i) + if !strings.Contains(m, w) { + t.Errorf("InfoDepth[%d] missing %q: %q", i, w, m) + } + + // pull out the line number (between : and ]) + msg := m[strings.LastIndex(m, ":")+1:] + x := strings.Index(msg, "]") + if x < 0 { + t.Errorf("InfoDepth[%d]: missing ']': %q", i, m) + continue + } + line, err := strconv.Atoi(msg[:x]) + if err != nil { + t.Errorf("InfoDepth[%d]: bad line number: %q", i, m) + continue + } + wantLine++ + if wantLine != line { + t.Errorf("InfoDepth[%d]: got line %d, want %d", i, line, wantLine) + } + } +} + +func init() { + CopyStandardLogTo("INFO") +} + +// Test that CopyStandardLogTo panics on bad input. +func TestCopyStandardLogToPanic(t *testing.T) { + defer func() { + if s, ok := recover().(string); !ok || !strings.Contains(s, "LOG") { + t.Errorf(`CopyStandardLogTo("LOG") should have panicked: %v`, s) + } + }() + CopyStandardLogTo("LOG") +} + +// Test that using the standard log package logs to INFO. +func TestStandardLog(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + stdLog.Print("test") + if !contains(infoLog, "I", t) { + t.Errorf("Info has wrong character: %q", contents(infoLog)) + } + if !contains(infoLog, "test", t) { + t.Error("Info failed") + } +} + +// Test that the header has the correct format. +func TestHeader(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + defer func(previous func() time.Time) { timeNow = previous }(timeNow) + timeNow = func() time.Time { + return time.Date(2006, 1, 2, 15, 4, 5, .067890e9, time.Local) + } + pid = 1234 + Info("test") + var line int + format := "I0102 15:04:05.067890 1234 glog_test.go:%d] test\n" + n, err := fmt.Sscanf(contents(infoLog), format, &line) + if n != 1 || err != nil { + t.Errorf("log format error: %d elements, error %s:\n%s", n, err, contents(infoLog)) + } + // Scanf treats multiple spaces as equivalent to a single space, + // so check for correct space-padding also. + want := fmt.Sprintf(format, line) + if contents(infoLog) != want { + t.Errorf("log format error: got:\n\t%q\nwant:\t%q", contents(infoLog), want) + } +} + +// Test that an Error log goes to Warning and Info. +// Even in the Info log, the source character will be E, so the data should +// all be identical. +func TestError(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + Error("test") + if !contains(errorLog, "E", t) { + t.Errorf("Error has wrong character: %q", contents(errorLog)) + } + if !contains(errorLog, "test", t) { + t.Error("Error failed") + } + str := contents(errorLog) + if !contains(warningLog, str, t) { + t.Error("Warning failed") + } + if !contains(infoLog, str, t) { + t.Error("Info failed") + } +} + +// Test that a Warning log goes to Info. +// Even in the Info log, the source character will be W, so the data should +// all be identical. +func TestWarning(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + Warning("test") + if !contains(warningLog, "W", t) { + t.Errorf("Warning has wrong character: %q", contents(warningLog)) + } + if !contains(warningLog, "test", t) { + t.Error("Warning failed") + } + str := contents(warningLog) + if !contains(infoLog, str, t) { + t.Error("Info failed") + } +} + +// Test that a V log goes to Info. +func TestV(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + logging.verbosity.Set("2") + defer logging.verbosity.Set("0") + V(2).Info("test") + if !contains(infoLog, "I", t) { + t.Errorf("Info has wrong character: %q", contents(infoLog)) + } + if !contains(infoLog, "test", t) { + t.Error("Info failed") + } +} + +// Test that a vmodule enables a log in this file. +func TestVmoduleOn(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + logging.vmodule.Set("glog_test=2") + defer logging.vmodule.Set("") + if !V(1) { + t.Error("V not enabled for 1") + } + if !V(2) { + t.Error("V not enabled for 2") + } + if V(3) { + t.Error("V enabled for 3") + } + V(2).Info("test") + if !contains(infoLog, "I", t) { + t.Errorf("Info has wrong character: %q", contents(infoLog)) + } + if !contains(infoLog, "test", t) { + t.Error("Info failed") + } +} + +// Test that a vmodule of another file does not enable a log in this file. +func TestVmoduleOff(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + logging.vmodule.Set("notthisfile=2") + defer logging.vmodule.Set("") + for i := 1; i <= 3; i++ { + if V(Level(i)) { + t.Errorf("V enabled for %d", i) + } + } + V(2).Info("test") + if contents(infoLog) != "" { + t.Error("V logged incorrectly") + } +} + +// vGlobs are patterns that match/don't match this file at V=2. +var vGlobs = map[string]bool{ + // Easy to test the numeric match here. + "glog_test=1": false, // If -vmodule sets V to 1, V(2) will fail. + "glog_test=2": true, + "glog_test=3": true, // If -vmodule sets V to 1, V(3) will succeed. + // These all use 2 and check the patterns. All are true. + "*=2": true, + "?l*=2": true, + "????_*=2": true, + "??[mno]?_*t=2": true, + // These all use 2 and check the patterns. All are false. + "*x=2": false, + "m*=2": false, + "??_*=2": false, + "?[abc]?_*t=2": false, +} + +// Test that vmodule globbing works as advertised. +func testVmoduleGlob(pat string, match bool, t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + defer logging.vmodule.Set("") + logging.vmodule.Set(pat) + if V(2) != Verbose(match) { + t.Errorf("incorrect match for %q: got %t expected %t", pat, V(2), match) + } +} + +// Test that a vmodule globbing works as advertised. +func TestVmoduleGlob(t *testing.T) { + for glob, match := range vGlobs { + testVmoduleGlob(glob, match, t) + } +} + +func TestRollover(t *testing.T) { + setFlags() + var err error + defer func(previous func(error)) { logExitFunc = previous }(logExitFunc) + logExitFunc = func(e error) { + err = e + } + defer func(previous uint64) { MaxSize = previous }(MaxSize) + MaxSize = 512 + + Info("x") // Be sure we have a file. + info, ok := logging.file[infoLog].(*syncBuffer) + if !ok { + t.Fatal("info wasn't created") + } + if err != nil { + t.Fatalf("info has initial error: %v", err) + } + fname0 := info.file.Name() + Info(strings.Repeat("x", int(MaxSize))) // force a rollover + if err != nil { + t.Fatalf("info has error after big write: %v", err) + } + + // Make sure the next log file gets a file name with a different + // time stamp. + // + // TODO: determine whether we need to support subsecond log + // rotation. C++ does not appear to handle this case (nor does it + // handle Daylight Savings Time properly). + time.Sleep(1 * time.Second) + + Info("x") // create a new file + if err != nil { + t.Fatalf("error after rotation: %v", err) + } + fname1 := info.file.Name() + if fname0 == fname1 { + t.Errorf("info.f.Name did not change: %v", fname0) + } + if info.nbytes >= MaxSize { + t.Errorf("file size was not reset: %d", info.nbytes) + } +} + +func TestLogBacktraceAt(t *testing.T) { + setFlags() + defer logging.swap(logging.newBuffers()) + // The peculiar style of this code simplifies line counting and maintenance of the + // tracing block below. + var infoLine string + setTraceLocation := func(file string, line int, ok bool, delta int) { + if !ok { + t.Fatal("could not get file:line") + } + _, file = filepath.Split(file) + infoLine = fmt.Sprintf("%s:%d", file, line+delta) + err := logging.traceLocation.Set(infoLine) + if err != nil { + t.Fatal("error setting log_backtrace_at: ", err) + } + } + { + // Start of tracing block. These lines know about each other's relative position. + _, file, line, ok := runtime.Caller(0) + setTraceLocation(file, line, ok, +2) // Two lines between Caller and Info calls. + Info("we want a stack trace here") + } + numAppearances := strings.Count(contents(infoLog), infoLine) + if numAppearances < 2 { + // Need 2 appearances, one in the log header and one in the trace: + // log_test.go:281: I0511 16:36:06.952398 02238 log_test.go:280] we want a stack trace here + // ... + // github.com/glog/glog_test.go:280 (0x41ba91) + // ... + // We could be more precise but that would require knowing the details + // of the traceback format, which may not be dependable. + t.Fatal("got no trace back; log is ", contents(infoLog)) + } +} + +func BenchmarkHeader(b *testing.B) { + for i := 0; i < b.N; i++ { + buf, _, _ := logging.header(infoLog, 0) + logging.putBuffer(buf) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/.travis.yml b/discovery/vendor/github.com/golang/protobuf/.travis.yml new file mode 100644 index 00000000..93c67805 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/.travis.yml @@ -0,0 +1,18 @@ +sudo: false +language: go +go: +- 1.6.x +- 1.7.x +- 1.8.x +- 1.9.x + +install: + - go get -v -d -t github.com/golang/protobuf/... + - curl -L https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip -o /tmp/protoc.zip + - unzip /tmp/protoc.zip -d $HOME/protoc + +env: + - PATH=$HOME/protoc/bin:$PATH + +script: + - make all test diff --git a/discovery/vendor/github.com/golang/protobuf/descriptor/descriptor_test.go b/discovery/vendor/github.com/golang/protobuf/descriptor/descriptor_test.go new file mode 100644 index 00000000..27b0729c --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/descriptor/descriptor_test.go @@ -0,0 +1,32 @@ +package descriptor_test + +import ( + "fmt" + "testing" + + "github.com/golang/protobuf/descriptor" + tpb "github.com/golang/protobuf/proto/testdata" + protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor" +) + +func TestMessage(t *testing.T) { + var msg *protobuf.DescriptorProto + fd, md := descriptor.ForMessage(msg) + if pkg, want := fd.GetPackage(), "google.protobuf"; pkg != want { + t.Errorf("descriptor.ForMessage(%T).GetPackage() = %q; want %q", msg, pkg, want) + } + if name, want := md.GetName(), "DescriptorProto"; name != want { + t.Fatalf("descriptor.ForMessage(%T).GetName() = %q; want %q", msg, name, want) + } +} + +func Example_Options() { + var msg *tpb.MyMessageSet + _, md := descriptor.ForMessage(msg) + if md.GetOptions().GetMessageSetWireFormat() { + fmt.Printf("%v uses option message_set_wire_format.\n", md.GetName()) + } + + // Output: + // MyMessageSet uses option message_set_wire_format. +} diff --git a/discovery/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go b/discovery/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go new file mode 100644 index 00000000..4fdbde15 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go @@ -0,0 +1,897 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package jsonpb + +import ( + "bytes" + "encoding/json" + "io" + "math" + "reflect" + "strings" + "testing" + + "github.com/golang/protobuf/proto" + + pb "github.com/golang/protobuf/jsonpb/jsonpb_test_proto" + proto3pb "github.com/golang/protobuf/proto/proto3_proto" + "github.com/golang/protobuf/ptypes" + anypb "github.com/golang/protobuf/ptypes/any" + durpb "github.com/golang/protobuf/ptypes/duration" + stpb "github.com/golang/protobuf/ptypes/struct" + tspb "github.com/golang/protobuf/ptypes/timestamp" + wpb "github.com/golang/protobuf/ptypes/wrappers" +) + +var ( + marshaler = Marshaler{} + + marshalerAllOptions = Marshaler{ + Indent: " ", + } + + simpleObject = &pb.Simple{ + OInt32: proto.Int32(-32), + OInt64: proto.Int64(-6400000000), + OUint32: proto.Uint32(32), + OUint64: proto.Uint64(6400000000), + OSint32: proto.Int32(-13), + OSint64: proto.Int64(-2600000000), + OFloat: proto.Float32(3.14), + ODouble: proto.Float64(6.02214179e23), + OBool: proto.Bool(true), + OString: proto.String("hello \"there\""), + OBytes: []byte("beep boop"), + } + + simpleObjectJSON = `{` + + `"oBool":true,` + + `"oInt32":-32,` + + `"oInt64":"-6400000000",` + + `"oUint32":32,` + + `"oUint64":"6400000000",` + + `"oSint32":-13,` + + `"oSint64":"-2600000000",` + + `"oFloat":3.14,` + + `"oDouble":6.02214179e+23,` + + `"oString":"hello \"there\"",` + + `"oBytes":"YmVlcCBib29w"` + + `}` + + simpleObjectPrettyJSON = `{ + "oBool": true, + "oInt32": -32, + "oInt64": "-6400000000", + "oUint32": 32, + "oUint64": "6400000000", + "oSint32": -13, + "oSint64": "-2600000000", + "oFloat": 3.14, + "oDouble": 6.02214179e+23, + "oString": "hello \"there\"", + "oBytes": "YmVlcCBib29w" +}` + + repeatsObject = &pb.Repeats{ + RBool: []bool{true, false, true}, + RInt32: []int32{-3, -4, -5}, + RInt64: []int64{-123456789, -987654321}, + RUint32: []uint32{1, 2, 3}, + RUint64: []uint64{6789012345, 3456789012}, + RSint32: []int32{-1, -2, -3}, + RSint64: []int64{-6789012345, -3456789012}, + RFloat: []float32{3.14, 6.28}, + RDouble: []float64{299792458 * 1e20, 6.62606957e-34}, + RString: []string{"happy", "days"}, + RBytes: [][]byte{[]byte("skittles"), []byte("m&m's")}, + } + + repeatsObjectJSON = `{` + + `"rBool":[true,false,true],` + + `"rInt32":[-3,-4,-5],` + + `"rInt64":["-123456789","-987654321"],` + + `"rUint32":[1,2,3],` + + `"rUint64":["6789012345","3456789012"],` + + `"rSint32":[-1,-2,-3],` + + `"rSint64":["-6789012345","-3456789012"],` + + `"rFloat":[3.14,6.28],` + + `"rDouble":[2.99792458e+28,6.62606957e-34],` + + `"rString":["happy","days"],` + + `"rBytes":["c2tpdHRsZXM=","bSZtJ3M="]` + + `}` + + repeatsObjectPrettyJSON = `{ + "rBool": [ + true, + false, + true + ], + "rInt32": [ + -3, + -4, + -5 + ], + "rInt64": [ + "-123456789", + "-987654321" + ], + "rUint32": [ + 1, + 2, + 3 + ], + "rUint64": [ + "6789012345", + "3456789012" + ], + "rSint32": [ + -1, + -2, + -3 + ], + "rSint64": [ + "-6789012345", + "-3456789012" + ], + "rFloat": [ + 3.14, + 6.28 + ], + "rDouble": [ + 2.99792458e+28, + 6.62606957e-34 + ], + "rString": [ + "happy", + "days" + ], + "rBytes": [ + "c2tpdHRsZXM=", + "bSZtJ3M=" + ] +}` + + innerSimple = &pb.Simple{OInt32: proto.Int32(-32)} + innerSimple2 = &pb.Simple{OInt64: proto.Int64(25)} + innerRepeats = &pb.Repeats{RString: []string{"roses", "red"}} + innerRepeats2 = &pb.Repeats{RString: []string{"violets", "blue"}} + complexObject = &pb.Widget{ + Color: pb.Widget_GREEN.Enum(), + RColor: []pb.Widget_Color{pb.Widget_RED, pb.Widget_GREEN, pb.Widget_BLUE}, + Simple: innerSimple, + RSimple: []*pb.Simple{innerSimple, innerSimple2}, + Repeats: innerRepeats, + RRepeats: []*pb.Repeats{innerRepeats, innerRepeats2}, + } + + complexObjectJSON = `{"color":"GREEN",` + + `"rColor":["RED","GREEN","BLUE"],` + + `"simple":{"oInt32":-32},` + + `"rSimple":[{"oInt32":-32},{"oInt64":"25"}],` + + `"repeats":{"rString":["roses","red"]},` + + `"rRepeats":[{"rString":["roses","red"]},{"rString":["violets","blue"]}]` + + `}` + + complexObjectPrettyJSON = `{ + "color": "GREEN", + "rColor": [ + "RED", + "GREEN", + "BLUE" + ], + "simple": { + "oInt32": -32 + }, + "rSimple": [ + { + "oInt32": -32 + }, + { + "oInt64": "25" + } + ], + "repeats": { + "rString": [ + "roses", + "red" + ] + }, + "rRepeats": [ + { + "rString": [ + "roses", + "red" + ] + }, + { + "rString": [ + "violets", + "blue" + ] + } + ] +}` + + colorPrettyJSON = `{ + "color": 2 +}` + + colorListPrettyJSON = `{ + "color": 1000, + "rColor": [ + "RED" + ] +}` + + nummyPrettyJSON = `{ + "nummy": { + "1": 2, + "3": 4 + } +}` + + objjyPrettyJSON = `{ + "objjy": { + "1": { + "dub": 1 + } + } +}` + realNumber = &pb.Real{Value: proto.Float64(3.14159265359)} + realNumberName = "Pi" + complexNumber = &pb.Complex{Imaginary: proto.Float64(0.5772156649)} + realNumberJSON = `{` + + `"value":3.14159265359,` + + `"[jsonpb.Complex.real_extension]":{"imaginary":0.5772156649},` + + `"[jsonpb.name]":"Pi"` + + `}` + + anySimple = &pb.KnownTypes{ + An: &anypb.Any{ + TypeUrl: "something.example.com/jsonpb.Simple", + Value: []byte{ + // &pb.Simple{OBool:true} + 1 << 3, 1, + }, + }, + } + anySimpleJSON = `{"an":{"@type":"something.example.com/jsonpb.Simple","oBool":true}}` + anySimplePrettyJSON = `{ + "an": { + "@type": "something.example.com/jsonpb.Simple", + "oBool": true + } +}` + + anyWellKnown = &pb.KnownTypes{ + An: &anypb.Any{ + TypeUrl: "type.googleapis.com/google.protobuf.Duration", + Value: []byte{ + // &durpb.Duration{Seconds: 1, Nanos: 212000000 } + 1 << 3, 1, // seconds + 2 << 3, 0x80, 0xba, 0x8b, 0x65, // nanos + }, + }, + } + anyWellKnownJSON = `{"an":{"@type":"type.googleapis.com/google.protobuf.Duration","value":"1.212s"}}` + anyWellKnownPrettyJSON = `{ + "an": { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } +}` + + nonFinites = &pb.NonFinites{ + FNan: proto.Float32(float32(math.NaN())), + FPinf: proto.Float32(float32(math.Inf(1))), + FNinf: proto.Float32(float32(math.Inf(-1))), + DNan: proto.Float64(float64(math.NaN())), + DPinf: proto.Float64(float64(math.Inf(1))), + DNinf: proto.Float64(float64(math.Inf(-1))), + } + nonFinitesJSON = `{` + + `"fNan":"NaN",` + + `"fPinf":"Infinity",` + + `"fNinf":"-Infinity",` + + `"dNan":"NaN",` + + `"dPinf":"Infinity",` + + `"dNinf":"-Infinity"` + + `}` +) + +func init() { + if err := proto.SetExtension(realNumber, pb.E_Name, &realNumberName); err != nil { + panic(err) + } + if err := proto.SetExtension(realNumber, pb.E_Complex_RealExtension, complexNumber); err != nil { + panic(err) + } +} + +var marshalingTests = []struct { + desc string + marshaler Marshaler + pb proto.Message + json string +}{ + {"simple flat object", marshaler, simpleObject, simpleObjectJSON}, + {"simple pretty object", marshalerAllOptions, simpleObject, simpleObjectPrettyJSON}, + {"non-finite floats fields object", marshaler, nonFinites, nonFinitesJSON}, + {"repeated fields flat object", marshaler, repeatsObject, repeatsObjectJSON}, + {"repeated fields pretty object", marshalerAllOptions, repeatsObject, repeatsObjectPrettyJSON}, + {"nested message/enum flat object", marshaler, complexObject, complexObjectJSON}, + {"nested message/enum pretty object", marshalerAllOptions, complexObject, complexObjectPrettyJSON}, + {"enum-string flat object", Marshaler{}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, `{"color":"BLUE"}`}, + {"enum-value pretty object", Marshaler{EnumsAsInts: true, Indent: " "}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, colorPrettyJSON}, + {"unknown enum value object", marshalerAllOptions, + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}, colorListPrettyJSON}, + {"repeated proto3 enum", Marshaler{}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":["PUNS","SLAPSTICK"]}`}, + {"repeated proto3 enum as int", Marshaler{EnumsAsInts: true}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":[1,2]}`}, + {"empty value", marshaler, &pb.Simple3{}, `{}`}, + {"empty value emitted", Marshaler{EmitDefaults: true}, &pb.Simple3{}, `{"dub":0}`}, + {"empty repeated emitted", Marshaler{EmitDefaults: true}, &pb.SimpleSlice3{}, `{"slices":[]}`}, + {"empty map emitted", Marshaler{EmitDefaults: true}, &pb.SimpleMap3{}, `{"stringy":{}}`}, + {"nested struct null", Marshaler{EmitDefaults: true}, &pb.SimpleNull3{}, `{"simple":null}`}, + {"map", marshaler, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`}, + {"map", marshalerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON}, + {"map", marshaler, + &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}, + `{"strry":{"\"one\"":"two","three":"four"}}`}, + {"map", marshaler, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, `{"objjy":{"1":{"dub":1}}}`}, + {"map", marshalerAllOptions, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, objjyPrettyJSON}, + {"map", marshaler, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}}, + `{"buggy":{"1234":"yup"}}`}, + {"map", marshaler, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`}, + // TODO: This is broken. + //{"map", marshaler, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":"ROMAN"}`}, + {"map", Marshaler{EnumsAsInts: true}, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":2}}`}, + {"map", marshaler, &pb.Mappy{S32Booly: map[int32]bool{1: true, 3: false, 10: true, 12: false}}, `{"s32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{S64Booly: map[int64]bool{1: true, 3: false, 10: true, 12: false}}, `{"s64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U32Booly: map[uint32]bool{1: true, 3: false, 10: true, 12: false}}, `{"u32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U64Booly: map[uint64]bool{1: true, 3: false, 10: true, 12: false}}, `{"u64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"proto2 map", marshaler, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}}, + `{"mInt64Str":{"213":"cat"}}`}, + {"proto2 map", marshaler, + &pb.Maps{MBoolSimple: map[bool]*pb.Simple{true: {OInt32: proto.Int32(1)}}}, + `{"mBoolSimple":{"true":{"oInt32":1}}}`}, + {"oneof, not set", marshaler, &pb.MsgWithOneof{}, `{}`}, + {"oneof, set", marshaler, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Title{"Grand Poobah"}}, `{"title":"Grand Poobah"}`}, + {"force orig_name", Marshaler{OrigName: true}, &pb.Simple{OInt32: proto.Int32(4)}, + `{"o_int32":4}`}, + {"proto2 extension", marshaler, realNumber, realNumberJSON}, + {"Any with message", marshaler, anySimple, anySimpleJSON}, + {"Any with message and indent", marshalerAllOptions, anySimple, anySimplePrettyJSON}, + {"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON}, + {"Any with WKT and indent", marshalerAllOptions, anyWellKnown, anyWellKnownPrettyJSON}, + {"Duration", marshaler, &pb.KnownTypes{Dur: &durpb.Duration{Seconds: 3}}, `{"dur":"3.000s"}`}, + {"Duration", marshaler, &pb.KnownTypes{Dur: &durpb.Duration{Seconds: 100000000, Nanos: 1}}, `{"dur":"100000000.000000001s"}`}, + {"Struct", marshaler, &pb.KnownTypes{St: &stpb.Struct{ + Fields: map[string]*stpb.Value{ + "one": {Kind: &stpb.Value_StringValue{"loneliest number"}}, + "two": {Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}}, + }, + }}, `{"st":{"one":"loneliest number","two":null}}`}, + {"empty ListValue", marshaler, &pb.KnownTypes{Lv: &stpb.ListValue{}}, `{"lv":[]}`}, + {"basic ListValue", marshaler, &pb.KnownTypes{Lv: &stpb.ListValue{Values: []*stpb.Value{ + {Kind: &stpb.Value_StringValue{"x"}}, + {Kind: &stpb.Value_NullValue{}}, + {Kind: &stpb.Value_NumberValue{3}}, + {Kind: &stpb.Value_BoolValue{true}}, + }}}, `{"lv":["x",null,3,true]}`}, + {"Timestamp", marshaler, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: 14e8, Nanos: 21e6}}, `{"ts":"2014-05-13T16:53:20.021Z"}`}, + {"number Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NumberValue{1}}}, `{"val":1}`}, + {"null Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}}}, `{"val":null}`}, + {"string number value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"9223372036854775807"}}}, `{"val":"9223372036854775807"}`}, + {"list of lists Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{ + Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{ + {Kind: &stpb.Value_StringValue{"x"}}, + {Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{ + {Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{{Kind: &stpb.Value_StringValue{"y"}}}, + }}}, + {Kind: &stpb.Value_StringValue{"z"}}, + }, + }}}, + }, + }}, + }}, `{"val":["x",[["y"],"z"]]}`}, + + {"DoubleValue", marshaler, &pb.KnownTypes{Dbl: &wpb.DoubleValue{Value: 1.2}}, `{"dbl":1.2}`}, + {"FloatValue", marshaler, &pb.KnownTypes{Flt: &wpb.FloatValue{Value: 1.2}}, `{"flt":1.2}`}, + {"Int64Value", marshaler, &pb.KnownTypes{I64: &wpb.Int64Value{Value: -3}}, `{"i64":"-3"}`}, + {"UInt64Value", marshaler, &pb.KnownTypes{U64: &wpb.UInt64Value{Value: 3}}, `{"u64":"3"}`}, + {"Int32Value", marshaler, &pb.KnownTypes{I32: &wpb.Int32Value{Value: -4}}, `{"i32":-4}`}, + {"UInt32Value", marshaler, &pb.KnownTypes{U32: &wpb.UInt32Value{Value: 4}}, `{"u32":4}`}, + {"BoolValue", marshaler, &pb.KnownTypes{Bool: &wpb.BoolValue{Value: true}}, `{"bool":true}`}, + {"StringValue", marshaler, &pb.KnownTypes{Str: &wpb.StringValue{Value: "plush"}}, `{"str":"plush"}`}, + {"BytesValue", marshaler, &pb.KnownTypes{Bytes: &wpb.BytesValue{Value: []byte("wow")}}, `{"bytes":"d293"}`}, +} + +func TestMarshaling(t *testing.T) { + for _, tt := range marshalingTests { + json, err := tt.marshaler.MarshalToString(tt.pb) + if err != nil { + t.Errorf("%s: marshaling error: %v", tt.desc, err) + } else if tt.json != json { + t.Errorf("%s: got [%v] want [%v]", tt.desc, json, tt.json) + } + } +} + +func TestMarshalJSONPBMarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + msg := dynamicMessage{rawJson: rawJson} + str, err := new(Marshaler).MarshalToString(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling JSONPBMarshaler: %v", err) + } + if str != rawJson { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, rawJson) + } +} + +func TestMarshalAnyJSONPBMarshaler(t *testing.T) { + msg := dynamicMessage{rawJson: `{ "foo": "bar", "baz": [0, 1, 2, 3] }`} + a, err := ptypes.MarshalAny(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling to Any: %v", err) + } + str, err := new(Marshaler).MarshalToString(a) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling Any to JSON: %v", err) + } + // after custom marshaling, it's round-tripped through JSON decoding/encoding already, + // so the keys are sorted, whitespace is compacted, and "@type" key has been added + expected := `{"@type":"type.googleapis.com/` + dynamicMessageName + `","baz":[0,1,2,3],"foo":"bar"}` + if str != expected { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, expected) + } +} + +var unmarshalingTests = []struct { + desc string + unmarshaler Unmarshaler + json string + pb proto.Message +}{ + {"simple flat object", Unmarshaler{}, simpleObjectJSON, simpleObject}, + {"simple pretty object", Unmarshaler{}, simpleObjectPrettyJSON, simpleObject}, + {"repeated fields flat object", Unmarshaler{}, repeatsObjectJSON, repeatsObject}, + {"repeated fields pretty object", Unmarshaler{}, repeatsObjectPrettyJSON, repeatsObject}, + {"nested message/enum flat object", Unmarshaler{}, complexObjectJSON, complexObject}, + {"nested message/enum pretty object", Unmarshaler{}, complexObjectPrettyJSON, complexObject}, + {"enum-string object", Unmarshaler{}, `{"color":"BLUE"}`, &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"enum-value object", Unmarshaler{}, "{\n \"color\": 2\n}", &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"unknown field with allowed option", Unmarshaler{AllowUnknownFields: true}, `{"unknown": "foo"}`, new(pb.Simple)}, + {"proto3 enum string", Unmarshaler{}, `{"hilarity":"PUNS"}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 enum value", Unmarshaler{}, `{"hilarity":1}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"unknown enum value object", + Unmarshaler{}, + "{\n \"color\": 1000,\n \"r_color\": [\n \"RED\"\n ]\n}", + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}}, + {"repeated proto3 enum", Unmarshaler{}, `{"rFunny":["PUNS","SLAPSTICK"]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as int", Unmarshaler{}, `{"rFunny":[1,2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as mix of strings and ints", Unmarshaler{}, `{"rFunny":["PUNS",2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"unquoted int64 object", Unmarshaler{}, `{"oInt64":-314}`, &pb.Simple{OInt64: proto.Int64(-314)}}, + {"unquoted uint64 object", Unmarshaler{}, `{"oUint64":123}`, &pb.Simple{OUint64: proto.Uint64(123)}}, + {"NaN", Unmarshaler{}, `{"oDouble":"NaN"}`, &pb.Simple{ODouble: proto.Float64(math.NaN())}}, + {"Inf", Unmarshaler{}, `{"oFloat":"Infinity"}`, &pb.Simple{OFloat: proto.Float32(float32(math.Inf(1)))}}, + {"-Inf", Unmarshaler{}, `{"oDouble":"-Infinity"}`, &pb.Simple{ODouble: proto.Float64(math.Inf(-1))}}, + {"map", Unmarshaler{}, `{"nummy":{"1":2,"3":4}}`, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}}, + {"map", Unmarshaler{}, `{"strry":{"\"one\"":"two","three":"four"}}`, &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}}, + {"map", Unmarshaler{}, `{"objjy":{"1":{"dub":1}}}`, &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}}, + {"proto2 extension", Unmarshaler{}, realNumberJSON, realNumber}, + {"Any with message", Unmarshaler{}, anySimpleJSON, anySimple}, + {"Any with message and indent", Unmarshaler{}, anySimplePrettyJSON, anySimple}, + {"Any with WKT", Unmarshaler{}, anyWellKnownJSON, anyWellKnown}, + {"Any with WKT and indent", Unmarshaler{}, anyWellKnownPrettyJSON, anyWellKnown}, + // TODO: This is broken. + //{"map", Unmarshaler{}, `{"enumy":{"XIV":"ROMAN"}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"map", Unmarshaler{}, `{"enumy":{"XIV":2}}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"oneof", Unmarshaler{}, `{"salary":31000}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Salary{31000}}}, + {"oneof spec name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{"Australia"}}}, + {"oneof orig_name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{"Australia"}}}, + {"oneof spec name2", Unmarshaler{}, `{"homeAddress":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{"Australia"}}}, + {"oneof orig_name2", Unmarshaler{}, `{"home_address":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{"Australia"}}}, + {"orig_name input", Unmarshaler{}, `{"o_bool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + {"camelName input", Unmarshaler{}, `{"oBool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + + {"Duration", Unmarshaler{}, `{"dur":"3.000s"}`, &pb.KnownTypes{Dur: &durpb.Duration{Seconds: 3}}}, + {"null Duration", Unmarshaler{}, `{"dur":null}`, &pb.KnownTypes{Dur: nil}}, + {"Timestamp", Unmarshaler{}, `{"ts":"2014-05-13T16:53:20.021Z"}`, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: 14e8, Nanos: 21e6}}}, + {"PreEpochTimestamp", Unmarshaler{}, `{"ts":"1969-12-31T23:59:58.999999995Z"}`, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: -2, Nanos: 999999995}}}, + {"ZeroTimeTimestamp", Unmarshaler{}, `{"ts":"0001-01-01T00:00:00Z"}`, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: -62135596800, Nanos: 0}}}, + {"null Timestamp", Unmarshaler{}, `{"ts":null}`, &pb.KnownTypes{Ts: nil}}, + {"null Struct", Unmarshaler{}, `{"st": null}`, &pb.KnownTypes{St: nil}}, + {"empty Struct", Unmarshaler{}, `{"st": {}}`, &pb.KnownTypes{St: &stpb.Struct{}}}, + {"basic Struct", Unmarshaler{}, `{"st": {"a": "x", "b": null, "c": 3, "d": true}}`, &pb.KnownTypes{St: &stpb.Struct{Fields: map[string]*stpb.Value{ + "a": {Kind: &stpb.Value_StringValue{"x"}}, + "b": {Kind: &stpb.Value_NullValue{}}, + "c": {Kind: &stpb.Value_NumberValue{3}}, + "d": {Kind: &stpb.Value_BoolValue{true}}, + }}}}, + {"nested Struct", Unmarshaler{}, `{"st": {"a": {"b": 1, "c": [{"d": true}, "f"]}}}`, &pb.KnownTypes{St: &stpb.Struct{Fields: map[string]*stpb.Value{ + "a": {Kind: &stpb.Value_StructValue{&stpb.Struct{Fields: map[string]*stpb.Value{ + "b": {Kind: &stpb.Value_NumberValue{1}}, + "c": {Kind: &stpb.Value_ListValue{&stpb.ListValue{Values: []*stpb.Value{ + {Kind: &stpb.Value_StructValue{&stpb.Struct{Fields: map[string]*stpb.Value{"d": {Kind: &stpb.Value_BoolValue{true}}}}}}, + {Kind: &stpb.Value_StringValue{"f"}}, + }}}}, + }}}}, + }}}}, + {"null ListValue", Unmarshaler{}, `{"lv": null}`, &pb.KnownTypes{Lv: nil}}, + {"empty ListValue", Unmarshaler{}, `{"lv": []}`, &pb.KnownTypes{Lv: &stpb.ListValue{}}}, + {"basic ListValue", Unmarshaler{}, `{"lv": ["x", null, 3, true]}`, &pb.KnownTypes{Lv: &stpb.ListValue{Values: []*stpb.Value{ + {Kind: &stpb.Value_StringValue{"x"}}, + {Kind: &stpb.Value_NullValue{}}, + {Kind: &stpb.Value_NumberValue{3}}, + {Kind: &stpb.Value_BoolValue{true}}, + }}}}, + {"number Value", Unmarshaler{}, `{"val":1}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NumberValue{1}}}}, + {"null Value", Unmarshaler{}, `{"val":null}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}}}}, + {"bool Value", Unmarshaler{}, `{"val":true}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_BoolValue{true}}}}, + {"string Value", Unmarshaler{}, `{"val":"x"}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"x"}}}}, + {"string number value", Unmarshaler{}, `{"val":"9223372036854775807"}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"9223372036854775807"}}}}, + {"list of lists Value", Unmarshaler{}, `{"val":["x", [["y"], "z"]]}`, &pb.KnownTypes{Val: &stpb.Value{ + Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{ + {Kind: &stpb.Value_StringValue{"x"}}, + {Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{ + {Kind: &stpb.Value_ListValue{&stpb.ListValue{ + Values: []*stpb.Value{{Kind: &stpb.Value_StringValue{"y"}}}, + }}}, + {Kind: &stpb.Value_StringValue{"z"}}, + }, + }}}, + }, + }}}}}, + + {"DoubleValue", Unmarshaler{}, `{"dbl":1.2}`, &pb.KnownTypes{Dbl: &wpb.DoubleValue{Value: 1.2}}}, + {"FloatValue", Unmarshaler{}, `{"flt":1.2}`, &pb.KnownTypes{Flt: &wpb.FloatValue{Value: 1.2}}}, + {"Int64Value", Unmarshaler{}, `{"i64":"-3"}`, &pb.KnownTypes{I64: &wpb.Int64Value{Value: -3}}}, + {"UInt64Value", Unmarshaler{}, `{"u64":"3"}`, &pb.KnownTypes{U64: &wpb.UInt64Value{Value: 3}}}, + {"Int32Value", Unmarshaler{}, `{"i32":-4}`, &pb.KnownTypes{I32: &wpb.Int32Value{Value: -4}}}, + {"UInt32Value", Unmarshaler{}, `{"u32":4}`, &pb.KnownTypes{U32: &wpb.UInt32Value{Value: 4}}}, + {"BoolValue", Unmarshaler{}, `{"bool":true}`, &pb.KnownTypes{Bool: &wpb.BoolValue{Value: true}}}, + {"StringValue", Unmarshaler{}, `{"str":"plush"}`, &pb.KnownTypes{Str: &wpb.StringValue{Value: "plush"}}}, + {"BytesValue", Unmarshaler{}, `{"bytes":"d293"}`, &pb.KnownTypes{Bytes: &wpb.BytesValue{Value: []byte("wow")}}}, + + // Ensure that `null` as a value ends up with a nil pointer instead of a [type]Value struct. + {"null DoubleValue", Unmarshaler{}, `{"dbl":null}`, &pb.KnownTypes{Dbl: nil}}, + {"null FloatValue", Unmarshaler{}, `{"flt":null}`, &pb.KnownTypes{Flt: nil}}, + {"null Int64Value", Unmarshaler{}, `{"i64":null}`, &pb.KnownTypes{I64: nil}}, + {"null UInt64Value", Unmarshaler{}, `{"u64":null}`, &pb.KnownTypes{U64: nil}}, + {"null Int32Value", Unmarshaler{}, `{"i32":null}`, &pb.KnownTypes{I32: nil}}, + {"null UInt32Value", Unmarshaler{}, `{"u32":null}`, &pb.KnownTypes{U32: nil}}, + {"null BoolValue", Unmarshaler{}, `{"bool":null}`, &pb.KnownTypes{Bool: nil}}, + {"null StringValue", Unmarshaler{}, `{"str":null}`, &pb.KnownTypes{Str: nil}}, + {"null BytesValue", Unmarshaler{}, `{"bytes":null}`, &pb.KnownTypes{Bytes: nil}}, +} + +func TestUnmarshaling(t *testing.T) { + for _, tt := range unmarshalingTests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.Unmarshal(strings.NewReader(tt.json), p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } +} + +func TestUnmarshalNullArray(t *testing.T) { + var repeats pb.Repeats + if err := UnmarshalString(`{"rBool":null}`, &repeats); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(repeats, pb.Repeats{}) { + t.Errorf("got non-nil fields in [%#v]", repeats) + } +} + +func TestUnmarshalNullObject(t *testing.T) { + var maps pb.Maps + if err := UnmarshalString(`{"mInt64Str":null}`, &maps); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(maps, pb.Maps{}) { + t.Errorf("got non-nil fields in [%#v]", maps) + } +} + +func TestUnmarshalNext(t *testing.T) { + // We only need to check against a few, not all of them. + tests := unmarshalingTests[:5] + + // Create a buffer with many concatenated JSON objects. + var b bytes.Buffer + for _, tt := range tests { + b.WriteString(tt.json) + } + + dec := json.NewDecoder(&b) + for _, tt := range tests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.UnmarshalNext(dec, p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } + + p := &pb.Simple{} + err := new(Unmarshaler).UnmarshalNext(dec, p) + if err != io.EOF { + t.Errorf("eof: got %v, expected io.EOF", err) + } +} + +var unmarshalingShouldError = []struct { + desc string + in string + pb proto.Message +}{ + {"a value", "666", new(pb.Simple)}, + {"gibberish", "{adskja123;l23=-=", new(pb.Simple)}, + {"unknown field", `{"unknown": "foo"}`, new(pb.Simple)}, + {"unknown enum name", `{"hilarity":"DAVE"}`, new(proto3pb.Message)}, +} + +func TestUnmarshalingBadInput(t *testing.T) { + for _, tt := range unmarshalingShouldError { + err := UnmarshalString(tt.in, tt.pb) + if err == nil { + t.Errorf("an error was expected when parsing %q instead of an object", tt.desc) + } + } +} + +type funcResolver func(turl string) (proto.Message, error) + +func (fn funcResolver) Resolve(turl string) (proto.Message, error) { + return fn(turl) +} + +func TestAnyWithCustomResolver(t *testing.T) { + var resolvedTypeUrls []string + resolver := funcResolver(func(turl string) (proto.Message, error) { + resolvedTypeUrls = append(resolvedTypeUrls, turl) + return new(pb.Simple), nil + }) + msg := &pb.Simple{ + OBytes: []byte{1, 2, 3, 4}, + OBool: proto.Bool(true), + OString: proto.String("foobar"), + OInt64: proto.Int64(1020304), + } + msgBytes, err := proto.Marshal(msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } + // make an Any with a type URL that won't resolve w/out custom resolver + any := &anypb.Any{ + TypeUrl: "https://foobar.com/some.random.MessageKind", + Value: msgBytes, + } + + m := Marshaler{AnyResolver: resolver} + js, err := m.MarshalToString(any) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling any to JSON: %v", err) + } + if len(resolvedTypeUrls) != 1 { + t.Errorf("custom resolver was not invoked during marshaling") + } else if resolvedTypeUrls[0] != "https://foobar.com/some.random.MessageKind" { + t.Errorf("custom resolver was invoked with wrong URL: got %q, wanted %q", resolvedTypeUrls[0], "https://foobar.com/some.random.MessageKind") + } + wanted := `{"@type":"https://foobar.com/some.random.MessageKind","oBool":true,"oInt64":"1020304","oString":"foobar","oBytes":"AQIDBA=="}` + if js != wanted { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", js, wanted) + } + + u := Unmarshaler{AnyResolver: resolver} + roundTrip := &anypb.Any{} + err = u.Unmarshal(bytes.NewReader([]byte(js)), roundTrip) + if err != nil { + t.Errorf("an unexpected error occurred when unmarshaling any from JSON: %v", err) + } + if len(resolvedTypeUrls) != 2 { + t.Errorf("custom resolver was not invoked during marshaling") + } else if resolvedTypeUrls[1] != "https://foobar.com/some.random.MessageKind" { + t.Errorf("custom resolver was invoked with wrong URL: got %q, wanted %q", resolvedTypeUrls[1], "https://foobar.com/some.random.MessageKind") + } + if !proto.Equal(any, roundTrip) { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", roundTrip, any) + } +} + +func TestUnmarshalJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + var msg dynamicMessage + if err := Unmarshal(strings.NewReader(rawJson), &msg); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + if msg.rawJson != rawJson { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", msg.rawJson, rawJson) + } +} + +func TestUnmarshalNullWithJSONPBUnmarshaler(t *testing.T) { + rawJson := `{"stringField":null}` + var ptrFieldMsg ptrFieldMessage + if err := Unmarshal(strings.NewReader(rawJson), &ptrFieldMsg); err != nil { + t.Errorf("unmarshal error: %v", err) + } + + want := ptrFieldMessage{StringField: &stringField{IsSet: true, StringValue: "null"}} + if !proto.Equal(&ptrFieldMsg, &want) { + t.Errorf("unmarshal result StringField: got %v, want %v", ptrFieldMsg, want) + } +} + +func TestUnmarshalAnyJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "@type": "blah.com/` + dynamicMessageName + `", "foo": "bar", "baz": [0, 1, 2, 3] }` + var got anypb.Any + if err := Unmarshal(strings.NewReader(rawJson), &got); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + + dm := &dynamicMessage{rawJson: `{"baz":[0,1,2,3],"foo":"bar"}`} + var want anypb.Any + if b, err := proto.Marshal(dm); err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } else { + want.TypeUrl = "blah.com/" + dynamicMessageName + want.Value = b + } + + if !proto.Equal(&got, &want) { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", got, want) + } +} + +const ( + dynamicMessageName = "google.protobuf.jsonpb.testing.dynamicMessage" +) + +func init() { + // we register the custom type below so that we can use it in Any types + proto.RegisterType((*dynamicMessage)(nil), dynamicMessageName) +} + +type ptrFieldMessage struct { + StringField *stringField `protobuf:"bytes,1,opt,name=stringField"` +} + +func (m *ptrFieldMessage) Reset() { +} + +func (m *ptrFieldMessage) String() string { + return m.StringField.StringValue +} + +func (m *ptrFieldMessage) ProtoMessage() { +} + +type stringField struct { + IsSet bool `protobuf:"varint,1,opt,name=isSet"` + StringValue string `protobuf:"bytes,2,opt,name=stringValue"` +} + +func (s *stringField) Reset() { +} + +func (s *stringField) String() string { + return s.StringValue +} + +func (s *stringField) ProtoMessage() { +} + +func (s *stringField) UnmarshalJSONPB(jum *Unmarshaler, js []byte) error { + s.IsSet = true + s.StringValue = string(js) + return nil +} + +// dynamicMessage implements protobuf.Message but is not a normal generated message type. +// It provides implementations of JSONPBMarshaler and JSONPBUnmarshaler for JSON support. +type dynamicMessage struct { + rawJson string `protobuf:"bytes,1,opt,name=rawJson"` +} + +func (m *dynamicMessage) Reset() { + m.rawJson = "{}" +} + +func (m *dynamicMessage) String() string { + return m.rawJson +} + +func (m *dynamicMessage) ProtoMessage() { +} + +func (m *dynamicMessage) MarshalJSONPB(jm *Marshaler) ([]byte, error) { + return []byte(m.rawJson), nil +} + +func (m *dynamicMessage) UnmarshalJSONPB(jum *Unmarshaler, js []byte) error { + m.rawJson = string(js) + return nil +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/all_test.go b/discovery/vendor/github.com/golang/protobuf/proto/all_test.go new file mode 100644 index 00000000..41451a40 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/all_test.go @@ -0,0 +1,2278 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "math" + "math/rand" + "reflect" + "runtime/debug" + "strings" + "testing" + "time" + + . "github.com/golang/protobuf/proto" + . "github.com/golang/protobuf/proto/testdata" +) + +var globalO *Buffer + +func old() *Buffer { + if globalO == nil { + globalO = NewBuffer(nil) + } + globalO.Reset() + return globalO +} + +func equalbytes(b1, b2 []byte, t *testing.T) { + if len(b1) != len(b2) { + t.Errorf("wrong lengths: 2*%d != %d", len(b1), len(b2)) + return + } + for i := 0; i < len(b1); i++ { + if b1[i] != b2[i] { + t.Errorf("bad byte[%d]:%x %x: %s %s", i, b1[i], b2[i], b1, b2) + } + } +} + +func initGoTestField() *GoTestField { + f := new(GoTestField) + f.Label = String("label") + f.Type = String("type") + return f +} + +// These are all structurally equivalent but the tag numbers differ. +// (It's remarkable that required, optional, and repeated all have +// 8 letters.) +func initGoTest_RequiredGroup() *GoTest_RequiredGroup { + return &GoTest_RequiredGroup{ + RequiredField: String("required"), + } +} + +func initGoTest_OptionalGroup() *GoTest_OptionalGroup { + return &GoTest_OptionalGroup{ + RequiredField: String("optional"), + } +} + +func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup { + return &GoTest_RepeatedGroup{ + RequiredField: String("repeated"), + } +} + +func initGoTest(setdefaults bool) *GoTest { + pb := new(GoTest) + if setdefaults { + pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted) + pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted) + pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted) + pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted) + pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted) + pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted) + pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted) + pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted) + pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted) + pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted) + pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted + pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted) + pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted) + } + + pb.Kind = GoTest_TIME.Enum() + pb.RequiredField = initGoTestField() + pb.F_BoolRequired = Bool(true) + pb.F_Int32Required = Int32(3) + pb.F_Int64Required = Int64(6) + pb.F_Fixed32Required = Uint32(32) + pb.F_Fixed64Required = Uint64(64) + pb.F_Uint32Required = Uint32(3232) + pb.F_Uint64Required = Uint64(6464) + pb.F_FloatRequired = Float32(3232) + pb.F_DoubleRequired = Float64(6464) + pb.F_StringRequired = String("string") + pb.F_BytesRequired = []byte("bytes") + pb.F_Sint32Required = Int32(-32) + pb.F_Sint64Required = Int64(-64) + pb.Requiredgroup = initGoTest_RequiredGroup() + + return pb +} + +func fail(msg string, b *bytes.Buffer, s string, t *testing.T) { + data := b.Bytes() + ld := len(data) + ls := len(s) / 2 + + fmt.Printf("fail %s ld=%d ls=%d\n", msg, ld, ls) + + // find the interesting spot - n + n := ls + if ld < ls { + n = ld + } + j := 0 + for i := 0; i < n; i++ { + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + if data[i] == bs { + continue + } + n = i + break + } + l := n - 10 + if l < 0 { + l = 0 + } + h := n + 10 + + // find the interesting spot - n + fmt.Printf("is[%d]:", l) + for i := l; i < h; i++ { + if i >= ld { + fmt.Printf(" --") + continue + } + fmt.Printf(" %.2x", data[i]) + } + fmt.Printf("\n") + + fmt.Printf("sb[%d]:", l) + for i := l; i < h; i++ { + if i >= ls { + fmt.Printf(" --") + continue + } + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + fmt.Printf(" %.2x", bs) + } + fmt.Printf("\n") + + t.Fail() + + // t.Errorf("%s: \ngood: %s\nbad: %x", msg, s, b.Bytes()) + // Print the output in a partially-decoded format; can + // be helpful when updating the test. It produces the output + // that is pasted, with minor edits, into the argument to verify(). + // data := b.Bytes() + // nesting := 0 + // for b.Len() > 0 { + // start := len(data) - b.Len() + // var u uint64 + // u, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // wire := u & 0x7 + // tag := u >> 3 + // switch wire { + // case WireVarint: + // v, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed32: + // v, err := DecodeFixed32(b) + // if err != nil { + // fmt.Printf("decode error on fixed32:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed64: + // v, err := DecodeFixed64(b) + // if err != nil { + // fmt.Printf("decode error on fixed64:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireBytes: + // nb, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // after_tag := len(data) - b.Len() + // str := make([]byte, nb) + // _, err = b.Read(str) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" \"%x\" // field %d, encoding %d (FIELD)\n", + // data[start:after_tag], str, tag, wire) + // case WireStartGroup: + // nesting++ + // fmt.Printf("\t\t\"%x\"\t\t// start group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // case WireEndGroup: + // fmt.Printf("\t\t\"%x\"\t\t// end group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // nesting-- + // default: + // fmt.Printf("unrecognized wire type %d\n", wire) + // return + // } + // } +} + +func hex(c uint8) uint8 { + if '0' <= c && c <= '9' { + return c - '0' + } + if 'a' <= c && c <= 'f' { + return 10 + c - 'a' + } + if 'A' <= c && c <= 'F' { + return 10 + c - 'A' + } + return 0 +} + +func equal(b []byte, s string, t *testing.T) bool { + if 2*len(b) != len(s) { + // fail(fmt.Sprintf("wrong lengths: 2*%d != %d", len(b), len(s)), b, s, t) + fmt.Printf("wrong lengths: 2*%d != %d\n", len(b), len(s)) + return false + } + for i, j := 0, 0; i < len(b); i, j = i+1, j+2 { + x := hex(s[j])*16 + hex(s[j+1]) + if b[i] != x { + // fail(fmt.Sprintf("bad byte[%d]:%x %x", i, b[i], x), b, s, t) + fmt.Printf("bad byte[%d]:%x %x", i, b[i], x) + return false + } + } + return true +} + +func overify(t *testing.T, pb *GoTest, expected string) { + o := old() + err := o.Marshal(pb) + if err != nil { + fmt.Printf("overify marshal-1 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 1", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = o.Unmarshal(pbd) + if err != nil { + t.Fatalf("overify unmarshal err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + o.Reset() + err = o.Marshal(pbd) + if err != nil { + t.Errorf("overify marshal-2 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 2", o.Bytes()) + t.Fatalf("string = %s", expected) + } +} + +// Simple tests for numeric encode/decode primitives (varint, etc.) +func TestNumericPrimitives(t *testing.T) { + for i := uint64(0); i < 1e6; i += 111 { + o := old() + if o.EncodeVarint(i) != nil { + t.Error("EncodeVarint") + break + } + x, e := o.DecodeVarint() + if e != nil { + t.Fatal("DecodeVarint") + } + if x != i { + t.Fatal("varint decode fail:", i, x) + } + + o = old() + if o.EncodeFixed32(i) != nil { + t.Fatal("encFixed32") + } + x, e = o.DecodeFixed32() + if e != nil { + t.Fatal("decFixed32") + } + if x != i { + t.Fatal("fixed32 decode fail:", i, x) + } + + o = old() + if o.EncodeFixed64(i*1234567) != nil { + t.Error("encFixed64") + break + } + x, e = o.DecodeFixed64() + if e != nil { + t.Error("decFixed64") + break + } + if x != i*1234567 { + t.Error("fixed64 decode fail:", i*1234567, x) + break + } + + o = old() + i32 := int32(i - 12345) + if o.EncodeZigzag32(uint64(i32)) != nil { + t.Fatal("EncodeZigzag32") + } + x, e = o.DecodeZigzag32() + if e != nil { + t.Fatal("DecodeZigzag32") + } + if x != uint64(uint32(i32)) { + t.Fatal("zigzag32 decode fail:", i32, x) + } + + o = old() + i64 := int64(i - 12345) + if o.EncodeZigzag64(uint64(i64)) != nil { + t.Fatal("EncodeZigzag64") + } + x, e = o.DecodeZigzag64() + if e != nil { + t.Fatal("DecodeZigzag64") + } + if x != uint64(i64) { + t.Fatal("zigzag64 decode fail:", i64, x) + } + } +} + +// fakeMarshaler is a simple struct implementing Marshaler and Message interfaces. +type fakeMarshaler struct { + b []byte + err error +} + +func (f *fakeMarshaler) Marshal() ([]byte, error) { return f.b, f.err } +func (f *fakeMarshaler) String() string { return fmt.Sprintf("Bytes: %v Error: %v", f.b, f.err) } +func (f *fakeMarshaler) ProtoMessage() {} +func (f *fakeMarshaler) Reset() {} + +type msgWithFakeMarshaler struct { + M *fakeMarshaler `protobuf:"bytes,1,opt,name=fake"` +} + +func (m *msgWithFakeMarshaler) String() string { return CompactTextString(m) } +func (m *msgWithFakeMarshaler) ProtoMessage() {} +func (m *msgWithFakeMarshaler) Reset() {} + +// Simple tests for proto messages that implement the Marshaler interface. +func TestMarshalerEncoding(t *testing.T) { + tests := []struct { + name string + m Message + want []byte + errType reflect.Type + }{ + { + name: "Marshaler that fails", + m: &fakeMarshaler{ + err: errors.New("some marshal err"), + b: []byte{5, 6, 7}, + }, + // Since the Marshal method returned bytes, they should be written to the + // buffer. (For efficiency, we assume that Marshal implementations are + // always correct w.r.t. RequiredNotSetError and output.) + want: []byte{5, 6, 7}, + errType: reflect.TypeOf(errors.New("some marshal err")), + }, + { + name: "Marshaler that fails with RequiredNotSetError", + m: &msgWithFakeMarshaler{ + M: &fakeMarshaler{ + err: &RequiredNotSetError{}, + b: []byte{5, 6, 7}, + }, + }, + // Since there's an error that can be continued after, + // the buffer should be written. + want: []byte{ + 10, 3, // for &msgWithFakeMarshaler + 5, 6, 7, // for &fakeMarshaler + }, + errType: reflect.TypeOf(&RequiredNotSetError{}), + }, + { + name: "Marshaler that succeeds", + m: &fakeMarshaler{ + b: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + want: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + } + for _, test := range tests { + b := NewBuffer(nil) + err := b.Marshal(test.m) + if reflect.TypeOf(err) != test.errType { + t.Errorf("%s: got err %T(%v) wanted %T", test.name, err, err, test.errType) + } + if !reflect.DeepEqual(test.want, b.Bytes()) { + t.Errorf("%s: got bytes %v wanted %v", test.name, b.Bytes(), test.want) + } + if size := Size(test.m); size != len(b.Bytes()) { + t.Errorf("%s: Size(_) = %v, but marshaled to %v bytes", test.name, size, len(b.Bytes())) + } + + m, mErr := Marshal(test.m) + if !bytes.Equal(b.Bytes(), m) { + t.Errorf("%s: Marshal returned %v, but (*Buffer).Marshal wrote %v", test.name, m, b.Bytes()) + } + if !reflect.DeepEqual(err, mErr) { + t.Errorf("%s: Marshal err = %q, but (*Buffer).Marshal returned %q", + test.name, fmt.Sprint(mErr), fmt.Sprint(err)) + } + } +} + +// Simple tests for bytes +func TestBytesPrimitives(t *testing.T) { + o := old() + bytes := []byte{'n', 'o', 'w', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 't', 'i', 'm', 'e'} + if o.EncodeRawBytes(bytes) != nil { + t.Error("EncodeRawBytes") + } + decb, e := o.DecodeRawBytes(false) + if e != nil { + t.Error("DecodeRawBytes") + } + equalbytes(bytes, decb, t) +} + +// Simple tests for strings +func TestStringPrimitives(t *testing.T) { + o := old() + s := "now is the time" + if o.EncodeStringBytes(s) != nil { + t.Error("enc_string") + } + decs, e := o.DecodeStringBytes() + if e != nil { + t.Error("dec_string") + } + if s != decs { + t.Error("string encode/decode fail:", s, decs) + } +} + +// Do we catch the "required bit not set" case? +func TestRequiredBit(t *testing.T) { + o := old() + pb := new(GoTest) + err := o.Marshal(pb) + if err == nil { + t.Error("did not catch missing required fields") + } else if strings.Index(err.Error(), "Kind") < 0 { + t.Error("wrong error type:", err) + } +} + +// Check that all fields are nil. +// Clearly silly, and a residue from a more interesting test with an earlier, +// different initialization property, but it once caught a compiler bug so +// it lives. +func checkInitialized(pb *GoTest, t *testing.T) { + if pb.F_BoolDefaulted != nil { + t.Error("New or Reset did not set boolean:", *pb.F_BoolDefaulted) + } + if pb.F_Int32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Int32Defaulted) + } + if pb.F_Int64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Int64Defaulted) + } + if pb.F_Fixed32Defaulted != nil { + t.Error("New or Reset did not set fixed32:", *pb.F_Fixed32Defaulted) + } + if pb.F_Fixed64Defaulted != nil { + t.Error("New or Reset did not set fixed64:", *pb.F_Fixed64Defaulted) + } + if pb.F_Uint32Defaulted != nil { + t.Error("New or Reset did not set uint32:", *pb.F_Uint32Defaulted) + } + if pb.F_Uint64Defaulted != nil { + t.Error("New or Reset did not set uint64:", *pb.F_Uint64Defaulted) + } + if pb.F_FloatDefaulted != nil { + t.Error("New or Reset did not set float:", *pb.F_FloatDefaulted) + } + if pb.F_DoubleDefaulted != nil { + t.Error("New or Reset did not set double:", *pb.F_DoubleDefaulted) + } + if pb.F_StringDefaulted != nil { + t.Error("New or Reset did not set string:", *pb.F_StringDefaulted) + } + if pb.F_BytesDefaulted != nil { + t.Error("New or Reset did not set bytes:", string(pb.F_BytesDefaulted)) + } + if pb.F_Sint32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Sint32Defaulted) + } + if pb.F_Sint64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Sint64Defaulted) + } +} + +// Does Reset() reset? +func TestReset(t *testing.T) { + pb := initGoTest(true) + // muck with some values + pb.F_BoolDefaulted = Bool(false) + pb.F_Int32Defaulted = Int32(237) + pb.F_Int64Defaulted = Int64(12346) + pb.F_Fixed32Defaulted = Uint32(32000) + pb.F_Fixed64Defaulted = Uint64(666) + pb.F_Uint32Defaulted = Uint32(323232) + pb.F_Uint64Defaulted = nil + pb.F_FloatDefaulted = nil + pb.F_DoubleDefaulted = Float64(0) + pb.F_StringDefaulted = String("gotcha") + pb.F_BytesDefaulted = []byte("asdfasdf") + pb.F_Sint32Defaulted = Int32(123) + pb.F_Sint64Defaulted = Int64(789) + pb.Reset() + checkInitialized(pb, t) +} + +// All required fields set, no defaults provided. +func TestEncodeDecode1(t *testing.T) { + pb := initGoTest(false) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 0x20 + "714000000000000000"+ // field 14, encoding 1, value 0x40 + "78a019"+ // field 15, encoding 0, value 0xca0 = 3232 + "8001c032"+ // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2, string "string" + "b304"+ // field 70, encoding 3, start group + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // field 70, encoding 4, end group + "aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f") // field 103, encoding 0, 0x7f zigzag64 +} + +// All required fields set, defaults provided. +func TestEncodeDecode2(t *testing.T) { + pb := initGoTest(true) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All default fields set to their default value by hand +func TestEncodeDecode3(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolDefaulted = Bool(true) + pb.F_Int32Defaulted = Int32(32) + pb.F_Int64Defaulted = Int64(64) + pb.F_Fixed32Defaulted = Uint32(320) + pb.F_Fixed64Defaulted = Uint64(640) + pb.F_Uint32Defaulted = Uint32(3200) + pb.F_Uint64Defaulted = Uint64(6400) + pb.F_FloatDefaulted = Float32(314159) + pb.F_DoubleDefaulted = Float64(271828) + pb.F_StringDefaulted = String("hello, \"world!\"\n") + pb.F_BytesDefaulted = []byte("Bignose") + pb.F_Sint32Defaulted = Int32(-32) + pb.F_Sint64Defaulted = Int64(-64) + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all non-defaulted optional fields have values. +func TestEncodeDecode4(t *testing.T) { + pb := initGoTest(true) + pb.Table = String("hello") + pb.Param = Int32(7) + pb.OptionalField = initGoTestField() + pb.F_BoolOptional = Bool(true) + pb.F_Int32Optional = Int32(32) + pb.F_Int64Optional = Int64(64) + pb.F_Fixed32Optional = Uint32(3232) + pb.F_Fixed64Optional = Uint64(6464) + pb.F_Uint32Optional = Uint32(323232) + pb.F_Uint64Optional = Uint64(646464) + pb.F_FloatOptional = Float32(32.) + pb.F_DoubleOptional = Float64(64.) + pb.F_StringOptional = String("hello") + pb.F_BytesOptional = []byte("Bignose") + pb.F_Sint32Optional = Int32(-32) + pb.F_Sint64Optional = Int64(-64) + pb.Optionalgroup = initGoTest_OptionalGroup() + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello" + "1807"+ // field 3, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "f00101"+ // field 30, encoding 0, value 1 + "f80120"+ // field 31, encoding 0, value 32 + "800240"+ // field 32, encoding 0, value 64 + "8d02a00c0000"+ // field 33, encoding 5, value 3232 + "91024019000000000000"+ // field 34, encoding 1, value 6464 + "9802a0dd13"+ // field 35, encoding 0, value 323232 + "a002c0ba27"+ // field 36, encoding 0, value 646464 + "ad0200000042"+ // field 37, encoding 5, value 32.0 + "b1020000000000005040"+ // field 38, encoding 1, value 64.0 + "ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "d305"+ // start group field 90 level 1 + "da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional" + "d405"+ // end group field 90 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose" + "f0123f"+ // field 302, encoding 0, value 63 + "f8127f"+ // field 303, encoding 0, value 127 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestEncodeDecode5(t *testing.T) { + pb := initGoTest(true) + pb.RepeatedField = []*GoTestField{initGoTestField(), initGoTestField()} + pb.F_BoolRepeated = []bool{false, true} + pb.F_Int32Repeated = []int32{32, 33} + pb.F_Int64Repeated = []int64{64, 65} + pb.F_Fixed32Repeated = []uint32{3232, 3333} + pb.F_Fixed64Repeated = []uint64{6464, 6565} + pb.F_Uint32Repeated = []uint32{323232, 333333} + pb.F_Uint64Repeated = []uint64{646464, 656565} + pb.F_FloatRepeated = []float32{32., 33.} + pb.F_DoubleRepeated = []float64{64., 65.} + pb.F_StringRepeated = []string{"hello", "sailor"} + pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")} + pb.F_Sint32Repeated = []int32{32, -32} + pb.F_Sint64Repeated = []int64{64, -64} + pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "a00100"+ // field 20, encoding 0, value 0 + "a00101"+ // field 20, encoding 0, value 1 + "a80120"+ // field 21, encoding 0, value 32 + "a80121"+ // field 21, encoding 0, value 33 + "b00140"+ // field 22, encoding 0, value 64 + "b00141"+ // field 22, encoding 0, value 65 + "bd01a00c0000"+ // field 23, encoding 5, value 3232 + "bd01050d0000"+ // field 23, encoding 5, value 3333 + "c1014019000000000000"+ // field 24, encoding 1, value 6464 + "c101a519000000000000"+ // field 24, encoding 1, value 6565 + "c801a0dd13"+ // field 25, encoding 0, value 323232 + "c80195ac14"+ // field 25, encoding 0, value 333333 + "d001c0ba27"+ // field 26, encoding 0, value 646464 + "d001b58928"+ // field 26, encoding 0, value 656565 + "dd0100000042"+ // field 27, encoding 5, value 32.0 + "dd0100000442"+ // field 27, encoding 5, value 33.0 + "e1010000000000005040"+ // field 28, encoding 1, value 64.0 + "e1010000000000405040"+ // field 28, encoding 1, value 65.0 + "ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello" + "ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ca0c03"+"626967"+ // field 201, encoding 2, string "big" + "ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose" + "d00c40"+ // field 202, encoding 0, value 32 + "d00c3f"+ // field 202, encoding 0, value -32 + "d80c8001"+ // field 203, encoding 0, value 64 + "d80c7f"+ // field 203, encoding 0, value -64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, all packed repeated fields given two values. +func TestEncodeDecode6(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolRepeatedPacked = []bool{false, true} + pb.F_Int32RepeatedPacked = []int32{32, 33} + pb.F_Int64RepeatedPacked = []int64{64, 65} + pb.F_Fixed32RepeatedPacked = []uint32{3232, 3333} + pb.F_Fixed64RepeatedPacked = []uint64{6464, 6565} + pb.F_Uint32RepeatedPacked = []uint32{323232, 333333} + pb.F_Uint64RepeatedPacked = []uint64{646464, 656565} + pb.F_FloatRepeatedPacked = []float32{32., 33.} + pb.F_DoubleRepeatedPacked = []float64{64., 65.} + pb.F_Sint32RepeatedPacked = []int32{32, -32} + pb.F_Sint64RepeatedPacked = []int64{64, -64} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1 + "9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33 + "a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65 + "aa0308"+ // field 53, encoding 2, 8 bytes + "a00c0000050d0000"+ // value 3232, value 3333 + "b20310"+ // field 54, encoding 2, 16 bytes + "4019000000000000a519000000000000"+ // value 6464, value 6565 + "ba0306"+ // field 55, encoding 2, 6 bytes + "a0dd1395ac14"+ // value 323232, value 333333 + "c20306"+ // field 56, encoding 2, 6 bytes + "c0ba27b58928"+ // value 646464, value 656565 + "ca0308"+ // field 57, encoding 2, 8 bytes + "0000004200000442"+ // value 32.0, value 33.0 + "d20310"+ // field 58, encoding 2, 16 bytes + "00000000000050400000000000405040"+ // value 64.0, value 65.0 + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "b21f02"+ // field 502, encoding 2, 2 bytes + "403f"+ // value 32, value -32 + "ba1f03"+ // field 503, encoding 2, 3 bytes + "80017f") // value 64, value -64 +} + +// Test that we can encode empty bytes fields. +func TestEncodeDecodeBytes1(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRequired = []byte{} + pb.F_BytesRepeated = [][]byte{{}} + pb.F_BytesOptional = []byte{} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 { + t.Error("required empty bytes field is incorrect") + } + if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil { + t.Error("repeated empty bytes field is incorrect") + } + if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 { + t.Error("optional empty bytes field is incorrect") + } +} + +// Test that we encode nil-valued fields of a repeated bytes field correctly. +// Since entries in a repeated field cannot be nil, nil must mean empty value. +func TestEncodeDecodeBytes2(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRepeated = [][]byte{nil} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil { + t.Error("Unexpected value for repeated bytes field") + } +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestSkippingUnrecognizedFields(t *testing.T) { + o := old() + pb := initGoTestField() + + // Marshal it normally. + o.Marshal(pb) + + // Now new a GoSkipTest record. + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + // Marshal it into same buffer. + o.Marshal(skip) + + pbd := new(GoTestField) + o.Unmarshal(pbd) + + // The __unrecognized field should be a marshaling of GoSkipTest + skipd := new(GoSkipTest) + + o.SetBuf(pbd.XXX_unrecognized) + o.Unmarshal(skipd) + + if *skipd.SkipInt32 != *skip.SkipInt32 { + t.Error("skip int32", skipd.SkipInt32) + } + if *skipd.SkipFixed32 != *skip.SkipFixed32 { + t.Error("skip fixed32", skipd.SkipFixed32) + } + if *skipd.SkipFixed64 != *skip.SkipFixed64 { + t.Error("skip fixed64", skipd.SkipFixed64) + } + if *skipd.SkipString != *skip.SkipString { + t.Error("skip string", *skipd.SkipString) + } + if *skipd.Skipgroup.GroupInt32 != *skip.Skipgroup.GroupInt32 { + t.Error("skip group int32", skipd.Skipgroup.GroupInt32) + } + if *skipd.Skipgroup.GroupString != *skip.Skipgroup.GroupString { + t.Error("skip group string", *skipd.Skipgroup.GroupString) + } +} + +// Check that unrecognized fields of a submessage are preserved. +func TestSubmessageUnrecognizedFields(t *testing.T) { + nm := &NewMessage{ + Nested: &NewMessage_Nested{ + Name: String("Nigel"), + FoodGroup: String("carbs"), + }, + } + b, err := Marshal(nm) + if err != nil { + t.Fatalf("Marshal of NewMessage: %v", err) + } + + // Unmarshal into an OldMessage. + om := new(OldMessage) + if err := Unmarshal(b, om); err != nil { + t.Fatalf("Unmarshal to OldMessage: %v", err) + } + exp := &OldMessage{ + Nested: &OldMessage_Nested{ + Name: String("Nigel"), + // normal protocol buffer users should not do this + XXX_unrecognized: []byte("\x12\x05carbs"), + }, + } + if !Equal(om, exp) { + t.Errorf("om = %v, want %v", om, exp) + } + + // Clone the OldMessage. + om = Clone(om).(*OldMessage) + if !Equal(om, exp) { + t.Errorf("Clone(om) = %v, want %v", om, exp) + } + + // Marshal the OldMessage, then unmarshal it into an empty NewMessage. + if b, err = Marshal(om); err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + t.Logf("Marshal(%v) -> %q", om, b) + nm2 := new(NewMessage) + if err := Unmarshal(b, nm2); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + if !Equal(nm, nm2) { + t.Errorf("NewMessage round-trip: %v => %v", nm, nm2) + } +} + +// Check that an int32 field can be upgraded to an int64 field. +func TestNegativeInt32(t *testing.T) { + om := &OldMessage{ + Num: Int32(-1), + } + b, err := Marshal(om) + if err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + + // Check the size. It should be 11 bytes; + // 1 for the field/wire type, and 10 for the negative number. + if len(b) != 11 { + t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b) + } + + // Unmarshal into a NewMessage. + nm := new(NewMessage) + if err := Unmarshal(b, nm); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + want := &NewMessage{ + Num: Int64(-1), + } + if !Equal(nm, want) { + t.Errorf("nm = %v, want %v", nm, want) + } +} + +// Check that we can grow an array (repeated field) to have many elements. +// This test doesn't depend only on our encoding; for variety, it makes sure +// we create, encode, and decode the correct contents explicitly. It's therefore +// a bit messier. +// This test also uses (and hence tests) the Marshal/Unmarshal functions +// instead of the methods. +func TestBigRepeated(t *testing.T) { + pb := initGoTest(true) + + // Create the arrays + const N = 50 // Internally the library starts much smaller. + pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N) + pb.F_Sint64Repeated = make([]int64, N) + pb.F_Sint32Repeated = make([]int32, N) + pb.F_BytesRepeated = make([][]byte, N) + pb.F_StringRepeated = make([]string, N) + pb.F_DoubleRepeated = make([]float64, N) + pb.F_FloatRepeated = make([]float32, N) + pb.F_Uint64Repeated = make([]uint64, N) + pb.F_Uint32Repeated = make([]uint32, N) + pb.F_Fixed64Repeated = make([]uint64, N) + pb.F_Fixed32Repeated = make([]uint32, N) + pb.F_Int64Repeated = make([]int64, N) + pb.F_Int32Repeated = make([]int32, N) + pb.F_BoolRepeated = make([]bool, N) + pb.RepeatedField = make([]*GoTestField, N) + + // Fill in the arrays with checkable values. + igtf := initGoTestField() + igtrg := initGoTest_RepeatedGroup() + for i := 0; i < N; i++ { + pb.Repeatedgroup[i] = igtrg + pb.F_Sint64Repeated[i] = int64(i) + pb.F_Sint32Repeated[i] = int32(i) + s := fmt.Sprint(i) + pb.F_BytesRepeated[i] = []byte(s) + pb.F_StringRepeated[i] = s + pb.F_DoubleRepeated[i] = float64(i) + pb.F_FloatRepeated[i] = float32(i) + pb.F_Uint64Repeated[i] = uint64(i) + pb.F_Uint32Repeated[i] = uint32(i) + pb.F_Fixed64Repeated[i] = uint64(i) + pb.F_Fixed32Repeated[i] = uint32(i) + pb.F_Int64Repeated[i] = int64(i) + pb.F_Int32Repeated[i] = int32(i) + pb.F_BoolRepeated[i] = i%2 == 0 + pb.RepeatedField[i] = igtf + } + + // Marshal. + buf, _ := Marshal(pb) + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + Unmarshal(buf, pbd) + + // Check the checkable values + for i := uint64(0); i < N; i++ { + if pbd.Repeatedgroup[i] == nil { // TODO: more checking? + t.Error("pbd.Repeatedgroup bad") + } + var x uint64 + x = uint64(pbd.F_Sint64Repeated[i]) + if x != i { + t.Error("pbd.F_Sint64Repeated bad", x, i) + } + x = uint64(pbd.F_Sint32Repeated[i]) + if x != i { + t.Error("pbd.F_Sint32Repeated bad", x, i) + } + s := fmt.Sprint(i) + equalbytes(pbd.F_BytesRepeated[i], []byte(s), t) + if pbd.F_StringRepeated[i] != s { + t.Error("pbd.F_Sint32Repeated bad", pbd.F_StringRepeated[i], i) + } + x = uint64(pbd.F_DoubleRepeated[i]) + if x != i { + t.Error("pbd.F_DoubleRepeated bad", x, i) + } + x = uint64(pbd.F_FloatRepeated[i]) + if x != i { + t.Error("pbd.F_FloatRepeated bad", x, i) + } + x = pbd.F_Uint64Repeated[i] + if x != i { + t.Error("pbd.F_Uint64Repeated bad", x, i) + } + x = uint64(pbd.F_Uint32Repeated[i]) + if x != i { + t.Error("pbd.F_Uint32Repeated bad", x, i) + } + x = pbd.F_Fixed64Repeated[i] + if x != i { + t.Error("pbd.F_Fixed64Repeated bad", x, i) + } + x = uint64(pbd.F_Fixed32Repeated[i]) + if x != i { + t.Error("pbd.F_Fixed32Repeated bad", x, i) + } + x = uint64(pbd.F_Int64Repeated[i]) + if x != i { + t.Error("pbd.F_Int64Repeated bad", x, i) + } + x = uint64(pbd.F_Int32Repeated[i]) + if x != i { + t.Error("pbd.F_Int32Repeated bad", x, i) + } + if pbd.F_BoolRepeated[i] != (i%2 == 0) { + t.Error("pbd.F_BoolRepeated bad", x, i) + } + if pbd.RepeatedField[i] == nil { // TODO: more checking? + t.Error("pbd.RepeatedField bad") + } + } +} + +// Verify we give a useful message when decoding to the wrong structure type. +func TestTypeMismatch(t *testing.T) { + pb1 := initGoTest(true) + + // Marshal + o := old() + o.Marshal(pb1) + + // Now Unmarshal it to the wrong type. + pb2 := initGoTestField() + err := o.Unmarshal(pb2) + if err == nil { + t.Error("expected error, got no error") + } else if !strings.Contains(err.Error(), "bad wiretype") { + t.Error("expected bad wiretype error, got", err) + } +} + +func encodeDecode(t *testing.T, in, out Message, msg string) { + buf, err := Marshal(in) + if err != nil { + t.Fatalf("failed marshaling %v: %v", msg, err) + } + if err := Unmarshal(buf, out); err != nil { + t.Fatalf("failed unmarshaling %v: %v", msg, err) + } +} + +func TestPackedNonPackedDecoderSwitching(t *testing.T) { + np, p := new(NonPackedTest), new(PackedTest) + + // non-packed -> packed + np.A = []int32{0, 1, 1, 2, 3, 5} + encodeDecode(t, np, p, "non-packed -> packed") + if !reflect.DeepEqual(np.A, p.B) { + t.Errorf("failed non-packed -> packed; np.A=%+v, p.B=%+v", np.A, p.B) + } + + // packed -> non-packed + np.Reset() + p.B = []int32{3, 1, 4, 1, 5, 9} + encodeDecode(t, p, np, "packed -> non-packed") + if !reflect.DeepEqual(p.B, np.A) { + t.Errorf("failed packed -> non-packed; p.B=%+v, np.A=%+v", p.B, np.A) + } +} + +func TestProto1RepeatedGroup(t *testing.T) { + pb := &MessageList{ + Message: []*MessageList_Message{ + { + Name: String("blah"), + Count: Int32(7), + }, + // NOTE: pb.Message[1] is a nil + nil, + }, + } + + o := old() + err := o.Marshal(pb) + if err == nil || !strings.Contains(err.Error(), "repeated field Message has nil") { + t.Fatalf("unexpected or no error when marshaling: %v", err) + } +} + +// Test that enums work. Checks for a bug introduced by making enums +// named types instead of int32: newInt32FromUint64 would crash with +// a type mismatch in reflect.PointTo. +func TestEnum(t *testing.T) { + pb := new(GoEnum) + pb.Foo = FOO_FOO1.Enum() + o := old() + if err := o.Marshal(pb); err != nil { + t.Fatal("error encoding enum:", err) + } + pb1 := new(GoEnum) + if err := o.Unmarshal(pb1); err != nil { + t.Fatal("error decoding enum:", err) + } + if *pb1.Foo != FOO_FOO1 { + t.Error("expected 7 but got ", *pb1.Foo) + } +} + +// Enum types have String methods. Check that enum fields can be printed. +// We don't care what the value actually is, just as long as it doesn't crash. +func TestPrintingNilEnumFields(t *testing.T) { + pb := new(GoEnum) + _ = fmt.Sprintf("%+v", pb) +} + +// Verify that absent required fields cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcement(t *testing.T) { + pb := new(GoTestField) + _, err := Marshal(pb) + if err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Label") { + t.Errorf("marshal: bad error type: %v", err) + } + + // A slightly sneaky, yet valid, proto. It encodes the same required field twice, + // so simply counting the required fields is insufficient. + // field 1, encoding 2, value "hi" + buf := []byte("\x0A\x02hi\x0A\x02hi") + err = Unmarshal(buf, pb) + if err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +// Verify that absent required fields in groups cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcementGroups(t *testing.T) { + pb := &GoTestRequiredGroupField{Group: &GoTestRequiredGroupField_Group{}} + if _, err := Marshal(pb); err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.Field") { + t.Errorf("marshal: bad error type: %v", err) + } + + buf := []byte{11, 12} + if err := Unmarshal(buf, pb); err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +func TestTypedNilMarshal(t *testing.T) { + // A typed nil should return ErrNil and not crash. + { + var m *GoEnum + if _, err := Marshal(m); err != ErrNil { + t.Errorf("Marshal(%#v): got %v, want ErrNil", m, err) + } + } + + { + m := &Communique{Union: &Communique_Msg{nil}} + if _, err := Marshal(m); err == nil || err == ErrNil { + t.Errorf("Marshal(%#v): got %v, want errOneofHasNil", m, err) + } + } +} + +// A type that implements the Marshaler interface, but is not nillable. +type nonNillableInt uint64 + +func (nni nonNillableInt) Marshal() ([]byte, error) { + return EncodeVarint(uint64(nni)), nil +} + +type NNIMessage struct { + nni nonNillableInt +} + +func (*NNIMessage) Reset() {} +func (*NNIMessage) String() string { return "" } +func (*NNIMessage) ProtoMessage() {} + +// A type that implements the Marshaler interface and is nillable. +type nillableMessage struct { + x uint64 +} + +func (nm *nillableMessage) Marshal() ([]byte, error) { + return EncodeVarint(nm.x), nil +} + +type NMMessage struct { + nm *nillableMessage +} + +func (*NMMessage) Reset() {} +func (*NMMessage) String() string { return "" } +func (*NMMessage) ProtoMessage() {} + +// Verify a type that uses the Marshaler interface, but has a nil pointer. +func TestNilMarshaler(t *testing.T) { + // Try a struct with a Marshaler field that is nil. + // It should be directly marshable. + nmm := new(NMMessage) + if _, err := Marshal(nmm); err != nil { + t.Error("unexpected error marshaling nmm: ", err) + } + + // Try a struct with a Marshaler field that is not nillable. + nnim := new(NNIMessage) + nnim.nni = 7 + var _ Marshaler = nnim.nni // verify it is truly a Marshaler + if _, err := Marshal(nnim); err != nil { + t.Error("unexpected error marshaling nnim: ", err) + } +} + +func TestAllSetDefaults(t *testing.T) { + // Exercise SetDefaults with all scalar field types. + m := &Defaults{ + // NaN != NaN, so override that here. + F_Nan: Float32(1.7), + } + expected := &Defaults{ + F_Bool: Bool(true), + F_Int32: Int32(32), + F_Int64: Int64(64), + F_Fixed32: Uint32(320), + F_Fixed64: Uint64(640), + F_Uint32: Uint32(3200), + F_Uint64: Uint64(6400), + F_Float: Float32(314159), + F_Double: Float64(271828), + F_String: String(`hello, "world!"` + "\n"), + F_Bytes: []byte("Bignose"), + F_Sint32: Int32(-32), + F_Sint64: Int64(-64), + F_Enum: Defaults_GREEN.Enum(), + F_Pinf: Float32(float32(math.Inf(1))), + F_Ninf: Float32(float32(math.Inf(-1))), + F_Nan: Float32(1.7), + StrZero: String(""), + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("SetDefaults failed\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithSetField(t *testing.T) { + // Check that a set value is not overridden. + m := &Defaults{ + F_Int32: Int32(12), + } + SetDefaults(m) + if v := m.GetF_Int32(); v != 12 { + t.Errorf("m.FInt32 = %v, want 12", v) + } +} + +func TestSetDefaultsWithSubMessage(t *testing.T) { + m := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + }, + } + expected := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + Port: Int32(4000), + }, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithRepeatedSubMessage(t *testing.T) { + m := &MyMessage{ + RepInner: []*InnerMessage{{}}, + } + expected := &MyMessage{ + RepInner: []*InnerMessage{{ + Port: Int32(4000), + }}, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultWithRepeatedNonMessage(t *testing.T) { + m := &MyMessage{ + Pet: []string{"turtle", "wombat"}, + } + expected := Clone(m) + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestMaximumTagNumber(t *testing.T) { + m := &MaxTag{ + LastField: String("natural goat essence"), + } + buf, err := Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal failed: %v", err) + } + m2 := new(MaxTag) + if err := Unmarshal(buf, m2); err != nil { + t.Fatalf("proto.Unmarshal failed: %v", err) + } + if got, want := m2.GetLastField(), *m.LastField; got != want { + t.Errorf("got %q, want %q", got, want) + } +} + +func TestJSON(t *testing.T) { + m := &MyMessage{ + Count: Int32(4), + Pet: []string{"bunny", "kitty"}, + Inner: &InnerMessage{ + Host: String("cauchy"), + }, + Bikeshed: MyMessage_GREEN.Enum(), + } + const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}` + + b, err := json.Marshal(m) + if err != nil { + t.Fatalf("json.Marshal failed: %v", err) + } + s := string(b) + if s != expected { + t.Errorf("got %s\nwant %s", s, expected) + } + + received := new(MyMessage) + if err := json.Unmarshal(b, received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } + + // Test unmarshalling of JSON with symbolic enum name. + const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}` + received.Reset() + if err := json.Unmarshal([]byte(old), received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } +} + +func TestBadWireType(t *testing.T) { + b := []byte{7<<3 | 6} // field 7, wire type 6 + pb := new(OtherMessage) + if err := Unmarshal(b, pb); err == nil { + t.Errorf("Unmarshal did not fail") + } else if !strings.Contains(err.Error(), "unknown wire type") { + t.Errorf("wrong error: %v", err) + } +} + +func TestBytesWithInvalidLength(t *testing.T) { + // If a byte sequence has an invalid (negative) length, Unmarshal should not panic. + b := []byte{2<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0} + Unmarshal(b, new(MyMessage)) +} + +func TestLengthOverflow(t *testing.T) { + // Overflowing a length should not panic. + b := []byte{2<<3 | WireBytes, 1, 1, 3<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01} + Unmarshal(b, new(MyMessage)) +} + +func TestVarintOverflow(t *testing.T) { + // Overflowing a 64-bit length should not be allowed. + b := []byte{1<<3 | WireVarint, 0x01, 3<<3 | WireBytes, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01} + if err := Unmarshal(b, new(MyMessage)); err == nil { + t.Fatalf("Overflowed uint64 length without error") + } +} + +func TestUnmarshalFuzz(t *testing.T) { + const N = 1000 + seed := time.Now().UnixNano() + t.Logf("RNG seed is %d", seed) + rng := rand.New(rand.NewSource(seed)) + buf := make([]byte, 20) + for i := 0; i < N; i++ { + for j := range buf { + buf[j] = byte(rng.Intn(256)) + } + fuzzUnmarshal(t, buf) + } +} + +func TestMergeMessages(t *testing.T) { + pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}} + data, err := Marshal(pb) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + pb1 := new(MessageList) + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("first Unmarshal: %v", err) + } + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("second Unmarshal: %v", err) + } + if len(pb1.Message) != 1 { + t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message)) + } + + pb2 := new(MessageList) + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("first UnmarshalMerge: %v", err) + } + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("second UnmarshalMerge: %v", err) + } + if len(pb2.Message) != 2 { + t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message)) + } +} + +func TestExtensionMarshalOrder(t *testing.T) { + m := &MyMessage{Count: Int(123)} + if err := SetExtension(m, E_Ext_More, &Ext{Data: String("alpha")}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Text, String("aleph")); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Number, Int32(1)); err != nil { + t.Fatalf("SetExtension: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + var orig []byte + for i := 0; i < 100; i++ { + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if i == 0 { + orig = b + continue + } + if !bytes.Equal(b, orig) { + t.Errorf("Bytes differ on attempt #%d", i) + } + } +} + +// Many extensions, because small maps might not iterate differently on each iteration. +var exts = []*ExtensionDesc{ + E_X201, + E_X202, + E_X203, + E_X204, + E_X205, + E_X206, + E_X207, + E_X208, + E_X209, + E_X210, + E_X211, + E_X212, + E_X213, + E_X214, + E_X215, + E_X216, + E_X217, + E_X218, + E_X219, + E_X220, + E_X221, + E_X222, + E_X223, + E_X224, + E_X225, + E_X226, + E_X227, + E_X228, + E_X229, + E_X230, + E_X231, + E_X232, + E_X233, + E_X234, + E_X235, + E_X236, + E_X237, + E_X238, + E_X239, + E_X240, + E_X241, + E_X242, + E_X243, + E_X244, + E_X245, + E_X246, + E_X247, + E_X248, + E_X249, + E_X250, +} + +func TestMessageSetMarshalOrder(t *testing.T) { + m := &MyMessageSet{} + for _, x := range exts { + if err := SetExtension(m, x, &Empty{}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + } + + buf, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + for i := 0; i < 10; i++ { + b1, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if !bytes.Equal(b1, buf) { + t.Errorf("Bytes differ on re-Marshal #%d", i) + } + + m2 := &MyMessageSet{} + if err := Unmarshal(buf, m2); err != nil { + t.Errorf("Unmarshal: %v", err) + } + b2, err := Marshal(m2) + if err != nil { + t.Errorf("re-Marshal: %v", err) + } + if !bytes.Equal(b2, buf) { + t.Errorf("Bytes differ on round-trip #%d", i) + } + } +} + +func TestUnmarshalMergesMessages(t *testing.T) { + // If a nested message occurs twice in the input, + // the fields should be merged when decoding. + a := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("polhode"), + Port: Int32(1234), + }, + } + aData, err := Marshal(a) + if err != nil { + t.Fatalf("Marshal(a): %v", err) + } + b := &OtherMessage{ + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Connected: Bool(true), + }, + } + bData, err := Marshal(b) + if err != nil { + t.Fatalf("Marshal(b): %v", err) + } + want := &OtherMessage{ + Key: Int64(123), + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Port: Int32(1234), + Connected: Bool(true), + }, + } + got := new(OtherMessage) + if err := Unmarshal(append(aData, bData...), got); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + if !Equal(got, want) { + t.Errorf("\n got %v\nwant %v", got, want) + } +} + +func TestEncodingSizes(t *testing.T) { + tests := []struct { + m Message + n int + }{ + {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6}, + {&Defaults{F_Int32: Int32(math.MinInt32)}, 11}, + {&Defaults{F_Uint32: Uint32(uint32(math.MaxInt32) + 1)}, 6}, + {&Defaults{F_Uint32: Uint32(math.MaxUint32)}, 6}, + } + for _, test := range tests { + b, err := Marshal(test.m) + if err != nil { + t.Errorf("Marshal(%v): %v", test.m, err) + continue + } + if len(b) != test.n { + t.Errorf("Marshal(%v) yielded %d bytes, want %d bytes", test.m, len(b), test.n) + } + } +} + +func TestRequiredNotSetError(t *testing.T) { + pb := initGoTest(false) + pb.RequiredField.Label = nil + pb.F_Int32Required = nil + pb.F_Int64Required = nil + + expected := "0807" + // field 1, encoding 0, value 7 + "2206" + "120474797065" + // field 4, encoding 2 (GoTestField) + "5001" + // field 10, encoding 0, value 1 + "6d20000000" + // field 13, encoding 5, value 0x20 + "714000000000000000" + // field 14, encoding 1, value 0x40 + "78a019" + // field 15, encoding 0, value 0xca0 = 3232 + "8001c032" + // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45" + // field 17, encoding 5, value 3232.0 + "9101000000000040b940" + // field 18, encoding 1, value 6464.0 + "9a0106" + "737472696e67" + // field 19, encoding 2, string "string" + "b304" + // field 70, encoding 3, start group + "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required" + "b404" + // field 70, encoding 4, end group + "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes" + "b0063f" + // field 102, encoding 0, 0x3f zigzag32 + "b8067f" // field 103, encoding 0, 0x7f zigzag64 + + o := old() + bytes, err := Marshal(pb) + if _, ok := err.(*RequiredNotSetError); !ok { + fmt.Printf("marshal-1 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", bytes) + t.Fatalf("expected = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-1 wrong err msg: %v", err) + } + if !equal(bytes, expected, t) { + o.DebugPrint("neq 1", bytes) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = Unmarshal(bytes, pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Fatalf("unmarshal err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", bytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 { + t.Errorf("unmarshal wrong err msg: %v", err) + } + bytes, err = Marshal(pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", bytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-2 wrong err msg: %v", err) + } + if !equal(bytes, expected, t) { + o.DebugPrint("neq 2", bytes) + t.Fatalf("string = %s", expected) + } +} + +func fuzzUnmarshal(t *testing.T, data []byte) { + defer func() { + if e := recover(); e != nil { + t.Errorf("These bytes caused a panic: %+v", data) + t.Logf("Stack:\n%s", debug.Stack()) + t.FailNow() + } + }() + + pb := new(MyMessage) + Unmarshal(data, pb) +} + +func TestMapFieldMarshal(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // b should be the concatenation of these three byte sequences in some order. + parts := []string{ + "\n\a\b\x01\x12\x03Rob", + "\n\a\b\x04\x12\x03Ian", + "\n\b\b\x08\x12\x04Dave", + } + ok := false + for i := range parts { + for j := range parts { + if j == i { + continue + } + for k := range parts { + if k == i || k == j { + continue + } + try := parts[i] + parts[j] + parts[k] + if bytes.Equal(b, []byte(try)) { + ok = true + break + } + } + } + } + if !ok { + t.Fatalf("Incorrect Marshal output.\n got %q\nwant %q (or a permutation of that)", b, parts[0]+parts[1]+parts[2]) + } + t.Logf("FYI b: %q", b) + + (new(Buffer)).DebugPrint("Dump of b", b) +} + +func TestMapFieldRoundTrips(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + MsgMapping: map[int64]*FloatingPoint{ + 0x7001: &FloatingPoint{F: Float64(2.0)}, + }, + ByteMapping: map[bool][]byte{ + false: []byte("that's not right!"), + true: []byte("aye, 'tis true!"), + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("FYI b: %q", b) + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + for _, pair := range [][2]interface{}{ + {m.NameMapping, m2.NameMapping}, + {m.MsgMapping, m2.MsgMapping}, + {m.ByteMapping, m2.ByteMapping}, + } { + if !reflect.DeepEqual(pair[0], pair[1]) { + t.Errorf("Map did not survive a round trip.\ninitial: %v\n final: %v", pair[0], pair[1]) + } + } +} + +func TestMapFieldWithNil(t *testing.T) { + m1 := &MessageWithMap{ + MsgMapping: map[int64]*FloatingPoint{ + 1: nil, + }, + } + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.MsgMapping[1]; !ok { + t.Error("msg_mapping[1] not present") + } else if v != nil { + t.Errorf("msg_mapping[1] not nil: %v", v) + } +} + +func TestMapFieldWithNilBytes(t *testing.T) { + m1 := &MessageWithMap{ + ByteMapping: map[bool][]byte{ + false: []byte{}, + true: nil, + }, + } + n := Size(m1) + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if n != len(b) { + t.Errorf("Size(m1) = %d; want len(Marshal(m1)) = %d", n, len(b)) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.ByteMapping[false]; !ok { + t.Error("byte_mapping[false] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[false] not empty: %#v", v) + } + if v, ok := m2.ByteMapping[true]; !ok { + t.Error("byte_mapping[true] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[true] not empty: %#v", v) + } +} + +func TestDecodeMapFieldMissingKey(t *testing.T) { + b := []byte{ + 0x0A, 0x03, // message, tag 1 (name_mapping), of length 3 bytes + // no key + 0x12, 0x01, 0x6D, // string value of length 1 byte, value "m" + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing key: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{0: "m"}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no key was not as expected. got: %v, want %v", got, want) + } +} + +func TestDecodeMapFieldMissingValue(t *testing.T) { + b := []byte{ + 0x0A, 0x02, // message, tag 1 (name_mapping), of length 2 bytes + 0x08, 0x01, // varint key, value 1 + // no value + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing value: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{1: ""}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no value was not as expected. got: %v, want %v", got, want) + } +} + +func TestOneof(t *testing.T) { + m := &Communique{} + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal of empty message with oneof: %v", err) + } + if len(b) != 0 { + t.Errorf("Marshal of empty message yielded too many bytes: %v", b) + } + + m = &Communique{ + Union: &Communique_Name{"Barry"}, + } + + // Round-trip. + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof: %v", err) + } + if len(b) != 7 { // name tag/wire (1) + name len (1) + name (5) + t.Errorf("Incorrect marshal of message with oneof: %v", b) + } + m.Reset() + if err := Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof: %v", err) + } + if x, ok := m.Union.(*Communique_Name); !ok || x.Name != "Barry" { + t.Errorf("After round trip, Union = %+v", m.Union) + } + if name := m.GetName(); name != "Barry" { + t.Errorf("After round trip, GetName = %q, want %q", name, "Barry") + } + + // Let's try with a message in the oneof. + m.Union = &Communique_Msg{&Strings{StringField: String("deep deep string")}} + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof set to message: %v", err) + } + if len(b) != 20 { // msg tag/wire (1) + msg len (1) + msg (1 + 1 + 16) + t.Errorf("Incorrect marshal of message with oneof set to message: %v", b) + } + m.Reset() + if err := Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof set to message: %v", err) + } + ss, ok := m.Union.(*Communique_Msg) + if !ok || ss.Msg.GetStringField() != "deep deep string" { + t.Errorf("After round trip with oneof set to message, Union = %+v", m.Union) + } +} + +func TestInefficientPackedBool(t *testing.T) { + // https://github.com/golang/protobuf/issues/76 + inp := []byte{ + 0x12, 0x02, // 0x12 = 2<<3|2; 2 bytes + // Usually a bool should take a single byte, + // but it is permitted to be any varint. + 0xb9, 0x30, + } + if err := Unmarshal(inp, new(MoreRepeated)); err != nil { + t.Error(err) + } +} + +// Benchmarks + +func testMsg() *GoTest { + pb := initGoTest(true) + const N = 1000 // Internally the library starts much smaller. + pb.F_Int32Repeated = make([]int32, N) + pb.F_DoubleRepeated = make([]float64, N) + for i := 0; i < N; i++ { + pb.F_Int32Repeated[i] = int32(i) + pb.F_DoubleRepeated[i] = float64(i) + } + return pb +} + +func bytesMsg() *GoTest { + pb := initGoTest(true) + buf := make([]byte, 4000) + for i := range buf { + buf[i] = byte(i) + } + pb.F_BytesDefaulted = buf + return pb +} + +func benchmarkMarshal(b *testing.B, pb Message, marshal func(Message) ([]byte, error)) { + d, _ := marshal(pb) + b.SetBytes(int64(len(d))) + b.ResetTimer() + for i := 0; i < b.N; i++ { + marshal(pb) + } +} + +func benchmarkBufferMarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + p.Reset() + err := p.Marshal(pb0) + return p.Bytes(), err + }) +} + +func benchmarkSize(b *testing.B, pb Message) { + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + Size(pb) + return nil, nil + }) +} + +func newOf(pb Message) Message { + in := reflect.ValueOf(pb) + if in.IsNil() { + return pb + } + return reflect.New(in.Type().Elem()).Interface().(Message) +} + +func benchmarkUnmarshal(b *testing.B, pb Message, unmarshal func([]byte, Message) error) { + d, _ := Marshal(pb) + b.SetBytes(int64(len(d))) + pbd := newOf(pb) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + unmarshal(d, pbd) + } +} + +func benchmarkBufferUnmarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkUnmarshal(b, pb, func(d []byte, pb0 Message) error { + p.SetBuf(d) + return p.Unmarshal(pb0) + }) +} + +// Benchmark{Marshal,BufferMarshal,Size,Unmarshal,BufferUnmarshal}{,Bytes} + +func BenchmarkMarshal(b *testing.B) { + benchmarkMarshal(b, testMsg(), Marshal) +} + +func BenchmarkBufferMarshal(b *testing.B) { + benchmarkBufferMarshal(b, testMsg()) +} + +func BenchmarkSize(b *testing.B) { + benchmarkSize(b, testMsg()) +} + +func BenchmarkUnmarshal(b *testing.B) { + benchmarkUnmarshal(b, testMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshal(b *testing.B) { + benchmarkBufferUnmarshal(b, testMsg()) +} + +func BenchmarkMarshalBytes(b *testing.B) { + benchmarkMarshal(b, bytesMsg(), Marshal) +} + +func BenchmarkBufferMarshalBytes(b *testing.B) { + benchmarkBufferMarshal(b, bytesMsg()) +} + +func BenchmarkSizeBytes(b *testing.B) { + benchmarkSize(b, bytesMsg()) +} + +func BenchmarkUnmarshalBytes(b *testing.B) { + benchmarkUnmarshal(b, bytesMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshalBytes(b *testing.B) { + benchmarkBufferUnmarshal(b, bytesMsg()) +} + +func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) { + b.StopTimer() + pb := initGoTestField() + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + pbd := new(GoTestField) + p := NewBuffer(nil) + p.Marshal(pb) + p.Marshal(skip) + p2 := NewBuffer(nil) + + b.StartTimer() + for i := 0; i < b.N; i++ { + p2.SetBuf(p.Bytes()) + p2.Unmarshal(pbd) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/any_test.go b/discovery/vendor/github.com/golang/protobuf/proto/any_test.go new file mode 100644 index 00000000..1a3c22ed --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/any_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "strings" + "testing" + + "github.com/golang/protobuf/proto" + + pb "github.com/golang/protobuf/proto/proto3_proto" + testpb "github.com/golang/protobuf/proto/testdata" + anypb "github.com/golang/protobuf/ptypes/any" +) + +var ( + expandedMarshaler = proto.TextMarshaler{ExpandAny: true} + expandedCompactMarshaler = proto.TextMarshaler{Compact: true, ExpandAny: true} +) + +// anyEqual reports whether two messages which may be google.protobuf.Any or may +// contain google.protobuf.Any fields are equal. We can't use proto.Equal for +// comparison, because semantically equivalent messages may be marshaled to +// binary in different tag order. Instead, trust that TextMarshaler with +// ExpandAny option works and compare the text marshaling results. +func anyEqual(got, want proto.Message) bool { + // if messages are proto.Equal, no need to marshal. + if proto.Equal(got, want) { + return true + } + g := expandedMarshaler.Text(got) + w := expandedMarshaler.Text(want) + return g == w +} + +type golden struct { + m proto.Message + t, c string +} + +var goldenMessages = makeGolden() + +func makeGolden() []golden { + nested := &pb.Nested{Bunny: "Monty"} + nb, err := proto.Marshal(nested) + if err != nil { + panic(err) + } + m1 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m2 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &anypb.Any{TypeUrl: "http://[::1]/type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m3 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &anypb.Any{TypeUrl: `type.googleapis.com/"/` + proto.MessageName(nested), Value: nb}, + } + m4 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &anypb.Any{TypeUrl: "type.googleapis.com/a/path/" + proto.MessageName(nested), Value: nb}, + } + m5 := &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb} + + any1 := &testpb.MyMessage{Count: proto.Int32(47), Name: proto.String("David")} + proto.SetExtension(any1, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("foo")}) + proto.SetExtension(any1, testpb.E_Ext_Text, proto.String("bar")) + any1b, err := proto.Marshal(any1) + if err != nil { + panic(err) + } + any2 := &testpb.MyMessage{Count: proto.Int32(42), Bikeshed: testpb.MyMessage_GREEN.Enum(), RepBytes: [][]byte{[]byte("roboto")}} + proto.SetExtension(any2, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("baz")}) + any2b, err := proto.Marshal(any2) + if err != nil { + panic(err) + } + m6 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + ManyThings: []*anypb.Any{ + &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any2), Value: any2b}, + &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + }, + } + + const ( + m1Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m2Golden = ` +name: "David" +result_count: 47 +anything: < + ["http://[::1]/type.googleapis.com/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m3Golden = ` +name: "David" +result_count: 47 +anything: < + ["type.googleapis.com/\"/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m4Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m5Golden = ` +[type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" +> +` + m6Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 42 + bikeshed: GREEN + rep_bytes: "roboto" + [testdata.Ext.more]: < + data: "baz" + > + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +` + ) + return []golden{ + {m1, strings.TrimSpace(m1Golden) + "\n", strings.TrimSpace(compact(m1Golden)) + " "}, + {m2, strings.TrimSpace(m2Golden) + "\n", strings.TrimSpace(compact(m2Golden)) + " "}, + {m3, strings.TrimSpace(m3Golden) + "\n", strings.TrimSpace(compact(m3Golden)) + " "}, + {m4, strings.TrimSpace(m4Golden) + "\n", strings.TrimSpace(compact(m4Golden)) + " "}, + {m5, strings.TrimSpace(m5Golden) + "\n", strings.TrimSpace(compact(m5Golden)) + " "}, + {m6, strings.TrimSpace(m6Golden) + "\n", strings.TrimSpace(compact(m6Golden)) + " "}, + } +} + +func TestMarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + if got, want := expandedMarshaler.Text(tt.m), tt.t; got != want { + t.Errorf("message %v: got:\n%s\nwant:\n%s", tt.m, got, want) + } + if got, want := expandedCompactMarshaler.Text(tt.m), tt.c; got != want { + t.Errorf("message %v: got:\n`%s`\nwant:\n`%s`", tt.m, got, want) + } + } +} + +func TestUnmarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + want := tt.m + got := proto.Clone(tt.m) + got.Reset() + if err := proto.UnmarshalText(tt.t, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.t, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.t, got, want) + } + got.Reset() + if err := proto.UnmarshalText(tt.c, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.c, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.c, got, want) + } + } +} + +func TestMarshalUnknownAny(t *testing.T) { + m := &pb.Message{ + Anything: &anypb.Any{ + TypeUrl: "foo", + Value: []byte("bar"), + }, + } + want := `anything: < + type_url: "foo" + value: "bar" +> +` + got := expandedMarshaler.Text(m) + if got != want { + t.Errorf("got\n`%s`\nwant\n`%s`", got, want) + } +} + +func TestAmbiguousAny(t *testing.T) { + pb := &anypb.Any{} + err := proto.UnmarshalText(` + type_url: "ttt/proto3_proto.Nested" + value: "\n\x05Monty" + `, pb) + t.Logf("result: %v (error: %v)", expandedMarshaler.Text(pb), err) + if err != nil { + t.Errorf("failed to parse ambiguous Any message: %v", err) + } +} + +func TestUnmarshalOverwriteAny(t *testing.T) { + pb := &anypb.Any{} + err := proto.UnmarshalText(` + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 7: Any message unpacked multiple times, or "type_url" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} + +func TestUnmarshalAnyMixAndMatch(t *testing.T) { + pb := &anypb.Any{} + err := proto.UnmarshalText(` + value: "\n\x05Monty" + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 5: Any message unpacked multiple times, or "value" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/clone_test.go b/discovery/vendor/github.com/golang/protobuf/proto/clone_test.go new file mode 100644 index 00000000..f607ff49 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/clone_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2011 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/golang/protobuf/proto" + + proto3pb "github.com/golang/protobuf/proto/proto3_proto" + pb "github.com/golang/protobuf/proto/testdata" +) + +var cloneTestMessage = &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, +} + +func init() { + ext := &pb.Ext{ + Data: proto.String("extension"), + } + if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil { + panic("SetExtension: " + err.Error()) + } +} + +func TestClone(t *testing.T) { + m := proto.Clone(cloneTestMessage).(*pb.MyMessage) + if !proto.Equal(m, cloneTestMessage) { + t.Errorf("Clone(%v) = %v", cloneTestMessage, m) + } + + // Verify it was a deep copy. + *m.Inner.Port++ + if proto.Equal(m, cloneTestMessage) { + t.Error("Mutating clone changed the original") + } + // Byte fields and repeated fields should be copied. + if &m.Pet[0] == &cloneTestMessage.Pet[0] { + t.Error("Pet: repeated field not copied") + } + if &m.Others[0] == &cloneTestMessage.Others[0] { + t.Error("Others: repeated field not copied") + } + if &m.Others[0].Value[0] == &cloneTestMessage.Others[0].Value[0] { + t.Error("Others[0].Value: bytes field not copied") + } + if &m.RepBytes[0] == &cloneTestMessage.RepBytes[0] { + t.Error("RepBytes: repeated field not copied") + } + if &m.RepBytes[0][0] == &cloneTestMessage.RepBytes[0][0] { + t.Error("RepBytes[0]: bytes field not copied") + } +} + +func TestCloneNil(t *testing.T) { + var m *pb.MyMessage + if c := proto.Clone(m); !proto.Equal(m, c) { + t.Errorf("Clone(%v) = %v", m, c) + } +} + +var mergeTests = []struct { + src, dst, want proto.Message +}{ + { + src: &pb.MyMessage{ + Count: proto.Int32(42), + }, + dst: &pb.MyMessage{ + Name: proto.String("Dave"), + }, + want: &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + }, + }, + { + src: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + }, + Pet: []string{"horsey"}, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + }, + dst: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + { + // Explicitly test a src=nil field + Inner: nil, + }, + }, + }, + want: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty", "horsey"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + {}, + { + Value: []byte("some bytes"), + }, + }, + }, + }, + { + src: &pb.MyMessage{ + RepBytes: [][]byte{[]byte("wow")}, + }, + dst: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham")}, + }, + want: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, + }, + }, + // Check that a scalar bytes field replaces rather than appends. + { + src: &pb.OtherMessage{Value: []byte("foo")}, + dst: &pb.OtherMessage{Value: []byte("bar")}, + want: &pb.OtherMessage{Value: []byte("foo")}, + }, + { + src: &pb.MessageWithMap{ + NameMapping: map[int32]string{6: "Nigel"}, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: &pb.FloatingPoint{F: proto.Float64(2.0)}, + 0x4002: &pb.FloatingPoint{ + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + dst: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Bruce", // should be overwritten + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4002: &pb.FloatingPoint{ + F: proto.Float64(3.0), + Exact: proto.Bool(true), + }, // the entire message should be overwritten + }, + }, + want: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Nigel", + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: &pb.FloatingPoint{F: proto.Float64(2.0)}, + 0x4002: &pb.FloatingPoint{ + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + }, + // proto3 shouldn't merge zero values, + // in the same way that proto2 shouldn't merge nils. + { + src: &proto3pb.Message{ + Name: "Aaron", + Data: []byte(""), // zero value, but not nil + }, + dst: &proto3pb.Message{ + HeightInCm: 176, + Data: []byte("texas!"), + }, + want: &proto3pb.Message{ + Name: "Aaron", + HeightInCm: 176, + Data: []byte("texas!"), + }, + }, + // Oneof fields should merge by assignment. + { + src: &pb.Communique{ + Union: &pb.Communique_Number{41}, + }, + dst: &pb.Communique{ + Union: &pb.Communique_Name{"Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Number{41}, + }, + }, + // Oneof nil is the same as not set. + { + src: &pb.Communique{}, + dst: &pb.Communique{ + Union: &pb.Communique_Name{"Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Name{"Bobby Tables"}, + }, + }, + { + src: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": &proto3pb.Nested{Cute: true}, // replace + "kay_b": &proto3pb.Nested{Bunny: "rabbit"}, // insert + }, + }, + dst: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": &proto3pb.Nested{Bunny: "lost"}, // replaced + "kay_c": &proto3pb.Nested{Bunny: "bunny"}, // keep + }, + }, + want: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": &proto3pb.Nested{Cute: true}, + "kay_b": &proto3pb.Nested{Bunny: "rabbit"}, + "kay_c": &proto3pb.Nested{Bunny: "bunny"}, + }, + }, + }, +} + +func TestMerge(t *testing.T) { + for _, m := range mergeTests { + got := proto.Clone(m.dst) + proto.Merge(got, m.src) + if !proto.Equal(got, m.want) { + t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/decode_test.go b/discovery/vendor/github.com/golang/protobuf/proto/decode_test.go new file mode 100644 index 00000000..2c4c31d1 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/decode_test.go @@ -0,0 +1,258 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// +build go1.7 + +package proto_test + +import ( + "fmt" + "testing" + + "github.com/golang/protobuf/proto" + tpb "github.com/golang/protobuf/proto/proto3_proto" +) + +var ( + bytesBlackhole []byte + msgBlackhole = new(tpb.Message) +) + +// BenchmarkVarint32ArraySmall shows the performance on an array of small int32 fields (1 and +// 2 bytes long). +func BenchmarkVarint32ArraySmall(b *testing.B) { + for i := uint(1); i <= 10; i++ { + dist := genInt32Dist([7]int{0, 3, 1}, 1<unmarshal. +} + +func TestMarshalUnmarshalRepeatedExtension(t *testing.T) { + // Add a repeated extension to the result. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + // Marshal message with a repeated extension. + msg1 := new(pb.OtherMessage) + err := proto.SetExtension(msg1, pb.E_RComplex, test.ext) + if err != nil { + t.Fatalf("[%s] Error setting extension: %v", test.name, err) + } + b, err := proto.Marshal(msg1) + if err != nil { + t.Fatalf("[%s] Error marshaling message: %v", test.name, err) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err = proto.Unmarshal(b, msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_RComplex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.([]*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(ext, test.ext) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %v want: %v\n", test.name, ext, test.ext) + } + } +} + +func TestUnmarshalRepeatingNonRepeatedExtension(t *testing.T) { + // We may see multiple instances of the same extension in the wire + // format. For example, the proto compiler may encode custom options in + // this way. Here, we verify that we merge the extensions together. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + var buf bytes.Buffer + var want pb.ComplexExtension + + // Generate a serialized representation of a repeated extension + // by catenating bytes together. + for i, e := range test.ext { + // Merge to create the wanted proto. + proto.Merge(&want, e) + + // serialize the message + msg := new(pb.OtherMessage) + err := proto.SetExtension(msg, pb.E_Complex, e) + if err != nil { + t.Fatalf("[%s] Error setting extension %d: %v", test.name, i, err) + } + b, err := proto.Marshal(msg) + if err != nil { + t.Fatalf("[%s] Error marshaling message %d: %v", test.name, i, err) + } + buf.Write(b) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err := proto.Unmarshal(buf.Bytes(), msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_Complex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.(*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(*ext, want) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %s want: %s\n", test.name, ext, want) + } + } +} + +func TestClearAllExtensions(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + m := &pb.MyMessage{} + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + if !proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got false, want true", proto.MarshalTextString(m)) + } + proto.ClearAllExtensions(m) + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } +} + +func TestMarshalRace(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + + m := &pb.MyMessage{Count: proto.Int32(4)} + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + + var g errgroup.Group + for n := 3; n > 0; n-- { + g.Go(func() error { + _, err := proto.Marshal(m) + return err + }) + } + if err := g.Wait(); err != nil { + t.Fatal(err) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/map_test.go b/discovery/vendor/github.com/golang/protobuf/proto/map_test.go new file mode 100644 index 00000000..313e8792 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/map_test.go @@ -0,0 +1,46 @@ +package proto_test + +import ( + "fmt" + "testing" + + "github.com/golang/protobuf/proto" + ppb "github.com/golang/protobuf/proto/proto3_proto" +) + +func marshalled() []byte { + m := &ppb.IntMaps{} + for i := 0; i < 1000; i++ { + m.Maps = append(m.Maps, &ppb.IntMap{ + Rtt: map[int32]int32{1: 2}, + }) + } + b, err := proto.Marshal(m) + if err != nil { + panic(fmt.Sprintf("Can't marshal %+v: %v", m, err)) + } + return b +} + +func BenchmarkConcurrentMapUnmarshal(b *testing.B) { + in := marshalled() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } + }) +} + +func BenchmarkSequentialMapUnmarshal(b *testing.B) { + in := marshalled() + b.ResetTimer() + for i := 0; i < b.N; i++ { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/message_set_test.go b/discovery/vendor/github.com/golang/protobuf/proto/message_set_test.go new file mode 100644 index 00000000..353a3ea7 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/message_set_test.go @@ -0,0 +1,66 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "bytes" + "testing" +) + +func TestUnmarshalMessageSetWithDuplicate(t *testing.T) { + // Check that a repeated message set entry will be concatenated. + in := &messageSet{ + Item: []*_MessageSet_Item{ + {TypeId: Int32(12345), Message: []byte("hoo")}, + {TypeId: Int32(12345), Message: []byte("hah")}, + }, + } + b, err := Marshal(in) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("Marshaled bytes: %q", b) + + var extensions XXX_InternalExtensions + if err := UnmarshalMessageSet(b, &extensions); err != nil { + t.Fatalf("UnmarshalMessageSet: %v", err) + } + ext, ok := extensions.p.extensionMap[12345] + if !ok { + t.Fatalf("Didn't retrieve extension 12345; map is %v", extensions.p.extensionMap) + } + // Skip wire type/field number and length varints. + got := skipVarint(skipVarint(ext.enc)) + if want := []byte("hoohah"); !bytes.Equal(got, want) { + t.Errorf("Combined extension is %q, want %q", got, want) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/proto3_test.go b/discovery/vendor/github.com/golang/protobuf/proto/proto3_test.go new file mode 100644 index 00000000..735837f2 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/proto3_test.go @@ -0,0 +1,135 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/golang/protobuf/proto" + pb "github.com/golang/protobuf/proto/proto3_proto" + tpb "github.com/golang/protobuf/proto/testdata" +) + +func TestProto3ZeroValues(t *testing.T) { + tests := []struct { + desc string + m proto.Message + }{ + {"zero message", &pb.Message{}}, + {"empty bytes field", &pb.Message{Data: []byte{}}}, + } + for _, test := range tests { + b, err := proto.Marshal(test.m) + if err != nil { + t.Errorf("%s: proto.Marshal: %v", test.desc, err) + continue + } + if len(b) > 0 { + t.Errorf("%s: Encoding is non-empty: %q", test.desc, b) + } + } +} + +func TestRoundTripProto3(t *testing.T) { + m := &pb.Message{ + Name: "David", // (2 | 1<<3): 0x0a 0x05 "David" + Hilarity: pb.Message_PUNS, // (0 | 2<<3): 0x10 0x01 + HeightInCm: 178, // (0 | 3<<3): 0x18 0xb2 0x01 + Data: []byte("roboto"), // (2 | 4<<3): 0x20 0x06 "roboto" + ResultCount: 47, // (0 | 7<<3): 0x38 0x2f + TrueScotsman: true, // (0 | 8<<3): 0x40 0x01 + Score: 8.1, // (5 | 9<<3): 0x4d <8.1> + + Key: []uint64{1, 0xdeadbeef}, + Nested: &pb.Nested{ + Bunny: "Monty", + }, + } + t.Logf(" m: %v", m) + + b, err := proto.Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal: %v", err) + } + t.Logf(" b: %q", b) + + m2 := new(pb.Message) + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatalf("proto.Unmarshal: %v", err) + } + t.Logf("m2: %v", m2) + + if !proto.Equal(m, m2) { + t.Errorf("proto.Equal returned false:\n m: %v\nm2: %v", m, m2) + } +} + +func TestGettersForBasicTypesExist(t *testing.T) { + var m pb.Message + if got := m.GetNested().GetBunny(); got != "" { + t.Errorf("m.GetNested().GetBunny() = %q, want empty string", got) + } + if got := m.GetNested().GetCute(); got { + t.Errorf("m.GetNested().GetCute() = %t, want false", got) + } +} + +func TestProto3SetDefaults(t *testing.T) { + in := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: new(tpb.SubDefaults), + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": new(tpb.SubDefaults), + }, + } + + got := proto.Clone(in).(*pb.Message) + proto.SetDefaults(got) + + // There are no defaults in proto3. Everything should be the zero value, but + // we need to remember to set defaults for nested proto2 messages. + want := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: &tpb.SubDefaults{N: proto.Int64(7)}, + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": &tpb.SubDefaults{N: proto.Int64(7)}, + }, + } + + if !proto.Equal(got, want) { + t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/size2_test.go b/discovery/vendor/github.com/golang/protobuf/proto/size2_test.go new file mode 100644 index 00000000..a2729c39 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/size2_test.go @@ -0,0 +1,63 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "testing" +) + +// This is a separate file and package from size_test.go because that one uses +// generated messages and thus may not be in package proto without having a circular +// dependency, whereas this file tests unexported details of size.go. + +func TestVarintSize(t *testing.T) { + // Check the edge cases carefully. + testCases := []struct { + n uint64 + size int + }{ + {0, 1}, + {1, 1}, + {127, 1}, + {128, 2}, + {16383, 2}, + {16384, 3}, + {1<<63 - 1, 9}, + {1 << 63, 10}, + } + for _, tc := range testCases { + size := sizeVarint(tc.n) + if size != tc.size { + t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/size_test.go b/discovery/vendor/github.com/golang/protobuf/proto/size_test.go new file mode 100644 index 00000000..af1034dc --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/size_test.go @@ -0,0 +1,164 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "log" + "strings" + "testing" + + . "github.com/golang/protobuf/proto" + proto3pb "github.com/golang/protobuf/proto/proto3_proto" + pb "github.com/golang/protobuf/proto/testdata" +) + +var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)} + +// messageWithExtension2 is in equal_test.go. +var messageWithExtension3 = &pb.MyMessage{Count: Int32(8)} + +func init() { + if err := SetExtension(messageWithExtension1, pb.E_Ext_More, &pb.Ext{Data: String("Abbott")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + if err := SetExtension(messageWithExtension3, pb.E_Ext_More, &pb.Ext{Data: String("Costello")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + + // Force messageWithExtension3 to have the extension encoded. + Marshal(messageWithExtension3) + +} + +var SizeTests = []struct { + desc string + pb Message +}{ + {"empty", &pb.OtherMessage{}}, + // Basic types. + {"bool", &pb.Defaults{F_Bool: Bool(true)}}, + {"int32", &pb.Defaults{F_Int32: Int32(12)}}, + {"negative int32", &pb.Defaults{F_Int32: Int32(-1)}}, + {"small int64", &pb.Defaults{F_Int64: Int64(1)}}, + {"big int64", &pb.Defaults{F_Int64: Int64(1 << 20)}}, + {"negative int64", &pb.Defaults{F_Int64: Int64(-1)}}, + {"fixed32", &pb.Defaults{F_Fixed32: Uint32(71)}}, + {"fixed64", &pb.Defaults{F_Fixed64: Uint64(72)}}, + {"uint32", &pb.Defaults{F_Uint32: Uint32(123)}}, + {"uint64", &pb.Defaults{F_Uint64: Uint64(124)}}, + {"float", &pb.Defaults{F_Float: Float32(12.6)}}, + {"double", &pb.Defaults{F_Double: Float64(13.9)}}, + {"string", &pb.Defaults{F_String: String("niles")}}, + {"bytes", &pb.Defaults{F_Bytes: []byte("wowsa")}}, + {"bytes, empty", &pb.Defaults{F_Bytes: []byte{}}}, + {"sint32", &pb.Defaults{F_Sint32: Int32(65)}}, + {"sint64", &pb.Defaults{F_Sint64: Int64(67)}}, + {"enum", &pb.Defaults{F_Enum: pb.Defaults_BLUE.Enum()}}, + // Repeated. + {"empty repeated bool", &pb.MoreRepeated{Bools: []bool{}}}, + {"repeated bool", &pb.MoreRepeated{Bools: []bool{false, true, true, false}}}, + {"packed repeated bool", &pb.MoreRepeated{BoolsPacked: []bool{false, true, true, false, true, true, true}}}, + {"repeated int32", &pb.MoreRepeated{Ints: []int32{1, 12203, 1729, -1}}}, + {"repeated int32 packed", &pb.MoreRepeated{IntsPacked: []int32{1, 12203, 1729}}}, + {"repeated int64 packed", &pb.MoreRepeated{Int64SPacked: []int64{ + // Need enough large numbers to verify that the header is counting the number of bytes + // for the field, not the number of elements. + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + }}}, + {"repeated string", &pb.MoreRepeated{Strings: []string{"r", "ken", "gri"}}}, + {"repeated fixed", &pb.MoreRepeated{Fixeds: []uint32{1, 2, 3, 4}}}, + // Nested. + {"nested", &pb.OldMessage{Nested: &pb.OldMessage_Nested{Name: String("whatever")}}}, + {"group", &pb.GroupOld{G: &pb.GroupOld_G{X: Int32(12345)}}}, + // Other things. + {"unrecognized", &pb.MoreRepeated{XXX_unrecognized: []byte{13<<3 | 0, 4}}}, + {"extension (unencoded)", messageWithExtension1}, + {"extension (encoded)", messageWithExtension3}, + // proto3 message + {"proto3 empty", &proto3pb.Message{}}, + {"proto3 bool", &proto3pb.Message{TrueScotsman: true}}, + {"proto3 int64", &proto3pb.Message{ResultCount: 1}}, + {"proto3 uint32", &proto3pb.Message{HeightInCm: 123}}, + {"proto3 float", &proto3pb.Message{Score: 12.6}}, + {"proto3 string", &proto3pb.Message{Name: "Snezana"}}, + {"proto3 bytes", &proto3pb.Message{Data: []byte("wowsa")}}, + {"proto3 bytes, empty", &proto3pb.Message{Data: []byte{}}}, + {"proto3 enum", &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 map field with empty bytes", &proto3pb.MessageWithMap{ByteMapping: map[bool][]byte{false: []byte{}}}}, + + {"map field", &pb.MessageWithMap{NameMapping: map[int32]string{1: "Rob", 7: "Andrew"}}}, + {"map field with message", &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{0x7001: &pb.FloatingPoint{F: Float64(2.0)}}}}, + {"map field with bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: []byte("this time for sure")}}}, + {"map field with empty bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: []byte{}}}}, + + {"map field with big entry", &pb.MessageWithMap{NameMapping: map[int32]string{8: strings.Repeat("x", 125)}}}, + {"map field with big key and val", &pb.MessageWithMap{StrToStr: map[string]string{strings.Repeat("x", 70): strings.Repeat("y", 70)}}}, + {"map field with big numeric key", &pb.MessageWithMap{NameMapping: map[int32]string{0xf00d: "om nom nom"}}}, + + {"oneof not set", &pb.Oneof{}}, + {"oneof bool", &pb.Oneof{Union: &pb.Oneof_F_Bool{true}}}, + {"oneof zero int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{0}}}, + {"oneof big int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{1 << 20}}}, + {"oneof int64", &pb.Oneof{Union: &pb.Oneof_F_Int64{42}}}, + {"oneof fixed32", &pb.Oneof{Union: &pb.Oneof_F_Fixed32{43}}}, + {"oneof fixed64", &pb.Oneof{Union: &pb.Oneof_F_Fixed64{44}}}, + {"oneof uint32", &pb.Oneof{Union: &pb.Oneof_F_Uint32{45}}}, + {"oneof uint64", &pb.Oneof{Union: &pb.Oneof_F_Uint64{46}}}, + {"oneof float", &pb.Oneof{Union: &pb.Oneof_F_Float{47.1}}}, + {"oneof double", &pb.Oneof{Union: &pb.Oneof_F_Double{48.9}}}, + {"oneof string", &pb.Oneof{Union: &pb.Oneof_F_String{"Rhythmic Fman"}}}, + {"oneof bytes", &pb.Oneof{Union: &pb.Oneof_F_Bytes{[]byte("let go")}}}, + {"oneof sint32", &pb.Oneof{Union: &pb.Oneof_F_Sint32{50}}}, + {"oneof sint64", &pb.Oneof{Union: &pb.Oneof_F_Sint64{51}}}, + {"oneof enum", &pb.Oneof{Union: &pb.Oneof_F_Enum{pb.MyMessage_BLUE}}}, + {"message for oneof", &pb.GoTestField{Label: String("k"), Type: String("v")}}, + {"oneof message", &pb.Oneof{Union: &pb.Oneof_F_Message{&pb.GoTestField{Label: String("k"), Type: String("v")}}}}, + {"oneof group", &pb.Oneof{Union: &pb.Oneof_FGroup{&pb.Oneof_F_Group{X: Int32(52)}}}}, + {"oneof largest tag", &pb.Oneof{Union: &pb.Oneof_F_Largest_Tag{1}}}, + {"multiple oneofs", &pb.Oneof{Union: &pb.Oneof_F_Int32{1}, Tormato: &pb.Oneof_Value{2}}}, +} + +func TestSize(t *testing.T) { + for _, tc := range SizeTests { + size := Size(tc.pb) + b, err := Marshal(tc.pb) + if err != nil { + t.Errorf("%v: Marshal failed: %v", tc.desc, err) + continue + } + if size != len(b) { + t.Errorf("%v: Size(%v) = %d, want %d", tc.desc, tc.pb, size, len(b)) + t.Logf("%v: bytes: %#v", tc.desc, b) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/testdata/golden_test.go b/discovery/vendor/github.com/golang/protobuf/proto/testdata/golden_test.go new file mode 100644 index 00000000..7172d0e9 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/testdata/golden_test.go @@ -0,0 +1,86 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Verify that the compiler output for test.proto is unchanged. + +package testdata + +import ( + "crypto/sha1" + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "testing" +) + +// sum returns in string form (for easy comparison) the SHA-1 hash of the named file. +func sum(t *testing.T, name string) string { + data, err := ioutil.ReadFile(name) + if err != nil { + t.Fatal(err) + } + t.Logf("sum(%q): length is %d", name, len(data)) + hash := sha1.New() + _, err = hash.Write(data) + if err != nil { + t.Fatal(err) + } + return fmt.Sprintf("% x", hash.Sum(nil)) +} + +func run(t *testing.T, name string, args ...string) { + cmd := exec.Command(name, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + t.Fatal(err) + } +} + +func TestGolden(t *testing.T) { + // Compute the original checksum. + goldenSum := sum(t, "test.pb.go") + // Run the proto compiler. + run(t, "protoc", "--go_out="+os.TempDir(), "test.proto") + newFile := filepath.Join(os.TempDir(), "test.pb.go") + defer os.Remove(newFile) + // Compute the new checksum. + newSum := sum(t, newFile) + // Verify + if newSum != goldenSum { + run(t, "diff", "-u", "test.pb.go", newFile) + t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/text_parser_test.go b/discovery/vendor/github.com/golang/protobuf/proto/text_parser_test.go new file mode 100644 index 00000000..8f7cb4d2 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/text_parser_test.go @@ -0,0 +1,673 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "math" + "reflect" + "testing" + + . "github.com/golang/protobuf/proto" + proto3pb "github.com/golang/protobuf/proto/proto3_proto" + . "github.com/golang/protobuf/proto/testdata" +) + +type UnmarshalTextTest struct { + in string + err string // if "", no error expected + out *MyMessage +} + +func buildExtStructTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_More, &Ext{ + Data: String("Hello, world!"), + }) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtDataTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_Text, String("Hello, world!")) + SetExtension(msg, E_Ext_Number, Int32(1729)) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtRepStringTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + if err := SetExtension(msg, E_Greeting, []string{"bula", "hola"}); err != nil { + panic(err) + } + return UnmarshalTextTest{in: text, out: msg} +} + +var unMarshalTextTests = []UnmarshalTextTest{ + // Basic + { + in: " count:42\n name:\"Dave\" ", + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + }, + }, + + // Empty quoted string + { + in: `count:42 name:""`, + out: &MyMessage{ + Count: Int32(42), + Name: String(""), + }, + }, + + // Quoted string concatenation with double quotes + { + in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenation with single quotes + { + in: "count:42 name: 'My name is '\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenations with mixed quotes + { + in: "count:42 name: 'My name is '\n\"elsewhere\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + { + in: "count:42 name: \"My name is \"\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string with escaped apostrophe + { + in: `count:42 name: "HOLIDAY - New Year\'s Day"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("HOLIDAY - New Year's Day"), + }, + }, + + // Quoted string with single quote + { + in: `count:42 name: 'Roger "The Ramster" Ramjet'`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`Roger "The Ramster" Ramjet`), + }, + }, + + // Quoted string with all the accepted special characters from the C++ test + { + in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"), + }, + }, + + // Quoted string with quoted backslash + { + in: `count:42 name: "\\'xyz"`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`\'xyz`), + }, + }, + + // Quoted string with UTF-8 bytes. + { + in: "count:42 name: '\303\277\302\201\xAB'", + out: &MyMessage{ + Count: Int32(42), + Name: String("\303\277\302\201\xAB"), + }, + }, + + // Bad quoted string + { + in: `inner: < host: "\0" >` + "\n", + err: `line 1.15: invalid quoted string "\0": \0 requires 2 following digits`, + }, + + // Number too large for int64 + { + in: "count: 1 others { key: 123456789012345678901 }", + err: "line 1.23: invalid int64: 123456789012345678901", + }, + + // Number too large for int32 + { + in: "count: 1234567890123", + err: "line 1.7: invalid int32: 1234567890123", + }, + + // Number in hexadecimal + { + in: "count: 0x2beef", + out: &MyMessage{ + Count: Int32(0x2beef), + }, + }, + + // Number in octal + { + in: "count: 024601", + out: &MyMessage{ + Count: Int32(024601), + }, + }, + + // Floating point number with "f" suffix + { + in: "count: 4 others:< weight: 17.0f >", + out: &MyMessage{ + Count: Int32(4), + Others: []*OtherMessage{ + { + Weight: Float32(17), + }, + }, + }, + }, + + // Floating point positive infinity + { + in: "count: 4 bigfloat: inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(1)), + }, + }, + + // Floating point negative infinity + { + in: "count: 4 bigfloat: -inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(-1)), + }, + }, + + // Number too large for float32 + { + in: "others:< weight: 12345678901234567890123456789012345678901234567890 >", + err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890", + }, + + // Number posing as a quoted string + { + in: `inner: < host: 12 >` + "\n", + err: `line 1.15: invalid string: 12`, + }, + + // Quoted string posing as int32 + { + in: `count: "12"`, + err: `line 1.7: invalid int32: "12"`, + }, + + // Quoted string posing a float32 + { + in: `others:< weight: "17.4" >`, + err: `line 1.17: invalid float32: "17.4"`, + }, + + // Enum + { + in: `count:42 bikeshed: BLUE`, + out: &MyMessage{ + Count: Int32(42), + Bikeshed: MyMessage_BLUE.Enum(), + }, + }, + + // Repeated field + { + in: `count:42 pet: "horsey" pet:"bunny"`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated field with list notation + { + in: `count:42 pet: ["horsey", "bunny"]`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated message with/without colon and <>/{} + { + in: `count:42 others:{} others{} others:<> others:{}`, + out: &MyMessage{ + Count: Int32(42), + Others: []*OtherMessage{ + {}, + {}, + {}, + {}, + }, + }, + }, + + // Missing colon for inner message + { + in: `count:42 inner < host: "cauchy.syd" >`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("cauchy.syd"), + }, + }, + }, + + // Missing colon for string field + { + in: `name "Dave"`, + err: `line 1.5: expected ':', found "\"Dave\""`, + }, + + // Missing colon for int32 field + { + in: `count 42`, + err: `line 1.6: expected ':', found "42"`, + }, + + // Missing required field + { + in: `name: "Pawel"`, + err: `proto: required field "testdata.MyMessage.count" not set`, + out: &MyMessage{ + Name: String("Pawel"), + }, + }, + + // Missing required field in a required submessage + { + in: `count: 42 we_must_go_deeper < leo_finally_won_an_oscar <> >`, + err: `proto: required field "testdata.InnerMessage.host" not set`, + out: &MyMessage{ + Count: Int32(42), + WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}}, + }, + }, + + // Repeated non-repeated field + { + in: `name: "Rob" name: "Russ"`, + err: `line 1.12: non-repeated field "name" was repeated`, + }, + + // Group + { + in: `count: 17 SomeGroup { group_field: 12 }`, + out: &MyMessage{ + Count: Int32(17), + Somegroup: &MyMessage_SomeGroup{ + GroupField: Int32(12), + }, + }, + }, + + // Semicolon between fields + { + in: `count:3;name:"Calvin"`, + out: &MyMessage{ + Count: Int32(3), + Name: String("Calvin"), + }, + }, + // Comma between fields + { + in: `count:4,name:"Ezekiel"`, + out: &MyMessage{ + Count: Int32(4), + Name: String("Ezekiel"), + }, + }, + + // Boolean false + { + in: `count:42 inner { host: "example.com" connected: false }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean true + { + in: `count:42 inner { host: "example.com" connected: true }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean 0 + { + in: `count:42 inner { host: "example.com" connected: 0 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean 1 + { + in: `count:42 inner { host: "example.com" connected: 1 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean f + { + in: `count:42 inner { host: "example.com" connected: f }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean t + { + in: `count:42 inner { host: "example.com" connected: t }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean False + { + in: `count:42 inner { host: "example.com" connected: False }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean True + { + in: `count:42 inner { host: "example.com" connected: True }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + + // Extension + buildExtStructTest(`count: 42 [testdata.Ext.more]:`), + buildExtStructTest(`count: 42 [testdata.Ext.more] {data:"Hello, world!"}`), + buildExtDataTest(`count: 42 [testdata.Ext.text]:"Hello, world!" [testdata.Ext.number]:1729`), + buildExtRepStringTest(`count: 42 [testdata.greeting]:"bula" [testdata.greeting]:"hola"`), + + // Big all-in-one + { + in: "count:42 # Meaning\n" + + `name:"Dave" ` + + `quote:"\"I didn't want to go.\"" ` + + `pet:"bunny" ` + + `pet:"kitty" ` + + `pet:"horsey" ` + + `inner:<` + + ` host:"footrest.syd" ` + + ` port:7001 ` + + ` connected:true ` + + `> ` + + `others:<` + + ` key:3735928559 ` + + ` value:"\x01A\a\f" ` + + `> ` + + `others:<` + + " weight:58.9 # Atomic weight of Co\n" + + ` inner:<` + + ` host:"lesha.mtv" ` + + ` port:8002 ` + + ` >` + + `>`, + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + Quote: String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &InnerMessage{ + Host: String("footrest.syd"), + Port: Int32(7001), + Connected: Bool(true), + }, + Others: []*OtherMessage{ + { + Key: Int64(3735928559), + Value: []byte{0x1, 'A', '\a', '\f'}, + }, + { + Weight: Float32(58.9), + Inner: &InnerMessage{ + Host: String("lesha.mtv"), + Port: Int32(8002), + }, + }, + }, + }, + }, +} + +func TestUnmarshalText(t *testing.T) { + for i, test := range unMarshalTextTests { + pb := new(MyMessage) + err := UnmarshalText(test.in, pb) + if test.err == "" { + // We don't expect failure. + if err != nil { + t.Errorf("Test %d: Unexpected error: %v", i, err) + } else if !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } else { + // We do expect failure. + if err == nil { + t.Errorf("Test %d: Didn't get expected error: %v", i, test.err) + } else if err.Error() != test.err { + t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v", + i, err.Error(), test.err) + } else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } + } +} + +func TestUnmarshalTextCustomMessage(t *testing.T) { + msg := &textMessage{} + if err := UnmarshalText("custom", msg); err != nil { + t.Errorf("Unexpected error from custom unmarshal: %v", err) + } + if UnmarshalText("not custom", msg) == nil { + t.Errorf("Didn't get expected error from custom unmarshal") + } +} + +// Regression test; this caused a panic. +func TestRepeatedEnum(t *testing.T) { + pb := new(RepeatedEnum) + if err := UnmarshalText("color: RED", pb); err != nil { + t.Fatal(err) + } + exp := &RepeatedEnum{ + Color: []RepeatedEnum_Color{RepeatedEnum_RED}, + } + if !Equal(pb, exp) { + t.Errorf("Incorrect populated \nHave: %v\nWant: %v", pb, exp) + } +} + +func TestProto3TextParsing(t *testing.T) { + m := new(proto3pb.Message) + const in = `name: "Wallace" true_scotsman: true` + want := &proto3pb.Message{ + Name: "Wallace", + TrueScotsman: true, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestMapParsing(t *testing.T) { + m := new(MessageWithMap) + const in = `name_mapping: name_mapping:` + + `msg_mapping:,>` + // separating commas are okay + `msg_mapping>` + // no colon after "value" + `msg_mapping:>` + // omitted key + `msg_mapping:` + // omitted value + `byte_mapping:` + + `byte_mapping:<>` // omitted key and value + want := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Beatles", + 1234: "Feist", + }, + MsgMapping: map[int64]*FloatingPoint{ + -4: {F: Float64(2.0)}, + -2: {F: Float64(4.0)}, + 0: {F: Float64(5.0)}, + 1: nil, + }, + ByteMapping: map[bool][]byte{ + false: nil, + true: []byte("so be it"), + }, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestOneofParsing(t *testing.T) { + const in = `name:"Shrek"` + m := new(Communique) + want := &Communique{Union: &Communique_Name{"Shrek"}} + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } + + const inOverwrite = `name:"Shrek" number:42` + m = new(Communique) + testErr := "line 1.13: field 'number' would overwrite already parsed oneof 'Union'" + if err := UnmarshalText(inOverwrite, m); err == nil { + t.Errorf("TestOneofParsing: Didn't get expected error: %v", testErr) + } else if err.Error() != testErr { + t.Errorf("TestOneofParsing: Incorrect error.\nHave: %v\nWant: %v", + err.Error(), testErr) + } + +} + +var benchInput string + +func init() { + benchInput = "count: 4\n" + for i := 0; i < 1000; i++ { + benchInput += "pet: \"fido\"\n" + } + + // Check it is valid input. + pb := new(MyMessage) + err := UnmarshalText(benchInput, pb) + if err != nil { + panic("Bad benchmark input: " + err.Error()) + } +} + +func BenchmarkUnmarshalText(b *testing.B) { + pb := new(MyMessage) + for i := 0; i < b.N; i++ { + UnmarshalText(benchInput, pb) + } + b.SetBytes(int64(len(benchInput))) +} diff --git a/discovery/vendor/github.com/golang/protobuf/proto/text_test.go b/discovery/vendor/github.com/golang/protobuf/proto/text_test.go new file mode 100644 index 00000000..3eabacac --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/proto/text_test.go @@ -0,0 +1,474 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "errors" + "io/ioutil" + "math" + "strings" + "testing" + + "github.com/golang/protobuf/proto" + + proto3pb "github.com/golang/protobuf/proto/proto3_proto" + pb "github.com/golang/protobuf/proto/testdata" +) + +// textMessage implements the methods that allow it to marshal and unmarshal +// itself as text. +type textMessage struct { +} + +func (*textMessage) MarshalText() ([]byte, error) { + return []byte("custom"), nil +} + +func (*textMessage) UnmarshalText(bytes []byte) error { + if string(bytes) != "custom" { + return errors.New("expected 'custom'") + } + return nil +} + +func (*textMessage) Reset() {} +func (*textMessage) String() string { return "" } +func (*textMessage) ProtoMessage() {} + +func newTestMessage() *pb.MyMessage { + msg := &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Quote: proto.String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("footrest.syd"), + Port: proto.Int32(7001), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(0xdeadbeef), + Value: []byte{1, 65, 7, 12}, + }, + { + Weight: proto.Float32(6.022), + Inner: &pb.InnerMessage{ + Host: proto.String("lesha.mtv"), + Port: proto.Int32(8002), + }, + }, + }, + Bikeshed: pb.MyMessage_BLUE.Enum(), + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(8), + }, + // One normally wouldn't do this. + // This is an undeclared tag 13, as a varint (wire type 0) with value 4. + XXX_unrecognized: []byte{13<<3 | 0, 4}, + } + ext := &pb.Ext{ + Data: proto.String("Big gobs for big rats"), + } + if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil { + panic(err) + } + greetings := []string{"adg", "easy", "cow"} + if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil { + panic(err) + } + + // Add an unknown extension. We marshal a pb.Ext, and fake the ID. + b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")}) + if err != nil { + panic(err) + } + b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...) + proto.SetRawExtension(msg, 201, b) + + // Extensions can be plain fields, too, so let's test that. + b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19) + proto.SetRawExtension(msg, 202, b) + + return msg +} + +const text = `count: 42 +name: "Dave" +quote: "\"I didn't want to go.\"" +pet: "bunny" +pet: "kitty" +pet: "horsey" +inner: < + host: "footrest.syd" + port: 7001 + connected: true +> +others: < + key: 3735928559 + value: "\001A\007\014" +> +others: < + weight: 6.022 + inner: < + host: "lesha.mtv" + port: 8002 + > +> +bikeshed: BLUE +SomeGroup { + group_field: 8 +} +/* 2 unknown bytes */ +13: 4 +[testdata.Ext.more]: < + data: "Big gobs for big rats" +> +[testdata.greeting]: "adg" +[testdata.greeting]: "easy" +[testdata.greeting]: "cow" +/* 13 unknown bytes */ +201: "\t3G skiing" +/* 3 unknown bytes */ +202: 19 +` + +func TestMarshalText(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, newTestMessage()); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != text { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, text) + } +} + +func TestMarshalTextCustomMessage(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, &textMessage{}); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != "custom" { + t.Errorf("Got %q, expected %q", s, "custom") + } +} +func TestMarshalTextNil(t *testing.T) { + want := "" + tests := []proto.Message{nil, (*pb.MyMessage)(nil)} + for i, test := range tests { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, test); err != nil { + t.Fatal(err) + } + if got := buf.String(); got != want { + t.Errorf("%d: got %q want %q", i, got, want) + } + } +} + +func TestMarshalTextUnknownEnum(t *testing.T) { + // The Color enum only specifies values 0-2. + m := &pb.MyMessage{Bikeshed: pb.MyMessage_Color(3).Enum()} + got := m.String() + const want = `bikeshed:3 ` + if got != want { + t.Errorf("\n got %q\nwant %q", got, want) + } +} + +func TestTextOneof(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&pb.Communique{}, ``}, + // scalar field + {&pb.Communique{Union: &pb.Communique_Number{4}}, `number:4`}, + // message field + {&pb.Communique{Union: &pb.Communique_Msg{ + &pb.Strings{StringField: proto.String("why hello!")}, + }}, `msg:`}, + // bad oneof (should not panic) + {&pb.Communique{Union: &pb.Communique_Msg{nil}}, `msg:/* nil */`}, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} + +func BenchmarkMarshalTextBuffered(b *testing.B) { + buf := new(bytes.Buffer) + m := newTestMessage() + for i := 0; i < b.N; i++ { + buf.Reset() + proto.MarshalText(buf, m) + } +} + +func BenchmarkMarshalTextUnbuffered(b *testing.B) { + w := ioutil.Discard + m := newTestMessage() + for i := 0; i < b.N; i++ { + proto.MarshalText(w, m) + } +} + +func compact(src string) string { + // s/[ \n]+/ /g; s/ $//; + dst := make([]byte, len(src)) + space, comment := false, false + j := 0 + for i := 0; i < len(src); i++ { + if strings.HasPrefix(src[i:], "/*") { + comment = true + i++ + continue + } + if comment && strings.HasPrefix(src[i:], "*/") { + comment = false + i++ + continue + } + if comment { + continue + } + c := src[i] + if c == ' ' || c == '\n' { + space = true + continue + } + if j > 0 && (dst[j-1] == ':' || dst[j-1] == '<' || dst[j-1] == '{') { + space = false + } + if c == '{' { + space = false + } + if space { + dst[j] = ' ' + j++ + space = false + } + dst[j] = c + j++ + } + if space { + dst[j] = ' ' + j++ + } + return string(dst[0:j]) +} + +var compactText = compact(text) + +func TestCompactText(t *testing.T) { + s := proto.CompactTextString(newTestMessage()) + if s != compactText { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v\n===\n", s, compactText) + } +} + +func TestStringEscaping(t *testing.T) { + testCases := []struct { + in *pb.Strings + out string + }{ + { + // Test data from C++ test (TextFormatTest.StringEscape). + // Single divergence: we don't escape apostrophes. + &pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")}, + "string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n", + }, + { + // Test data from the same C++ test. + &pb.Strings{StringField: proto.String("\350\260\267\346\255\214")}, + "string_field: \"\\350\\260\\267\\346\\255\\214\"\n", + }, + { + // Some UTF-8. + &pb.Strings{StringField: proto.String("\x00\x01\xff\x81")}, + `string_field: "\000\001\377\201"` + "\n", + }, + } + + for i, tc := range testCases { + var buf bytes.Buffer + if err := proto.MarshalText(&buf, tc.in); err != nil { + t.Errorf("proto.MarsalText: %v", err) + continue + } + s := buf.String() + if s != tc.out { + t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out) + continue + } + + // Check round-trip. + pb := new(pb.Strings) + if err := proto.UnmarshalText(s, pb); err != nil { + t.Errorf("#%d: UnmarshalText: %v", i, err) + continue + } + if !proto.Equal(pb, tc.in) { + t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pb) + } + } +} + +// A limitedWriter accepts some output before it fails. +// This is a proxy for something like a nearly-full or imminently-failing disk, +// or a network connection that is about to die. +type limitedWriter struct { + b bytes.Buffer + limit int +} + +var outOfSpace = errors.New("proto: insufficient space") + +func (w *limitedWriter) Write(p []byte) (n int, err error) { + var avail = w.limit - w.b.Len() + if avail <= 0 { + return 0, outOfSpace + } + if len(p) <= avail { + return w.b.Write(p) + } + n, _ = w.b.Write(p[:avail]) + return n, outOfSpace +} + +func TestMarshalTextFailing(t *testing.T) { + // Try lots of different sizes to exercise more error code-paths. + for lim := 0; lim < len(text); lim++ { + buf := new(limitedWriter) + buf.limit = lim + err := proto.MarshalText(buf, newTestMessage()) + // We expect a certain error, but also some partial results in the buffer. + if err != outOfSpace { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", err, outOfSpace) + } + s := buf.b.String() + x := text[:buf.limit] + if s != x { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, x) + } + } +} + +func TestFloats(t *testing.T) { + tests := []struct { + f float64 + want string + }{ + {0, "0"}, + {4.7, "4.7"}, + {math.Inf(1), "inf"}, + {math.Inf(-1), "-inf"}, + {math.NaN(), "nan"}, + } + for _, test := range tests { + msg := &pb.FloatingPoint{F: &test.f} + got := strings.TrimSpace(msg.String()) + want := `f:` + test.want + if got != want { + t.Errorf("f=%f: got %q, want %q", test.f, got, want) + } + } +} + +func TestRepeatedNilText(t *testing.T) { + m := &pb.MessageList{ + Message: []*pb.MessageList_Message{ + nil, + &pb.MessageList_Message{ + Name: proto.String("Horse"), + }, + nil, + }, + } + want := `Message +Message { + name: "Horse" +} +Message +` + if s := proto.MarshalTextString(m); s != want { + t.Errorf(" got: %s\nwant: %s", s, want) + } +} + +func TestProto3Text(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&proto3pb.Message{}, ``}, + // zero message except for an empty byte slice + {&proto3pb.Message{Data: []byte{}}, ``}, + // trivial case + {&proto3pb.Message{Name: "Rob", HeightInCm: 175}, `name:"Rob" height_in_cm:175`}, + // empty map + {&pb.MessageWithMap{}, ``}, + // non-empty map; map format is the same as a repeated struct, + // and they are sorted by key (numerically for numeric keys). + { + &pb.MessageWithMap{NameMapping: map[int32]string{ + -1: "Negatory", + 7: "Lucky", + 1234: "Feist", + 6345789: "Otis", + }}, + `name_mapping: ` + + `name_mapping: ` + + `name_mapping: ` + + `name_mapping:`, + }, + // map with nil value; not well-defined, but we shouldn't crash + { + &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{7: nil}}, + `msg_mapping:`, + }, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go new file mode 100644 index 00000000..76808f3b --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go @@ -0,0 +1,114 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2013 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package generator + +import ( + "testing" + + "github.com/golang/protobuf/protoc-gen-go/descriptor" +) + +func TestCamelCase(t *testing.T) { + tests := []struct { + in, want string + }{ + {"one", "One"}, + {"one_two", "OneTwo"}, + {"_my_field_name_2", "XMyFieldName_2"}, + {"Something_Capped", "Something_Capped"}, + {"my_Name", "My_Name"}, + {"OneTwo", "OneTwo"}, + {"_", "X"}, + {"_a_", "XA_"}, + } + for _, tc := range tests { + if got := CamelCase(tc.in); got != tc.want { + t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) + } + } +} + +func TestGoPackageOption(t *testing.T) { + tests := []struct { + in string + impPath, pkg string + ok bool + }{ + {"", "", "", false}, + {"foo", "", "foo", true}, + {"github.com/golang/bar", "github.com/golang/bar", "bar", true}, + {"github.com/golang/bar;baz", "github.com/golang/bar", "baz", true}, + } + for _, tc := range tests { + d := &FileDescriptor{ + FileDescriptorProto: &descriptor.FileDescriptorProto{ + Options: &descriptor.FileOptions{ + GoPackage: &tc.in, + }, + }, + } + impPath, pkg, ok := d.goPackageOption() + if impPath != tc.impPath || pkg != tc.pkg || ok != tc.ok { + t.Errorf("go_package = %q => (%q, %q, %t), want (%q, %q, %t)", tc.in, + impPath, pkg, ok, tc.impPath, tc.pkg, tc.ok) + } + } +} + +func TestUnescape(t *testing.T) { + tests := []struct { + in string + out string + }{ + // successful cases, including all kinds of escapes + {"", ""}, + {"foo bar baz frob nitz", "foo bar baz frob nitz"}, + {`\000\001\002\003\004\005\006\007`, string([]byte{0, 1, 2, 3, 4, 5, 6, 7})}, + {`\a\b\f\n\r\t\v\\\?\'\"`, string([]byte{'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '?', '\'', '"'})}, + {`\x10\x20\x30\x40\x50\x60\x70\x80`, string([]byte{16, 32, 48, 64, 80, 96, 112, 128})}, + // variable length octal escapes + {`\0\018\222\377\3\04\005\6\07`, string([]byte{0, 1, '8', 0222, 255, 3, 4, 5, 6, 7})}, + // malformed escape sequences left as is + {"foo \\g bar", "foo \\g bar"}, + {"foo \\xg0 bar", "foo \\xg0 bar"}, + {"\\", "\\"}, + {"\\x", "\\x"}, + {"\\xf", "\\xf"}, + {"\\777", "\\777"}, // overflows byte + } + for _, tc := range tests { + s := unescape(tc.in) + if s != tc.out { + t.Errorf("doUnescape(%q) = %q; should have been %q", tc.in, s, tc.out) + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go new file mode 100644 index 00000000..86e9c118 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go @@ -0,0 +1,210 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Test that we can use protocol buffers that use extensions. + +package testdata + +/* + +import ( + "bytes" + "regexp" + "testing" + + "github.com/golang/protobuf/proto" + base "extension_base.pb" + user "extension_user.pb" +) + +func TestSingleFieldExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(178), + } + + // Use extension within scope of another type. + vol := proto.Uint32(11) + err := proto.SetExtension(bm, user.E_LoudMessage_Volume, vol) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Decoded message didn't contain extension.") + } + vol_out, err := proto.GetExtension(bm_new, user.E_LoudMessage_Volume) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if v := vol_out.(*uint32); *v != *vol { + t.Errorf("vol_out = %v, expected %v", *v, *vol) + } + proto.ClearExtension(bm_new, user.E_LoudMessage_Volume) + if proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + // Use extension that is itself a message. + um := &user.UserMessage{ + Name: proto.String("Dave"), + Rank: proto.String("Major"), + } + err := proto.SetExtension(bm, user.E_LoginMessage_UserMessage, um) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Decoded message didn't contain extension.") + } + um_out, err := proto.GetExtension(bm_new, user.E_LoginMessage_UserMessage) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if n := um_out.(*user.UserMessage).Name; *n != *um.Name { + t.Errorf("um_out.Name = %q, expected %q", *n, *um.Name) + } + if r := um_out.(*user.UserMessage).Rank; *r != *um.Rank { + t.Errorf("um_out.Rank = %q, expected %q", *r, *um.Rank) + } + proto.ClearExtension(bm_new, user.E_LoginMessage_UserMessage) + if proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Failed clearing extension.") + } +} + +func TestTopLevelExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + width := proto.Int32(17) + err := proto.SetExtension(bm, user.E_Width, width) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Decoded message didn't contain extension.") + } + width_out, err := proto.GetExtension(bm_new, user.E_Width) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if w := width_out.(*int32); *w != *width { + t.Errorf("width_out = %v, expected %v", *w, *width) + } + proto.ClearExtension(bm_new, user.E_Width) + if proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageSetWireFormat(t *testing.T) { + osm := new(base.OldStyleMessage) + osp := &user.OldStyleParcel{ + Name: proto.String("Dave"), + Height: proto.Int32(178), + } + + err := proto.SetExtension(osm, user.E_OldStyleParcel_MessageSetExtension, osp) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + + buf, err := proto.Marshal(osm) + if err != nil { + t.Fatal("Failed encoding message:", err) + } + + // Data generated from Python implementation. + expected := []byte{ + 11, 16, 209, 15, 26, 9, 10, 4, 68, 97, 118, 101, 16, 178, 1, 12, + } + + if !bytes.Equal(expected, buf) { + t.Errorf("Encoding mismatch.\nwant %+v\n got %+v", expected, buf) + } + + // Check that it is restored correctly. + osm = new(base.OldStyleMessage) + if err := proto.Unmarshal(buf, osm); err != nil { + t.Fatal("Failed decoding message:", err) + } + osp_out, err := proto.GetExtension(osm, user.E_OldStyleParcel_MessageSetExtension) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + osp = osp_out.(*user.OldStyleParcel) + if *osp.Name != "Dave" || *osp.Height != 178 { + t.Errorf("Retrieved extension from decoded message is not correct: %+v", osp) + } +} + +func main() { + // simpler than rigging up gotest + testing.Main(regexp.MatchString, []testing.InternalTest{ + {"TestSingleFieldExtension", TestSingleFieldExtension}, + {"TestMessageExtension", TestMessageExtension}, + {"TestTopLevelExtension", TestTopLevelExtension}, + }, + []testing.InternalBenchmark{}, + []testing.InternalExample{}) +} + +*/ diff --git a/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/main_test.go b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/main_test.go new file mode 100644 index 00000000..f9b5ccf2 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/protoc-gen-go/testdata/main_test.go @@ -0,0 +1,46 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// A simple binary to link together the protocol buffers in this test. + +package testdata + +import ( + "testing" + + mytestpb "./my_test" + multipb "github.com/golang/protobuf/protoc-gen-go/testdata/multi" +) + +func TestLink(t *testing.T) { + _ = &multipb.Multi1{} + _ = &mytestpb.Request{} +} diff --git a/discovery/vendor/github.com/golang/protobuf/ptypes/any_test.go b/discovery/vendor/github.com/golang/protobuf/ptypes/any_test.go new file mode 100644 index 00000000..ed675b48 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/ptypes/any_test.go @@ -0,0 +1,113 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package ptypes + +import ( + "testing" + + "github.com/golang/protobuf/proto" + pb "github.com/golang/protobuf/protoc-gen-go/descriptor" + "github.com/golang/protobuf/ptypes/any" +) + +func TestMarshalUnmarshal(t *testing.T) { + orig := &any.Any{Value: []byte("test")} + + packed, err := MarshalAny(orig) + if err != nil { + t.Errorf("MarshalAny(%+v): got: _, %v exp: _, nil", orig, err) + } + + unpacked := &any.Any{} + err = UnmarshalAny(packed, unpacked) + if err != nil || !proto.Equal(unpacked, orig) { + t.Errorf("got: %v, %+v; want nil, %+v", err, unpacked, orig) + } +} + +func TestIs(t *testing.T) { + a, err := MarshalAny(&pb.FileDescriptorProto{}) + if err != nil { + t.Fatal(err) + } + if Is(a, &pb.DescriptorProto{}) { + t.Error("FileDescriptorProto is not a DescriptorProto, but Is says it is") + } + if !Is(a, &pb.FileDescriptorProto{}) { + t.Error("FileDescriptorProto is indeed a FileDescriptorProto, but Is says it is not") + } +} + +func TestIsDifferentUrlPrefixes(t *testing.T) { + m := &pb.FileDescriptorProto{} + a := &any.Any{TypeUrl: "foo/bar/" + proto.MessageName(m)} + if !Is(a, m) { + t.Errorf("message with type url %q didn't satisfy Is for type %q", a.TypeUrl, proto.MessageName(m)) + } +} + +func TestUnmarshalDynamic(t *testing.T) { + want := &pb.FileDescriptorProto{Name: proto.String("foo")} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + var got DynamicAny + if err := UnmarshalAny(a, &got); err != nil { + t.Fatal(err) + } + if !proto.Equal(got.Message, want) { + t.Errorf("invalid result from UnmarshalAny, got %q want %q", got.Message, want) + } +} + +func TestEmpty(t *testing.T) { + want := &pb.FileDescriptorProto{} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + got, err := Empty(a) + if err != nil { + t.Fatal(err) + } + if !proto.Equal(got, want) { + t.Errorf("unequal empty message, got %q, want %q", got, want) + } + + // that's a valid type_url for a message which shouldn't be linked into this + // test binary. We want an error. + a.TypeUrl = "type.googleapis.com/google.protobuf.FieldMask" + if _, err := Empty(a); err == nil { + t.Errorf("got no error for an attempt to create a message of type %q, which shouldn't be linked in", a.TypeUrl) + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/ptypes/duration_test.go b/discovery/vendor/github.com/golang/protobuf/ptypes/duration_test.go new file mode 100644 index 00000000..e00491a3 --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/ptypes/duration_test.go @@ -0,0 +1,121 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package ptypes + +import ( + "math" + "testing" + "time" + + "github.com/golang/protobuf/proto" + durpb "github.com/golang/protobuf/ptypes/duration" +) + +const ( + minGoSeconds = math.MinInt64 / int64(1e9) + maxGoSeconds = math.MaxInt64 / int64(1e9) +) + +var durationTests = []struct { + proto *durpb.Duration + isValid bool + inRange bool + dur time.Duration +}{ + // The zero duration. + {&durpb.Duration{Seconds: 0, Nanos: 0}, true, true, 0}, + // Some ordinary non-zero durations. + {&durpb.Duration{Seconds: 100, Nanos: 0}, true, true, 100 * time.Second}, + {&durpb.Duration{Seconds: -100, Nanos: 0}, true, true, -100 * time.Second}, + {&durpb.Duration{Seconds: 100, Nanos: 987}, true, true, 100*time.Second + 987}, + {&durpb.Duration{Seconds: -100, Nanos: -987}, true, true, -(100*time.Second + 987)}, + // The largest duration representable in Go. + {&durpb.Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, true, math.MaxInt64}, + // The smallest duration representable in Go. + {&durpb.Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, true, math.MinInt64}, + {nil, false, false, 0}, + {&durpb.Duration{Seconds: -100, Nanos: 987}, false, false, 0}, + {&durpb.Duration{Seconds: 100, Nanos: -987}, false, false, 0}, + {&durpb.Duration{Seconds: math.MinInt64, Nanos: 0}, false, false, 0}, + {&durpb.Duration{Seconds: math.MaxInt64, Nanos: 0}, false, false, 0}, + // The largest valid duration. + {&durpb.Duration{Seconds: maxSeconds, Nanos: 1e9 - 1}, true, false, 0}, + // The smallest valid duration. + {&durpb.Duration{Seconds: minSeconds, Nanos: -(1e9 - 1)}, true, false, 0}, + // The smallest invalid duration above the valid range. + {&durpb.Duration{Seconds: maxSeconds + 1, Nanos: 0}, false, false, 0}, + // The largest invalid duration below the valid range. + {&durpb.Duration{Seconds: minSeconds - 1, Nanos: -(1e9 - 1)}, false, false, 0}, + // One nanosecond past the largest duration representable in Go. + {&durpb.Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64-1e9*maxGoSeconds) + 1}, true, false, 0}, + // One nanosecond past the smallest duration representable in Go. + {&durpb.Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64-1e9*minGoSeconds) - 1}, true, false, 0}, + // One second past the largest duration representable in Go. + {&durpb.Duration{Seconds: maxGoSeconds + 1, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, false, 0}, + // One second past the smallest duration representable in Go. + {&durpb.Duration{Seconds: minGoSeconds - 1, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, false, 0}, +} + +func TestValidateDuration(t *testing.T) { + for _, test := range durationTests { + err := validateDuration(test.proto) + gotValid := (err == nil) + if gotValid != test.isValid { + t.Errorf("validateDuration(%v) = %t, want %t", test.proto, gotValid, test.isValid) + } + } +} + +func TestDuration(t *testing.T) { + for _, test := range durationTests { + got, err := Duration(test.proto) + gotOK := (err == nil) + wantOK := test.isValid && test.inRange + if gotOK != wantOK { + t.Errorf("Duration(%v) ok = %t, want %t", test.proto, gotOK, wantOK) + } + if err == nil && got != test.dur { + t.Errorf("Duration(%v) = %v, want %v", test.proto, got, test.dur) + } + } +} + +func TestDurationProto(t *testing.T) { + for _, test := range durationTests { + if test.isValid && test.inRange { + got := DurationProto(test.dur) + if !proto.Equal(got, test.proto) { + t.Errorf("DurationProto(%v) = %v, want %v", test.dur, got, test.proto) + } + } + } +} diff --git a/discovery/vendor/github.com/golang/protobuf/ptypes/timestamp_test.go b/discovery/vendor/github.com/golang/protobuf/ptypes/timestamp_test.go new file mode 100644 index 00000000..6e3c969b --- /dev/null +++ b/discovery/vendor/github.com/golang/protobuf/ptypes/timestamp_test.go @@ -0,0 +1,153 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package ptypes + +import ( + "math" + "testing" + "time" + + "github.com/golang/protobuf/proto" + tspb "github.com/golang/protobuf/ptypes/timestamp" +) + +var tests = []struct { + ts *tspb.Timestamp + valid bool + t time.Time +}{ + // The timestamp representing the Unix epoch date. + {&tspb.Timestamp{Seconds: 0, Nanos: 0}, true, utcDate(1970, 1, 1)}, + // The smallest representable timestamp. + {&tspb.Timestamp{Seconds: math.MinInt64, Nanos: math.MinInt32}, false, + time.Unix(math.MinInt64, math.MinInt32).UTC()}, + // The smallest representable timestamp with non-negative nanos. + {&tspb.Timestamp{Seconds: math.MinInt64, Nanos: 0}, false, time.Unix(math.MinInt64, 0).UTC()}, + // The earliest valid timestamp. + {&tspb.Timestamp{Seconds: minValidSeconds, Nanos: 0}, true, utcDate(1, 1, 1)}, + //"0001-01-01T00:00:00Z"}, + // The largest representable timestamp. + {&tspb.Timestamp{Seconds: math.MaxInt64, Nanos: math.MaxInt32}, false, + time.Unix(math.MaxInt64, math.MaxInt32).UTC()}, + // The largest representable timestamp with nanos in range. + {&tspb.Timestamp{Seconds: math.MaxInt64, Nanos: 1e9 - 1}, false, + time.Unix(math.MaxInt64, 1e9-1).UTC()}, + // The largest valid timestamp. + {&tspb.Timestamp{Seconds: maxValidSeconds - 1, Nanos: 1e9 - 1}, true, + time.Date(9999, 12, 31, 23, 59, 59, 1e9-1, time.UTC)}, + // The smallest invalid timestamp that is larger than the valid range. + {&tspb.Timestamp{Seconds: maxValidSeconds, Nanos: 0}, false, time.Unix(maxValidSeconds, 0).UTC()}, + // A date before the epoch. + {&tspb.Timestamp{Seconds: -281836800, Nanos: 0}, true, utcDate(1961, 1, 26)}, + // A date after the epoch. + {&tspb.Timestamp{Seconds: 1296000000, Nanos: 0}, true, utcDate(2011, 1, 26)}, + // A date after the epoch, in the middle of the day. + {&tspb.Timestamp{Seconds: 1296012345, Nanos: 940483}, true, + time.Date(2011, 1, 26, 3, 25, 45, 940483, time.UTC)}, +} + +func TestValidateTimestamp(t *testing.T) { + for _, s := range tests { + got := validateTimestamp(s.ts) + if (got == nil) != s.valid { + t.Errorf("validateTimestamp(%v) = %v, want %v", s.ts, got, s.valid) + } + } +} + +func TestTimestamp(t *testing.T) { + for _, s := range tests { + got, err := Timestamp(s.ts) + if (err == nil) != s.valid { + t.Errorf("Timestamp(%v) error = %v, but valid = %t", s.ts, err, s.valid) + } else if s.valid && got != s.t { + t.Errorf("Timestamp(%v) = %v, want %v", s.ts, got, s.t) + } + } + // Special case: a nil Timestamp is an error, but returns the 0 Unix time. + got, err := Timestamp(nil) + want := time.Unix(0, 0).UTC() + if got != want { + t.Errorf("Timestamp(nil) = %v, want %v", got, want) + } + if err == nil { + t.Errorf("Timestamp(nil) error = nil, expected error") + } +} + +func TestTimestampProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampProto(s.t) + if (err == nil) != s.valid { + t.Errorf("TimestampProto(%v) error = %v, but valid = %t", s.t, err, s.valid) + } else if s.valid && !proto.Equal(got, s.ts) { + t.Errorf("TimestampProto(%v) = %v, want %v", s.t, got, s.ts) + } + } + // No corresponding special case here: no time.Time results in a nil Timestamp. +} + +func TestTimestampString(t *testing.T) { + for _, test := range []struct { + ts *tspb.Timestamp + want string + }{ + // Not much testing needed because presumably time.Format is + // well-tested. + {&tspb.Timestamp{Seconds: 0, Nanos: 0}, "1970-01-01T00:00:00Z"}, + {&tspb.Timestamp{Seconds: minValidSeconds - 1, Nanos: 0}, "(timestamp: seconds:-62135596801 before 0001-01-01)"}, + } { + got := TimestampString(test.ts) + if got != test.want { + t.Errorf("TimestampString(%v) = %q, want %q", test.ts, got, test.want) + } + } +} + +func utcDate(year, month, day int) time.Time { + return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) +} + +func TestTimestampNow(t *testing.T) { + // Bracket the expected time. + before := time.Now() + ts := TimestampNow() + after := time.Now() + + tm, err := Timestamp(ts) + if err != nil { + t.Errorf("between %v and %v\nTimestampNow() = %v\nwhich is invalid (%v)", before, after, ts, err) + } + if tm.Before(before) || tm.After(after) { + t.Errorf("between %v and %v\nTimestamp(TimestampNow()) = %v", before, after, tm) + } +} diff --git a/discovery/vendor/github.com/google/btree/LICENSE b/discovery/vendor/github.com/google/btree/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/discovery/vendor/github.com/google/btree/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/discovery/vendor/github.com/google/btree/README.md b/discovery/vendor/github.com/google/btree/README.md deleted file mode 100644 index 6062a4da..00000000 --- a/discovery/vendor/github.com/google/btree/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# BTree implementation for Go - -![Travis CI Build Status](https://api.travis-ci.org/google/btree.svg?branch=master) - -This package provides an in-memory B-Tree implementation for Go, useful as -an ordered, mutable data structure. - -The API is based off of the wonderful -http://godoc.org/github.com/petar/GoLLRB/llrb, and is meant to allow btree to -act as a drop-in replacement for gollrb trees. - -See http://godoc.org/github.com/google/btree for documentation. diff --git a/discovery/vendor/github.com/google/btree/btree.go b/discovery/vendor/github.com/google/btree/btree.go deleted file mode 100644 index eb74b1d3..00000000 --- a/discovery/vendor/github.com/google/btree/btree.go +++ /dev/null @@ -1,821 +0,0 @@ -// Copyright 2014 Google Inc. -// -// 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 btree implements in-memory B-Trees of arbitrary degree. -// -// btree implements an in-memory B-Tree for use as an ordered data structure. -// It is not meant for persistent storage solutions. -// -// It has a flatter structure than an equivalent red-black or other binary tree, -// which in some cases yields better memory usage and/or performance. -// See some discussion on the matter here: -// http://google-opensource.blogspot.com/2013/01/c-containers-that-save-memory-and-time.html -// Note, though, that this project is in no way related to the C++ B-Tree -// implementation written about there. -// -// Within this tree, each node contains a slice of items and a (possibly nil) -// slice of children. For basic numeric values or raw structs, this can cause -// efficiency differences when compared to equivalent C++ template code that -// stores values in arrays within the node: -// * Due to the overhead of storing values as interfaces (each -// value needs to be stored as the value itself, then 2 words for the -// interface pointing to that value and its type), resulting in higher -// memory use. -// * Since interfaces can point to values anywhere in memory, values are -// most likely not stored in contiguous blocks, resulting in a higher -// number of cache misses. -// These issues don't tend to matter, though, when working with strings or other -// heap-allocated structures, since C++-equivalent structures also must store -// pointers and also distribute their values across the heap. -// -// This implementation is designed to be a drop-in replacement to gollrb.LLRB -// trees, (http://github.com/petar/gollrb), an excellent and probably the most -// widely used ordered tree implementation in the Go ecosystem currently. -// Its functions, therefore, exactly mirror those of -// llrb.LLRB where possible. Unlike gollrb, though, we currently don't -// support storing multiple equivalent values. -package btree - -import ( - "fmt" - "io" - "sort" - "strings" - "sync" -) - -// Item represents a single object in the tree. -type Item interface { - // Less tests whether the current item is less than the given argument. - // - // This must provide a strict weak ordering. - // If !a.Less(b) && !b.Less(a), we treat this to mean a == b (i.e. we can only - // hold one of either a or b in the tree). - Less(than Item) bool -} - -const ( - DefaultFreeListSize = 32 -) - -var ( - nilItems = make(items, 16) - nilChildren = make(children, 16) -) - -// FreeList represents a free list of btree nodes. By default each -// BTree has its own FreeList, but multiple BTrees can share the same -// FreeList. -// Two Btrees using the same freelist are safe for concurrent write access. -type FreeList struct { - mu sync.Mutex - freelist []*node -} - -// NewFreeList creates a new free list. -// size is the maximum size of the returned free list. -func NewFreeList(size int) *FreeList { - return &FreeList{freelist: make([]*node, 0, size)} -} - -func (f *FreeList) newNode() (n *node) { - f.mu.Lock() - index := len(f.freelist) - 1 - if index < 0 { - f.mu.Unlock() - return new(node) - } - n = f.freelist[index] - f.freelist[index] = nil - f.freelist = f.freelist[:index] - f.mu.Unlock() - return -} - -func (f *FreeList) freeNode(n *node) { - f.mu.Lock() - if len(f.freelist) < cap(f.freelist) { - f.freelist = append(f.freelist, n) - } - f.mu.Unlock() -} - -// ItemIterator allows callers of Ascend* to iterate in-order over portions of -// the tree. When this function returns false, iteration will stop and the -// associated Ascend* function will immediately return. -type ItemIterator func(i Item) bool - -// New creates a new B-Tree with the given degree. -// -// New(2), for example, will create a 2-3-4 tree (each node contains 1-3 items -// and 2-4 children). -func New(degree int) *BTree { - return NewWithFreeList(degree, NewFreeList(DefaultFreeListSize)) -} - -// NewWithFreeList creates a new B-Tree that uses the given node free list. -func NewWithFreeList(degree int, f *FreeList) *BTree { - if degree <= 1 { - panic("bad degree") - } - return &BTree{ - degree: degree, - cow: ©OnWriteContext{freelist: f}, - } -} - -// items stores items in a node. -type items []Item - -// insertAt inserts a value into the given index, pushing all subsequent values -// forward. -func (s *items) insertAt(index int, item Item) { - *s = append(*s, nil) - if index < len(*s) { - copy((*s)[index+1:], (*s)[index:]) - } - (*s)[index] = item -} - -// removeAt removes a value at a given index, pulling all subsequent values -// back. -func (s *items) removeAt(index int) Item { - item := (*s)[index] - copy((*s)[index:], (*s)[index+1:]) - (*s)[len(*s)-1] = nil - *s = (*s)[:len(*s)-1] - return item -} - -// pop removes and returns the last element in the list. -func (s *items) pop() (out Item) { - index := len(*s) - 1 - out = (*s)[index] - (*s)[index] = nil - *s = (*s)[:index] - return -} - -// truncate truncates this instance at index so that it contains only the -// first index items. index must be less than or equal to length. -func (s *items) truncate(index int) { - var toClear items - *s, toClear = (*s)[:index], (*s)[index:] - for len(toClear) > 0 { - toClear = toClear[copy(toClear, nilItems):] - } -} - -// find returns the index where the given item should be inserted into this -// list. 'found' is true if the item already exists in the list at the given -// index. -func (s items) find(item Item) (index int, found bool) { - i := sort.Search(len(s), func(i int) bool { - return item.Less(s[i]) - }) - if i > 0 && !s[i-1].Less(item) { - return i - 1, true - } - return i, false -} - -// children stores child nodes in a node. -type children []*node - -// insertAt inserts a value into the given index, pushing all subsequent values -// forward. -func (s *children) insertAt(index int, n *node) { - *s = append(*s, nil) - if index < len(*s) { - copy((*s)[index+1:], (*s)[index:]) - } - (*s)[index] = n -} - -// removeAt removes a value at a given index, pulling all subsequent values -// back. -func (s *children) removeAt(index int) *node { - n := (*s)[index] - copy((*s)[index:], (*s)[index+1:]) - (*s)[len(*s)-1] = nil - *s = (*s)[:len(*s)-1] - return n -} - -// pop removes and returns the last element in the list. -func (s *children) pop() (out *node) { - index := len(*s) - 1 - out = (*s)[index] - (*s)[index] = nil - *s = (*s)[:index] - return -} - -// truncate truncates this instance at index so that it contains only the -// first index children. index must be less than or equal to length. -func (s *children) truncate(index int) { - var toClear children - *s, toClear = (*s)[:index], (*s)[index:] - for len(toClear) > 0 { - toClear = toClear[copy(toClear, nilChildren):] - } -} - -// node is an internal node in a tree. -// -// It must at all times maintain the invariant that either -// * len(children) == 0, len(items) unconstrained -// * len(children) == len(items) + 1 -type node struct { - items items - children children - cow *copyOnWriteContext -} - -func (n *node) mutableFor(cow *copyOnWriteContext) *node { - if n.cow == cow { - return n - } - out := cow.newNode() - if cap(out.items) >= len(n.items) { - out.items = out.items[:len(n.items)] - } else { - out.items = make(items, len(n.items), cap(n.items)) - } - copy(out.items, n.items) - // Copy children - if cap(out.children) >= len(n.children) { - out.children = out.children[:len(n.children)] - } else { - out.children = make(children, len(n.children), cap(n.children)) - } - copy(out.children, n.children) - return out -} - -func (n *node) mutableChild(i int) *node { - c := n.children[i].mutableFor(n.cow) - n.children[i] = c - return c -} - -// split splits the given node at the given index. The current node shrinks, -// and this function returns the item that existed at that index and a new node -// containing all items/children after it. -func (n *node) split(i int) (Item, *node) { - item := n.items[i] - next := n.cow.newNode() - next.items = append(next.items, n.items[i+1:]...) - n.items.truncate(i) - if len(n.children) > 0 { - next.children = append(next.children, n.children[i+1:]...) - n.children.truncate(i + 1) - } - return item, next -} - -// maybeSplitChild checks if a child should be split, and if so splits it. -// Returns whether or not a split occurred. -func (n *node) maybeSplitChild(i, maxItems int) bool { - if len(n.children[i].items) < maxItems { - return false - } - first := n.mutableChild(i) - item, second := first.split(maxItems / 2) - n.items.insertAt(i, item) - n.children.insertAt(i+1, second) - return true -} - -// insert inserts an item into the subtree rooted at this node, making sure -// no nodes in the subtree exceed maxItems items. Should an equivalent item be -// be found/replaced by insert, it will be returned. -func (n *node) insert(item Item, maxItems int) Item { - i, found := n.items.find(item) - if found { - out := n.items[i] - n.items[i] = item - return out - } - if len(n.children) == 0 { - n.items.insertAt(i, item) - return nil - } - if n.maybeSplitChild(i, maxItems) { - inTree := n.items[i] - switch { - case item.Less(inTree): - // no change, we want first split node - case inTree.Less(item): - i++ // we want second split node - default: - out := n.items[i] - n.items[i] = item - return out - } - } - return n.mutableChild(i).insert(item, maxItems) -} - -// get finds the given key in the subtree and returns it. -func (n *node) get(key Item) Item { - i, found := n.items.find(key) - if found { - return n.items[i] - } else if len(n.children) > 0 { - return n.children[i].get(key) - } - return nil -} - -// min returns the first item in the subtree. -func min(n *node) Item { - if n == nil { - return nil - } - for len(n.children) > 0 { - n = n.children[0] - } - if len(n.items) == 0 { - return nil - } - return n.items[0] -} - -// max returns the last item in the subtree. -func max(n *node) Item { - if n == nil { - return nil - } - for len(n.children) > 0 { - n = n.children[len(n.children)-1] - } - if len(n.items) == 0 { - return nil - } - return n.items[len(n.items)-1] -} - -// toRemove details what item to remove in a node.remove call. -type toRemove int - -const ( - removeItem toRemove = iota // removes the given item - removeMin // removes smallest item in the subtree - removeMax // removes largest item in the subtree -) - -// remove removes an item from the subtree rooted at this node. -func (n *node) remove(item Item, minItems int, typ toRemove) Item { - var i int - var found bool - switch typ { - case removeMax: - if len(n.children) == 0 { - return n.items.pop() - } - i = len(n.items) - case removeMin: - if len(n.children) == 0 { - return n.items.removeAt(0) - } - i = 0 - case removeItem: - i, found = n.items.find(item) - if len(n.children) == 0 { - if found { - return n.items.removeAt(i) - } - return nil - } - default: - panic("invalid type") - } - // If we get to here, we have children. - if len(n.children[i].items) <= minItems { - return n.growChildAndRemove(i, item, minItems, typ) - } - child := n.mutableChild(i) - // Either we had enough items to begin with, or we've done some - // merging/stealing, because we've got enough now and we're ready to return - // stuff. - if found { - // The item exists at index 'i', and the child we've selected can give us a - // predecessor, since if we've gotten here it's got > minItems items in it. - out := n.items[i] - // We use our special-case 'remove' call with typ=maxItem to pull the - // predecessor of item i (the rightmost leaf of our immediate left child) - // and set it into where we pulled the item from. - n.items[i] = child.remove(nil, minItems, removeMax) - return out - } - // Final recursive call. Once we're here, we know that the item isn't in this - // node and that the child is big enough to remove from. - return child.remove(item, minItems, typ) -} - -// growChildAndRemove grows child 'i' to make sure it's possible to remove an -// item from it while keeping it at minItems, then calls remove to actually -// remove it. -// -// Most documentation says we have to do two sets of special casing: -// 1) item is in this node -// 2) item is in child -// In both cases, we need to handle the two subcases: -// A) node has enough values that it can spare one -// B) node doesn't have enough values -// For the latter, we have to check: -// a) left sibling has node to spare -// b) right sibling has node to spare -// c) we must merge -// To simplify our code here, we handle cases #1 and #2 the same: -// If a node doesn't have enough items, we make sure it does (using a,b,c). -// We then simply redo our remove call, and the second time (regardless of -// whether we're in case 1 or 2), we'll have enough items and can guarantee -// that we hit case A. -func (n *node) growChildAndRemove(i int, item Item, minItems int, typ toRemove) Item { - if i > 0 && len(n.children[i-1].items) > minItems { - // Steal from left child - child := n.mutableChild(i) - stealFrom := n.mutableChild(i - 1) - stolenItem := stealFrom.items.pop() - child.items.insertAt(0, n.items[i-1]) - n.items[i-1] = stolenItem - if len(stealFrom.children) > 0 { - child.children.insertAt(0, stealFrom.children.pop()) - } - } else if i < len(n.items) && len(n.children[i+1].items) > minItems { - // steal from right child - child := n.mutableChild(i) - stealFrom := n.mutableChild(i + 1) - stolenItem := stealFrom.items.removeAt(0) - child.items = append(child.items, n.items[i]) - n.items[i] = stolenItem - if len(stealFrom.children) > 0 { - child.children = append(child.children, stealFrom.children.removeAt(0)) - } - } else { - if i >= len(n.items) { - i-- - } - child := n.mutableChild(i) - // merge with right child - mergeItem := n.items.removeAt(i) - mergeChild := n.children.removeAt(i + 1) - child.items = append(child.items, mergeItem) - child.items = append(child.items, mergeChild.items...) - child.children = append(child.children, mergeChild.children...) - n.cow.freeNode(mergeChild) - } - return n.remove(item, minItems, typ) -} - -type direction int - -const ( - descend = direction(-1) - ascend = direction(+1) -) - -// iterate provides a simple method for iterating over elements in the tree. -// -// When ascending, the 'start' should be less than 'stop' and when descending, -// the 'start' should be greater than 'stop'. Setting 'includeStart' to true -// will force the iterator to include the first item when it equals 'start', -// thus creating a "greaterOrEqual" or "lessThanEqual" rather than just a -// "greaterThan" or "lessThan" queries. -func (n *node) iterate(dir direction, start, stop Item, includeStart bool, hit bool, iter ItemIterator) (bool, bool) { - var ok bool - switch dir { - case ascend: - for i := 0; i < len(n.items); i++ { - if start != nil && n.items[i].Less(start) { - continue - } - if len(n.children) > 0 { - if hit, ok = n.children[i].iterate(dir, start, stop, includeStart, hit, iter); !ok { - return hit, false - } - } - if !includeStart && !hit && start != nil && !start.Less(n.items[i]) { - hit = true - continue - } - hit = true - if stop != nil && !n.items[i].Less(stop) { - return hit, false - } - if !iter(n.items[i]) { - return hit, false - } - } - if len(n.children) > 0 { - if hit, ok = n.children[len(n.children)-1].iterate(dir, start, stop, includeStart, hit, iter); !ok { - return hit, false - } - } - case descend: - for i := len(n.items) - 1; i >= 0; i-- { - if start != nil && !n.items[i].Less(start) { - if !includeStart || hit || start.Less(n.items[i]) { - continue - } - } - if len(n.children) > 0 { - if hit, ok = n.children[i+1].iterate(dir, start, stop, includeStart, hit, iter); !ok { - return hit, false - } - } - if stop != nil && !stop.Less(n.items[i]) { - return hit, false // continue - } - hit = true - if !iter(n.items[i]) { - return hit, false - } - } - if len(n.children) > 0 { - if hit, ok = n.children[0].iterate(dir, start, stop, includeStart, hit, iter); !ok { - return hit, false - } - } - } - return hit, true -} - -// Used for testing/debugging purposes. -func (n *node) print(w io.Writer, level int) { - fmt.Fprintf(w, "%sNODE:%v\n", strings.Repeat(" ", level), n.items) - for _, c := range n.children { - c.print(w, level+1) - } -} - -// BTree is an implementation of a B-Tree. -// -// BTree stores Item instances in an ordered structure, allowing easy insertion, -// removal, and iteration. -// -// Write operations are not safe for concurrent mutation by multiple -// goroutines, but Read operations are. -type BTree struct { - degree int - length int - root *node - cow *copyOnWriteContext -} - -// copyOnWriteContext pointers determine node ownership... a tree with a write -// context equivalent to a node's write context is allowed to modify that node. -// A tree whose write context does not match a node's is not allowed to modify -// it, and must create a new, writable copy (IE: it's a Clone). -// -// When doing any write operation, we maintain the invariant that the current -// node's context is equal to the context of the tree that requested the write. -// We do this by, before we descend into any node, creating a copy with the -// correct context if the contexts don't match. -// -// Since the node we're currently visiting on any write has the requesting -// tree's context, that node is modifiable in place. Children of that node may -// not share context, but before we descend into them, we'll make a mutable -// copy. -type copyOnWriteContext struct { - freelist *FreeList -} - -// Clone clones the btree, lazily. Clone should not be called concurrently, -// but the original tree (t) and the new tree (t2) can be used concurrently -// once the Clone call completes. -// -// The internal tree structure of b is marked read-only and shared between t and -// t2. Writes to both t and t2 use copy-on-write logic, creating new nodes -// whenever one of b's original nodes would have been modified. Read operations -// should have no performance degredation. Write operations for both t and t2 -// will initially experience minor slow-downs caused by additional allocs and -// copies due to the aforementioned copy-on-write logic, but should converge to -// the original performance characteristics of the original tree. -func (t *BTree) Clone() (t2 *BTree) { - // Create two entirely new copy-on-write contexts. - // This operation effectively creates three trees: - // the original, shared nodes (old b.cow) - // the new b.cow nodes - // the new out.cow nodes - cow1, cow2 := *t.cow, *t.cow - out := *t - t.cow = &cow1 - out.cow = &cow2 - return &out -} - -// maxItems returns the max number of items to allow per node. -func (t *BTree) maxItems() int { - return t.degree*2 - 1 -} - -// minItems returns the min number of items to allow per node (ignored for the -// root node). -func (t *BTree) minItems() int { - return t.degree - 1 -} - -func (c *copyOnWriteContext) newNode() (n *node) { - n = c.freelist.newNode() - n.cow = c - return -} - -func (c *copyOnWriteContext) freeNode(n *node) { - if n.cow == c { - // clear to allow GC - n.items.truncate(0) - n.children.truncate(0) - n.cow = nil - c.freelist.freeNode(n) - } -} - -// ReplaceOrInsert adds the given item to the tree. If an item in the tree -// already equals the given one, it is removed from the tree and returned. -// Otherwise, nil is returned. -// -// nil cannot be added to the tree (will panic). -func (t *BTree) ReplaceOrInsert(item Item) Item { - if item == nil { - panic("nil item being added to BTree") - } - if t.root == nil { - t.root = t.cow.newNode() - t.root.items = append(t.root.items, item) - t.length++ - return nil - } else { - t.root = t.root.mutableFor(t.cow) - if len(t.root.items) >= t.maxItems() { - item2, second := t.root.split(t.maxItems() / 2) - oldroot := t.root - t.root = t.cow.newNode() - t.root.items = append(t.root.items, item2) - t.root.children = append(t.root.children, oldroot, second) - } - } - out := t.root.insert(item, t.maxItems()) - if out == nil { - t.length++ - } - return out -} - -// Delete removes an item equal to the passed in item from the tree, returning -// it. If no such item exists, returns nil. -func (t *BTree) Delete(item Item) Item { - return t.deleteItem(item, removeItem) -} - -// DeleteMin removes the smallest item in the tree and returns it. -// If no such item exists, returns nil. -func (t *BTree) DeleteMin() Item { - return t.deleteItem(nil, removeMin) -} - -// DeleteMax removes the largest item in the tree and returns it. -// If no such item exists, returns nil. -func (t *BTree) DeleteMax() Item { - return t.deleteItem(nil, removeMax) -} - -func (t *BTree) deleteItem(item Item, typ toRemove) Item { - if t.root == nil || len(t.root.items) == 0 { - return nil - } - t.root = t.root.mutableFor(t.cow) - out := t.root.remove(item, t.minItems(), typ) - if len(t.root.items) == 0 && len(t.root.children) > 0 { - oldroot := t.root - t.root = t.root.children[0] - t.cow.freeNode(oldroot) - } - if out != nil { - t.length-- - } - return out -} - -// AscendRange calls the iterator for every value in the tree within the range -// [greaterOrEqual, lessThan), until iterator returns false. -func (t *BTree) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(ascend, greaterOrEqual, lessThan, true, false, iterator) -} - -// AscendLessThan calls the iterator for every value in the tree within the range -// [first, pivot), until iterator returns false. -func (t *BTree) AscendLessThan(pivot Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(ascend, nil, pivot, false, false, iterator) -} - -// AscendGreaterOrEqual calls the iterator for every value in the tree within -// the range [pivot, last], until iterator returns false. -func (t *BTree) AscendGreaterOrEqual(pivot Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(ascend, pivot, nil, true, false, iterator) -} - -// Ascend calls the iterator for every value in the tree within the range -// [first, last], until iterator returns false. -func (t *BTree) Ascend(iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(ascend, nil, nil, false, false, iterator) -} - -// DescendRange calls the iterator for every value in the tree within the range -// [lessOrEqual, greaterThan), until iterator returns false. -func (t *BTree) DescendRange(lessOrEqual, greaterThan Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(descend, lessOrEqual, greaterThan, true, false, iterator) -} - -// DescendLessOrEqual calls the iterator for every value in the tree within the range -// [pivot, first], until iterator returns false. -func (t *BTree) DescendLessOrEqual(pivot Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(descend, pivot, nil, true, false, iterator) -} - -// DescendGreaterThan calls the iterator for every value in the tree within -// the range (pivot, last], until iterator returns false. -func (t *BTree) DescendGreaterThan(pivot Item, iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(descend, nil, pivot, false, false, iterator) -} - -// Descend calls the iterator for every value in the tree within the range -// [last, first], until iterator returns false. -func (t *BTree) Descend(iterator ItemIterator) { - if t.root == nil { - return - } - t.root.iterate(descend, nil, nil, false, false, iterator) -} - -// Get looks for the key item in the tree, returning it. It returns nil if -// unable to find that item. -func (t *BTree) Get(key Item) Item { - if t.root == nil { - return nil - } - return t.root.get(key) -} - -// Min returns the smallest item in the tree, or nil if the tree is empty. -func (t *BTree) Min() Item { - return min(t.root) -} - -// Max returns the largest item in the tree, or nil if the tree is empty. -func (t *BTree) Max() Item { - return max(t.root) -} - -// Has returns true if the given key is in the tree. -func (t *BTree) Has(key Item) bool { - return t.Get(key) != nil -} - -// Len returns the number of items currently in the tree. -func (t *BTree) Len() int { - return t.length -} - -// Int implements the Item interface for integers. -type Int int - -// Less returns true if int(a) < int(b). -func (a Int) Less(b Item) bool { - return a < b.(Int) -} diff --git a/discovery/vendor/github.com/google/btree/btree_mem.go b/discovery/vendor/github.com/google/btree/btree_mem.go deleted file mode 100644 index cb95b7fa..00000000 --- a/discovery/vendor/github.com/google/btree/btree_mem.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 Google Inc. -// -// 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. - -// +build ignore - -// This binary compares memory usage between btree and gollrb. -package main - -import ( - "flag" - "fmt" - "math/rand" - "runtime" - "time" - - "github.com/google/btree" - "github.com/petar/GoLLRB/llrb" -) - -var ( - size = flag.Int("size", 1000000, "size of the tree to build") - degree = flag.Int("degree", 8, "degree of btree") - gollrb = flag.Bool("llrb", false, "use llrb instead of btree") -) - -func main() { - flag.Parse() - vals := rand.Perm(*size) - var t, v interface{} - v = vals - var stats runtime.MemStats - for i := 0; i < 10; i++ { - runtime.GC() - } - fmt.Println("-------- BEFORE ----------") - runtime.ReadMemStats(&stats) - fmt.Printf("%+v\n", stats) - start := time.Now() - if *gollrb { - tr := llrb.New() - for _, v := range vals { - tr.ReplaceOrInsert(llrb.Int(v)) - } - t = tr // keep it around - } else { - tr := btree.New(*degree) - for _, v := range vals { - tr.ReplaceOrInsert(btree.Int(v)) - } - t = tr // keep it around - } - fmt.Printf("%v inserts in %v\n", *size, time.Since(start)) - fmt.Println("-------- AFTER ----------") - runtime.ReadMemStats(&stats) - fmt.Printf("%+v\n", stats) - for i := 0; i < 10; i++ { - runtime.GC() - } - fmt.Println("-------- AFTER GC ----------") - runtime.ReadMemStats(&stats) - fmt.Printf("%+v\n", stats) - if t == v { - fmt.Println("to make sure vals and tree aren't GC'd") - } -} diff --git a/discovery/vendor/github.com/google/gofuzz/.travis.yml b/discovery/vendor/github.com/google/gofuzz/.travis.yml new file mode 100644 index 00000000..f8684d99 --- /dev/null +++ b/discovery/vendor/github.com/google/gofuzz/.travis.yml @@ -0,0 +1,13 @@ +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 diff --git a/discovery/vendor/github.com/google/gofuzz/example_test.go b/discovery/vendor/github.com/google/gofuzz/example_test.go new file mode 100644 index 00000000..792707a3 --- /dev/null +++ b/discovery/vendor/github.com/google/gofuzz/example_test.go @@ -0,0 +1,225 @@ +/* +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: +} diff --git a/discovery/vendor/github.com/google/gofuzz/fuzz_test.go b/discovery/vendor/github.com/google/gofuzz/fuzz_test.go new file mode 100644 index 00000000..4059ea6f --- /dev/null +++ b/discovery/vendor/github.com/google/gofuzz/fuzz_test.go @@ -0,0 +1,472 @@ +/* +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") + } + } +} diff --git a/discovery/vendor/github.com/googleapis/gnostic/.travis.yml b/discovery/vendor/github.com/googleapis/gnostic/.travis.yml new file mode 100644 index 00000000..d31126d1 --- /dev/null +++ b/discovery/vendor/github.com/googleapis/gnostic/.travis.yml @@ -0,0 +1,46 @@ +# Travis CI build file for OpenAPI Compiler, including Go and Swift plugins + +# Use Ubuntu 14.04 +dist: trusty + +sudo: false + +language: go + +addons: + apt: + packages: + - clang-3.8 + - lldb-3.8 + - libicu-dev + - libtool + - libcurl4-openssl-dev + - libbsd-dev + - build-essential + - libssl-dev + - uuid-dev + - curl + - unzip + +install: + - ./.travis-install.sh + - export PATH=.:$HOME/local/bin:$PATH + - make + +script: + - go test . -v + - pushd plugins/gnostic-go-generator/examples/v2.0/bookstore + - make test + - popd + - pushd plugins/gnostic-go-generator/examples/v3.0/bookstore + - make test + - popd + - export PATH=.:$HOME/local/bin:$PATH + - export LD_LIBRARY_PATH=$HOME/local/lib + - pushd plugins/gnostic-swift-generator + - make + - cd examples/bookstore + - make + - .build/debug/Server & + - make test + diff --git a/discovery/vendor/github.com/googleapis/gnostic/generate-gnostic/generate-extension_test.go b/discovery/vendor/github.com/googleapis/gnostic/generate-gnostic/generate-extension_test.go new file mode 100644 index 00000000..004a7861 --- /dev/null +++ b/discovery/vendor/github.com/googleapis/gnostic/generate-gnostic/generate-extension_test.go @@ -0,0 +1,52 @@ +package main + +import ( + "io/ioutil" + "os" + "os/exec" + "testing" +) + +func TestErrorExtensionGeneratorUnsupportedPrimitive(t *testing.T) { + var err error + + output, err := exec.Command( + "generator", + "--extension", + "test/x-unsupportedprimitives.json", + "--out_dir=/tmp", + ).Output() + + outputFile := "x-unsupportedprimitives.errors" + _ = ioutil.WriteFile(outputFile, output, 0644) + err = exec.Command("diff", outputFile, "test/errors/x-unsupportedprimitives.errors").Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(outputFile) + } +} + +func TestErrorExtensionGeneratorNameCollision(t *testing.T) { + var err error + + output, err := exec.Command( + "generator", + "--extension", + "test/x-extension-name-collision.json", + "--out_dir=/tmp", + ).Output() + + outputFile := "x-extension-name-collision.errors" + _ = ioutil.WriteFile(outputFile, output, 0644) + err = exec.Command("diff", outputFile, "test/errors/x-extension-name-collision.errors").Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(outputFile) + } +} diff --git a/discovery/vendor/github.com/googleapis/gnostic/gnostic_test.go b/discovery/vendor/github.com/googleapis/gnostic/gnostic_test.go new file mode 100644 index 00000000..22eaee82 --- /dev/null +++ b/discovery/vendor/github.com/googleapis/gnostic/gnostic_test.go @@ -0,0 +1,453 @@ +package main + +import ( + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +func testCompiler(t *testing.T, inputFile string, referenceFile string, expectErrors bool) { + textFile := strings.Replace(filepath.Base(inputFile), filepath.Ext(inputFile), ".text", 1) + errorsFile := strings.Replace(filepath.Base(inputFile), filepath.Ext(inputFile), ".errors", 1) + // remove any preexisting output files + os.Remove(textFile) + os.Remove(errorsFile) + // run the compiler + var err error + var cmd = exec.Command( + "gnostic", + inputFile, + "--text-out=.", + "--errors-out=.", + "--resolve-refs") + //t.Log(cmd.Args) + err = cmd.Run() + if err != nil && !expectErrors { + t.Logf("Compile failed: %+v", err) + t.FailNow() + } + // verify the output against a reference + var outputFile string + if expectErrors { + outputFile = errorsFile + } else { + outputFile = textFile + } + err = exec.Command("diff", outputFile, referenceFile).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(textFile) + os.Remove(errorsFile) + } +} + +func testNormal(t *testing.T, inputFile string, referenceFile string) { + testCompiler(t, inputFile, referenceFile, false) +} + +func testErrors(t *testing.T, inputFile string, referenceFile string) { + testCompiler(t, inputFile, referenceFile, true) +} + +func TestPetstoreJSON(t *testing.T) { + testNormal(t, + "examples/v2.0/json/petstore.json", + "test/v2.0/petstore.text") +} + +func TestPetstoreYAML(t *testing.T) { + testNormal(t, + "examples/v2.0/yaml/petstore.yaml", + "test/v2.0/petstore.text") +} + +func TestSeparateYAML(t *testing.T) { + testNormal(t, + "examples/v2.0/yaml/petstore-separate/spec/swagger.yaml", + "test/v2.0/yaml/petstore-separate/spec/swagger.text") +} + +func TestSeparateJSON(t *testing.T) { + testNormal(t, + "examples/v2.0/json/petstore-separate/spec/swagger.json", + "test/v2.0/yaml/petstore-separate/spec/swagger.text") // yaml and json results should be identical +} + +func TestRemotePetstoreJSON(t *testing.T) { + testNormal(t, + "https://raw.githubusercontent.com/googleapis/openapi-compiler/master/examples/v2.0/json/petstore.json", + "test/v2.0/petstore.text") +} + +func TestRemotePetstoreYAML(t *testing.T) { + testNormal(t, + "https://raw.githubusercontent.com/googleapis/openapi-compiler/master/examples/v2.0/yaml/petstore.yaml", + "test/v2.0/petstore.text") +} + +func TestRemoteSeparateYAML(t *testing.T) { + testNormal(t, + "https://raw.githubusercontent.com/googleapis/openapi-compiler/master/examples/v2.0/yaml/petstore-separate/spec/swagger.yaml", + "test/v2.0/yaml/petstore-separate/spec/swagger.text") +} + +func TestRemoteSeparateJSON(t *testing.T) { + testNormal(t, + "https://raw.githubusercontent.com/googleapis/openapi-compiler/master/examples/v2.0/json/petstore-separate/spec/swagger.json", + "test/v2.0/yaml/petstore-separate/spec/swagger.text") +} + +func TestErrorBadProperties(t *testing.T) { + testErrors(t, + "examples/errors/petstore-badproperties.yaml", + "test/errors/petstore-badproperties.errors") +} + +func TestErrorUnresolvedRefs(t *testing.T) { + testErrors(t, + "examples/errors/petstore-unresolvedrefs.yaml", + "test/errors/petstore-unresolvedrefs.errors") +} + +func TestErrorMissingVersion(t *testing.T) { + testErrors(t, + "examples/errors/petstore-missingversion.yaml", + "test/errors/petstore-missingversion.errors") +} + +func testPlugin(t *testing.T, plugin string, inputFile string, outputFile string, referenceFile string) { + // remove any preexisting output files + os.Remove(outputFile) + // run the compiler + var err error + output, err := exec.Command( + "gnostic", + "--"+plugin+"-out=-", + inputFile).Output() + if err != nil { + t.Logf("Compile failed: %+v", err) + t.FailNow() + } + _ = ioutil.WriteFile(outputFile, output, 0644) + err = exec.Command("diff", outputFile, referenceFile).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(outputFile) + } +} + +func TestSamplePluginWithPetstore(t *testing.T) { + testPlugin(t, + "summary", + "examples/v2.0/yaml/petstore.yaml", + "sample-petstore.out", + "test/v2.0/yaml/sample-petstore.out") +} + +func TestErrorInvalidPluginInvocations(t *testing.T) { + var err error + output, err := exec.Command( + "gnostic", + "examples/v2.0/yaml/petstore.yaml", + "--errors-out=-", + "--plugin-out=foo=bar,:abc", + "--plugin-out=,foo=bar:abc", + "--plugin-out=foo=:abc", + "--plugin-out==bar:abc", + "--plugin-out=,,:abc", + "--plugin-out=foo=bar=baz:abc", + ).Output() + if err == nil { + t.Logf("Invalid invocations were accepted") + t.FailNow() + } + outputFile := "invalid-plugin-invocation.errors" + _ = ioutil.WriteFile(outputFile, output, 0644) + err = exec.Command("diff", outputFile, "test/errors/invalid-plugin-invocation.errors").Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(outputFile) + } +} + +func TestValidPluginInvocations(t *testing.T) { + var err error + output, err := exec.Command( + "gnostic", + "examples/v2.0/yaml/petstore.yaml", + "--errors-out=-", + // verify an invocation with no parameters + "--summary-out=!", // "!" indicates that no output should be generated + // verify single pair of parameters + "--summary-out=a=b:!", + // verify multiple parameters + "--summary-out=a=b,c=123,xyz=alphabetagammadelta:!", + // verify that special characters / . - _ can be included in parameter keys and values + "--summary-out=a/b/c=x/y/z:!", + "--summary-out=a.b.c=x.y.z:!", + "--summary-out=a-b-c=x-y-z:!", + "--summary-out=a_b_c=x_y_z:!", + ).Output() + if len(output) != 0 { + t.Logf("Valid invocations generated invalid errors\n%s", string(output)) + t.FailNow() + } + if err != nil { + t.Logf("Valid invocations were not accepted") + t.FailNow() + } +} + +func TestExtensionHandlerWithLibraryExample(t *testing.T) { + outputFile := "library-example-with-ext.text.out" + inputFile := "test/library-example-with-ext.json" + referenceFile := "test/library-example-with-ext.text.out" + + os.Remove(outputFile) + // run the compiler + var err error + + command := exec.Command( + "gnostic", + "--x-sampleone", + "--x-sampletwo", + "--text-out="+outputFile, + "--resolve-refs", + inputFile) + + _, err = command.Output() + if err != nil { + t.Logf("Compile failed for command %v: %+v", command, err) + t.FailNow() + } + //_ = ioutil.WriteFile(outputFile, output, 0644) + err = exec.Command("diff", outputFile, referenceFile).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(outputFile) + } +} + +func TestJSONOutput(t *testing.T) { + inputFile := "test/library-example-with-ext.json" + + textFile := "sample.text" + jsonFile := "sample.json" + textFile2 := "sample2.text" + jsonFile2 := "sample2.json" + + os.Remove(textFile) + os.Remove(jsonFile) + os.Remove(textFile2) + os.Remove(jsonFile2) + + var err error + + // Run the compiler once. + command := exec.Command( + "gnostic", + "--text-out="+textFile, + "--json-out="+jsonFile, + inputFile) + _, err = command.Output() + if err != nil { + t.Logf("Compile failed for command %v: %+v", command, err) + t.FailNow() + } + + // Run the compiler again, this time on the generated output. + command = exec.Command( + "gnostic", + "--text-out="+textFile2, + "--json-out="+jsonFile2, + jsonFile) + _, err = command.Output() + if err != nil { + t.Logf("Compile failed for command %v: %+v", command, err) + t.FailNow() + } + + // Verify that both models have the same internal representation. + err = exec.Command("diff", textFile, textFile2).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(textFile) + os.Remove(jsonFile) + os.Remove(textFile2) + os.Remove(jsonFile2) + } +} + +func TestYAMLOutput(t *testing.T) { + inputFile := "test/library-example-with-ext.json" + + textFile := "sample.text" + yamlFile := "sample.yaml" + textFile2 := "sample2.text" + yamlFile2 := "sample2.yaml" + + os.Remove(textFile) + os.Remove(yamlFile) + os.Remove(textFile2) + os.Remove(yamlFile2) + + var err error + + // Run the compiler once. + command := exec.Command( + "gnostic", + "--text-out="+textFile, + "--yaml-out="+yamlFile, + inputFile) + _, err = command.Output() + if err != nil { + t.Logf("Compile failed for command %v: %+v", command, err) + t.FailNow() + } + + // Run the compiler again, this time on the generated output. + command = exec.Command( + "gnostic", + "--text-out="+textFile2, + "--yaml-out="+yamlFile2, + yamlFile) + _, err = command.Output() + if err != nil { + t.Logf("Compile failed for command %v: %+v", command, err) + t.FailNow() + } + + // Verify that both models have the same internal representation. + err = exec.Command("diff", textFile, textFile2).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } else { + // if the test succeeded, clean up + os.Remove(textFile) + os.Remove(yamlFile) + os.Remove(textFile2) + os.Remove(yamlFile2) + } +} + +func testBuilder(version string, t *testing.T) { + var err error + + pbFile := "petstore-" + version + ".pb" + yamlFile := "petstore.yaml" + jsonFile := "petstore.json" + textFile := "petstore.text" + textReference := "test/" + version + ".0/petstore.text" + + os.Remove(pbFile) + os.Remove(textFile) + os.Remove(yamlFile) + os.Remove(jsonFile) + + // Generate petstore.pb. + command := exec.Command( + "petstore-builder", + "--"+version) + _, err = command.Output() + if err != nil { + t.Logf("Command %v failed: %+v", command, err) + t.FailNow() + } + + // Convert petstore.pb to yaml and json. + command = exec.Command( + "gnostic", + pbFile, + "--json-out="+jsonFile, + "--yaml-out="+yamlFile) + _, err = command.Output() + if err != nil { + t.Logf("Command %v failed: %+v", command, err) + t.FailNow() + } + + // Read petstore.yaml, resolve references, and export text. + command = exec.Command( + "gnostic", + yamlFile, + "--resolve-refs", + "--text-out="+textFile) + _, err = command.Output() + if err != nil { + t.Logf("Command %v failed: %+v", command, err) + t.FailNow() + } + + // Verify that the generated text matches our reference. + err = exec.Command("diff", textFile, textReference).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } + + // Read petstore.json, resolve references, and export text. + command = exec.Command( + "gnostic", + jsonFile, + "--resolve-refs", + "--text-out="+textFile) + _, err = command.Output() + if err != nil { + t.Logf("Command %v failed: %+v", command, err) + t.FailNow() + } + + // Verify that the generated text matches our reference. + err = exec.Command("diff", textFile, textReference).Run() + if err != nil { + t.Logf("Diff failed: %+v", err) + t.FailNow() + } + + // if the test succeeded, clean up + os.Remove(pbFile) + os.Remove(textFile) + os.Remove(yamlFile) + os.Remove(jsonFile) +} + +func TestBuilderV2(t *testing.T) { + testBuilder("v2", t) +} + +func TestBuilderV3(t *testing.T) { + testBuilder("v3", t) +} + +// OpenAPI 3.0 tests + +func TestPetstoreYAML_30(t *testing.T) { + testNormal(t, + "examples/v3.0/yaml/petstore.yaml", + "test/v3.0/petstore.text") +} + +func TestPetstoreJSON_30(t *testing.T) { + testNormal(t, + "examples/v3.0/json/petstore.json", + "test/v3.0/petstore.text") +} diff --git a/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/bookstore/bookstore_test.go b/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/bookstore/bookstore_test.go new file mode 100644 index 00000000..10506a89 --- /dev/null +++ b/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/bookstore/bookstore_test.go @@ -0,0 +1,239 @@ +/* + 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 test + +import ( + "fmt" + "net/http" + "strings" + "testing" + + "github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/bookstore/bookstore" +) + +const service = "http://localhost:8080" + +//const service = "http://generated-bookstore.appspot.com" + +func TestBookstore(t *testing.T) { + // create a client + b := bookstore.NewClient(service, nil) + // reset the service by deleting all shelves + { + err := b.DeleteShelves() + if err != nil { + t.Log("delete shelves failed") + t.Fail() + } + } + // verify that the service has no shelves + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if (response == nil) || (response.OK == nil) || (response.OK.Shelves != nil) { + t.Log(fmt.Sprintf("list shelves failed %+v", response.OK)) + t.Log(fmt.Sprintf("list shelves failed len=%d", len(response.OK.Shelves))) + t.Fail() + } + } + // attempting to get a shelf should return an error + { + _, err := b.GetShelf(1) + if err == nil { + t.Log("get shelf failed to return an error") + t.Fail() + } + } + // attempting to get a book should return an error + { + _, err := b.GetBook(1, 2) + if err == nil { + t.Log("get book failed to return an error") + t.Fail() + } + } + // add a shelf + { + var shelf bookstore.Shelf + shelf.Theme = "mysteries" + response, err := b.CreateShelf(shelf) + if err != nil { + t.Log("create shelf mysteries failed") + t.Fail() + } + if (response.OK.Name != "shelves/1") || + (response.OK.Theme != "mysteries") { + t.Log("create shelf mysteries failed") + t.Fail() + } + } + // add another shelf + { + var shelf bookstore.Shelf + shelf.Theme = "comedies" + response, err := b.CreateShelf(shelf) + if err != nil { + t.Log("create shelf comedies failed") + t.Fail() + } + if (response.OK.Name != "shelves/2") || + (response.OK.Theme != "comedies") { + t.Log("create shelf comedies failed") + t.Fail() + } + } + // get the first shelf that was added + { + response, err := b.GetShelf(1) + if err != nil { + t.Log("get shelf mysteries failed") + t.Fail() + } + if (response.OK.Name != "shelves/1") || + (response.OK.Theme != "mysteries") { + t.Log("get shelf mysteries failed") + t.Fail() + } + } + // list shelves and verify that there are 2 + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if len(response.OK.Shelves) != 2 { + t.Log("list shelves failed") + t.Fail() + } + } + // delete a shelf + { + err := b.DeleteShelf(2) + if err != nil { + t.Log("delete shelf failed") + t.Fail() + } + } + // list shelves and verify that there is only 1 + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if len(response.OK.Shelves) != 1 { + t.Log("list shelves failed") + t.Fail() + } + } + // list books on a shelf, verify that there are none + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 0 { + t.Log("list books failed") + t.Fail() + } + } + // create a book + { + var book bookstore.Book + book.Author = "Agatha Christie" + book.Title = "And Then There Were None" + _, err := b.CreateBook(1, book) + if err != nil { + t.Log("create book failed") + t.Fail() + } + } + // create another book + { + var book bookstore.Book + book.Author = "Agatha Christie" + book.Title = "Murder on the Orient Express" + _, err := b.CreateBook(1, book) + if err != nil { + t.Log("create book failed") + t.Fail() + } + } + // get the first book that was added + { + _, err := b.GetBook(1, 1) + if err != nil { + t.Log("get book failed") + t.Fail() + } + } + // list the books on a shelf and verify that there are 2 + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 2 { + t.Log("list books failed") + t.Fail() + } + } + // delete a book + { + err := b.DeleteBook(1, 2) + if err != nil { + t.Log("delete book failed") + t.Fail() + } + } + // list the books on a shelf and verify that is only 1 + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 1 { + t.Log("list books failed") + t.Fail() + } + } + // verify the handling of a badly-formed request + { + req, err := http.NewRequest("POST", service+"/shelves", strings.NewReader("")) + if err != nil { + t.Log("bad request failed") + return + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + return + } + // we expect a 400 (Bad Request) code + if resp.StatusCode != 400 { + t.Log("bad request failed") + t.Fail() + } + return + } +} diff --git a/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v3.0/bookstore/bookstore_test.go b/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v3.0/bookstore/bookstore_test.go new file mode 100644 index 00000000..1490cf88 --- /dev/null +++ b/discovery/vendor/github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v3.0/bookstore/bookstore_test.go @@ -0,0 +1,239 @@ +/* + 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 test + +import ( + "fmt" + "net/http" + "strings" + "testing" + + "github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v3.0/bookstore/bookstore" +) + +const service = "http://localhost:8080" + +//const service = "http://generated-bookstore.appspot.com" + +func TestBookstore(t *testing.T) { + // create a client + b := bookstore.NewClient(service, nil) + // reset the service by deleting all shelves + { + err := b.DeleteShelves() + if err != nil { + t.Log("delete shelves failed") + t.Fail() + } + } + // verify that the service has no shelves + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if (response == nil) || (response.OK == nil) || (response.OK.Shelves != nil) { + t.Log(fmt.Sprintf("list shelves failed %+v", response.OK)) + t.Log(fmt.Sprintf("list shelves failed len=%d", len(response.OK.Shelves))) + t.Fail() + } + } + // attempting to get a shelf should return an error + { + response, err := b.GetShelf(1) + if err == nil { + t.Logf("get shelf failed to return an error (%+v)", response.OK) + t.Fail() + } + } + // attempting to get a book should return an error + { + response, err := b.GetBook(1, 2) + if err == nil { + t.Logf("get book failed to return an error (%+v)", response.OK) + t.Fail() + } + } + // add a shelf + { + var shelf bookstore.Shelf + shelf.Theme = "mysteries" + response, err := b.CreateShelf(shelf) + if err != nil { + t.Log("create shelf mysteries failed") + t.Fail() + } + if (response.OK.Name != "shelves/1") || + (response.OK.Theme != "mysteries") { + t.Log("create shelf mysteries failed") + t.Fail() + } + } + // add another shelf + { + var shelf bookstore.Shelf + shelf.Theme = "comedies" + response, err := b.CreateShelf(shelf) + if err != nil { + t.Log("create shelf comedies failed") + t.Fail() + } + if (response.OK.Name != "shelves/2") || + (response.OK.Theme != "comedies") { + t.Log("create shelf comedies failed") + t.Fail() + } + } + // get the first shelf that was added + { + response, err := b.GetShelf(1) + if err != nil { + t.Log("get shelf mysteries failed") + t.Fail() + } + if (response.OK.Name != "shelves/1") || + (response.OK.Theme != "mysteries") { + t.Log("get shelf mysteries failed") + t.Fail() + } + } + // list shelves and verify that there are 2 + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if len(response.OK.Shelves) != 2 { + t.Log("list shelves failed") + t.Fail() + } + } + // delete a shelf + { + err := b.DeleteShelf(2) + if err != nil { + t.Log("delete shelf failed") + t.Fail() + } + } + // list shelves and verify that there is only 1 + { + response, err := b.ListShelves() + if err != nil { + t.Log("list shelves failed") + t.Fail() + } + if len(response.OK.Shelves) != 1 { + t.Log("list shelves failed") + t.Fail() + } + } + // list books on a shelf, verify that there are none + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 0 { + t.Log("list books failed") + t.Fail() + } + } + // create a book + { + var book bookstore.Book + book.Author = "Agatha Christie" + book.Title = "And Then There Were None" + _, err := b.CreateBook(1, book) + if err != nil { + t.Log("create book failed") + t.Fail() + } + } + // create another book + { + var book bookstore.Book + book.Author = "Agatha Christie" + book.Title = "Murder on the Orient Express" + _, err := b.CreateBook(1, book) + if err != nil { + t.Log("create book failed") + t.Fail() + } + } + // get the first book that was added + { + _, err := b.GetBook(1, 1) + if err != nil { + t.Log("get book failed") + t.Fail() + } + } + // list the books on a shelf and verify that there are 2 + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 2 { + t.Log("list books failed") + t.Fail() + } + } + // delete a book + { + err := b.DeleteBook(1, 2) + if err != nil { + t.Log("delete book failed") + t.Fail() + } + } + // list the books on a shelf and verify that is only 1 + { + response, err := b.ListBooks(1) + if err != nil { + t.Log("list books failed") + t.Fail() + } + if len(response.OK.Books) != 1 { + t.Log("list books failed") + t.Fail() + } + } + // verify the handling of a badly-formed request + { + req, err := http.NewRequest("POST", service+"/shelves", strings.NewReader("")) + if err != nil { + t.Log("bad request failed") + return + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + return + } + // we expect a 400 (Bad Request) code + if resp.StatusCode != 400 { + t.Log("bad request failed") + t.Fail() + } + return + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.github/CONTRIBUTING.md b/discovery/vendor/github.com/gophercloud/gophercloud/.github/CONTRIBUTING.md index 3092511a..af0bdb97 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/.github/CONTRIBUTING.md +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.github/CONTRIBUTING.md @@ -1,10 +1,16 @@ # Contributing to Gophercloud +- [New Contributor Tutorial](#new-contributor-tutorial) - [3 ways to get involved](#3-ways-to-get-involved) - [Getting started](#getting-started) - [Tests](#tests) - [Style guide](#basic-style-guide) +## New Contributor Tutorial + +For new contributors, we've put together a detailed tutorial +[here](https://github.com/gophercloud/gophercloud/tree/master/docs/contributor-tutorial)! + ## 3 ways to get involved There are three main ways you can get involved in our open-source project, and @@ -31,13 +37,15 @@ enthusiasm as any other contribution! ### 3. Working on a new feature -If you've found something we've left out, definitely feel free to start work on -introducing that feature. It's always useful to open an issue or submit a pull -request early on to indicate your intent to a core contributor - this enables -quick/early feedback and can help steer you in the right direction by avoiding -known issues. It might also help you avoid losing time implementing something -that might not ever work. One tip is to prefix your Pull Request issue title -with [wip] - then people know it's a work in progress. +If you've found something we've left out, we'd love for you to add it! Please +first open an issue to indicate your interest to a core contributor - this +enables quick/early feedback and can help steer you in the right direction by +avoiding known issues. It might also help you avoid losing time implementing +something that might not ever work or is outside the scope of the project. + +While you're implementing the feature, one tip is to prefix your Pull Request +title with `[wip]` - then people know it's a work in progress. Once the PR is +ready for review, you can remove the `[wip]` tag and request a review. We ask that you do not submit a feature that you have not spent time researching and testing first-hand in an actual OpenStack environment. While we appreciate @@ -99,7 +107,7 @@ need to checkout a new feature branch: git commit ``` -7. Submit your branch as a [Pull Request](https://help.github.com/articles/creating-a-pull-request/). When submitting a Pull Request, please follow our [Style Guide](https://github.com/gophercloud/gophercloud/blob/master/STYLEGUIDE.md). +7. Submit your branch as a [Pull Request](https://help.github.com/articles/creating-a-pull-request/). When submitting a Pull Request, please follow our [Style Guide](https://github.com/gophercloud/gophercloud/blob/master/docs/STYLEGUIDE.md). > Further information about using Git can be found [here](https://git-scm.com/book/en/v2). @@ -245,4 +253,4 @@ To run tests for a particular sub-package: ## Style guide -See [here](/STYLEGUIDE.md) +See [here](/docs/STYLEGUIDE.md) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.github/ISSUE_TEMPLATE b/discovery/vendor/github.com/gophercloud/gophercloud/.github/ISSUE_TEMPLATE index 1451b81b..2c3be773 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/.github/ISSUE_TEMPLATE +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.github/ISSUE_TEMPLATE @@ -1 +1 @@ -Before starting a PR, please read the [style guide](https://github.com/gophercloud/gophercloud/blob/master/STYLEGUIDE.md). +Before starting a PR, please read our [contributor tutorial](https://github.com/gophercloud/gophercloud/tree/master/docs/contributor-tutorial). diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.github/PULL_REQUEST_TEMPLATE b/discovery/vendor/github.com/gophercloud/gophercloud/.github/PULL_REQUEST_TEMPLATE index 43aafa02..ea3abc8f 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/.github/PULL_REQUEST_TEMPLATE +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.github/PULL_REQUEST_TEMPLATE @@ -1,3 +1,6 @@ +Prior to starting a PR, please make sure you have read our +[contributor tutorial](https://github.com/gophercloud/gophercloud/tree/master/docs/contributor-tutorial). + Prior to a PR being reviewed, there needs to be a Github issue that the PR addresses. Replace the brackets and text below with that issue number. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.gitignore b/discovery/vendor/github.com/gophercloud/gophercloud/.gitignore index df9048a0..dd91ed20 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/.gitignore +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.gitignore @@ -1,2 +1,3 @@ **/*.swp .idea +.vscode diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.travis.yml b/discovery/vendor/github.com/gophercloud/gophercloud/.travis.yml new file mode 100644 index 00000000..02728f49 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.travis.yml @@ -0,0 +1,21 @@ +language: go +sudo: false +install: +- go get golang.org/x/crypto/ssh +- go get -v -tags 'fixtures acceptance' ./... +- go get github.com/wadey/gocovmerge +- go get github.com/mattn/goveralls +- go get golang.org/x/tools/cmd/goimports +go: +- "1.10" +- "tip" +env: + global: + - secure: "xSQsAG5wlL9emjbCdxzz/hYQsSpJ/bABO1kkbwMSISVcJ3Nk0u4ywF+LS4bgeOnwPfmFvNTOqVDu3RwEvMeWXSI76t1piCPcObutb2faKLVD/hLoAS76gYX+Z8yGWGHrSB7Do5vTPj1ERe2UljdrnsSeOXzoDwFxYRaZLX4bBOB4AyoGvRniil5QXPATiA1tsWX1VMicj8a4F8X+xeESzjt1Q5Iy31e7vkptu71bhvXCaoo5QhYwT+pLR9dN0S1b7Ro0KVvkRefmr1lUOSYd2e74h6Lc34tC1h3uYZCS4h47t7v5cOXvMNxinEj2C51RvbjvZI1RLVdkuAEJD1Iz4+Ote46nXbZ//6XRZMZz/YxQ13l7ux1PFjgEB6HAapmF5Xd8PRsgeTU9LRJxpiTJ3P5QJ3leS1va8qnziM5kYipj/Rn+V8g2ad/rgkRox9LSiR9VYZD2Pe45YCb1mTKSl2aIJnV7nkOqsShY5LNB4JZSg7xIffA+9YVDktw8dJlATjZqt7WvJJ49g6A61mIUV4C15q2JPGKTkZzDiG81NtmS7hFa7k0yaE2ELgYocbcuyUcAahhxntYTC0i23nJmEHVNiZmBO3u7EgpWe4KGVfumU+lt12tIn5b3dZRBBUk3QakKKozSK1QPHGpk/AZGrhu7H6l8to6IICKWtDcyMPQ=" +before_script: +- go vet ./... +script: +- ./script/coverage +- ./script/format +after_success: +- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=cover.out diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.zuul.yaml b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul.yaml index c259d03e..92fd9d48 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/.zuul.yaml +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul.yaml @@ -1,3 +1,64 @@ +- job: + name: gophercloud-unittest + parent: golang-test + description: | + Run gophercloud unit test + run: .zuul/playbooks/gophercloud-unittest/run.yaml + nodeset: ubuntu-xenial-ut + +- job: + name: gophercloud-acceptance-test + parent: golang-test + description: | + Run gophercloud acceptance test on master branch + run: .zuul/playbooks/gophercloud-acceptance-test/run.yaml + +- job: + name: gophercloud-acceptance-test-queens + parent: gophercloud-acceptance-test + description: | + Run gophercloud acceptance test on queens branch + vars: + global_env: + OS_BRANCH: stable/queens + +- job: + name: gophercloud-acceptance-test-pike + parent: gophercloud-acceptance-test + description: | + Run gophercloud acceptance test on pike branch + vars: + global_env: + OS_BRANCH: stable/pike + +- job: + name: gophercloud-acceptance-test-ocata + parent: gophercloud-acceptance-test + description: | + Run gophercloud acceptance test on ocata branch + vars: + global_env: + OS_BRANCH: stable/ocata + +- job: + name: gophercloud-acceptance-test-newton + parent: gophercloud-acceptance-test + description: | + Run gophercloud acceptance test on newton branch + vars: + global_env: + OS_BRANCH: stable/newton + +- job: + name: gophercloud-acceptance-test-mitaka + parent: gophercloud-acceptance-test + description: | + Run gophercloud acceptance test on mitaka branch + vars: + global_env: + OS_BRANCH: stable/mitaka + nodeset: ubuntu-trusty + - project: name: gophercloud/gophercloud check: @@ -7,6 +68,19 @@ recheck-mitaka: jobs: - gophercloud-acceptance-test-mitaka + recheck-newton: + jobs: + - gophercloud-acceptance-test-newton + recheck-ocata: + jobs: + - gophercloud-acceptance-test-ocata recheck-pike: jobs: - gophercloud-acceptance-test-pike + recheck-queens: + jobs: + - gophercloud-acceptance-test-queens + periodic: + jobs: + - gophercloud-unittest + - gophercloud-acceptance-test diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-acceptance-test/run.yaml b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-acceptance-test/run.yaml new file mode 100644 index 00000000..ce8635a4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-acceptance-test/run.yaml @@ -0,0 +1,26 @@ +- hosts: all + become: yes + roles: + - config-golang + - clone-devstack-gate-to-workspace + - role: create-devstack-local-conf + enable_services: + - 'manila' + - 'designate' + - 'zun' + - 'octavia' + - install-devstack + tasks: + - name: Run acceptance tests with gophercloud + shell: + cmd: | + set -e + set -o pipefail + set -x + echo $(export |grep OS_BRANCH) + + go get ./... || true + ./script/acceptancetest -v 2>&1 | tee $TEST_RESULTS_TXT + executable: /bin/bash + chdir: '{{ zuul.project.src_dir }}' + environment: '{{ global_env }}' diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-unittest/run.yaml b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-unittest/run.yaml new file mode 100644 index 00000000..feefa54f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/.zuul/playbooks/gophercloud-unittest/run.yaml @@ -0,0 +1,16 @@ +- hosts: all + become: yes + roles: + - config-golang + tasks: + - name: Run unit tests with gophercloud + shell: + cmd: | + set -e + set -o pipefail + set -x + go get ./... || true + ./script/unittest -v 2>&1 | tee $TEST_RESULTS_TXT + executable: /bin/bash + chdir: '{{ zuul.project.src_dir }}' + environment: '{{ global_env }}' diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/README.md b/discovery/vendor/github.com/gophercloud/gophercloud/README.md index bb218c3f..8c5bfce7 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/README.md +++ b/discovery/vendor/github.com/gophercloud/gophercloud/README.md @@ -127,7 +127,7 @@ new resource in the `server` variable (a ## Advanced Usage -Have a look at the [FAQ](./FAQ.md) for some tips on customizing the way Gophercloud works. +Have a look at the [FAQ](./docs/FAQ.md) for some tips on customizing the way Gophercloud works. ## Backwards-Compatibility Guarantees @@ -148,12 +148,12 @@ We'd like to extend special thanks and appreciation to the following: ### OpenLab - + OpenLab is providing a full CI environment to test each PR and merge for a variety of OpenStack releases. ### VEXXHOST - + VEXXHOST is providing their services to assist with the development and testing of Gophercloud. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/clients.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/clients.go index d5c9cccd..e1458ebd 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/clients.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/clients.go @@ -5,6 +5,7 @@ package clients import ( "fmt" + "net/http" "os" "strings" @@ -28,6 +29,9 @@ type AcceptanceTestChoices struct { // FloatingIPPool contains the name of the pool from where to obtain floating IPs. FloatingIPPoolName string + // MagnumImageID contains the ID of a valid magnum image. + MagnumImageID string + // NetworkName is the name of a network to launch the instance on. NetworkName string @@ -42,9 +46,6 @@ type AcceptanceTestChoices struct { // DBDatastoreTypeID is the datastore type version for DB tests. DBDatastoreVersion string - - // LiveMigrate indicates ability to run multi-node migration tests - LiveMigrate bool } // AcceptanceTestChoicesFromEnv populates a ComputeChoices struct from environment variables. @@ -53,6 +54,7 @@ func AcceptanceTestChoicesFromEnv() (*AcceptanceTestChoices, error) { imageID := os.Getenv("OS_IMAGE_ID") flavorID := os.Getenv("OS_FLAVOR_ID") flavorIDResize := os.Getenv("OS_FLAVOR_ID_RESIZE") + magnumImageID := os.Getenv("OS_MAGNUM_IMAGE_ID") networkName := os.Getenv("OS_NETWORK_NAME") floatingIPPoolName := os.Getenv("OS_POOL_NAME") externalNetworkID := os.Getenv("OS_EXTGW_ID") @@ -60,11 +62,6 @@ func AcceptanceTestChoicesFromEnv() (*AcceptanceTestChoices, error) { dbDatastoreType := os.Getenv("OS_DB_DATASTORE_TYPE") dbDatastoreVersion := os.Getenv("OS_DB_DATASTORE_VERSION") - var liveMigrate bool - if v := os.Getenv("OS_LIVE_MIGRATE"); v != "" { - liveMigrate = true - } - missing := make([]string, 0, 3) if imageID == "" { missing = append(missing, "OS_IMAGE_ID") @@ -109,12 +106,12 @@ func AcceptanceTestChoicesFromEnv() (*AcceptanceTestChoices, error) { FlavorID: flavorID, FlavorIDResize: flavorIDResize, FloatingIPPoolName: floatingIPPoolName, + MagnumImageID: magnumImageID, NetworkName: networkName, ExternalNetworkID: externalNetworkID, ShareNetworkID: shareNetworkID, DBDatastoreType: dbDatastoreType, DBDatastoreVersion: dbDatastoreVersion, - LiveMigrate: liveMigrate, }, nil } @@ -132,6 +129,8 @@ func NewBlockStorageV1Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -151,6 +150,8 @@ func NewBlockStorageV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewBlockStorageV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -170,6 +171,8 @@ func NewBlockStorageV3Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewBlockStorageV3(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -187,6 +190,8 @@ func NewBlockStorageV2NoAuthClient() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return noauth.NewBlockStorageNoAuth(client, noauth.EndpointOpts{ CinderEndpoint: os.Getenv("CINDER_ENDPOINT"), }) @@ -204,6 +209,8 @@ func NewBlockStorageV3NoAuthClient() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return noauth.NewBlockStorageNoAuth(client, noauth.EndpointOpts{ CinderEndpoint: os.Getenv("CINDER_ENDPOINT"), }) @@ -223,6 +230,8 @@ func NewComputeV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewComputeV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -242,6 +251,8 @@ func NewDBV1Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewDBV1(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -261,6 +272,8 @@ func NewDNSV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewDNSV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -280,6 +293,8 @@ func NewIdentityV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewIdentityV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -299,6 +314,8 @@ func NewIdentityV2AdminClient() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewIdentityV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), Availability: gophercloud.AvailabilityAdmin, @@ -319,6 +336,8 @@ func NewIdentityV2UnauthenticatedClient() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewIdentityV2(client, gophercloud.EndpointOpts{}) } @@ -336,6 +355,8 @@ func NewIdentityV3Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewIdentityV3(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -355,6 +376,8 @@ func NewIdentityV3UnauthenticatedClient() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewIdentityV3(client, gophercloud.EndpointOpts{}) } @@ -372,6 +395,8 @@ func NewImageServiceV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewImageServiceV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -391,6 +416,8 @@ func NewNetworkV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewNetworkV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -410,6 +437,8 @@ func NewObjectStorageV1Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) @@ -429,7 +458,147 @@ func NewSharedFileSystemV2Client() (*gophercloud.ServiceClient, error) { return nil, err } + client = configureDebug(client) + return openstack.NewSharedFileSystemV2(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) } + +// NewLoadBalancerV2Client returns a *ServiceClient for making calls to the +// OpenStack Octavia v2 API. An error will be returned if authentication +// or client creation was not possible. +func NewLoadBalancerV2Client() (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + client = configureDebug(client) + + return openstack.NewLoadBalancerV2(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} + +// NewClusteringV1Client returns a *ServiceClient for making calls +// to the OpenStack Clustering v1 API. An error will be returned +// if authentication or client creation was not possible. +func NewClusteringV1Client() (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + client = configureDebug(client) + + return openstack.NewClusteringV1(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} + +// NewMessagingV2Client returns a *ServiceClient for making calls +// to the OpenStack Messaging (Zaqar) v2 API. An error will be returned +// if authentication or client creation was not possible. +func NewMessagingV2Client(clientID string) (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + client = configureDebug(client) + + return openstack.NewMessagingV2(client, clientID, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} + +// NewContainerV1Client returns a *ServiceClient for making calls +// to the OpenStack Container V1 API. An error will be returned +// if authentication or client creation was not possible. +func NewContainerV1Client() (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + return openstack.NewContainerV1(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} + +// NewKeyManagerV1Client returns a *ServiceClient for making calls +// to the OpenStack Key Manager (Barbican) v1 API. An error will be +// returned if authentication or client creation was not possible. +func NewKeyManagerV1Client() (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + client = configureDebug(client) + + return openstack.NewKeyManagerV1(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} + +// configureDebug will configure the provider client to print the API +// requests and responses if OS_DEBUG is enabled. +func configureDebug(client *gophercloud.ProviderClient) *gophercloud.ProviderClient { + if os.Getenv("OS_DEBUG") != "" { + client.HTTPClient = http.Client{ + Transport: &LogRoundTripper{ + Rt: &http.Transport{}, + }, + } + } + + return client +} + +// NewContainerInfraV1Client returns a *ServiceClient for making calls +// to the OpenStack Container Infra Management v1 API. An error will be returned +// if authentication or client creation was not possible. +func NewContainerInfraV1Client() (*gophercloud.ServiceClient, error) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + return nil, err + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + return nil, err + } + + client = configureDebug(client) + + return openstack.NewContainerInfraV1(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/conditions.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/conditions.go new file mode 100644 index 00000000..9cbbc074 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/conditions.go @@ -0,0 +1,68 @@ +package clients + +import ( + "os" + "testing" +) + +// RequireAdmin will restrict a test to only be run by admin users. +func RequireAdmin(t *testing.T) { + if os.Getenv("OS_USERNAME") != "admin" { + t.Skip("must be admin to run this test") + } +} + +// RequireDNS will restrict a test to only be run in environments +// that support DNSaaS. +func RequireDNS(t *testing.T) { + if os.Getenv("OS_DNS_ENVIRONMENT") == "" { + t.Skip("this test requires DNSaaS") + } +} + +// RequireGuestAgent will restrict a test to only be run in +// environments that support the QEMU guest agent. +func RequireGuestAgent(t *testing.T) { + if os.Getenv("OS_GUEST_AGENT") == "" { + t.Skip("this test requires support for qemu guest agent and to set OS_GUEST_AGENT to 1") + } +} + +// RequireIdentityV2 will restrict a test to only be run in +// environments that support the Identity V2 API. +func RequireIdentityV2(t *testing.T) { + if os.Getenv("OS_IDENTITY_API_VERSION") != "2.0" { + t.Skip("this test requires support for the identity v2 API") + } +} + +// RequireLiveMigration will restrict a test to only be run in +// environments that support live migration. +func RequireLiveMigration(t *testing.T) { + if os.Getenv("OS_LIVE_MIGRATE") == "" { + t.Skip("this test requires support for live migration and to set OS_LIVE_MIGRATE to 1") + } +} + +// RequireLong will ensure long-running tests can run. +func RequireLong(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } +} + +// RequireNovaNetwork will restrict a test to only be run in +// environments that support nova-network. +func RequireNovaNetwork(t *testing.T) { + if os.Getenv("OS_NOVANET") == "" { + t.Skip("this test requires nova-network and to set OS_NOVANET to 1") + } +} + +// SkipRelease will have the test be skipped on a certain +// release. Releases are named such as 'stable/mitaka', master, etc. +func SkipRelease(t *testing.T, release string) { + if os.Getenv("OS_BRANCH") == release { + t.Skipf("this is not supported in %s", release) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/http.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/http.go new file mode 100644 index 00000000..ed09a1ac --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/clients/http.go @@ -0,0 +1,168 @@ +package clients + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "log" + "net/http" + "sort" + "strings" +) + +// List of headers that need to be redacted +var REDACT_HEADERS = []string{"x-auth-token", "x-auth-key", "x-service-token", + "x-storage-token", "x-account-meta-temp-url-key", "x-account-meta-temp-url-key-2", + "x-container-meta-temp-url-key", "x-container-meta-temp-url-key-2", "set-cookie", + "x-subject-token"} + +// LogRoundTripper satisfies the http.RoundTripper interface and is used to +// customize the default http client RoundTripper to allow logging. +type LogRoundTripper struct { + Rt http.RoundTripper +} + +// RoundTrip performs a round-trip HTTP request and logs relevant information +// about it. +func (lrt *LogRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) { + defer func() { + if request.Body != nil { + request.Body.Close() + } + }() + + var err error + + log.Printf("[DEBUG] OpenStack Request URL: %s %s", request.Method, request.URL) + log.Printf("[DEBUG] OpenStack request Headers:\n%s", formatHeaders(request.Header)) + + if request.Body != nil { + request.Body, err = lrt.logRequest(request.Body, request.Header.Get("Content-Type")) + if err != nil { + return nil, err + } + } + + response, err := lrt.Rt.RoundTrip(request) + if response == nil { + return nil, err + } + + log.Printf("[DEBUG] OpenStack Response Code: %d", response.StatusCode) + log.Printf("[DEBUG] OpenStack Response Headers:\n%s", formatHeaders(response.Header)) + + response.Body, err = lrt.logResponse(response.Body, response.Header.Get("Content-Type")) + + return response, err +} + +// logRequest will log the HTTP Request details. +// If the body is JSON, it will attempt to be pretty-formatted. +func (lrt *LogRoundTripper) logRequest(original io.ReadCloser, contentType string) (io.ReadCloser, error) { + defer original.Close() + + var bs bytes.Buffer + _, err := io.Copy(&bs, original) + if err != nil { + return nil, err + } + + // Handle request contentType + if strings.HasPrefix(contentType, "application/json") { + debugInfo := lrt.formatJSON(bs.Bytes()) + log.Printf("[DEBUG] OpenStack Request Body: %s", debugInfo) + } + + return ioutil.NopCloser(strings.NewReader(bs.String())), nil +} + +// logResponse will log the HTTP Response details. +// If the body is JSON, it will attempt to be pretty-formatted. +func (lrt *LogRoundTripper) logResponse(original io.ReadCloser, contentType string) (io.ReadCloser, error) { + if strings.HasPrefix(contentType, "application/json") { + var bs bytes.Buffer + defer original.Close() + _, err := io.Copy(&bs, original) + if err != nil { + return nil, err + } + debugInfo := lrt.formatJSON(bs.Bytes()) + if debugInfo != "" { + log.Printf("[DEBUG] OpenStack Response Body: %s", debugInfo) + } + return ioutil.NopCloser(strings.NewReader(bs.String())), nil + } + + log.Printf("[DEBUG] Not logging because OpenStack response body isn't JSON") + return original, nil +} + +// formatJSON will try to pretty-format a JSON body. +// It will also mask known fields which contain sensitive information. +func (lrt *LogRoundTripper) formatJSON(raw []byte) string { + var data map[string]interface{} + + err := json.Unmarshal(raw, &data) + if err != nil { + log.Printf("[DEBUG] Unable to parse OpenStack JSON: %s", err) + return string(raw) + } + + // Mask known password fields + if v, ok := data["auth"].(map[string]interface{}); ok { + if v, ok := v["identity"].(map[string]interface{}); ok { + if v, ok := v["password"].(map[string]interface{}); ok { + if v, ok := v["user"].(map[string]interface{}); ok { + v["password"] = "***" + } + } + } + } + + // Ignore the catalog + if v, ok := data["token"].(map[string]interface{}); ok { + if _, ok := v["catalog"]; ok { + return "" + } + } + + pretty, err := json.MarshalIndent(data, "", " ") + if err != nil { + log.Printf("[DEBUG] Unable to re-marshal OpenStack JSON: %s", err) + return string(raw) + } + + return string(pretty) +} + +// redactHeaders processes a headers object, returning a redacted list +func redactHeaders(headers http.Header) (processedHeaders []string) { + for name, header := range headers { + var sensitive bool + + for _, redact_header := range REDACT_HEADERS { + if strings.ToLower(name) == strings.ToLower(redact_header) { + sensitive = true + } + } + + for _, v := range header { + if sensitive { + processedHeaders = append(processedHeaders, fmt.Sprintf("%v: %v", name, "***")) + } else { + processedHeaders = append(processedHeaders, fmt.Sprintf("%v: %v", name, v)) + } + } + } + return +} + +// formatHeaders processes a headers object plus a deliminator, returning a string +func formatHeaders(headers http.Header) string { + redactedHeaders := redactHeaders(headers) + sort.Strings(redactedHeaders) + + return strings.Join(redactedHeaders, "\n") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/schedulerstats_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/schedulerstats_test.go new file mode 100644 index 00000000..76093f4c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/schedulerstats_test.go @@ -0,0 +1,36 @@ +// +build acceptance blockstorage + +package extensions + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats" +) + +func TestSchedulerStatsList(t *testing.T) { + blockClient, err := clients.NewBlockStorageV2Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + listOpts := schedulerstats.ListOpts{ + Detail: true, + } + + allPages, err := schedulerstats.List(blockClient, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to query schedulerstats: %v", err) + } + + allStats, err := schedulerstats.ExtractStoragePools(allPages) + if err != nil { + t.Fatalf("Unable to extract pools: %v", err) + } + + for _, stat := range allStats { + tools.PrintResource(t, stat) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/services_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/services_test.go new file mode 100644 index 00000000..b65f586e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/services_test.go @@ -0,0 +1,32 @@ +// +build acceptance blockstorage + +package extensions + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services" +) + +func TestServicesList(t *testing.T) { + blockClient, err := clients.NewBlockStorageV3Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := services.List(blockClient, services.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to list services: %v", err) + } + + allServices, err := services.ExtractServices(allPages) + if err != nil { + t.Fatalf("Unable to extract services") + } + + for _, service := range allServices { + tools.PrintResource(t, service) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/volumeactions_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/volumeactions_test.go new file mode 100644 index 00000000..0c885167 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/extensions/volumeactions_test.go @@ -0,0 +1,170 @@ +// +build acceptance blockstorage + +package extensions + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + + blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2" + compute "github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2" +) + +func TestVolumeActionsUploadImageDestroy(t *testing.T) { + blockClient, err := clients.NewBlockStorageV2Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + computeClient, err := clients.NewComputeV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + volume, err := blockstorage.CreateVolume(t, blockClient) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer blockstorage.DeleteVolume(t, blockClient, volume) + + volumeImage, err := CreateUploadImage(t, blockClient, volume) + if err != nil { + t.Fatalf("Unable to upload volume-backed image: %v", err) + } + + tools.PrintResource(t, volumeImage) + + err = DeleteUploadedImage(t, computeClient, volumeImage.ImageName) + if err != nil { + t.Fatalf("Unable to delete volume-backed image: %v", err) + } +} + +func TestVolumeActionsAttachCreateDestroy(t *testing.T) { + blockClient, err := clients.NewBlockStorageV2Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + computeClient, err := clients.NewComputeV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + server, err := compute.CreateServer(t, computeClient) + if err != nil { + t.Fatalf("Unable to create server: %v", err) + } + defer compute.DeleteServer(t, computeClient, server) + + volume, err := blockstorage.CreateVolume(t, blockClient) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer blockstorage.DeleteVolume(t, blockClient, volume) + + err = CreateVolumeAttach(t, blockClient, volume, server) + if err != nil { + t.Fatalf("Unable to attach volume: %v", err) + } + + newVolume, err := volumes.Get(blockClient, volume.ID).Extract() + if err != nil { + t.Fatal("Unable to get updated volume information: %v", err) + } + + DeleteVolumeAttach(t, blockClient, newVolume) +} + +func TestVolumeActionsReserveUnreserve(t *testing.T) { + client, err := clients.NewBlockStorageV2Client() + if err != nil { + t.Fatalf("Unable to create blockstorage client: %v", err) + } + + volume, err := blockstorage.CreateVolume(t, client) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer blockstorage.DeleteVolume(t, client, volume) + + err = CreateVolumeReserve(t, client, volume) + if err != nil { + t.Fatalf("Unable to create volume reserve: %v", err) + } + defer DeleteVolumeReserve(t, client, volume) +} + +func TestVolumeActionsExtendSize(t *testing.T) { + blockClient, err := clients.NewBlockStorageV2Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + volume, err := blockstorage.CreateVolume(t, blockClient) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer blockstorage.DeleteVolume(t, blockClient, volume) + + tools.PrintResource(t, volume) + + err = ExtendVolumeSize(t, blockClient, volume) + if err != nil { + t.Fatalf("Unable to resize volume: %v", err) + } + + newVolume, err := volumes.Get(blockClient, volume.ID).Extract() + if err != nil { + t.Fatal("Unable to get updated volume information: %v", err) + } + + tools.PrintResource(t, newVolume) +} + +// Note(jtopjian): I plan to work on this at some point, but it requires +// setting up a server with iscsi utils. +/* +func TestVolumeConns(t *testing.T) { + client, err := newClient() + th.AssertNoErr(t, err) + + t.Logf("Creating volume") + cv, err := volumes.Create(client, &volumes.CreateOpts{ + Size: 1, + Name: "blockv2-volume", + }).Extract() + th.AssertNoErr(t, err) + + defer func() { + err = volumes.WaitForStatus(client, cv.ID, "available", 60) + th.AssertNoErr(t, err) + + t.Logf("Deleting volume") + err = volumes.Delete(client, cv.ID).ExtractErr() + th.AssertNoErr(t, err) + }() + + err = volumes.WaitForStatus(client, cv.ID, "available", 60) + th.AssertNoErr(t, err) + + connOpts := &volumeactions.ConnectorOpts{ + IP: "127.0.0.1", + Host: "stack", + Initiator: "iqn.1994-05.com.redhat:17cf566367d2", + Multipath: false, + Platform: "x86_64", + OSType: "linux2", + } + + t.Logf("Initializing connection") + _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract() + th.AssertNoErr(t, err) + + t.Logf("Terminating connection") + err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr() + th.AssertNoErr(t, err) +} +*/ diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/snapshots_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/snapshots_test.go new file mode 100644 index 00000000..f287c3e5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/snapshots_test.go @@ -0,0 +1,58 @@ +// +build acceptance blockstorage + +package noauth + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" +) + +func TestSnapshotsList(t *testing.T) { + client, err := clients.NewBlockStorageV2NoAuthClient() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve snapshots: %v", err) + } + + allSnapshots, err := snapshots.ExtractSnapshots(allPages) + if err != nil { + t.Fatalf("Unable to extract snapshots: %v", err) + } + + for _, snapshot := range allSnapshots { + tools.PrintResource(t, snapshot) + } +} + +func TestSnapshotsCreateDelete(t *testing.T) { + client, err := clients.NewBlockStorageV2NoAuthClient() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + volume, err := CreateVolume(t, client) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer DeleteVolume(t, client, volume) + + snapshot, err := CreateSnapshot(t, client, volume) + if err != nil { + t.Fatalf("Unable to create snapshot: %v", err) + } + defer DeleteSnapshot(t, client, snapshot) + + newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve snapshot: %v", err) + } + + tools.PrintResource(t, newSnapshot) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/volumes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/volumes_test.go new file mode 100644 index 00000000..4e10344c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/noauth/volumes_test.go @@ -0,0 +1,52 @@ +// +build acceptance blockstorage + +package noauth + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" +) + +func TestVolumesList(t *testing.T) { + client, err := clients.NewBlockStorageV2NoAuthClient() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve volumes: %v", err) + } + + allVolumes, err := volumes.ExtractVolumes(allPages) + if err != nil { + t.Fatalf("Unable to extract volumes: %v", err) + } + + for _, volume := range allVolumes { + tools.PrintResource(t, volume) + } +} + +func TestVolumesCreateDestroy(t *testing.T) { + client, err := clients.NewBlockStorageV2NoAuthClient() + if err != nil { + t.Fatalf("Unable to create blockstorage client: %v", err) + } + + volume, err := CreateVolume(t, client) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer DeleteVolume(t, client, volume) + + newVolume, err := volumes.Get(client, volume.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve volume: %v", err) + } + + tools.PrintResource(t, newVolume) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/snapshots_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/snapshots_test.go new file mode 100644 index 00000000..35453718 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/snapshots_test.go @@ -0,0 +1,58 @@ +// +build acceptance blockstorage + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots" +) + +func TestSnapshotsList(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve snapshots: %v", err) + } + + allSnapshots, err := snapshots.ExtractSnapshots(allPages) + if err != nil { + t.Fatalf("Unable to extract snapshots: %v", err) + } + + for _, snapshot := range allSnapshots { + tools.PrintResource(t, snapshot) + } +} + +func TestSnapshotsCreateDelete(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + volume, err := CreateVolume(t, client) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer DeleteVolume(t, client, volume) + + snapshot, err := CreateSnapshot(t, client, volume) + if err != nil { + t.Fatalf("Unable to create snapshot: %v", err) + } + defer DeleteSnapshotshot(t, client, snapshot) + + newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve snapshot: %v", err) + } + + tools.PrintResource(t, newSnapshot) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumes_test.go new file mode 100644 index 00000000..9a555009 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumes_test.go @@ -0,0 +1,52 @@ +// +build acceptance blockstorage + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" +) + +func TestVolumesList(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve volumes: %v", err) + } + + allVolumes, err := volumes.ExtractVolumes(allPages) + if err != nil { + t.Fatalf("Unable to extract volumes: %v", err) + } + + for _, volume := range allVolumes { + tools.PrintResource(t, volume) + } +} + +func TestVolumesCreateDestroy(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create blockstorage client: %v", err) + } + + volume, err := CreateVolume(t, client) + if err != nil { + t.Fatalf("Unable to create volume: %v", err) + } + defer DeleteVolume(t, client, volume) + + newVolume, err := volumes.Get(client, volume.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve volume: %v", err) + } + + tools.PrintResource(t, newVolume) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumetypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumetypes_test.go new file mode 100644 index 00000000..ace09bc4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v1/volumetypes_test.go @@ -0,0 +1,47 @@ +// +build acceptance blockstorage + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes" +) + +func TestVolumeTypesList(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + allPages, err := volumetypes.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve volume types: %v", err) + } + + allVolumeTypes, err := volumetypes.ExtractVolumeTypes(allPages) + if err != nil { + t.Fatalf("Unable to extract volume types: %v", err) + } + + for _, volumeType := range allVolumeTypes { + tools.PrintResource(t, volumeType) + } +} + +func TestVolumeTypesCreateDestroy(t *testing.T) { + client, err := clients.NewBlockStorageV1Client() + if err != nil { + t.Fatalf("Unable to create a blockstorage client: %v", err) + } + + volumeType, err := CreateVolumeType(t, client) + if err != nil { + t.Fatalf("Unable to create volume type: %v", err) + } + defer DeleteVolumeType(t, client, volumeType) + + tools.PrintResource(t, volumeType) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/blockstorage.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/blockstorage.go index 51c8e59c..5b6ea75e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/blockstorage.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/blockstorage.go @@ -11,15 +11,40 @@ import ( "github.com/gophercloud/gophercloud/acceptance/tools" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + th "github.com/gophercloud/gophercloud/testhelper" ) +// CreateSnapshot will create a snapshot of the specified volume. +// Snapshot will be assigned a random name and description. +func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) { + snapshotName := tools.RandomString("ACPTTEST", 16) + snapshotDescription := tools.RandomString("ACPTTEST", 16) + t.Logf("Attempting to create snapshot: %s", snapshotName) + + createOpts := snapshots.CreateOpts{ + VolumeID: volume.ID, + Name: snapshotName, + Description: snapshotDescription, + } + + snapshot, err := snapshots.Create(client, createOpts).Extract() + if err != nil { + return snapshot, err + } + + err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60) + if err != nil { + return snapshot, err + } + + t.Logf("Successfully created snapshot: %s", snapshot.ID) + + return snapshot, nil +} + // CreateVolume will create a volume with a random name and size of 1GB. An // error will be returned if the volume was unable to be created. func CreateVolume(t *testing.T, client *gophercloud.ServiceClient) (*volumes.Volume, error) { - if testing.Short() { - t.Skip("Skipping test that requires volume creation in short mode.") - } - volumeName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create volume: %s", volumeName) @@ -38,16 +63,19 @@ func CreateVolume(t *testing.T, client *gophercloud.ServiceClient) (*volumes.Vol return volume, err } + th.AssertEquals(t, volume.Name, volumeName) + th.AssertEquals(t, volume.Size, 1) + + tools.PrintResource(t, volume) + + t.Logf("Successfully created volume: %s", volume.ID) + return volume, nil } // CreateVolumeFromImage will create a volume from with a random name and size of // 1GB. An error will be returned if the volume was unable to be created. func CreateVolumeFromImage(t *testing.T, client *gophercloud.ServiceClient) (*volumes.Volume, error) { - if testing.Short() { - t.Skip("Skipping test that requires volume creation in short mode.") - } - choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) @@ -72,53 +100,37 @@ func CreateVolumeFromImage(t *testing.T, client *gophercloud.ServiceClient) (*vo return volume, err } - return volume, nil -} - -// DeleteVolume will delete a volume. A fatal error will occur if the volume -// failed to be deleted. This works best when used as a deferred function. -func DeleteVolume(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) { - err := volumes.Delete(client, volume.ID).ExtractErr() + newVolume, err := volumes.Get(client, volume.ID).Extract() if err != nil { - t.Fatalf("Unable to delete volume %s: %v", volume.ID, err) + return nil, err } - t.Logf("Deleted volume: %s", volume.ID) -} - -// CreateSnapshot will create a snapshot of the specified volume. -// Snapshot will be assigned a random name and description. -func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) { - if testing.Short() { - t.Skip("Skipping test that requires snapshot creation in short mode.") - } + th.AssertEquals(t, newVolume.Name, volumeName) + th.AssertEquals(t, newVolume.Size, 1) - snapshotName := tools.RandomString("ACPTTEST", 16) - snapshotDescription := tools.RandomString("ACPTTEST", 16) - t.Logf("Attempting to create snapshot: %s", snapshotName) + t.Logf("Successfully created volume from image: %s", newVolume.ID) - createOpts := snapshots.CreateOpts{ - VolumeID: volume.ID, - Name: snapshotName, - Description: snapshotDescription, - } + return newVolume, nil +} - snapshot, err := snapshots.Create(client, createOpts).Extract() - if err != nil { - return snapshot, err - } +// DeleteVolume will delete a volume. A fatal error will occur if the volume +// failed to be deleted. This works best when used as a deferred function. +func DeleteVolume(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) { + t.Logf("Attempting to delete volume: %s", volume.ID) - err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60) + err := volumes.Delete(client, volume.ID).ExtractErr() if err != nil { - return snapshot, err + t.Fatalf("Unable to delete volume %s: %v", volume.ID, err) } - return snapshot, nil + t.Logf("Successfully deleted volume: %s", volume.ID) } // DeleteSnapshot will delete a snapshot. A fatal error will occur if the // snapshot failed to be deleted. func DeleteSnapshot(t *testing.T, client *gophercloud.ServiceClient, snapshot *snapshots.Snapshot) { + t.Logf("Attempting to delete snapshot: %s", snapshot.ID) + err := snapshots.Delete(client, snapshot.ID).ExtractErr() if err != nil { t.Fatalf("Unable to delete snapshot %s: %+v", snapshot.ID, err) @@ -138,5 +150,5 @@ func DeleteSnapshot(t *testing.T, client *gophercloud.ServiceClient, snapshot *s t.Fatalf("Error waiting for snapshot to delete: %v", err) } - t.Logf("Deleted snapshot: %s", snapshot.ID) + t.Logf("Successfully deleted snapshot: %s", snapshot.ID) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/snapshots_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/snapshots_test.go new file mode 100644 index 00000000..a24f4dce --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/snapshots_test.go @@ -0,0 +1,46 @@ +// +build acceptance blockstorage + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestSnapshots(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + volume, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume) + + snapshot, err := CreateSnapshot(t, client, volume) + th.AssertNoErr(t, err) + defer DeleteSnapshot(t, client, snapshot) + + newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract() + th.AssertNoErr(t, err) + + allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + allSnapshots, err := snapshots.ExtractSnapshots(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allSnapshots { + tools.PrintResource(t, snapshot) + if v.ID == newSnapshot.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/volumes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/volumes_test.go new file mode 100644 index 00000000..03f659f5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2/volumes_test.go @@ -0,0 +1,61 @@ +// +build acceptance blockstorage + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestVolumesCreateDestroy(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + volume, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume) + + newVolume, err := volumes.Get(client, volume.ID).Extract() + th.AssertNoErr(t, err) + + allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + allVolumes, err := volumes.ExtractVolumes(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allVolumes { + tools.PrintResource(t, volume) + if v.ID == newVolume.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestVolumesCreateForceDestroy(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + volume, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + + newVolume, err := volumes.Get(client, volume.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newVolume) + + err = volumeactions.ForceDelete(client, newVolume.ID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/blockstorage.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/blockstorage.go index 4fedc8b8..aee4fcea 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/blockstorage.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/blockstorage.go @@ -10,15 +10,45 @@ import ( "github.com/gophercloud/gophercloud/acceptance/tools" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes" + th "github.com/gophercloud/gophercloud/testhelper" ) +// CreateSnapshot will create a snapshot of the specified volume. +// Snapshot will be assigned a random name and description. +func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) { + snapshotName := tools.RandomString("ACPTTEST", 16) + snapshotDescription := tools.RandomString("ACPTTEST", 16) + t.Logf("Attempting to create snapshot: %s", snapshotName) + + createOpts := snapshots.CreateOpts{ + VolumeID: volume.ID, + Name: snapshotName, + Description: snapshotDescription, + } + + snapshot, err := snapshots.Create(client, createOpts).Extract() + if err != nil { + return snapshot, err + } + + err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60) + if err != nil { + return snapshot, err + } + + th.AssertEquals(t, snapshot.Name, snapshotName) + th.AssertEquals(t, snapshot.VolumeID, volume.ID) + tools.PrintResource(t, snapshot) + + t.Logf("Successfully created snapshot: %s", snapshot.ID) + + return snapshot, nil +} + // CreateVolume will create a volume with a random name and size of 1GB. An // error will be returned if the volume was unable to be created. func CreateVolume(t *testing.T, client *gophercloud.ServiceClient) (*volumes.Volume, error) { - if testing.Short() { - t.Skip("Skipping test that requires volume creation in short mode.") - } - volumeName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create volume: %s", volumeName) @@ -37,48 +67,37 @@ func CreateVolume(t *testing.T, client *gophercloud.ServiceClient) (*volumes.Vol return volume, err } - return volume, nil -} + th.AssertEquals(t, volume.Name, volumeName) + tools.PrintResource(t, volume) -// DeleteVolume will delete a volume. A fatal error will occur if the volume -// failed to be deleted. This works best when used as a deferred function. -func DeleteVolume(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) { - err := volumes.Delete(client, volume.ID).ExtractErr() - if err != nil { - t.Fatalf("Unable to delete volume %s: %v", volume.ID, err) - } + t.Logf("Successfully created volume: %s", volume.ID) - t.Logf("Deleted volume: %s", volume.ID) + return volume, nil } -// CreateSnapshot will create a snapshot of the specified volume. -// Snapshot will be assigned a random name and description. -func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) { - if testing.Short() { - t.Skip("Skipping test that requires snapshot creation in short mode.") - } - - snapshotName := tools.RandomString("ACPTTEST", 16) - snapshotDescription := tools.RandomString("ACPTTEST", 16) - t.Logf("Attempting to create snapshot: %s", snapshotName) - - createOpts := snapshots.CreateOpts{ - VolumeID: volume.ID, - Name: snapshotName, - Description: snapshotDescription, +// CreateVolumeType will create a volume type with a random name. An +// error will be returned if the volume was unable to be created. +func CreateVolumeType(t *testing.T, client *gophercloud.ServiceClient) (*volumetypes.VolumeType, error) { + name := tools.RandomString("ACPTTEST", 16) + t.Logf("Attempting to create volume type: %s", name) + + createOpts := volumetypes.CreateOpts{ + Name: name, + ExtraSpecs: map[string]string{"volume_backend_name": "fake_backend_name"}, + Description: "create_from_gophercloud", } - snapshot, err := snapshots.Create(client, createOpts).Extract() + vt, err := volumetypes.Create(client, createOpts).Extract() if err != nil { - return snapshot, err + return nil, err } - err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60) - if err != nil { - return snapshot, err - } + th.AssertEquals(t, vt.IsPublic, true) + tools.PrintResource(t, vt) - return snapshot, nil + t.Logf("Successfully created volume type: %s", vt.ID) + + return vt, nil } // DeleteSnapshot will delete a snapshot. A fatal error will occur if the @@ -105,3 +124,30 @@ func DeleteSnapshot(t *testing.T, client *gophercloud.ServiceClient, snapshot *s t.Logf("Deleted snapshot: %s", snapshot.ID) } + +// DeleteVolume will delete a volume. A fatal error will occur if the volume +// failed to be deleted. This works best when used as a deferred function. +func DeleteVolume(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) { + t.Logf("Attempting to delete volume: %s", volume.ID) + + err := volumes.Delete(client, volume.ID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete volume %s: %v", volume.ID, err) + } + + t.Logf("Successfully deleted volume: %s", volume.ID) +} + +// DeleteVolumeType will delete a volume type. A fatal error will occur if the +// volume type failed to be deleted. This works best when used as a deferred +// function. +func DeleteVolumeType(t *testing.T, client *gophercloud.ServiceClient, vt *volumetypes.VolumeType) { + t.Logf("Attempting to delete volume type: %s", vt.ID) + + err := volumetypes.Delete(client, vt.ID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete volume %s: %v", vt.ID, err) + } + + t.Logf("Successfully deleted volume type: %s", vt.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/quotaset_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/quotaset_test.go new file mode 100644 index 00000000..f69e6866 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/quotaset_test.go @@ -0,0 +1,145 @@ +// +build acceptance quotasets + +package v3 + +import ( + "os" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestQuotasetGet(t *testing.T) { + clients.RequireAdmin(t) + + client, projectID := getClientAndProject(t) + + quotaSet, err := quotasets.Get(client, projectID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, quotaSet) +} + +func TestQuotasetGetDefaults(t *testing.T) { + clients.RequireAdmin(t) + + client, projectID := getClientAndProject(t) + + quotaSet, err := quotasets.GetDefaults(client, projectID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, quotaSet) +} + +func TestQuotasetGetUsage(t *testing.T) { + clients.RequireAdmin(t) + + client, projectID := getClientAndProject(t) + + quotaSetUsage, err := quotasets.GetUsage(client, projectID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, quotaSetUsage) +} + +var UpdateQuotaOpts = quotasets.UpdateOpts{ + Volumes: gophercloud.IntToPointer(100), + Snapshots: gophercloud.IntToPointer(200), + Gigabytes: gophercloud.IntToPointer(300), + PerVolumeGigabytes: gophercloud.IntToPointer(50), + Backups: gophercloud.IntToPointer(2), + BackupGigabytes: gophercloud.IntToPointer(300), +} + +var UpdatedQuotas = quotasets.QuotaSet{ + Volumes: 100, + Snapshots: 200, + Gigabytes: 300, + PerVolumeGigabytes: 50, + Backups: 2, + BackupGigabytes: 300, +} + +func TestQuotasetUpdate(t *testing.T) { + clients.RequireAdmin(t) + + client, projectID := getClientAndProject(t) + + // save original quotas + orig, err := quotasets.Get(client, projectID).Extract() + th.AssertNoErr(t, err) + + defer func() { + restore := quotasets.UpdateOpts{} + FillUpdateOptsFromQuotaSet(*orig, &restore) + + _, err = quotasets.Update(client, projectID, restore).Extract() + th.AssertNoErr(t, err) + }() + + // test Update + resultQuotas, err := quotasets.Update(client, projectID, UpdateQuotaOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, UpdatedQuotas, *resultQuotas) + + // We dont know the default quotas, so just check if the quotas are not the + // same as before + newQuotas, err := quotasets.Get(client, projectID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, resultQuotas.Volumes, newQuotas.Volumes) +} + +func TestQuotasetDelete(t *testing.T) { + clients.RequireAdmin(t) + + client, projectID := getClientAndProject(t) + + // save original quotas + orig, err := quotasets.Get(client, projectID).Extract() + th.AssertNoErr(t, err) + + defer func() { + restore := quotasets.UpdateOpts{} + FillUpdateOptsFromQuotaSet(*orig, &restore) + + _, err = quotasets.Update(client, projectID, restore).Extract() + th.AssertNoErr(t, err) + }() + + // Obtain environment default quotaset values to validate deletion. + defaultQuotaSet, err := quotasets.GetDefaults(client, projectID).Extract() + th.AssertNoErr(t, err) + + // Test Delete + err = quotasets.Delete(client, projectID).ExtractErr() + th.AssertNoErr(t, err) + + newQuotas, err := quotasets.Get(client, projectID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, newQuotas.Volumes, defaultQuotaSet.Volumes) +} + +// getClientAndProject reduces boilerplate by returning a new blockstorage v3 +// ServiceClient and a project ID obtained from the OS_PROJECT_NAME envvar. +func getClientAndProject(t *testing.T) (*gophercloud.ServiceClient, string) { + client, err := clients.NewBlockStorageV3Client() + th.AssertNoErr(t, err) + + projectID := os.Getenv("OS_PROJECT_NAME") + th.AssertNoErr(t, err) + return client, projectID +} + +func FillUpdateOptsFromQuotaSet(src quotasets.QuotaSet, dest *quotasets.UpdateOpts) { + dest.Volumes = &src.Volumes + dest.Snapshots = &src.Snapshots + dest.Gigabytes = &src.Gigabytes + dest.PerVolumeGigabytes = &src.PerVolumeGigabytes + dest.Backups = &src.Backups + dest.BackupGigabytes = &src.BackupGigabytes +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/snapshots_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/snapshots_test.go new file mode 100644 index 00000000..60bfb705 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/snapshots_test.go @@ -0,0 +1,58 @@ +// +build acceptance blockstorage + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestSnapshots(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewBlockStorageV3Client() + th.AssertNoErr(t, err) + + volume1, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume1) + + snapshot1, err := CreateSnapshot(t, client, volume1) + th.AssertNoErr(t, err) + defer DeleteSnapshot(t, client, snapshot1) + + volume2, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume2) + + snapshot2, err := CreateSnapshot(t, client, volume2) + th.AssertNoErr(t, err) + defer DeleteSnapshot(t, client, snapshot2) + + listOpts := snapshots.ListOpts{ + Limit: 1, + } + + err = snapshots.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) { + actual, err := snapshots.ExtractSnapshots(page) + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, len(actual)) + + var found bool + for _, v := range actual { + if v.ID == snapshot1.ID || v.ID == snapshot2.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + return true, nil + }) + + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumes_test.go new file mode 100644 index 00000000..32ad756c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumes_test.go @@ -0,0 +1,50 @@ +// +build acceptance blockstorage + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestVolumes(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewBlockStorageV3Client() + th.AssertNoErr(t, err) + + volume1, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume1) + + volume2, err := CreateVolume(t, client) + th.AssertNoErr(t, err) + defer DeleteVolume(t, client, volume2) + + listOpts := volumes.ListOpts{ + Limit: 1, + } + + err = volumes.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) { + actual, err := volumes.ExtractVolumes(page) + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, len(actual)) + + var found bool + for _, v := range actual { + if v.ID == volume1.ID || v.ID == volume2.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + return true, nil + }) + + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumetypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumetypes_test.go new file mode 100644 index 00000000..635d0547 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v3/volumetypes_test.go @@ -0,0 +1,52 @@ +// +build acceptance blockstorage + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestVolumeTypes(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewBlockStorageV3Client() + th.AssertNoErr(t, err) + + vt, err := CreateVolumeType(t, client) + th.AssertNoErr(t, err) + defer DeleteVolumeType(t, client, vt) + + allPages, err := volumetypes.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allVolumeTypes, err := volumetypes.ExtractVolumeTypes(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allVolumeTypes { + tools.PrintResource(t, v) + if v.ID == vt.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + var isPublic = false + updateOpts := volumetypes.UpdateOpts{ + Name: vt.Name + "-UPDATED", + IsPublic: &isPublic, + } + + newVT, err := volumetypes.Update(client, vt.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, vt.Name+"-UPDATED", newVT.Name) + th.AssertEquals(t, false, newVT.IsPublic) + + tools.PrintResource(t, newVT) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/client_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/client_test.go new file mode 100644 index 00000000..eed3a82f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/client_test.go @@ -0,0 +1,86 @@ +// +build acceptance + +package openstack + +import ( + "os" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack" +) + +func TestAuthenticatedClient(t *testing.T) { + // Obtain credentials from the environment. + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + t.Fatalf("Unable to acquire credentials: %v", err) + } + + client, err := openstack.AuthenticatedClient(ao) + if err != nil { + t.Fatalf("Unable to authenticate: %v", err) + } + + if client.TokenID == "" { + t.Errorf("No token ID assigned to the client") + } + + t.Logf("Client successfully acquired a token: %v", client.TokenID) + + // Find the storage service in the service catalog. + storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) + if err != nil { + t.Errorf("Unable to locate a storage service: %v", err) + } else { + t.Logf("Located a storage service at endpoint: [%s]", storage.Endpoint) + } +} + +func TestReauth(t *testing.T) { + ao, err := openstack.AuthOptionsFromEnv() + if err != nil { + t.Fatalf("Unable to obtain environment auth options: %v", err) + } + + // Allow reauth + ao.AllowReauth = true + + provider, err := openstack.NewClient(ao.IdentityEndpoint) + if err != nil { + t.Fatalf("Unable to create provider: %v", err) + } + + err = openstack.Authenticate(provider, ao) + if err != nil { + t.Fatalf("Unable to authenticate: %v", err) + } + + t.Logf("Creating a compute client") + _, err = openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) + if err != nil { + t.Fatalf("Unable to create compute client: %v", err) + } + + t.Logf("Sleeping for 1 second") + time.Sleep(1 * time.Second) + t.Logf("Attempting to reauthenticate") + + err = provider.ReauthFunc() + if err != nil { + t.Fatalf("Unable to reauthenticate: %v", err) + } + + t.Logf("Creating a compute client") + _, err = openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ + Region: os.Getenv("OS_REGION_NAME"), + }) + if err != nil { + t.Fatalf("Unable to create compute client: %v", err) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/actions_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/actions_test.go new file mode 100644 index 00000000..eca8fc62 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/actions_test.go @@ -0,0 +1,31 @@ +// +build acceptance clustering actions + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/actions" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestActionsList(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + opts := actions.ListOpts{ + Limit: 200, + } + + allPages, err := actions.List(client, opts).AllPages() + th.AssertNoErr(t, err) + + allActions, err := actions.ExtractActions(allPages) + th.AssertNoErr(t, err) + + for _, action := range allActions { + tools.PrintResource(t, action) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clustering.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clustering.go new file mode 100644 index 00000000..35da0a66 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clustering.go @@ -0,0 +1,433 @@ +package v1 + +import ( + "fmt" + "net/http" + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/actions" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policies" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +var TestPolicySpec = policies.Spec{ + Description: "new policy description", + Properties: map[string]interface{}{ + "destroy_after_deletion": true, + "grace_period": 60, + "reduce_desired_capacity": false, + "criteria": "OLDEST_FIRST", + }, + Type: "senlin.policy.deletion", + Version: "1.1", +} + +// CreateCluster creates a random cluster. An error will be returned if +// the cluster could not be created. +func CreateCluster(t *testing.T, client *gophercloud.ServiceClient, profileID string) (*clusters.Cluster, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create cluster: %s", name) + + createOpts := clusters.CreateOpts{ + Name: name, + DesiredCapacity: 1, + ProfileID: profileID, + MinSize: new(int), + MaxSize: 20, + Timeout: 3600, + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Config: map[string]interface{}{}, + } + + res := clusters.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, true, requestID != "") + t.Logf("Cluster %s request ID: %s", name, requestID) + + actionID, err := GetActionID(res.Header) + th.AssertNoErr(t, err) + th.AssertEquals(t, true, actionID != "") + t.Logf("Cluster %s action ID: %s", name, actionID) + + err = WaitForAction(client, actionID) + if err != nil { + return nil, err + } + + cluster, err := res.Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created cluster: %s", cluster.ID) + + tools.PrintResource(t, cluster) + tools.PrintResource(t, cluster.CreatedAt) + + th.AssertEquals(t, name, cluster.Name) + th.AssertEquals(t, profileID, cluster.ProfileID) + + return cluster, nil +} + +// CreateNode creates a random node. An error will be returned if +// the node could not be created. +func CreateNode(t *testing.T, client *gophercloud.ServiceClient, clusterID, profileID string) (*nodes.Node, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create node: %s", name) + + createOpts := nodes.CreateOpts{ + ClusterID: clusterID, + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Name: name, + ProfileID: profileID, + Role: "", + } + + res := nodes.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, true, requestID != "") + t.Logf("Node %s request ID: %s", name, requestID) + + actionID, err := GetActionID(res.Header) + th.AssertNoErr(t, err) + th.AssertEquals(t, true, actionID != "") + t.Logf("Node %s action ID: %s", name, actionID) + + err = WaitForAction(client, actionID) + if err != nil { + return nil, err + } + + node, err := res.Extract() + if err != nil { + return nil, err + } + + err = WaitForNodeStatus(client, node.ID, "ACTIVE") + if err != nil { + return nil, err + } + + t.Logf("Successfully created node: %s", node.ID) + + node, err = nodes.Get(client, node.ID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, node) + tools.PrintResource(t, node.CreatedAt) + + th.AssertEquals(t, profileID, node.ProfileID) + th.AssertEquals(t, clusterID, node.ClusterID) + th.AssertDeepEquals(t, createOpts.Metadata, node.Metadata) + + return node, nil +} + +// CreatePolicy creates a random policy. An error will be returned if the +// policy could not be created. +func CreatePolicy(t *testing.T, client *gophercloud.ServiceClient) (*policies.Policy, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create policy: %s", name) + + createOpts := policies.CreateOpts{ + Name: name, + Spec: TestPolicySpec, + } + + res := policies.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, true, requestID != "") + + t.Logf("Policy %s request ID: %s", name, requestID) + + policy, err := res.Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created policy: %s", policy.ID) + + tools.PrintResource(t, policy) + tools.PrintResource(t, policy.CreatedAt) + + th.AssertEquals(t, name, policy.Name) + + return policy, nil +} + +// CreateProfile will create a random profile. An error will be returned if the +// profile could not be created. +func CreateProfile(t *testing.T, client *gophercloud.ServiceClient) (*profiles.Profile, error) { + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + return nil, err + } + + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create profile: %s", name) + + networks := []map[string]interface{}{ + {"network": choices.NetworkName}, + } + + props := map[string]interface{}{ + "name": name, + "flavor": choices.FlavorID, + "image": choices.ImageID, + "networks": networks, + "security_groups": "", + } + + createOpts := profiles.CreateOpts{ + Name: name, + Spec: profiles.Spec{ + Type: "os.nova.server", + Version: "1.0", + Properties: props, + }, + } + + res := profiles.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, true, requestID != "") + + t.Logf("Profile %s request ID: %s", name, requestID) + + profile, err := res.Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created profile: %s", profile.ID) + + tools.PrintResource(t, profile) + tools.PrintResource(t, profile.CreatedAt) + + th.AssertEquals(t, name, profile.Name) + th.AssertEquals(t, profile.Spec.Type, "os.nova.server") + th.AssertEquals(t, profile.Spec.Version, "1.0") + + return profile, nil +} + +// CreateReceiver will create a random profile. An error will be returned if the +// profile could not be created. +func CreateReceiver(t *testing.T, client *gophercloud.ServiceClient, clusterID string) (*receivers.Receiver, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create receiver: %s", name) + + createOpts := receivers.CreateOpts{ + Name: name, + ClusterID: clusterID, + Type: receivers.WebhookReceiver, + Action: "CLUSTER_SCALE_OUT", + } + + res := receivers.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + receiver, err := res.Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created receiver: %s", receiver.ID) + + tools.PrintResource(t, receiver) + tools.PrintResource(t, receiver.CreatedAt) + + th.AssertEquals(t, name, receiver.Name) + th.AssertEquals(t, createOpts.Action, receiver.Action) + + return receiver, nil +} + +// DeleteCluster will delete a given policy. A fatal error will occur if the +// cluster could not be deleted. This works best as a deferred function. +func DeleteCluster(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete cluster: %s", id) + + res := clusters.Delete(client, id) + if res.Err != nil { + t.Fatalf("Error deleting cluster %s: %s:", id, res.Err) + } + + actionID, err := GetActionID(res.Header) + if err != nil { + t.Fatalf("Error deleting cluster %s: %s:", id, res.Err) + } + + err = WaitForAction(client, actionID) + if err != nil { + t.Fatalf("Error deleting cluster %s: %s:", id, res.Err) + } + + t.Logf("Successfully deleted cluster: %s", id) + + return +} + +// DeleteNode will delete a given node. A fatal error will occur if the +// node could not be deleted. This works best as a deferred function. +func DeleteNode(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete node: %s", id) + + err := nodes.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Error deleting node %s: %s:", id, err) + } + + err = WaitForNodeStatus(client, id, "DELETED") + if err != nil { + t.Fatalf("Error deleting node %s: %s", id, err) + } + + t.Logf("Successfully deleted node: %s", id) + + return +} + +// DeletePolicy will delete a given policy. A fatal error will occur if the +// policy could not be deleted. This works best as a deferred function. +func DeletePolicy(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete policy: %s", id) + + _, err := policies.Delete(client, id).Extract() + if err != nil { + t.Fatalf("Error deleting policy %s: %s:", id, err) + } + + t.Logf("Successfully deleted policy: %s", id) + + return +} + +// DeleteProfile will delete a given profile. A fatal error will occur if the +// profile could not be deleted. This works best as a deferred function. +func DeleteProfile(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete profile: %s", id) + + err := profiles.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Error deleting profile %s: %s:", id, err) + } + + t.Logf("Successfully deleted profile: %s", id) + + return +} + +// DeleteReceiver will delete a given receiver. A fatal error will occur if the +// receiver could not be deleted. This works best as a deferred function. +func DeleteReceiver(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete Receiver: %s", id) + + res := receivers.Delete(client, id) + if res.Err != nil { + t.Fatalf("Error deleting receiver %s: %s:", id, res.Err) + } + + t.Logf("Successfully deleted receiver: %s", id) + + return +} + +// GetActionID parses an HTTP header and returns the action ID. +func GetActionID(headers http.Header) (string, error) { + location := headers.Get("Location") + v := strings.Split(location, "actions/") + if len(v) < 2 { + return "", fmt.Errorf("unable to determine action ID") + } + + actionID := v[1] + + return actionID, nil +} + +func WaitForAction(client *gophercloud.ServiceClient, actionID string) error { + return tools.WaitFor(func() (bool, error) { + action, err := actions.Get(client, actionID).Extract() + if err != nil { + return false, err + } + + if action.Status == "SUCCEEDED" { + return true, nil + } + + if action.Status == "FAILED" { + return false, fmt.Errorf("Action %s in FAILED state", actionID) + } + + return false, nil + }) +} + +func WaitForNodeStatus(client *gophercloud.ServiceClient, id string, status string) error { + return tools.WaitFor(func() (bool, error) { + latest, err := nodes.Get(client, id).Extract() + if err != nil { + if _, ok := err.(gophercloud.ErrDefault404); ok && status == "DELETED" { + return true, nil + } + + return false, err + } + + if latest.Status == status { + return true, nil + } + + if latest.Status == "ERROR" { + return false, fmt.Errorf("Node %s in ERROR state", id) + } + + return false, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clusters_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clusters_test.go new file mode 100644 index 00000000..ba759b9b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/clusters_test.go @@ -0,0 +1,267 @@ +// +build acceptance clustering policies + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestClustersCRUD(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + // Test clusters list + allPages, err := clusters.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allClusters, err := clusters.ExtractClusters(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allClusters { + if v.ID == cluster.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test cluster update + updateOpts := clusters.UpdateOpts{ + Name: cluster.Name + "-UPDATED", + } + + res := clusters.Update(client, cluster.ID, updateOpts) + th.AssertNoErr(t, res.Err) + + actionID, err := GetActionID(res.Header) + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + newCluster, err := clusters.Get(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, newCluster.Name, cluster.Name+"-UPDATED") + + tools.PrintResource(t, newCluster) + + // Test cluster health + actionID, err = clusters.Check(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) +} + +func TestClustersResize(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + iTrue := true + resizeOpts := clusters.ResizeOpts{ + AdjustmentType: clusters.ChangeInCapacityAdjustment, + Number: 1, + Strict: &iTrue, + } + + actionID, err := clusters.Resize(client, cluster.ID, resizeOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + newCluster, err := clusters.Get(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, newCluster.DesiredCapacity, 2) + + tools.PrintResource(t, newCluster) +} + +func TestClustersScale(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + // increase cluster size to 2 + scaleOutOpts := clusters.ScaleOutOpts{ + Count: 1, + } + actionID, err := clusters.ScaleOut(client, cluster.ID, scaleOutOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + newCluster, err := clusters.Get(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, newCluster.DesiredCapacity, 2) + + // reduce cluster size to 0 + count := 2 + scaleInOpts := clusters.ScaleInOpts{ + Count: &count, + } + + actionID, err = clusters.ScaleIn(client, cluster.ID, scaleInOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + newCluster, err = clusters.Get(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, newCluster.DesiredCapacity, 0) + + tools.PrintResource(t, newCluster) +} + +func TestClustersPolicies(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + client.Microversion = "1.5" + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + policy, err := CreatePolicy(t, client) + th.AssertNoErr(t, err) + defer DeletePolicy(t, client, policy.ID) + + iTrue := true + attachPolicyOpts := clusters.AttachPolicyOpts{ + PolicyID: policy.ID, + Enabled: &iTrue, + } + + actionID, err := clusters.AttachPolicy(client, cluster.ID, attachPolicyOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + // List all policies in the cluster to see if the policy was + // successfully attached. + allPages, err := clusters.ListPolicies(client, cluster.ID, nil).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err := clusters.ExtractClusterPolicies(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allPolicies { + tools.PrintResource(t, v) + if v.PolicyID == policy.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Set the policy to disabled + iFalse := false + updatePolicyOpts := clusters.UpdatePolicyOpts{ + PolicyID: policy.ID, + Enabled: &iFalse, + } + + actionID, err = clusters.UpdatePolicy(client, cluster.ID, updatePolicyOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + clusterPolicy, err := clusters.GetPolicy(client, cluster.ID, policy.ID).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, clusterPolicy.Enabled, false) + + // Detach the policy + detachPolicyOpts := clusters.DetachPolicyOpts{ + PolicyID: policy.ID, + } + + actionID, err = clusters.DetachPolicy(client, cluster.ID, detachPolicyOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + // List all policies in the cluster to see if the policy was + // successfully detached. + allPages, err = clusters.ListPolicies(client, cluster.ID, nil).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err = clusters.ExtractClusterPolicies(allPages) + th.AssertNoErr(t, err) + + found = false + for _, v := range allPolicies { + tools.PrintResource(t, v) + if v.PolicyID == policy.ID { + found = true + } + } + + th.AssertEquals(t, found, false) +} + +func TestClustersRecovery(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + recoverOpts := clusters.RecoverOpts{ + Operation: clusters.RebuildRecovery, + } + + actionID, err := clusters.Recover(client, cluster.ID, recoverOpts).Extract() + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + newCluster, err := clusters.Get(client, cluster.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newCluster) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/nodes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/nodes_test.go new file mode 100644 index 00000000..0890d45f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/nodes_test.go @@ -0,0 +1,69 @@ +// +build acceptance clustering policies + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestNodesCRUD(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + node, err := CreateNode(t, client, cluster.ID, profile.ID) + th.AssertNoErr(t, err) + defer DeleteNode(t, client, node.ID) + + // Test nodes list + allPages, err := nodes.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allNodes, err := nodes.ExtractNodes(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allNodes { + if v.ID == node.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test nodes update + t.Logf("Attempting to update node %s", node.ID) + + updateOpts := nodes.UpdateOpts{ + Metadata: map[string]interface{}{ + "bar": "baz", + }, + } + + res := nodes.Update(client, node.ID, updateOpts) + th.AssertNoErr(t, res.Err) + + actionID, err := GetActionID(res.Header) + th.AssertNoErr(t, err) + + err = WaitForAction(client, actionID) + th.AssertNoErr(t, err) + + node, err = nodes.Get(client, node.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, node) + tools.PrintResource(t, node.Metadata) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/pkg.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/pkg.go new file mode 100644 index 00000000..e2200bc5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/pkg.go @@ -0,0 +1,2 @@ +// Package v1 package contains acceptance tests for the Openstack Clustering V1 service. +package v1 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policies_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policies_test.go new file mode 100644 index 00000000..3d583515 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policies_test.go @@ -0,0 +1,69 @@ +// +build acceptance clustering policies + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policies" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestPoliciesCRUD(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + client.Microversion = "1.5" + + policy, err := CreatePolicy(t, client) + th.AssertNoErr(t, err) + defer DeletePolicy(t, client, policy.ID) + + // Test listing policies + allPages, err := policies.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err := policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allPolicies { + if v.ID == policy.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test Get policy + getPolicy, err := policies.Get(client, policy.ID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, getPolicy) + + // Test updating policy + updateOpts := policies.UpdateOpts{ + Name: policy.Name + "-UPDATE", + } + + t.Logf("Attempting to update policy: %s", policy.ID) + updatePolicy, err := policies.Update(client, policy.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, updatePolicy) + tools.PrintResource(t, updatePolicy.UpdatedAt) + + // Test validating policy + t.Logf("Attempting to validate policy: %s", policy.ID) + validateOpts := policies.ValidateOpts{ + Spec: TestPolicySpec, + } + + validatePolicy, err := policies.Validate(client, validateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, validatePolicy) + + th.AssertEquals(t, validatePolicy.Name, "validated_policy") + th.AssertEquals(t, validatePolicy.Spec.Version, TestPolicySpec.Version) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policytypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policytypes_test.go new file mode 100644 index 00000000..fdb42a31 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/policytypes_test.go @@ -0,0 +1,64 @@ +// +build acceptance clustering policytypes + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestPolicyTypeList(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + allPages, err := policytypes.List(client).AllPages() + th.AssertNoErr(t, err) + + allPolicyTypes, err := policytypes.ExtractPolicyTypes(allPages) + th.AssertNoErr(t, err) + + for _, v := range allPolicyTypes { + tools.PrintResource(t, v) + } +} + +func TestPolicyTypeList_v_1_5(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + client.Microversion = "1.5" + allPages, err := policytypes.List(client).AllPages() + th.AssertNoErr(t, err) + + allPolicyTypes, err := policytypes.ExtractPolicyTypes(allPages) + th.AssertNoErr(t, err) + + for _, v := range allPolicyTypes { + tools.PrintResource(t, v) + } +} + +func TestPolicyTypeGet(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + policyType, err := policytypes.Get(client, "senlin.policy.batch-1.0").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, policyType) +} + +func TestPolicyTypeGet_v_1_5(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + client.Microversion = "1.5" + policyType, err := policytypes.Get(client, "senlin.policy.batch-1.0").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, policyType) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiles_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiles_test.go new file mode 100644 index 00000000..f426f832 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiles_test.go @@ -0,0 +1,49 @@ +// +build acceptance clustering policies + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestProfilesCRUD(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + // Test listing profiles + allPages, err := profiles.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allProfiles, err := profiles.ExtractProfiles(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allProfiles { + if v.ID == profile.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test updating profile + updateOpts := profiles.UpdateOpts{ + Name: profile.Name + "-UPDATED", + } + + newProfile, err := profiles.Update(client, profile.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, newProfile.Name, profile.Name+"-UPDATED") + + tools.PrintResource(t, newProfile) + tools.PrintResource(t, newProfile.UpdatedAt) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiletypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiletypes_test.go new file mode 100644 index 00000000..039f926f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/profiletypes_test.go @@ -0,0 +1,47 @@ +// +build acceptance clustering profiletypes + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestProfileTypesList(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + client.Microversion = "1.5" + + allPages, err := profiletypes.List(client).AllPages() + th.AssertNoErr(t, err) + + allProfileTypes, err := profiletypes.ExtractProfileTypes(allPages) + th.AssertNoErr(t, err) + + for _, profileType := range allProfileTypes { + tools.PrintResource(t, profileType) + } +} +func TestProfileTypesOpsList(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + client.Microversion = "1.5" + + profileTypeName := "os.nova.server-1.0" + allPages, err := profiletypes.ListOps(client, profileTypeName).AllPages() + th.AssertNoErr(t, err) + + ops, err := profiletypes.ExtractOps(allPages) + th.AssertNoErr(t, err) + + for k, v := range ops { + tools.PrintResource(t, k) + tools.PrintResource(t, v) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/receivers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/receivers_test.go new file mode 100644 index 00000000..ff0ca8ee --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/receivers_test.go @@ -0,0 +1,59 @@ +// +build acceptance clustering policies + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestReceiversCRUD(t *testing.T) { + client, err := clients.NewClusteringV1Client() + th.AssertNoErr(t, err) + + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + receiver, err := CreateReceiver(t, client, cluster.ID) + th.AssertNoErr(t, err) + defer DeleteReceiver(t, client, receiver.ID) + + // Test listing receivers + allPages, err := receivers.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allReceivers, err := receivers.ExtractReceivers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allReceivers { + if v.ID == receiver.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test updating receivers + newName := receiver.Name + "-UPDATED" + updateOpts := receivers.UpdateOpts{ + Name: newName, + } + + receiver, err = receivers.Update(client, receiver.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, receiver) + tools.PrintResource(t, receiver.UpdatedAt) + + th.AssertEquals(t, receiver.Name, newName) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/webhooktrigger_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/webhooktrigger_test.go new file mode 100644 index 00000000..4b5434d1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/clustering/v1/webhooktrigger_test.go @@ -0,0 +1,65 @@ +// +build acceptance clustering webhooks + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestClusteringWebhookTrigger(t *testing.T) { + + client, err := clients.NewClusteringV1Client() + if err != nil { + t.Fatalf("Unable to create clustering client: %v", err) + } + + opts := webhooks.TriggerOpts{ + V: "1", + } + + // create profile, cluster and receiver first + profile, err := CreateProfile(t, client) + th.AssertNoErr(t, err) + defer DeleteProfile(t, client, profile.ID) + + cluster, err := CreateCluster(t, client, profile.ID) + th.AssertNoErr(t, err) + defer DeleteCluster(t, client, cluster.ID) + + receiver, err := CreateReceiver(t, client, cluster.ID) + th.AssertNoErr(t, err) + defer DeleteReceiver(t, client, receiver.ID) + + // trigger webhook + actionID, err := webhooks.Trigger(client, receiver.ID, opts).Extract() + if err != nil { + t.Fatalf("Unable to extract webhooks trigger: %v", err) + } else { + t.Logf("Webhook trigger action id %s", actionID) + } + + err = WaitForAction(client, actionID) + if err != nil { + t.Fatalf("Error scaling out cluster %s as a result from webhook trigger: %s:", cluster.ID, err) + } + + // check that new node was created + nodelistopts := nodes.ListOpts{ + ClusterID: cluster.ID, + } + + allPages, err := nodes.List(client, nodelistopts).AllPages() + th.AssertNoErr(t, err) + + allNodes, err := nodes.ExtractNodes(allPages) + th.AssertNoErr(t, err) + + // there should be 2 nodes in the cluster after triggering webhook + th.AssertEquals(t, len(allNodes), 2) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/aggregates_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/aggregates_test.go new file mode 100644 index 00000000..352adb38 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/aggregates_test.go @@ -0,0 +1,146 @@ +// +build acceptance compute aggregates + +package v2 + +import ( + "fmt" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestAggregatesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := aggregates.List(client).AllPages() + th.AssertNoErr(t, err) + + allAggregates, err := aggregates.ExtractAggregates(allPages) + th.AssertNoErr(t, err) + + for _, v := range allAggregates { + tools.PrintResource(t, v) + } +} + +func TestAggregatesCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + aggregate, err := CreateAggregate(t, client) + th.AssertNoErr(t, err) + + defer DeleteAggregate(t, client, aggregate) + + tools.PrintResource(t, aggregate) + + updateOpts := aggregates.UpdateOpts{ + Name: "new_aggregate_name", + AvailabilityZone: "new_azone", + } + + updatedAggregate, err := aggregates.Update(client, aggregate.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, aggregate) + + th.AssertEquals(t, updatedAggregate.Name, "new_aggregate_name") + th.AssertEquals(t, updatedAggregate.AvailabilityZone, "new_azone") +} + +func TestAggregatesAddRemoveHost(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + hostToAdd, err := getHypervisor(t, client) + th.AssertNoErr(t, err) + + aggregate, err := CreateAggregate(t, client) + th.AssertNoErr(t, err) + defer DeleteAggregate(t, client, aggregate) + + addHostOpts := aggregates.AddHostOpts{ + Host: hostToAdd.HypervisorHostname, + } + + aggregateWithNewHost, err := aggregates.AddHost(client, aggregate.ID, addHostOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, aggregateWithNewHost) + + th.AssertEquals(t, aggregateWithNewHost.Hosts[0], hostToAdd.HypervisorHostname) + + removeHostOpts := aggregates.RemoveHostOpts{ + Host: hostToAdd.HypervisorHostname, + } + + aggregateWithRemovedHost, err := aggregates.RemoveHost(client, aggregate.ID, removeHostOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, aggregateWithRemovedHost) + + th.AssertEquals(t, len(aggregateWithRemovedHost.Hosts), 0) +} + +func TestAggregatesSetRemoveMetadata(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + aggregate, err := CreateAggregate(t, client) + th.AssertNoErr(t, err) + defer DeleteAggregate(t, client, aggregate) + + opts := aggregates.SetMetadataOpts{ + Metadata: map[string]interface{}{"key": "value"}, + } + + aggregateWithMetadata, err := aggregates.SetMetadata(client, aggregate.ID, opts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, aggregateWithMetadata) + + if _, ok := aggregateWithMetadata.Metadata["key"]; !ok { + t.Fatalf("aggregate %s did not contain metadata", aggregateWithMetadata.Name) + } + + optsToRemove := aggregates.SetMetadataOpts{ + Metadata: map[string]interface{}{"key": nil}, + } + + aggregateWithRemovedKey, err := aggregates.SetMetadata(client, aggregate.ID, optsToRemove).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, aggregateWithRemovedKey) + + if _, ok := aggregateWithRemovedKey.Metadata["key"]; ok { + t.Fatalf("aggregate %s still contains metadata", aggregateWithRemovedKey.Name) + } +} + +func getHypervisor(t *testing.T, client *gophercloud.ServiceClient) (*hypervisors.Hypervisor, error) { + allPages, err := hypervisors.List(client).AllPages() + th.AssertNoErr(t, err) + + allHypervisors, err := hypervisors.ExtractHypervisors(allPages) + th.AssertNoErr(t, err) + + for _, h := range allHypervisors { + return &h, nil + } + + return nil, fmt.Errorf("Unable to get hypervisor") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/attachinterfaces_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/attachinterfaces_test.go new file mode 100644 index 00000000..b8f96802 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/attachinterfaces_test.go @@ -0,0 +1,51 @@ +// +build acceptance compute servers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestAttachDetachInterface(t *testing.T) { + clients.RequireLong(t) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + iface, err := AttachInterface(t, client, server.ID) + th.AssertNoErr(t, err) + defer DetachInterface(t, client, server.ID, iface.PortID) + + tools.PrintResource(t, iface) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + var found bool + for _, networkAddresses := range server.Addresses[choices.NetworkName].([]interface{}) { + address := networkAddresses.(map[string]interface{}) + if address["OS-EXT-IPS:type"] == "fixed" { + fixedIP := address["addr"].(string) + + for _, v := range iface.FixedIPs { + if fixedIP == v.IPAddress { + found = true + } + } + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/availabilityzones_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/availabilityzones_test.go new file mode 100644 index 00000000..4d030c29 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/availabilityzones_test.go @@ -0,0 +1,58 @@ +// +build acceptance compute availabilityzones + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestAvailabilityZonesList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := availabilityzones.List(client).AllPages() + th.AssertNoErr(t, err) + + availabilityZoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, zoneInfo := range availabilityZoneInfo { + tools.PrintResource(t, zoneInfo) + + if zoneInfo.ZoneName == "nova" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestAvailabilityZonesListDetail(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := availabilityzones.ListDetail(client).AllPages() + th.AssertNoErr(t, err) + + availabilityZoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, zoneInfo := range availabilityZoneInfo { + tools.PrintResource(t, zoneInfo) + + if zoneInfo.ZoneName == "nova" { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/bootfromvolume_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/bootfromvolume_test.go new file mode 100644 index 00000000..ec5d72f7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/bootfromvolume_test.go @@ -0,0 +1,304 @@ +// +build acceptance compute bootfromvolume + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestBootFromImage(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + }, + } + + server, err := CreateBootableVolumeServer(t, client, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + tools.PrintResource(t, server) + + th.AssertEquals(t, server.Image["id"], choices.ImageID) +} + +func TestBootFromNewVolume(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + VolumeSize: 2, + }, + } + + server, err := CreateBootableVolumeServer(t, client, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + attachPages, err := volumeattach.List(client, server.ID).AllPages() + th.AssertNoErr(t, err) + + attachments, err := volumeattach.ExtractVolumeAttachments(attachPages) + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + tools.PrintResource(t, attachments) + + if server.Image != nil { + t.Fatalf("server image should be nil") + } + + th.AssertEquals(t, len(attachments), 1) + + // TODO: volumes_attached extension +} + +func TestBootFromExistingVolume(t *testing.T) { + clients.RequireLong(t) + + computeClient, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + blockStorageClient, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient) + th.AssertNoErr(t, err) + + tools.PrintResource(t, volume) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceVolume, + UUID: volume.ID, + }, + } + + server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, computeClient, server) + + attachPages, err := volumeattach.List(computeClient, server.ID).AllPages() + th.AssertNoErr(t, err) + + attachments, err := volumeattach.ExtractVolumeAttachments(attachPages) + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + tools.PrintResource(t, attachments) + + if server.Image != nil { + t.Fatalf("server image should be nil") + } + + th.AssertEquals(t, len(attachments), 1) + th.AssertEquals(t, attachments[0].VolumeID, volume.ID) + // TODO: volumes_attached extension +} + +func TestBootFromMultiEphemeralServer(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + BootIndex: 0, + DestinationType: bootfromvolume.DestinationLocal, + DeleteOnTermination: true, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + VolumeSize: 5, + }, + bootfromvolume.BlockDevice{ + BootIndex: -1, + DestinationType: bootfromvolume.DestinationLocal, + DeleteOnTermination: true, + GuestFormat: "ext4", + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 1, + }, + bootfromvolume.BlockDevice{ + BootIndex: -1, + DestinationType: bootfromvolume.DestinationLocal, + DeleteOnTermination: true, + GuestFormat: "ext4", + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 1, + }, + } + + server, err := CreateMultiEphemeralServer(t, client, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + tools.PrintResource(t, server) +} + +func TestAttachNewVolume(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + }, + bootfromvolume.BlockDevice{ + BootIndex: 1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 2, + }, + } + + server, err := CreateBootableVolumeServer(t, client, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + attachPages, err := volumeattach.List(client, server.ID).AllPages() + th.AssertNoErr(t, err) + + attachments, err := volumeattach.ExtractVolumeAttachments(attachPages) + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + tools.PrintResource(t, attachments) + + th.AssertEquals(t, server.Image["id"], choices.ImageID) + th.AssertEquals(t, len(attachments), 1) + + // TODO: volumes_attached extension +} + +func TestAttachExistingVolume(t *testing.T) { + clients.RequireLong(t) + + computeClient, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + blockStorageClient, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + volume, err := blockstorage.CreateVolume(t, blockStorageClient) + th.AssertNoErr(t, err) + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + }, + bootfromvolume.BlockDevice{ + BootIndex: 1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceVolume, + UUID: volume.ID, + }, + } + + server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) + th.AssertNoErr(t, err) + defer DeleteServer(t, computeClient, server) + + attachPages, err := volumeattach.List(computeClient, server.ID).AllPages() + th.AssertNoErr(t, err) + + attachments, err := volumeattach.ExtractVolumeAttachments(attachPages) + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + tools.PrintResource(t, attachments) + + th.AssertEquals(t, server.Image["id"], choices.ImageID) + th.AssertEquals(t, len(attachments), 1) + th.AssertEquals(t, attachments[0].VolumeID, volume.ID) + + // TODO: volumes_attached extension +} + +func TestBootFromNewCustomizedVolume(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test that requires server creation in short mode.") + } + + client, err := clients.NewComputeV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatal(err) + } + + blockDevices := []bootfromvolume.BlockDevice{ + bootfromvolume.BlockDevice{ + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceImage, + UUID: choices.ImageID, + VolumeSize: 2, + DeviceType: "disk", + DiskBus: "virtio", + }, + } + + server, err := CreateBootableVolumeServer(t, client, blockDevices) + if err != nil { + t.Fatalf("Unable to create server: %v", err) + } + defer DeleteServer(t, client, server) + + tools.PrintResource(t, server) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/compute.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/compute.go index 5cb86185..570378dd 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/compute.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/compute.go @@ -11,7 +11,8 @@ import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/acceptance/clients" "github.com/gophercloud/gophercloud/acceptance/tools" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume" dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" @@ -25,6 +26,7 @@ import ( "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" "golang.org/x/crypto/ssh" @@ -64,14 +66,69 @@ func AssociateFloatingIPWithFixedIP(t *testing.T, client *gophercloud.ServiceCli return nil } +// AttachInterface will create and attach an interface on a given server. +// An error will returned if the interface could not be created. +func AttachInterface(t *testing.T, client *gophercloud.ServiceClient, serverID string) (*attachinterfaces.Interface, error) { + t.Logf("Attempting to attach interface to server %s", serverID) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatal(err) + } + + networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) + if err != nil { + return nil, err + } + + createOpts := attachinterfaces.CreateOpts{ + NetworkID: networkID, + } + + iface, err := attachinterfaces.Create(client, serverID, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created interface %s on server %s", iface.PortID, serverID) + + return iface, nil +} + +// CreateAggregate will create an aggregate with random name and available zone. +// An error will be returned if the aggregate could not be created. +func CreateAggregate(t *testing.T, client *gophercloud.ServiceClient) (*aggregates.Aggregate, error) { + aggregateName := tools.RandomString("aggregate_", 5) + availabilityZone := tools.RandomString("zone_", 5) + t.Logf("Attempting to create aggregate %s", aggregateName) + + createOpts := aggregates.CreateOpts{ + Name: aggregateName, + AvailabilityZone: availabilityZone, + } + + aggregate, err := aggregates.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created aggregate %d", aggregate.ID) + + aggregate, err = aggregates.Get(client, aggregate.ID).Extract() + if err != nil { + return nil, err + } + + th.AssertEquals(t, aggregate.Name, aggregateName) + th.AssertEquals(t, aggregate.AvailabilityZone, availabilityZone) + + return aggregate, nil +} + // CreateBootableVolumeServer works like CreateServer but is configured with // one or more block devices defined by passing in []bootfromvolume.BlockDevice. // An error will be returned if a server was unable to be created. func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - var server *servers.Server choices, err := clients.AcceptanceTestChoicesFromEnv() @@ -113,6 +170,12 @@ func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient, } newServer, err := servers.Get(client, server.ID).Extract() + if err != nil { + return nil, err + } + + th.AssertEquals(t, newServer.Name, name) + th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID) return newServer, nil } @@ -160,6 +223,12 @@ func CreateFlavor(t *testing.T, client *gophercloud.ServiceClient) (*flavors.Fla t.Logf("Successfully created flavor %s", flavor.ID) + th.AssertEquals(t, flavor.Name, flavorName) + th.AssertEquals(t, flavor.RAM, 1) + th.AssertEquals(t, flavor.Disk, 1) + th.AssertEquals(t, flavor.VCPUs, 1) + th.AssertEquals(t, flavor.IsPublic, true) + return flavor, nil } @@ -216,6 +285,9 @@ func CreateKeyPair(t *testing.T, client *gophercloud.ServiceClient) (*keypairs.K } t.Logf("Created keypair: %s", keyPairName) + + th.AssertEquals(t, keyPair.Name, keyPairName) + return keyPair, nil } @@ -225,10 +297,6 @@ func CreateKeyPair(t *testing.T, client *gophercloud.ServiceClient) (*keypairs.K // are actually local ephemeral disks. // An error will be returned if a server was unable to be created. func CreateMultiEphemeralServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - var server *servers.Server choices, err := clients.AcceptanceTestChoicesFromEnv() @@ -268,6 +336,10 @@ func CreateMultiEphemeralServer(t *testing.T, client *gophercloud.ServiceClient, newServer, err := servers.Get(client, server.ID).Extract() + th.AssertEquals(t, newServer.Name, name) + th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID) + th.AssertEquals(t, newServer.Image["id"], choices.ImageID) + return newServer, nil } @@ -293,45 +365,63 @@ func CreatePrivateFlavor(t *testing.T, client *gophercloud.ServiceClient) (*flav t.Logf("Successfully created flavor %s", flavor.ID) + th.AssertEquals(t, flavor.Name, flavorName) + th.AssertEquals(t, flavor.RAM, 1) + th.AssertEquals(t, flavor.Disk, 1) + th.AssertEquals(t, flavor.VCPUs, 1) + th.AssertEquals(t, flavor.IsPublic, false) + return flavor, nil } // CreateSecurityGroup will create a security group with a random name. // An error will be returned if one was failed to be created. -func CreateSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (secgroups.SecurityGroup, error) { +func CreateSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (*secgroups.SecurityGroup, error) { + name := tools.RandomString("secgroup_", 5) + createOpts := secgroups.CreateOpts{ - Name: tools.RandomString("secgroup_", 5), + Name: name, Description: "something", } securityGroup, err := secgroups.Create(client, createOpts).Extract() if err != nil { - return *securityGroup, err + return nil, err } t.Logf("Created security group: %s", securityGroup.ID) - return *securityGroup, nil + + th.AssertEquals(t, securityGroup.Name, name) + + return securityGroup, nil } // CreateSecurityGroupRule will create a security group rule with a random name // and a random TCP port range between port 80 and 99. An error will be // returned if the rule failed to be created. -func CreateSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, securityGroupID string) (secgroups.Rule, error) { +func CreateSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, securityGroupID string) (*secgroups.Rule, error) { + fromPort := tools.RandomInt(80, 89) + toPort := tools.RandomInt(90, 99) createOpts := secgroups.CreateRuleOpts{ ParentGroupID: securityGroupID, - FromPort: tools.RandomInt(80, 89), - ToPort: tools.RandomInt(90, 99), + FromPort: fromPort, + ToPort: toPort, IPProtocol: "TCP", CIDR: "0.0.0.0/0", } rule, err := secgroups.CreateRule(client, createOpts).Extract() if err != nil { - return *rule, err + return nil, err } t.Logf("Created security group rule: %s", rule.ID) - return *rule, nil + + th.AssertEquals(t, rule.FromPort, fromPort) + th.AssertEquals(t, rule.ToPort, toPort) + th.AssertEquals(t, rule.ParentGroupID, securityGroupID) + + return rule, nil } // CreateServer creates a basic instance with a randomly generated name. @@ -340,12 +430,6 @@ func CreateSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, se // The instance will be launched on the network specified in OS_NETWORK_NAME. // An error will be returned if the instance was unable to be created. func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - - var server *servers.Server - choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) @@ -353,7 +437,7 @@ func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Ser networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { - return server, err + return nil, err } name := tools.RandomString("ACPTTEST", 16) @@ -361,7 +445,7 @@ func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Ser pwd := tools.MakeNewPassword("") - server, err = servers.Create(client, servers.CreateOpts{ + server, err := servers.Create(client, servers.CreateOpts{ Name: name, FlavorRef: choices.FlavorID, ImageRef: choices.ImageID, @@ -384,10 +468,19 @@ func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Ser } if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { - return server, err + return nil, err } - return server, nil + newServer, err := servers.Get(client, server.ID).Extract() + if err != nil { + return nil, err + } + + th.AssertEquals(t, newServer.Name, name) + th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID) + th.AssertEquals(t, newServer.Image["id"], choices.ImageID) + + return newServer, nil } // CreateServerWithoutImageRef creates a basic instance with a randomly generated name. @@ -396,12 +489,6 @@ func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Ser // The instance will be launched on the network specified in OS_NETWORK_NAME. // An error will be returned if the instance was unable to be created. func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - - var server *servers.Server - choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) @@ -409,7 +496,7 @@ func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { - return server, err + return nil, err } name := tools.RandomString("ACPTTEST", 16) @@ -417,7 +504,7 @@ func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient pwd := tools.MakeNewPassword("") - server, err = servers.Create(client, servers.CreateOpts{ + server, err := servers.Create(client, servers.CreateOpts{ Name: name, FlavorRef: choices.FlavorID, AdminPass: pwd, @@ -432,11 +519,11 @@ func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient }, }).Extract() if err != nil { - return server, err + return nil, err } if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { - return server, err + return nil, err } return server, nil @@ -445,27 +532,29 @@ func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient // CreateServerGroup will create a server with a random name. An error will be // returned if the server group failed to be created. func CreateServerGroup(t *testing.T, client *gophercloud.ServiceClient, policy string) (*servergroups.ServerGroup, error) { + name := tools.RandomString("ACPTTEST", 16) + + t.Logf("Attempting to create server group %s", name) + sg, err := servergroups.Create(client, &servergroups.CreateOpts{ - Name: "test", + Name: name, Policies: []string{policy}, }).Extract() if err != nil { - return sg, err + return nil, err } + t.Logf("Successfully created server group %s", name) + + th.AssertEquals(t, sg.Name, name) + return sg, nil } // CreateServerInServerGroup works like CreateServer but places the instance in // a specified Server Group. func CreateServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, serverGroup *servergroups.ServerGroup) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - - var server *servers.Server - choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) @@ -473,7 +562,7 @@ func CreateServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { - return server, err + return nil, err } name := tools.RandomString("ACPTTEST", 16) @@ -497,23 +586,30 @@ func CreateServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, Group: serverGroup.ID, }, } - server, err = servers.Create(client, schedulerHintsOpts).Extract() + server, err := servers.Create(client, schedulerHintsOpts).Extract() if err != nil { - return server, err + return nil, err } - return server, nil + if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { + return nil, err + } + + newServer, err := servers.Get(client, server.ID).Extract() + if err != nil { + return nil, err + } + + th.AssertEquals(t, newServer.Name, name) + th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID) + th.AssertEquals(t, newServer.Image["id"], choices.ImageID) + + return newServer, nil } // CreateServerWithPublicKey works the same as CreateServer, but additionally // configures the server with a specified Key Pair name. func CreateServerWithPublicKey(t *testing.T, client *gophercloud.ServiceClient, keyPairName string) (*servers.Server, error) { - if testing.Short() { - t.Skip("Skipping test that requires server creation in short mode.") - } - - var server *servers.Server - choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) @@ -521,7 +617,7 @@ func CreateServerWithPublicKey(t *testing.T, client *gophercloud.ServiceClient, networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { - return server, err + return nil, err } name := tools.RandomString("ACPTTEST", 16) @@ -536,19 +632,28 @@ func CreateServerWithPublicKey(t *testing.T, client *gophercloud.ServiceClient, }, } - server, err = servers.Create(client, keypairs.CreateOptsExt{ + server, err := servers.Create(client, keypairs.CreateOptsExt{ CreateOptsBuilder: serverCreateOpts, KeyName: keyPairName, }).Extract() if err != nil { - return server, err + return nil, err } if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { - return server, err + return nil, err } - return server, nil + newServer, err := servers.Get(client, server.ID).Extract() + if err != nil { + return nil, err + } + + th.AssertEquals(t, newServer.Name, name) + th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID) + th.AssertEquals(t, newServer.Image["id"], choices.ImageID) + + return newServer, nil } // CreateVolumeAttachment will attach a volume to a server. An error will be @@ -571,25 +676,6 @@ func CreateVolumeAttachment(t *testing.T, client *gophercloud.ServiceClient, blo return volumeAttachment, nil } -// CreateAggregate will create an aggregate with random name and available zone. -// An error will be returned if the aggregate could not be created. -func CreateAggregate(t *testing.T, client *gophercloud.ServiceClient) (*aggregates.Aggregate, error) { - aggregateName := tools.RandomString("aggregate_", 5) - availableZone := tools.RandomString("zone_", 5) - t.Logf("Attempting to create aggregate %s", aggregateName) - - createOpts := aggregates.CreateOpts{Name: aggregateName, AvailabilityZone: availableZone} - - aggregate, err := aggregates.Create(client, createOpts).Extract() - if err != nil { - return nil, err - } - - t.Logf("Successfully created aggregate %d", aggregate.ID) - - return aggregate, nil -} - // DeleteAggregate will delete a given host aggregate. A fatal error will occur if // the aggregate deleting is failed. This works best when using it as a // deferred function. @@ -651,25 +737,25 @@ func DeleteKeyPair(t *testing.T, client *gophercloud.ServiceClient, keyPair *key // DeleteSecurityGroup will delete a security group. A fatal error will occur // if the group failed to be deleted. This works best as a deferred function. -func DeleteSecurityGroup(t *testing.T, client *gophercloud.ServiceClient, securityGroup secgroups.SecurityGroup) { - err := secgroups.Delete(client, securityGroup.ID).ExtractErr() +func DeleteSecurityGroup(t *testing.T, client *gophercloud.ServiceClient, securityGroupID string) { + err := secgroups.Delete(client, securityGroupID).ExtractErr() if err != nil { - t.Fatalf("Unable to delete security group %s: %s", securityGroup.ID, err) + t.Fatalf("Unable to delete security group %s: %s", securityGroupID, err) } - t.Logf("Deleted security group: %s", securityGroup.ID) + t.Logf("Deleted security group: %s", securityGroupID) } // DeleteSecurityGroupRule will delete a security group rule. A fatal error // will occur if the rule failed to be deleted. This works best when used // as a deferred function. -func DeleteSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, rule secgroups.Rule) { - err := secgroups.DeleteRule(client, rule.ID).ExtractErr() +func DeleteSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, ruleID string) { + err := secgroups.DeleteRule(client, ruleID).ExtractErr() if err != nil { t.Fatalf("Unable to delete rule: %v", err) } - t.Logf("Deleted security group rule: %s", rule.ID) + t.Logf("Deleted security group rule: %s", ruleID) } // DeleteServer deletes an instance via its UUID. @@ -681,6 +767,16 @@ func DeleteServer(t *testing.T, client *gophercloud.ServiceClient, server *serve t.Fatalf("Unable to delete server %s: %s", server.ID, err) } + if err := WaitForComputeStatus(client, server, "DELETED"); err != nil { + if _, ok := err.(gophercloud.ErrDefault404); ok { + t.Logf("Deleted server: %s", server.ID) + return + } + t.Fatalf("Error deleting server %s: %s", server.ID, err) + } + + // If we reach this point, the API returned an actual DELETED status + // which is a very short window of time, but happens occasionally. t.Logf("Deleted server: %s", server.ID) } @@ -712,6 +808,20 @@ func DeleteVolumeAttachment(t *testing.T, client *gophercloud.ServiceClient, blo t.Logf("Deleted volume: %s", volumeAttachment.VolumeID) } +// DetachInterface will detach an interface from a server. A fatal +// error will occur if the interface could not be detached. This works best +// when used as a deferred function. +func DetachInterface(t *testing.T, client *gophercloud.ServiceClient, serverID, portID string) { + t.Logf("Attempting to detach interface %s from server %s", portID, serverID) + + err := attachinterfaces.Delete(client, serverID, portID).ExtractErr() + if err != nil { + t.Fatalf("Unable to detach interface %s from server %s", portID, serverID) + } + + t.Logf("Detached interface %s from server %s", portID, serverID) +} + // DisassociateFloatingIP will disassociate a floating IP from an instance. A // fatal error will occur if the floating IP failed to disassociate. This works // best when using it as a deferred function. @@ -794,6 +904,10 @@ func ImportPublicKey(t *testing.T, client *gophercloud.ServiceClient, publicKey } t.Logf("Created keypair: %s", keyPairName) + + th.AssertEquals(t, keyPair.Name, keyPairName) + th.AssertEquals(t, keyPair.PublicKey, publicKey) + return keyPair, nil } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/defsecrules_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/defsecrules_test.go new file mode 100644 index 00000000..e97a3787 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/defsecrules_test.go @@ -0,0 +1,61 @@ +// +build acceptance compute defsecrules + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestDefSecRulesList(t *testing.T) { + clients.RequireAdmin(t) + clients.RequireNovaNetwork(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := dsr.List(client).AllPages() + th.AssertNoErr(t, err) + + allDefaultRules, err := dsr.ExtractDefaultRules(allPages) + th.AssertNoErr(t, err) + + for _, defaultRule := range allDefaultRules { + tools.PrintResource(t, defaultRule) + } +} + +func TestDefSecRulesCreate(t *testing.T) { + clients.RequireAdmin(t) + clients.RequireNovaNetwork(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + defaultRule, err := CreateDefaultRule(t, client) + th.AssertNoErr(t, err) + defer DeleteDefaultRule(t, client, defaultRule) + + tools.PrintResource(t, defaultRule) +} + +func TestDefSecRulesGet(t *testing.T) { + clients.RequireAdmin(t) + clients.RequireNovaNetwork(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + defaultRule, err := CreateDefaultRule(t, client) + th.AssertNoErr(t, err) + defer DeleteDefaultRule(t, client, defaultRule) + + newDefaultRule, err := dsr.Get(client, defaultRule.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newDefaultRule) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/extension_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/extension_test.go new file mode 100644 index 00000000..f76cc52e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/extension_test.go @@ -0,0 +1,46 @@ +// +build acceptance compute extensions + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/common/extensions" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestExtensionsList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := extensions.List(client).AllPages() + th.AssertNoErr(t, err) + + allExtensions, err := extensions.ExtractExtensions(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, extension := range allExtensions { + tools.PrintResource(t, extension) + + if extension.Name == "SchedulerHints" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestExtensionsGet(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + extension, err := extensions.Get(client, "os-admin-actions").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, extension) + + th.AssertEquals(t, extension.Name, "AdminActions") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/flavors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/flavors_test.go new file mode 100644 index 00000000..d4aa341a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/flavors_test.go @@ -0,0 +1,202 @@ +// +build acceptance compute flavors + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" + th "github.com/gophercloud/gophercloud/testhelper" + + identity "github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3" +) + +func TestFlavorsList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + allPages, err := flavors.ListDetail(client, nil).AllPages() + th.AssertNoErr(t, err) + + allFlavors, err := flavors.ExtractFlavors(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, flavor := range allFlavors { + tools.PrintResource(t, flavor) + + if flavor.ID == choices.FlavorID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestFlavorsAccessTypeList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + flavorAccessTypes := map[string]flavors.AccessType{ + "public": flavors.PublicAccess, + "private": flavors.PrivateAccess, + "all": flavors.AllAccess, + } + + for flavorTypeName, flavorAccessType := range flavorAccessTypes { + t.Logf("** %s flavors: **", flavorTypeName) + allPages, err := flavors.ListDetail(client, flavors.ListOpts{AccessType: flavorAccessType}).AllPages() + th.AssertNoErr(t, err) + + allFlavors, err := flavors.ExtractFlavors(allPages) + th.AssertNoErr(t, err) + + for _, flavor := range allFlavors { + tools.PrintResource(t, flavor) + } + } +} + +func TestFlavorsGet(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + flavor, err := flavors.Get(client, choices.FlavorID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, flavor) + + th.AssertEquals(t, flavor.ID, choices.FlavorID) +} + +func TestFlavorsCreateDelete(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + flavor, err := CreateFlavor(t, client) + th.AssertNoErr(t, err) + defer DeleteFlavor(t, client, flavor) + + tools.PrintResource(t, flavor) +} + +func TestFlavorsAccessesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + flavor, err := CreatePrivateFlavor(t, client) + th.AssertNoErr(t, err) + defer DeleteFlavor(t, client, flavor) + + allPages, err := flavors.ListAccesses(client, flavor.ID).AllPages() + th.AssertNoErr(t, err) + + allAccesses, err := flavors.ExtractAccesses(allPages) + th.AssertNoErr(t, err) + + th.AssertEquals(t, len(allAccesses), 0) +} + +func TestFlavorsAccessCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + identityClient, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := identity.CreateProject(t, identityClient, nil) + th.AssertNoErr(t, err) + defer identity.DeleteProject(t, identityClient, project.ID) + + flavor, err := CreatePrivateFlavor(t, client) + th.AssertNoErr(t, err) + defer DeleteFlavor(t, client, flavor) + + addAccessOpts := flavors.AddAccessOpts{ + Tenant: project.ID, + } + + accessList, err := flavors.AddAccess(client, flavor.ID, addAccessOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, len(accessList), 1) + th.AssertEquals(t, accessList[0].TenantID, project.ID) + th.AssertEquals(t, accessList[0].FlavorID, flavor.ID) + + for _, access := range accessList { + tools.PrintResource(t, access) + } + + removeAccessOpts := flavors.RemoveAccessOpts{ + Tenant: project.ID, + } + + accessList, err = flavors.RemoveAccess(client, flavor.ID, removeAccessOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, len(accessList), 0) +} + +func TestFlavorsExtraSpecsCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + flavor, err := CreatePrivateFlavor(t, client) + th.AssertNoErr(t, err) + defer DeleteFlavor(t, client, flavor) + + createOpts := flavors.ExtraSpecsOpts{ + "hw:cpu_policy": "CPU-POLICY", + "hw:cpu_thread_policy": "CPU-THREAD-POLICY", + } + createdExtraSpecs, err := flavors.CreateExtraSpecs(client, flavor.ID, createOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, createdExtraSpecs) + + th.AssertEquals(t, len(createdExtraSpecs), 2) + th.AssertEquals(t, createdExtraSpecs["hw:cpu_policy"], "CPU-POLICY") + th.AssertEquals(t, createdExtraSpecs["hw:cpu_thread_policy"], "CPU-THREAD-POLICY") + + err = flavors.DeleteExtraSpec(client, flavor.ID, "hw:cpu_policy").ExtractErr() + th.AssertNoErr(t, err) + + updateOpts := flavors.ExtraSpecsOpts{ + "hw:cpu_thread_policy": "CPU-THREAD-POLICY-BETTER", + } + updatedExtraSpec, err := flavors.UpdateExtraSpec(client, flavor.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, updatedExtraSpec) + + allExtraSpecs, err := flavors.ListExtraSpecs(client, flavor.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, allExtraSpecs) + + th.AssertEquals(t, len(allExtraSpecs), 1) + th.AssertEquals(t, allExtraSpecs["hw:cpu_thread_policy"], "CPU-THREAD-POLICY-BETTER") + + spec, err := flavors.GetExtraSpec(client, flavor.ID, "hw:cpu_thread_policy").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, spec) + + th.AssertEquals(t, spec["hw:cpu_thread_policy"], "CPU-THREAD-POLICY-BETTER") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/floatingip_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/floatingip_test.go new file mode 100644 index 00000000..81308736 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/floatingip_test.go @@ -0,0 +1,123 @@ +// +build acceptance compute servers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestFloatingIPsCreateDelete(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + floatingIP, err := CreateFloatingIP(t, client) + th.AssertNoErr(t, err) + defer DeleteFloatingIP(t, client, floatingIP) + + tools.PrintResource(t, floatingIP) + + allPages, err := floatingips.List(client).AllPages() + th.AssertNoErr(t, err) + + allFloatingIPs, err := floatingips.ExtractFloatingIPs(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, fip := range allFloatingIPs { + tools.PrintResource(t, floatingIP) + + if fip.ID == floatingIP.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + fip, err := floatingips.Get(client, floatingIP.ID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, floatingIP.ID, fip.ID) +} + +func TestFloatingIPsAssociate(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + floatingIP, err := CreateFloatingIP(t, client) + th.AssertNoErr(t, err) + defer DeleteFloatingIP(t, client, floatingIP) + + tools.PrintResource(t, floatingIP) + + err = AssociateFloatingIP(t, client, floatingIP, server) + th.AssertNoErr(t, err) + defer DisassociateFloatingIP(t, client, floatingIP, server) + + newFloatingIP, err := floatingips.Get(client, floatingIP.ID).Extract() + th.AssertNoErr(t, err) + + t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP) + + tools.PrintResource(t, newFloatingIP) + + th.AssertEquals(t, newFloatingIP.InstanceID, server.ID) +} + +func TestFloatingIPsFixedIPAssociate(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + newServer, err := servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + floatingIP, err := CreateFloatingIP(t, client) + th.AssertNoErr(t, err) + defer DeleteFloatingIP(t, client, floatingIP) + + tools.PrintResource(t, floatingIP) + + var fixedIP string + for _, networkAddresses := range newServer.Addresses[choices.NetworkName].([]interface{}) { + address := networkAddresses.(map[string]interface{}) + if address["OS-EXT-IPS:type"] == "fixed" { + if address["version"].(float64) == 4 { + fixedIP = address["addr"].(string) + } + } + } + + err = AssociateFloatingIPWithFixedIP(t, client, floatingIP, newServer, fixedIP) + th.AssertNoErr(t, err) + defer DisassociateFloatingIP(t, client, floatingIP, newServer) + + newFloatingIP, err := floatingips.Get(client, floatingIP.ID).Extract() + th.AssertNoErr(t, err) + + t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP) + + tools.PrintResource(t, newFloatingIP) + + th.AssertEquals(t, newFloatingIP.InstanceID, server.ID) + th.AssertEquals(t, newFloatingIP.FixedIP, fixedIP) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/hypervisors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/hypervisors_test.go new file mode 100644 index 00000000..29d49a27 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/hypervisors_test.go @@ -0,0 +1,95 @@ +// +build acceptance compute hypervisors + +package v2 + +import ( + "fmt" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestHypervisorsList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := hypervisors.List(client).AllPages() + th.AssertNoErr(t, err) + + allHypervisors, err := hypervisors.ExtractHypervisors(allPages) + th.AssertNoErr(t, err) + + for _, h := range allHypervisors { + tools.PrintResource(t, h) + } +} + +func TestHypervisorsGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + hypervisorID, err := getHypervisorID(t, client) + th.AssertNoErr(t, err) + + hypervisor, err := hypervisors.Get(client, hypervisorID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, hypervisor) + + th.AssertEquals(t, hypervisorID, hypervisor.ID) +} + +func TestHypervisorsGetStatistics(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + hypervisorsStats, err := hypervisors.GetStatistics(client).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, hypervisorsStats) + + if hypervisorsStats.Count == 0 { + t.Fatalf("Unable to get hypervisor stats") + } +} + +func TestHypervisorsGetUptime(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + hypervisorID, err := getHypervisorID(t, client) + th.AssertNoErr(t, err) + + hypervisor, err := hypervisors.GetUptime(client, hypervisorID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, hypervisor) + + th.AssertEquals(t, hypervisorID, hypervisor.ID) +} + +func getHypervisorID(t *testing.T, client *gophercloud.ServiceClient) (int, error) { + allPages, err := hypervisors.List(client).AllPages() + th.AssertNoErr(t, err) + + allHypervisors, err := hypervisors.ExtractHypervisors(allPages) + th.AssertNoErr(t, err) + + if len(allHypervisors) > 0 { + return allHypervisors[0].ID, nil + } + + return 0, fmt.Errorf("Unable to get hypervisor ID") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/images_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/images_test.go new file mode 100644 index 00000000..d7fe19b3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/images_test.go @@ -0,0 +1,52 @@ +// +build acceptance compute images + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/images" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestImagesList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + allPages, err := images.ListDetail(client, nil).AllPages() + th.AssertNoErr(t, err) + + allImages, err := images.ExtractImages(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, image := range allImages { + tools.PrintResource(t, image) + + if image.ID == choices.ImageID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestImagesGet(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + image, err := images.Get(client, choices.ImageID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, image) + + th.AssertEquals(t, choices.ImageID, image.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/keypairs_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/keypairs_test.go new file mode 100644 index 00000000..4bb0ed97 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/keypairs_test.go @@ -0,0 +1,102 @@ +// +build acceptance compute keypairs + +package v2 + +import ( + "testing" + + "golang.org/x/crypto/ssh" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +const keyName = "gophercloud_test_key_pair" + +func TestKeypairsParse(t *testing.T) { + clients.SkipRelease(t, "stable/mitaka") + clients.SkipRelease(t, "stable/newton") + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + keyPair, err := CreateKeyPair(t, client) + th.AssertNoErr(t, err) + defer DeleteKeyPair(t, client, keyPair) + + // There was a series of OpenStack releases, between Liberty and Ocata, + // where the returned SSH key was not parsable by Go. + // This checks if the issue is happening again. + _, err = ssh.ParsePrivateKey([]byte(keyPair.PrivateKey)) + th.AssertNoErr(t, err) + + tools.PrintResource(t, keyPair) +} + +func TestKeypairsCreateDelete(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + keyPair, err := CreateKeyPair(t, client) + th.AssertNoErr(t, err) + defer DeleteKeyPair(t, client, keyPair) + + tools.PrintResource(t, keyPair) + + allPages, err := keypairs.List(client).AllPages() + th.AssertNoErr(t, err) + + allKeys, err := keypairs.ExtractKeyPairs(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, kp := range allKeys { + tools.PrintResource(t, kp) + + if kp.Name == keyPair.Name { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestKeypairsImportPublicKey(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + publicKey, err := createKey() + th.AssertNoErr(t, err) + + keyPair, err := ImportPublicKey(t, client, publicKey) + th.AssertNoErr(t, err) + defer DeleteKeyPair(t, client, keyPair) + + tools.PrintResource(t, keyPair) +} + +func TestKeypairsServerCreateWithKey(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + publicKey, err := createKey() + th.AssertNoErr(t, err) + + keyPair, err := ImportPublicKey(t, client, publicKey) + th.AssertNoErr(t, err) + defer DeleteKeyPair(t, client, keyPair) + + server, err := CreateServerWithPublicKey(t, client, keyPair.Name) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, server.KeyName, keyPair.Name) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/limits_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/limits_test.go new file mode 100644 index 00000000..8133999c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/limits_test.go @@ -0,0 +1,50 @@ +// +build acceptance compute limits + +package v2 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestLimits(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + limits, err := limits.Get(client, nil).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, limits) + + th.AssertEquals(t, limits.Absolute.MaxPersonalitySize, 10240) +} + +func TestLimitsForTenant(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + // I think this is the easiest way to get the tenant ID while being + // agnostic to Identity v2 and v3. + // Technically we're just returning the limits for ourselves, but it's + // the fact that we're specifying a tenant ID that is important here. + endpointParts := strings.Split(client.Endpoint, "/") + tenantID := endpointParts[4] + + getOpts := limits.GetOpts{ + TenantID: tenantID, + } + + limits, err := limits.Get(client, getOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, limits) + + th.AssertEquals(t, limits.Absolute.MaxPersonalitySize, 10240) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/migrate_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/migrate_test.go new file mode 100644 index 00000000..0661d12d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/migrate_test.go @@ -0,0 +1,56 @@ +// +build acceptance compute servers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestMigrate(t *testing.T) { + t.Skip("This is not passing in OpenLab. Works locally") + + clients.RequireLong(t) + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to migrate server %s", server.ID) + + err = migrate.Migrate(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestLiveMigrate(t *testing.T) { + clients.RequireLong(t) + clients.RequireAdmin(t) + clients.RequireLiveMigration(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to migrate server %s", server.ID) + + blockMigration := false + diskOverCommit := false + + liveMigrateOpts := migrate.LiveMigrateOpts{ + BlockMigration: &blockMigration, + DiskOverCommit: &diskOverCommit, + } + + err = migrate.LiveMigrate(client, server.ID, liveMigrateOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/network_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/network_test.go new file mode 100644 index 00000000..25fbe414 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/network_test.go @@ -0,0 +1,55 @@ +// +build acceptance compute servers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestNetworksList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + allPages, err := networks.List(client).AllPages() + th.AssertNoErr(t, err) + + allNetworks, err := networks.ExtractNetworks(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, network := range allNetworks { + tools.PrintResource(t, network) + + if network.Label == choices.NetworkName { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestNetworksGet(t *testing.T) { + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + networkID, err := GetNetworkIDFromNetworks(t, client, choices.NetworkName) + th.AssertNoErr(t, err) + + network, err := networks.Get(client, networkID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, network) + + th.AssertEquals(t, network.Label, choices.NetworkName) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/quotaset_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/quotaset_test.go new file mode 100644 index 00000000..867d3fb5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/quotaset_test.go @@ -0,0 +1,147 @@ +// +build acceptance compute quotasets + +package v2 + +import ( + "fmt" + "os" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" + "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestQuotasetGet(t *testing.T) { + clients.SkipRelease(t, "master") + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + identityClient, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + tenantID, err := getTenantID(t, identityClient) + th.AssertNoErr(t, err) + + quotaSet, err := quotasets.Get(client, tenantID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, quotaSet) + + th.AssertEquals(t, quotaSet.FixedIPs, -1) +} + +func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) { + allPages, err := tenants.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allTenants, err := tenants.ExtractTenants(allPages) + th.AssertNoErr(t, err) + + for _, tenant := range allTenants { + return tenant.ID, nil + } + + return "", fmt.Errorf("Unable to get tenant ID") +} + +func getTenantIDByName(t *testing.T, client *gophercloud.ServiceClient, name string) (string, error) { + allPages, err := tenants.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allTenants, err := tenants.ExtractTenants(allPages) + th.AssertNoErr(t, err) + + for _, tenant := range allTenants { + if tenant.Name == name { + return tenant.ID, nil + } + } + + return "", fmt.Errorf("Unable to get tenant ID") +} + +// What will be sent as desired Quotas to the Server +var UpdateQuotaOpts = quotasets.UpdateOpts{ + FixedIPs: gophercloud.IntToPointer(10), + FloatingIPs: gophercloud.IntToPointer(10), + InjectedFileContentBytes: gophercloud.IntToPointer(10240), + InjectedFilePathBytes: gophercloud.IntToPointer(255), + InjectedFiles: gophercloud.IntToPointer(5), + KeyPairs: gophercloud.IntToPointer(10), + MetadataItems: gophercloud.IntToPointer(128), + RAM: gophercloud.IntToPointer(20000), + SecurityGroupRules: gophercloud.IntToPointer(20), + SecurityGroups: gophercloud.IntToPointer(10), + Cores: gophercloud.IntToPointer(10), + Instances: gophercloud.IntToPointer(4), + ServerGroups: gophercloud.IntToPointer(2), + ServerGroupMembers: gophercloud.IntToPointer(3), +} + +// What the Server hopefully returns as the new Quotas +var UpdatedQuotas = quotasets.QuotaSet{ + FixedIPs: 10, + FloatingIPs: 10, + InjectedFileContentBytes: 10240, + InjectedFilePathBytes: 255, + InjectedFiles: 5, + KeyPairs: 10, + MetadataItems: 128, + RAM: 20000, + SecurityGroupRules: 20, + SecurityGroups: 10, + Cores: 10, + Instances: 4, + ServerGroups: 2, + ServerGroupMembers: 3, +} + +func TestQuotasetUpdateDelete(t *testing.T) { + clients.SkipRelease(t, "master") + + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + idclient, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + tenantid, err := getTenantIDByName(t, idclient, os.Getenv("OS_TENANT_NAME")) + th.AssertNoErr(t, err) + + // save original quotas + orig, err := quotasets.Get(client, tenantid).Extract() + th.AssertNoErr(t, err) + + // Test Update + res, err := quotasets.Update(client, tenantid, UpdateQuotaOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, UpdatedQuotas, *res) + + // Test Delete + _, err = quotasets.Delete(client, tenantid).Extract() + th.AssertNoErr(t, err) + + // We dont know the default quotas, so just check if the quotas are not the same as before + newres, err := quotasets.Get(client, tenantid).Extract() + th.AssertNoErr(t, err) + if newres.RAM == res.RAM { + t.Fatalf("Failed to update quotas") + } + + restore := quotasets.UpdateOpts{} + FillUpdateOptsFromQuotaSet(*orig, &restore) + + // restore original quotas + res, err = quotasets.Update(client, tenantid, restore).Extract() + th.AssertNoErr(t, err) + + orig.ID = "" + th.AssertDeepEquals(t, orig, res) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/secgroup_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/secgroup_test.go new file mode 100644 index 00000000..6f302843 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/secgroup_test.go @@ -0,0 +1,140 @@ +// +build acceptance compute secgroups + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestSecGroupsList(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := secgroups.List(client).AllPages() + th.AssertNoErr(t, err) + + allSecGroups, err := secgroups.ExtractSecurityGroups(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, secgroup := range allSecGroups { + tools.PrintResource(t, secgroup) + + if secgroup.Name == "default" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestSecGroupsCRUD(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + securityGroup, err := CreateSecurityGroup(t, client) + th.AssertNoErr(t, err) + defer DeleteSecurityGroup(t, client, securityGroup.ID) + + tools.PrintResource(t, securityGroup) + + newName := tools.RandomString("secgroup_", 4) + updateOpts := secgroups.UpdateOpts{ + Name: newName, + Description: tools.RandomString("dec_", 10), + } + updatedSecurityGroup, err := secgroups.Update(client, securityGroup.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, updatedSecurityGroup) + + t.Logf("Updated %s's name to %s", updatedSecurityGroup.ID, updatedSecurityGroup.Name) + + th.AssertEquals(t, updatedSecurityGroup.Name, newName) +} + +func TestSecGroupsRuleCreate(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + securityGroup, err := CreateSecurityGroup(t, client) + th.AssertNoErr(t, err) + defer DeleteSecurityGroup(t, client, securityGroup.ID) + + tools.PrintResource(t, securityGroup) + + rule, err := CreateSecurityGroupRule(t, client, securityGroup.ID) + th.AssertNoErr(t, err) + defer DeleteSecurityGroupRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + newSecurityGroup, err := secgroups.Get(client, securityGroup.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newSecurityGroup) + + th.AssertEquals(t, len(newSecurityGroup.Rules), 1) +} + +func TestSecGroupsAddGroupToServer(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + securityGroup, err := CreateSecurityGroup(t, client) + th.AssertNoErr(t, err) + defer DeleteSecurityGroup(t, client, securityGroup.ID) + + rule, err := CreateSecurityGroupRule(t, client, securityGroup.ID) + th.AssertNoErr(t, err) + defer DeleteSecurityGroupRule(t, client, rule.ID) + + t.Logf("Adding group %s to server %s", securityGroup.ID, server.ID) + err = secgroups.AddServer(client, server.ID, securityGroup.Name).ExtractErr() + th.AssertNoErr(t, err) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + + var found bool + for _, sg := range server.SecurityGroups { + if sg["name"] == securityGroup.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + t.Logf("Removing group %s from server %s", securityGroup.ID, server.ID) + err = secgroups.RemoveServer(client, server.ID, securityGroup.Name).ExtractErr() + th.AssertNoErr(t, err) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + found = false + + tools.PrintResource(t, server) + + for _, sg := range server.SecurityGroups { + if sg["name"] == securityGroup.Name { + found = true + } + } + + th.AssertEquals(t, found, false) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servergroup_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servergroup_test.go new file mode 100644 index 00000000..8b7af0f3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servergroup_test.go @@ -0,0 +1,71 @@ +// +build acceptance compute servergroups + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestServergroupsCreateDelete(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + serverGroup, err := CreateServerGroup(t, client, "anti-affinity") + th.AssertNoErr(t, err) + defer DeleteServerGroup(t, client, serverGroup) + + serverGroup, err = servergroups.Get(client, serverGroup.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, serverGroup) + + allPages, err := servergroups.List(client).AllPages() + th.AssertNoErr(t, err) + + allServerGroups, err := servergroups.ExtractServerGroups(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, sg := range allServerGroups { + tools.PrintResource(t, serverGroup) + + if sg.ID == serverGroup.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestServergroupsAffinityPolicy(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + serverGroup, err := CreateServerGroup(t, client, "affinity") + th.AssertNoErr(t, err) + defer DeleteServerGroup(t, client, serverGroup) + + firstServer, err := CreateServerInServerGroup(t, client, serverGroup) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, firstServer) + + firstServer, err = servers.Get(client, firstServer.ID).Extract() + th.AssertNoErr(t, err) + + secondServer, err := CreateServerInServerGroup(t, client, serverGroup) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, secondServer) + + secondServer, err = servers.Get(client, secondServer.ID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, firstServer.HostID, secondServer.HostID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servers_test.go new file mode 100644 index 00000000..92652c47 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/servers_test.go @@ -0,0 +1,482 @@ +// +build acceptance compute servers + +package v2 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/extendedstatus" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestServersCreateDestroy(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + allPages, err := servers.List(client, servers.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + allServers, err := servers.ExtractServers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, s := range allServers { + tools.PrintResource(t, server) + + if s.ID == server.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages() + th.AssertNoErr(t, err) + + allAddresses, err := servers.ExtractAddresses(allAddressPages) + th.AssertNoErr(t, err) + + for network, address := range allAddresses { + t.Logf("Addresses on %s: %+v", network, address) + } + + allInterfacePages, err := attachinterfaces.List(client, server.ID).AllPages() + th.AssertNoErr(t, err) + + allInterfaces, err := attachinterfaces.ExtractInterfaces(allInterfacePages) + th.AssertNoErr(t, err) + + for _, iface := range allInterfaces { + t.Logf("Interfaces: %+v", iface) + } + + allNetworkAddressPages, err := servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName).AllPages() + th.AssertNoErr(t, err) + + allNetworkAddresses, err := servers.ExtractNetworkAddresses(allNetworkAddressPages) + th.AssertNoErr(t, err) + + t.Logf("Addresses on %s:", choices.NetworkName) + for _, address := range allNetworkAddresses { + t.Logf("%+v", address) + } +} + +func TestServersWithExtensionsCreateDestroy(t *testing.T) { + clients.RequireLong(t) + + var extendedServer struct { + servers.Server + availabilityzones.ServerAvailabilityZoneExt + extendedstatus.ServerExtendedStatusExt + } + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + err = servers.Get(client, server.ID).ExtractInto(&extendedServer) + th.AssertNoErr(t, err) + tools.PrintResource(t, extendedServer) + + th.AssertEquals(t, extendedServer.AvailabilityZone, "nova") + th.AssertEquals(t, int(extendedServer.PowerState), extendedstatus.RUNNING) + th.AssertEquals(t, extendedServer.TaskState, "") + th.AssertEquals(t, extendedServer.VmState, "active") +} + +func TestServersWithoutImageRef(t *testing.T) { + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServerWithoutImageRef(t, client) + if err != nil { + if err400, ok := err.(*gophercloud.ErrUnexpectedResponseCode); ok { + if !strings.Contains("Missing imageRef attribute", string(err400.Body)) { + defer DeleteServer(t, client, server) + } + } + } +} + +func TestServersUpdate(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + alternateName := tools.RandomString("ACPTTEST", 16) + for alternateName == server.Name { + alternateName = tools.RandomString("ACPTTEST", 16) + } + + t.Logf("Attempting to rename the server to %s.", alternateName) + + updateOpts := servers.UpdateOpts{ + Name: alternateName, + } + + updated, err := servers.Update(client, server.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, updated.ID, server.ID) + + err = tools.WaitFor(func() (bool, error) { + latest, err := servers.Get(client, updated.ID).Extract() + if err != nil { + return false, err + } + + return latest.Name == alternateName, nil + }) +} + +func TestServersMetadata(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + tools.PrintResource(t, server) + + metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ + "foo": "bar", + "this": "that", + }).Extract() + th.AssertNoErr(t, err) + t.Logf("UpdateMetadata result: %+v\n", metadata) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + + expectedMetadata := map[string]string{ + "abc": "def", + "foo": "bar", + "this": "that", + } + th.AssertDeepEquals(t, expectedMetadata, server.Metadata) + + err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() + th.AssertNoErr(t, err) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + + expectedMetadata = map[string]string{ + "abc": "def", + "this": "that", + } + th.AssertDeepEquals(t, expectedMetadata, server.Metadata) + + metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ + "foo": "baz", + }).Extract() + th.AssertNoErr(t, err) + t.Logf("CreateMetadatum result: %+v\n", metadata) + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, server) + + expectedMetadata = map[string]string{ + "abc": "def", + "this": "that", + "foo": "baz", + } + th.AssertDeepEquals(t, expectedMetadata, server.Metadata) + + metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() + th.AssertNoErr(t, err) + t.Logf("Metadatum result: %+v\n", metadata) + th.AssertEquals(t, "baz", metadata["foo"]) + + metadata, err = servers.Metadata(client, server.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("Metadata result: %+v\n", metadata) + + th.AssertDeepEquals(t, expectedMetadata, metadata) + + metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() + th.AssertNoErr(t, err) + t.Logf("ResetMetadata result: %+v\n", metadata) + th.AssertDeepEquals(t, map[string]string{}, metadata) +} + +func TestServersActionChangeAdminPassword(t *testing.T) { + clients.RequireLong(t) + clients.RequireGuestAgent(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + randomPassword := tools.MakeNewPassword(server.AdminPass) + res := servers.ChangeAdminPassword(client, server.ID, randomPassword) + th.AssertNoErr(t, res.Err) + + if err = WaitForComputeStatus(client, server, "PASSWORD"); err != nil { + t.Fatal(err) + } + + if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { + t.Fatal(err) + } +} + +func TestServersActionReboot(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + rebootOpts := servers.RebootOpts{ + Type: servers.SoftReboot, + } + + t.Logf("Attempting reboot of server %s", server.ID) + res := servers.Reboot(client, server.ID, rebootOpts) + th.AssertNoErr(t, res.Err) + + if err = WaitForComputeStatus(client, server, "REBOOT"); err != nil { + t.Fatal(err) + } + + if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { + t.Fatal(err) + } +} + +func TestServersActionRebuild(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to rebuild server %s", server.ID) + + rebuildOpts := servers.RebuildOpts{ + Name: tools.RandomString("ACPTTEST", 16), + AdminPass: tools.MakeNewPassword(server.AdminPass), + ImageID: choices.ImageID, + } + + rebuilt, err := servers.Rebuild(client, server.ID, rebuildOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, rebuilt.ID, server.ID) + + if err = WaitForComputeStatus(client, rebuilt, "REBUILD"); err != nil { + t.Fatal(err) + } + + if err = WaitForComputeStatus(client, rebuilt, "ACTIVE"); err != nil { + t.Fatal(err) + } +} + +func TestServersActionResizeConfirm(t *testing.T) { + clients.RequireLong(t) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to resize server %s", server.ID) + ResizeServer(t, client, server) + + t.Logf("Attempting to confirm resize for server %s", server.ID) + if res := servers.ConfirmResize(client, server.ID); res.Err != nil { + t.Fatal(res.Err) + } + + if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { + t.Fatal(err) + } + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, server.Flavor["id"], choices.FlavorIDResize) +} + +func TestServersActionResizeRevert(t *testing.T) { + clients.RequireLong(t) + + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to resize server %s", server.ID) + ResizeServer(t, client, server) + + t.Logf("Attempting to revert resize for server %s", server.ID) + if res := servers.RevertResize(client, server.ID); res.Err != nil { + t.Fatal(res.Err) + } + + if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { + t.Fatal(err) + } + + server, err = servers.Get(client, server.ID).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, server.Flavor["id"], choices.FlavorID) +} + +func TestServersActionPause(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to pause server %s", server.ID) + err = pauseunpause.Pause(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = WaitForComputeStatus(client, server, "PAUSED") + th.AssertNoErr(t, err) + + err = pauseunpause.Unpause(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = WaitForComputeStatus(client, server, "ACTIVE") + th.AssertNoErr(t, err) +} + +func TestServersActionSuspend(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to suspend server %s", server.ID) + err = suspendresume.Suspend(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = WaitForComputeStatus(client, server, "SUSPENDED") + th.AssertNoErr(t, err) + + err = suspendresume.Resume(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = WaitForComputeStatus(client, server, "ACTIVE") + th.AssertNoErr(t, err) +} + +func TestServersActionLock(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + t.Logf("Attempting to Lock server %s", server.ID) + err = lockunlock.Lock(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = servers.Delete(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = lockunlock.Unlock(client, server.ID).ExtractErr() + th.AssertNoErr(t, err) + + err = WaitForComputeStatus(client, server, "ACTIVE") + th.AssertNoErr(t, err) +} + +func TestServersConsoleOutput(t *testing.T) { + client, err := clients.NewComputeV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + server, err := CreateServer(t, client) + if err != nil { + t.Fatalf("Unable to create server: %v", err) + } + + defer DeleteServer(t, client, server) + + outputOpts := &servers.ShowConsoleOutputOpts{ + Length: 4, + } + output, err := servers.ShowConsoleOutput(client, server.ID, outputOpts).Extract() + if err != nil { + t.Fatal(err) + } + + tools.PrintResource(t, output) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/services_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/services_test.go new file mode 100644 index 00000000..5c6484e0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/services_test.go @@ -0,0 +1,36 @@ +// +build acceptance compute services + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestServicesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := services.List(client).AllPages() + th.AssertNoErr(t, err) + + allServices, err := services.ExtractServices(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, service := range allServices { + tools.PrintResource(t, service) + + if service.Binary == "nova-scheduler" { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go new file mode 100644 index 00000000..a53c64d3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go @@ -0,0 +1,53 @@ +// +build acceptance compute servers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTenantNetworksList(t *testing.T) { + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + allPages, err := tenantnetworks.List(client).AllPages() + th.AssertNoErr(t, err) + + allTenantNetworks, err := tenantnetworks.ExtractNetworks(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, network := range allTenantNetworks { + tools.PrintResource(t, network) + + if network.Name == choices.NetworkName { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestTenantNetworksGet(t *testing.T) { + choices, err := clients.AcceptanceTestChoicesFromEnv() + th.AssertNoErr(t, err) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) + th.AssertNoErr(t, err) + + network, err := tenantnetworks.Get(client, networkID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, network) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/usage_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/usage_test.go new file mode 100644 index 00000000..c998b59e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/usage_test.go @@ -0,0 +1,91 @@ +// +build acceptance compute usage + +package v2 + +import ( + "strings" + "testing" + "time" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestUsageSingleTenant(t *testing.T) { + t.Skip("This is not passing in OpenLab. Works locally") + + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + DeleteServer(t, client, server) + + endpointParts := strings.Split(client.Endpoint, "/") + tenantID := endpointParts[4] + + end := time.Now() + start := end.AddDate(0, -1, 0) + opts := usage.SingleTenantOpts{ + Start: &start, + End: &end, + } + + err = usage.SingleTenant(client, tenantID, opts).EachPage(func(page pagination.Page) (bool, error) { + tenantUsage, err := usage.ExtractSingleTenant(page) + th.AssertNoErr(t, err) + + tools.PrintResource(t, tenantUsage) + if tenantUsage.TotalHours == 0 { + t.Fatalf("TotalHours should not be 0") + } + + return true, nil + }) + + th.AssertNoErr(t, err) +} + +func TestUsageAllTenants(t *testing.T) { + t.Skip("This is not passing in OpenLab. Works locally") + + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + DeleteServer(t, client, server) + + end := time.Now() + start := end.AddDate(0, -1, 0) + opts := usage.AllTenantsOpts{ + Detailed: true, + Start: &start, + End: &end, + } + + err = usage.AllTenants(client, opts).EachPage(func(page pagination.Page) (bool, error) { + allUsage, err := usage.ExtractAllTenants(page) + th.AssertNoErr(t, err) + + tools.PrintResource(t, allUsage) + + if len(allUsage) == 0 { + t.Fatalf("No usage returned") + } + + if allUsage[0].TotalHours == 0 { + t.Fatalf("TotalHours should not be 0") + } + return true, nil + }) + + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/volumeattach_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/volumeattach_test.go new file mode 100644 index 00000000..022df830 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/volumeattach_test.go @@ -0,0 +1,38 @@ +// +build acceptance compute volumeattach + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + bs "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestVolumeAttachAttachment(t *testing.T) { + clients.RequireLong(t) + + client, err := clients.NewComputeV2Client() + th.AssertNoErr(t, err) + + blockClient, err := clients.NewBlockStorageV2Client() + th.AssertNoErr(t, err) + + server, err := CreateServer(t, client) + th.AssertNoErr(t, err) + defer DeleteServer(t, client, server) + + volume, err := bs.CreateVolume(t, blockClient) + th.AssertNoErr(t, err) + defer bs.DeleteVolume(t, blockClient, volume) + + volumeAttachment, err := CreateVolumeAttachment(t, client, blockClient, server, volume) + th.AssertNoErr(t, err) + defer DeleteVolumeAttachment(t, client, blockClient, server, volumeAttachment) + + tools.PrintResource(t, volumeAttachment) + + th.AssertEquals(t, volumeAttachment.ServerID, server.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules.go new file mode 100644 index 00000000..6bf682cd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules.go @@ -0,0 +1,31 @@ +package v1 + +import ( + "fmt" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/container/v1/capsules" +) + +// WaitForCapsuleStatus will poll a capsule's status until it either matches +// the specified status or the status becomes Failed. +func WaitForCapsuleStatus(client *gophercloud.ServiceClient, capsule *capsules.Capsule, status string) error { + return tools.WaitFor(func() (bool, error) { + latest, err := capsules.Get(client, capsule.UUID).Extract() + if err != nil { + return false, err + } + + if latest.Status == status { + // Success! + return true, nil + } + + if latest.Status == "Failed" { + return false, fmt.Errorf("Capsule in FAILED state") + } + + return false, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules_test.go new file mode 100644 index 00000000..48f001df --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/container/v1/capsules_test.go @@ -0,0 +1,88 @@ +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/container/v1/capsules" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCapsule(t *testing.T) { + client, err := clients.NewContainerV1Client() + if err != nil { + t.Fatalf("Unable to create an container v1 client: %v", err) + } + th.AssertNoErr(t, err) + template := new(capsules.Template) + template.Bin = []byte(`{ + "capsuleVersion": "beta", + "kind": "capsule", + "metadata": { + "labels": { + "app": "web", + "app1": "web1" + }, + "name": "template" + }, + "spec": { + "restartPolicy": "Always", + "containers": [ + { + "command": [ + "sleep", + "1000000" + ], + "env": { + "ENV1": "/usr/local/bin", + "ENV2": "/usr/bin" + }, + "image": "ubuntu", + "imagePullPolicy": "ifnotpresent", + "ports": [ + { + "containerPort": 80, + "hostPort": 80, + "name": "nginx-port", + "protocol": "TCP" + } + ], + "resources": { + "requests": { + "cpu": 1, + "memory": 1024 + } + }, + "workDir": "/root" + } + ] + } + }`) + createOpts := capsules.CreateOpts{ + TemplateOpts: template, + } + capsule, err := capsules.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + err = WaitForCapsuleStatus(client, capsule, "Running") + th.AssertNoErr(t, err) + pager := capsules.List(client, nil) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + CapsuleList, err := capsules.ExtractCapsules(page) + th.AssertNoErr(t, err) + + for _, m := range CapsuleList { + capsuleUUID := m.UUID + capsule, err := capsules.Get(client, capsuleUUID).Extract() + + th.AssertNoErr(t, err) + th.AssertEquals(t, capsule.MetaName, "template") + + err = capsules.Delete(client, capsuleUUID).ExtractErr() + th.AssertNoErr(t, err) + + } + return true, nil + }) + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/certificates_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/certificates_test.go new file mode 100644 index 00000000..d1b17278 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/certificates_test.go @@ -0,0 +1,22 @@ +// +build acceptance containerinfra + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCertificatesCRUD(t *testing.T) { + client, err := clients.NewContainerInfraV1Client() + th.AssertNoErr(t, err) + + clusterID := "8934d2d1-6bce-4ffa-a017-fb437777269d" + + certificate, err := certificates.Get(client, clusterID).Extract() + th.AssertNoErr(t, err) + t.Log(certificate.Pem) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/clustertemplates_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/clustertemplates_test.go new file mode 100644 index 00000000..48e76d3f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/clustertemplates_test.go @@ -0,0 +1,67 @@ +// +build acceptance containerinfra + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + //"github.com/gophercloud/gophercloud/acceptance/tools" + //"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestClusterTemplatesCRUD(t *testing.T) { + client, err := clients.NewContainerInfraV1Client() + th.AssertNoErr(t, err) + + clusterTemplate, err := CreateClusterTemplate(t, client) + th.AssertNoErr(t, err) + t.Log(clusterTemplate.Name) + /* + defer DeleteClusterTemplate(t, client, clusterTemplate.UUID) + + // Test clusters list + allPages, err := clustertemplates.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allClusterTemplates, err := clustertemplates.ExtractClusterTemplates(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allClusterTemplates { + if v.UUID == clusterTemplate.UUID { + found = true + } + } + + th.AssertEquals(t, found, true) + + // Test cluster update + updateOpts := []clustertemplates.UpdateOptsBuilder{ + clustertemplates.UpdateOpts{ + Path: "/master_lb_enabled", + Value: "false", + Op: "replace", + }, + clustertemplates.UpdateOpts{ + Path: "/registry_enabled", + Value: "false", + Op: "replace", + }, + clustertemplates.UpdateOpts{ + Path: "/labels/test", + Value: "test", + Op: "add", + }, + } + + updateClusterTemplate, err := clustertemplates.Update(client, clusterTemplate.UUID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, false, updateClusterTemplate.MasterLBEnabled) + th.AssertEquals(t, false, updateClusterTemplate.RegistryEnabled) + th.AssertEquals(t, "test", updateClusterTemplate.Labels["test"]) + tools.PrintResource(t, updateClusterTemplate) + + */ +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/containerinfra.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/containerinfra.go new file mode 100644 index 00000000..e4c24b09 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/containerinfra.go @@ -0,0 +1,83 @@ +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" + th "github.com/gophercloud/gophercloud/testhelper" +) + +// CreateClusterTemplate will create a random cluster tempalte. An error will be returned if the +// cluster-template could not be created. +func CreateClusterTemplate(t *testing.T, client *gophercloud.ServiceClient) (*clustertemplates.ClusterTemplate, error) { + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + return nil, err + } + + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create cluster template: %s", name) + + boolFalse := false + createOpts := clustertemplates.CreateOpts{ + Name: name, + MasterFlavorID: "m1.small", + Public: &boolFalse, + ServerType: "vm", + ExternalNetworkID: choices.ExternalNetworkID, + ImageID: choices.MagnumImageID, + RegistryEnabled: &boolFalse, + DockerStorageDriver: "devicemapper", + COE: "swarm", + FlavorID: choices.FlavorID, + MasterLBEnabled: &boolFalse, + DNSNameServer: "8.8.8.8", + FloatingIPEnabled: &boolFalse, + } + + res := clustertemplates.Create(client, createOpts) + if res.Err != nil { + return nil, res.Err + } + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, true, requestID != "") + + t.Logf("Cluster Template %s request ID: %s", name, requestID) + + clusterTemplate, err := res.Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created cluster template: %s", clusterTemplate.Name) + + tools.PrintResource(t, clusterTemplate) + tools.PrintResource(t, clusterTemplate.CreatedAt) + + th.AssertEquals(t, name, clusterTemplate.Name) + th.AssertEquals(t, choices.ExternalNetworkID, clusterTemplate.ExternalNetworkID) + th.AssertEquals(t, choices.MagnumImageID, clusterTemplate.ImageID) + + return clusterTemplate, nil +} + +/* +// DeleteClusterTemplate will delete a given cluster-template. A fatal error will occur if the +// cluster-template could not be deleted. This works best as a deferred function. +func DeleteClusterTemplate(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete cluster-template: %s", id) + + err := clustertemplates.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Error deleting cluster-template %s: %s:", id, err) + } + + t.Logf("Successfully deleted cluster-template: %s", id) + + return +} +*/ diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/pkg.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/pkg.go new file mode 100644 index 00000000..b7b1f993 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/containerinfra/v1/pkg.go @@ -0,0 +1 @@ +package v1 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/configurations_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/configurations_test.go new file mode 100644 index 00000000..87e883f4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/configurations_test.go @@ -0,0 +1,50 @@ +// +build acceptance db + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" +) + +func TestConfigurationsCRUD(t *testing.T) { + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatalf("Unable to get environment settings") + } + + createOpts := &configurations.CreateOpts{ + Name: "test", + Description: "description", + } + + datastore := configurations.DatastoreOpts{ + Type: choices.DBDatastoreType, + Version: choices.DBDatastoreVersion, + } + createOpts.Datastore = &datastore + + values := make(map[string]interface{}) + values["collation_server"] = "latin1_swedish_ci" + createOpts.Values = values + + cgroup, err := configurations.Create(client, createOpts).Extract() + if err != nil { + t.Fatalf("Unable to create configuration: %v", err) + } + + err = configurations.Delete(client, cgroup.ID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete configuration: %v", err) + } + + tools.PrintResource(t, cgroup) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/databases_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/databases_test.go new file mode 100644 index 00000000..dcbf72f0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/databases_test.go @@ -0,0 +1,55 @@ +// +build acceptance db + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/db/v1/databases" +) + +// Because it takes so long to create an instance, +// all tests will be housed in a single function. +func TestDatabases(t *testing.T) { + if testing.Short() { + t.Skip("Skipping in short mode") + } + + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + // Create and Get an instance. + instance, err := CreateInstance(t, client) + if err != nil { + t.Fatalf("Unable to create instance: %v", err) + } + defer DeleteInstance(t, client, instance.ID) + + // Create a database. + err = CreateDatabase(t, client, instance.ID) + if err != nil { + t.Fatalf("Unable to create database: %v", err) + } + + // List all databases. + allPages, err := databases.List(client, instance.ID).AllPages() + if err != nil { + t.Fatalf("Unable to list databases: %v", err) + } + + allDatabases, err := databases.ExtractDBs(allPages) + if err != nil { + t.Fatalf("Unable to extract databases: %v", err) + } + + for _, db := range allDatabases { + tools.PrintResource(t, db) + } + + defer DeleteDatabase(t, client, instance.ID, allDatabases[0].Name) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/flavors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/flavors_test.go new file mode 100644 index 00000000..73171b94 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/flavors_test.go @@ -0,0 +1,58 @@ +// +build acceptance db + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/db/v1/flavors" +) + +func TestFlavorsList(t *testing.T) { + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + allPages, err := flavors.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve flavors: %v", err) + } + + allFlavors, err := flavors.ExtractFlavors(allPages) + if err != nil { + t.Fatalf("Unable to extract flavors: %v", err) + } + + for _, flavor := range allFlavors { + tools.PrintResource(t, &flavor) + } +} + +func TestFlavorsGet(t *testing.T) { + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + allPages, err := flavors.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve flavors: %v", err) + } + + allFlavors, err := flavors.ExtractFlavors(allPages) + if err != nil { + t.Fatalf("Unable to extract flavors: %v", err) + } + + if len(allFlavors) > 0 { + flavor, err := flavors.Get(client, allFlavors[0].StrID).Extract() + if err != nil { + t.Fatalf("Unable to get flavor: %v", err) + } + + tools.PrintResource(t, flavor) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/instances_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/instances_test.go new file mode 100644 index 00000000..a98047f3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/instances_test.go @@ -0,0 +1,71 @@ +// +build acceptance db + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/db/v1/instances" +) + +// Because it takes so long to create an instance, +// all tests will be housed in a single function. +func TestInstances(t *testing.T) { + if testing.Short() { + t.Skip("Skipping in short mode") + } + + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + // Create and Get an instance. + instance, err := CreateInstance(t, client) + if err != nil { + t.Fatalf("Unable to create instance: %v", err) + } + defer DeleteInstance(t, client, instance.ID) + tools.PrintResource(t, &instance) + + // List all instances. + allPages, err := instances.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to list instances: %v", err) + } + + allInstances, err := instances.ExtractInstances(allPages) + if err != nil { + t.Fatalf("Unable to extract instances: %v", err) + } + + for _, instance := range allInstances { + tools.PrintResource(t, instance) + } + + // Enable root user. + _, err = instances.EnableRootUser(client, instance.ID).Extract() + if err != nil { + t.Fatalf("Unable to enable root user: %v", err) + } + + enabled, err := instances.IsRootEnabled(client, instance.ID).Extract() + if err != nil { + t.Fatalf("Unable to check if root user is enabled: %v", err) + } + + t.Logf("Root user is enabled: %t", enabled) + + // Restart + err = instances.Restart(client, instance.ID).ExtractErr() + if err != nil { + t.Fatalf("Unable to restart instance: %v", err) + } + + err = WaitForInstanceStatus(client, instance, "ACTIVE") + if err != nil { + t.Fatalf("Unable to restart instance: %v", err) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/users_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/users_test.go new file mode 100644 index 00000000..4335eabb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/db/v1/users_test.go @@ -0,0 +1,54 @@ +// +build acceptance db + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/db/v1/users" +) + +// Because it takes so long to create an instance, +// all tests will be housed in a single function. +func TestUsers(t *testing.T) { + if testing.Short() { + t.Skip("Skipping in short mode") + } + + client, err := clients.NewDBV1Client() + if err != nil { + t.Fatalf("Unable to create a DB client: %v", err) + } + + // Create and Get an instance. + instance, err := CreateInstance(t, client) + if err != nil { + t.Fatalf("Unable to create instance: %v", err) + } + defer DeleteInstance(t, client, instance.ID) + + // Create a user. + err = CreateUser(t, client, instance.ID) + if err != nil { + t.Fatalf("Unable to create user: %v", err) + } + + // List all users. + allPages, err := users.List(client, instance.ID).AllPages() + if err != nil { + t.Fatalf("Unable to list users: %v", err) + } + + allUsers, err := users.ExtractUsers(allPages) + if err != nil { + t.Fatalf("Unable to extract users: %v", err) + } + + for _, user := range allUsers { + tools.PrintResource(t, user) + } + + defer DeleteUser(t, client, instance.ID, allUsers[0].Name) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/dns.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/dns.go index 7a0893ff..18cd157f 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/dns.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/dns.go @@ -7,6 +7,7 @@ import ( "github.com/gophercloud/gophercloud/acceptance/tools" "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" + th "github.com/gophercloud/gophercloud/testhelper" ) // CreateRecordSet will create a RecordSet with a random name. An error will @@ -38,6 +39,8 @@ func CreateRecordSet(t *testing.T, client *gophercloud.ServiceClient, zone *zone t.Logf("Created record set: %s", newRS.Name) + th.AssertEquals(t, newRS.Name, zone.Name) + return rs, nil } @@ -70,6 +73,10 @@ func CreateZone(t *testing.T, client *gophercloud.ServiceClient) (*zones.Zone, e } t.Logf("Created Zone: %s", zoneName) + + th.AssertEquals(t, newZone.Name, zoneName) + th.AssertEquals(t, newZone.TTL, 7200) + return newZone, nil } @@ -102,6 +109,10 @@ func CreateSecondaryZone(t *testing.T, client *gophercloud.ServiceClient) (*zone } t.Logf("Created Zone: %s", zoneName) + + th.AssertEquals(t, newZone.Name, zoneName) + th.AssertEquals(t, newZone.Masters[0], "10.0.0.1") + return newZone, nil } @@ -132,7 +143,7 @@ func DeleteZone(t *testing.T, client *gophercloud.ServiceClient, zone *zones.Zon // WaitForRecordSetStatus will poll a record set's status until it either matches // the specified status or the status becomes ERROR. func WaitForRecordSetStatus(client *gophercloud.ServiceClient, rs *recordsets.RecordSet, status string) error { - return gophercloud.WaitFor(60, func() (bool, error) { + return gophercloud.WaitFor(600, func() (bool, error) { current, err := recordsets.Get(client, rs.ZoneID, rs.ID).Extract() if err != nil { return false, err @@ -149,7 +160,7 @@ func WaitForRecordSetStatus(client *gophercloud.ServiceClient, rs *recordsets.Re // WaitForZoneStatus will poll a zone's status until it either matches // the specified status or the status becomes ERROR. func WaitForZoneStatus(client *gophercloud.ServiceClient, zone *zones.Zone, status string) error { - return gophercloud.WaitFor(60, func() (bool, error) { + return gophercloud.WaitFor(600, func() (bool, error) { current, err := zones.Get(client, zone.ID).Extract() if err != nil { return false, err diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/recordsets_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/recordsets_test.go new file mode 100644 index 00000000..d2d862ba --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/recordsets_test.go @@ -0,0 +1,86 @@ +// +build acceptance dns recordsets + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestRecordSetsListByZone(t *testing.T) { + clients.RequireDNS(t) + + client, err := clients.NewDNSV2Client() + th.AssertNoErr(t, err) + + zone, err := CreateZone(t, client) + th.AssertNoErr(t, err) + defer DeleteZone(t, client, zone) + + allPages, err := recordsets.ListByZone(client, zone.ID, nil).AllPages() + th.AssertNoErr(t, err) + + allRecordSets, err := recordsets.ExtractRecordSets(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, recordset := range allRecordSets { + tools.PrintResource(t, &recordset) + + if recordset.ZoneID == zone.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts := recordsets.ListOpts{ + Limit: 1, + } + + err = recordsets.ListByZone(client, zone.ID, listOpts).EachPage( + func(page pagination.Page) (bool, error) { + rr, err := recordsets.ExtractRecordSets(page) + th.AssertNoErr(t, err) + th.AssertEquals(t, len(rr), 1) + return true, nil + }, + ) + th.AssertNoErr(t, err) +} + +func TestRecordSetsCRUD(t *testing.T) { + clients.RequireDNS(t) + + client, err := clients.NewDNSV2Client() + th.AssertNoErr(t, err) + + zone, err := CreateZone(t, client) + th.AssertNoErr(t, err) + defer DeleteZone(t, client, zone) + + tools.PrintResource(t, &zone) + + rs, err := CreateRecordSet(t, client, zone) + th.AssertNoErr(t, err) + defer DeleteRecordSet(t, client, rs) + + tools.PrintResource(t, &rs) + + updateOpts := recordsets.UpdateOpts{ + Description: "New description", + TTL: 0, + } + + newRS, err := recordsets.Update(client, rs.ZoneID, rs.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, &newRS) + + th.AssertEquals(t, newRS.Description, "New description") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/zones_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/zones_test.go new file mode 100644 index 00000000..263e9fea --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/dns/v2/zones_test.go @@ -0,0 +1,54 @@ +// +build acceptance dns zones + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestZonesCRUD(t *testing.T) { + clients.RequireDNS(t) + + client, err := clients.NewDNSV2Client() + th.AssertNoErr(t, err) + + zone, err := CreateZone(t, client) + th.AssertNoErr(t, err) + defer DeleteZone(t, client, zone) + + tools.PrintResource(t, &zone) + + allPages, err := zones.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allZones, err := zones.ExtractZones(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, z := range allZones { + tools.PrintResource(t, &z) + + if zone.Name == z.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + updateOpts := zones.UpdateOpts{ + Description: "New description", + TTL: 0, + } + + newZone, err := zones.Update(client, zone.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, &newZone) + + th.AssertEquals(t, newZone.Description, "New description") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/extension_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/extension_test.go new file mode 100644 index 00000000..593d75ca --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/extension_test.go @@ -0,0 +1,49 @@ +// +build acceptance identity + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestExtensionsList(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + allPages, err := extensions.List(client).AllPages() + th.AssertNoErr(t, err) + + allExtensions, err := extensions.ExtractExtensions(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, extension := range allExtensions { + tools.PrintResource(t, extension) + if extension.Name == "OS-KSCRUD" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestExtensionsGet(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + extension, err := extensions.Get(client, "OS-KSCRUD").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, extension) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/identity.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/identity.go index 6d0d0f20..b8e9ee22 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/identity.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/identity.go @@ -10,6 +10,7 @@ import ( "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles" "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" "github.com/gophercloud/gophercloud/openstack/identity/v2/users" + th "github.com/gophercloud/gophercloud/testhelper" ) // AddUserRole will grant a role to a user in a tenant. An error will be @@ -46,12 +47,13 @@ func CreateTenant(t *testing.T, client *gophercloud.ServiceClient, c *tenants.Cr tenant, err := tenants.Create(client, createOpts).Extract() if err != nil { - t.Logf("Foo") return tenant, err } t.Logf("Successfully created project %s with ID %s", name, tenant.ID) + th.AssertEquals(t, name, tenant.Name) + return tenant, nil } @@ -74,6 +76,8 @@ func CreateUser(t *testing.T, client *gophercloud.ServiceClient, tenant *tenants return user, err } + th.AssertEquals(t, userName, user.Name) + return user, nil } @@ -182,5 +186,7 @@ func UpdateUser(t *testing.T, client *gophercloud.ServiceClient, user *users.Use return newUser, err } + th.AssertEquals(t, userName, newUser.Name) + return newUser, nil } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/role_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/role_test.go new file mode 100644 index 00000000..bc9d26ec --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/role_test.go @@ -0,0 +1,76 @@ +// +build acceptance identity roles + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles" + "github.com/gophercloud/gophercloud/openstack/identity/v2/users" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestRolesAddToUser(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2AdminClient() + th.AssertNoErr(t, err) + + tenant, err := FindTenant(t, client) + th.AssertNoErr(t, err) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, tenant) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user) + + err = AddUserRole(t, client, tenant, user, role) + th.AssertNoErr(t, err) + defer DeleteUserRole(t, client, tenant, user, role) + + allPages, err := users.ListRoles(client, tenant.ID, user.ID).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := users.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + t.Logf("Roles of user %s:", user.Name) + var found bool + for _, r := range allRoles { + tools.PrintResource(t, role) + if r.Name == role.Name { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRolesList(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2AdminClient() + th.AssertNoErr(t, err) + + allPages, err := roles.List(client).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, r := range allRoles { + tools.PrintResource(t, r) + if r.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/tenant_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/tenant_test.go new file mode 100644 index 00000000..13a1c08c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/tenant_test.go @@ -0,0 +1,65 @@ +// +build acceptance identity + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTenantsList(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + allPages, err := tenants.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allTenants, err := tenants.ExtractTenants(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, tenant := range allTenants { + tools.PrintResource(t, tenant) + + if tenant.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestTenantsCRUD(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2AdminClient() + th.AssertNoErr(t, err) + + tenant, err := CreateTenant(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteTenant(t, client, tenant.ID) + + tenant, err = tenants.Get(client, tenant.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, tenant) + + updateOpts := tenants.UpdateOpts{ + Description: "some tenant", + } + + newTenant, err := tenants.Update(client, tenant.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newTenant) + + th.AssertEquals(t, newTenant.Description, "some tenant") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/token_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/token_test.go new file mode 100644 index 00000000..30ebcc2b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/token_test.go @@ -0,0 +1,60 @@ +// +build acceptance identity + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTokenAuthenticate(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2UnauthenticatedClient() + th.AssertNoErr(t, err) + + authOptions, err := openstack.AuthOptionsFromEnv() + th.AssertNoErr(t, err) + + result := tokens.Create(client, authOptions) + token, err := result.ExtractToken() + th.AssertNoErr(t, err) + + tools.PrintResource(t, token) + + catalog, err := result.ExtractServiceCatalog() + th.AssertNoErr(t, err) + + for _, entry := range catalog.Entries { + tools.PrintResource(t, entry) + } +} + +func TestTokenValidate(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2Client() + th.AssertNoErr(t, err) + + authOptions, err := openstack.AuthOptionsFromEnv() + th.AssertNoErr(t, err) + + result := tokens.Create(client, authOptions) + token, err := result.ExtractToken() + th.AssertNoErr(t, err) + + tools.PrintResource(t, token) + + getResult := tokens.Get(client, token.ID) + user, err := getResult.ExtractUser() + th.AssertNoErr(t, err) + + tools.PrintResource(t, user) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/user_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/user_test.go new file mode 100644 index 00000000..caaaaf93 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v2/user_test.go @@ -0,0 +1,59 @@ +// +build acceptance identity + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v2/users" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestUsersList(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2AdminClient() + th.AssertNoErr(t, err) + + allPages, err := users.List(client).AllPages() + th.AssertNoErr(t, err) + + allUsers, err := users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, user := range allUsers { + tools.PrintResource(t, user) + + if user.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestUsersCreateUpdateDelete(t *testing.T) { + clients.RequireIdentityV2(t) + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV2AdminClient() + th.AssertNoErr(t, err) + + tenant, err := FindTenant(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, tenant) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user) + + tools.PrintResource(t, user) + + newUser, err := UpdateUser(t, client, user) + th.AssertNoErr(t, err) + + tools.PrintResource(t, newUser) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/domains_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/domains_test.go new file mode 100644 index 00000000..7d146464 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/domains_test.go @@ -0,0 +1,89 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/domains" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestDomainsList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + var iTrue bool = true + listOpts := domains.ListOpts{ + Enabled: &iTrue, + } + + allPages, err := domains.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allDomains, err := domains.ExtractDomains(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, domain := range allDomains { + tools.PrintResource(t, domain) + + if domain.Name == "Default" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestDomainsGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + p, err := domains.Get(client, "default").Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, p) + + th.AssertEquals(t, p.Name, "Default") +} + +func TestDomainsCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + var iTrue bool = true + createOpts := domains.CreateOpts{ + Description: "Testing Domain", + Enabled: &iTrue, + } + + domain, err := CreateDomain(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteDomain(t, client, domain.ID) + + tools.PrintResource(t, domain) + + th.AssertEquals(t, domain.Description, "Testing Domain") + + var iFalse bool = false + updateOpts := domains.UpdateOpts{ + Description: "Staging Test Domain", + Enabled: &iFalse, + } + + newDomain, err := domains.Update(client, domain.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newDomain) + + th.AssertEquals(t, newDomain.Description, "Staging Test Domain") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/endpoint_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/endpoint_test.go new file mode 100644 index 00000000..4bc606b3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/endpoint_test.go @@ -0,0 +1,78 @@ +// +build acceptance + +package v3 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" + "github.com/gophercloud/gophercloud/openstack/identity/v3/services" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestEndpointsList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allPages, err := endpoints.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allEndpoints, err := endpoints.ExtractEndpoints(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, endpoint := range allEndpoints { + tools.PrintResource(t, endpoint) + + if strings.Contains(endpoint.URL, "/v3") { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestEndpointsNavigateCatalog(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + // Discover the service we're interested in. + serviceListOpts := services.ListOpts{ + ServiceType: "compute", + } + + allPages, err := services.List(client, serviceListOpts).AllPages() + th.AssertNoErr(t, err) + + allServices, err := services.ExtractServices(allPages) + th.AssertNoErr(t, err) + + th.AssertEquals(t, len(allServices), 1) + + computeService := allServices[0] + tools.PrintResource(t, computeService) + + // Enumerate the endpoints available for this service. + endpointListOpts := endpoints.ListOpts{ + Availability: gophercloud.AvailabilityPublic, + ServiceID: computeService.ID, + } + + allPages, err = endpoints.List(client, endpointListOpts).AllPages() + th.AssertNoErr(t, err) + + allEndpoints, err := endpoints.ExtractEndpoints(allPages) + th.AssertNoErr(t, err) + + th.AssertEquals(t, len(allServices), 1) + + tools.PrintResource(t, allEndpoints[0]) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/groups_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/groups_test.go new file mode 100644 index 00000000..18c5ae05 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/groups_test.go @@ -0,0 +1,126 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestGroupCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := groups.CreateOpts{ + Name: "testgroup", + DomainID: "default", + Extra: map[string]interface{}{ + "email": "testgroup@example.com", + }, + } + + // Create Group in the default domain + group, err := CreateGroup(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + tools.PrintResource(t, group) + tools.PrintResource(t, group.Extra) + + updateOpts := groups.UpdateOpts{ + Description: "Test Groups", + Extra: map[string]interface{}{ + "email": "thetestgroup@example.com", + }, + } + + newGroup, err := groups.Update(client, group.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newGroup) + tools.PrintResource(t, newGroup.Extra) + + listOpts := groups.ListOpts{ + DomainID: "default", + } + + // List all Groups in default domain + allPages, err := groups.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allGroups, err := groups.ExtractGroups(allPages) + th.AssertNoErr(t, err) + + for _, g := range allGroups { + tools.PrintResource(t, g) + tools.PrintResource(t, g.Extra) + } + + var found bool + for _, group := range allGroups { + tools.PrintResource(t, group) + tools.PrintResource(t, group.Extra) + + if group.Name == newGroup.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "TEST", + } + + allPages, err = groups.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allGroups, err = groups.ExtractGroups(allPages) + th.AssertNoErr(t, err) + + found = false + for _, group := range allGroups { + tools.PrintResource(t, group) + tools.PrintResource(t, group.Extra) + + if group.Name == newGroup.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "foo", + } + + allPages, err = groups.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allGroups, err = groups.ExtractGroups(allPages) + th.AssertNoErr(t, err) + + found = false + for _, group := range allGroups { + tools.PrintResource(t, group) + tools.PrintResource(t, group.Extra) + + if group.Name == newGroup.Name { + found = true + } + } + + th.AssertEquals(t, found, false) + + // Get the recently created group by ID + p, err := groups.Get(client, group.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, p) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/identity.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/identity.go index ae7560dd..88dee1ec 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/identity.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/identity.go @@ -12,6 +12,7 @@ import ( "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" "github.com/gophercloud/gophercloud/openstack/identity/v3/services" "github.com/gophercloud/gophercloud/openstack/identity/v3/users" + th "github.com/gophercloud/gophercloud/testhelper" ) // CreateProject will create a project with a random name. @@ -38,6 +39,8 @@ func CreateProject(t *testing.T, client *gophercloud.ServiceClient, c *projects. t.Logf("Successfully created project %s with ID %s", name, project.ID) + th.AssertEquals(t, project.Name, name) + return project, nil } @@ -65,6 +68,8 @@ func CreateUser(t *testing.T, client *gophercloud.ServiceClient, c *users.Create t.Logf("Successfully created user %s with ID %s", name, user.ID) + th.AssertEquals(t, user.Name, name) + return user, nil } @@ -92,6 +97,8 @@ func CreateGroup(t *testing.T, client *gophercloud.ServiceClient, c *groups.Crea t.Logf("Successfully created group %s with ID %s", name, group.ID) + th.AssertEquals(t, group.Name, name) + return group, nil } @@ -119,6 +126,8 @@ func CreateDomain(t *testing.T, client *gophercloud.ServiceClient, c *domains.Cr t.Logf("Successfully created domain %s with ID %s", name, domain.ID) + th.AssertEquals(t, domain.Name, name) + return domain, nil } @@ -146,6 +155,8 @@ func CreateRole(t *testing.T, client *gophercloud.ServiceClient, c *roles.Create t.Logf("Successfully created role %s with ID %s", name, role.ID) + th.AssertEquals(t, role.Name, name) + return role, nil } @@ -173,6 +184,8 @@ func CreateRegion(t *testing.T, client *gophercloud.ServiceClient, c *regions.Cr t.Logf("Successfully created region %s", id) + th.AssertEquals(t, region.ID, id) + return region, nil } @@ -200,6 +213,8 @@ func CreateService(t *testing.T, client *gophercloud.ServiceClient, c *services. t.Logf("Successfully created service %s", service.ID) + th.AssertEquals(t, service.Extra["name"], name) + return service, nil } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/policies_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/policies_test.go new file mode 100644 index 00000000..3fb22bb2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/policies_test.go @@ -0,0 +1,143 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/policies" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestPoliciesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allPages, err := policies.List(client, policies.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err := policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + + for _, policy := range allPolicies { + tools.PrintResource(t, policy) + } +} + +func TestPoliciesCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := policies.CreateOpts{ + Type: "application/json", + Blob: []byte("{'foobar_user': 'role:compute-user'}"), + Extra: map[string]interface{}{ + "description": "policy for foobar_user", + }, + } + + policy, err := policies.Create(client, &createOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, policy) + tools.PrintResource(t, policy.Extra) + + th.AssertEquals(t, policy.Type, createOpts.Type) + th.AssertEquals(t, policy.Blob, string(createOpts.Blob)) + th.AssertEquals(t, policy.Extra["description"], createOpts.Extra["description"]) + + var listOpts policies.ListOpts + + allPages, err := policies.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err := policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, p := range allPolicies { + tools.PrintResource(t, p) + tools.PrintResource(t, p.Extra) + + if p.ID == policy.ID { + found = true + } + } + + th.AssertEquals(t, true, found) + + listOpts.Filters = map[string]string{ + "type__contains": "json", + } + + allPages, err = policies.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err = policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + + found = false + for _, p := range allPolicies { + tools.PrintResource(t, p) + tools.PrintResource(t, p.Extra) + + if p.ID == policy.ID { + found = true + } + } + + th.AssertEquals(t, true, found) + + listOpts.Filters = map[string]string{ + "type__contains": "foobar", + } + + allPages, err = policies.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allPolicies, err = policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + + found = false + for _, p := range allPolicies { + tools.PrintResource(t, p) + tools.PrintResource(t, p.Extra) + + if p.ID == policy.ID { + found = true + } + } + + th.AssertEquals(t, false, found) + + gotPolicy, err := policies.Get(client, policy.ID).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, policy, gotPolicy) + + updateOpts := policies.UpdateOpts{ + Type: "text/plain", + Blob: []byte("'foobar_user': 'role:compute-user'"), + Extra: map[string]interface{}{ + "description": "updated policy for foobar_user", + }, + } + + updatedPolicy, err := policies.Update(client, policy.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, updatedPolicy) + tools.PrintResource(t, updatedPolicy.Extra) + + th.AssertEquals(t, updatedPolicy.Type, updateOpts.Type) + th.AssertEquals(t, updatedPolicy.Blob, string(updateOpts.Blob)) + th.AssertEquals(t, updatedPolicy.Extra["description"], updateOpts.Extra["description"]) + + err = policies.Delete(client, policy.ID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/projects_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/projects_test.go new file mode 100644 index 00000000..7256b80d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/projects_test.go @@ -0,0 +1,192 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestProjectsList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + var iTrue bool = true + listOpts := projects.ListOpts{ + Enabled: &iTrue, + } + + allPages, err := projects.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allProjects, err := projects.ExtractProjects(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, project := range allProjects { + tools.PrintResource(t, project) + + if project.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "dmi", + } + + allPages, err = projects.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allProjects, err = projects.ExtractProjects(allPages) + th.AssertNoErr(t, err) + + found = false + for _, project := range allProjects { + tools.PrintResource(t, project) + + if project.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "foo", + } + + allPages, err = projects.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allProjects, err = projects.ExtractProjects(allPages) + th.AssertNoErr(t, err) + + found = false + for _, project := range allProjects { + tools.PrintResource(t, project) + + if project.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, false) +} + +func TestProjectsGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allPages, err := projects.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allProjects, err := projects.ExtractProjects(allPages) + th.AssertNoErr(t, err) + + project := allProjects[0] + p, err := projects.Get(client, project.ID).Extract() + if err != nil { + t.Fatalf("Unable to get project: %v", err) + } + + tools.PrintResource(t, p) + + th.AssertEquals(t, project.Name, p.Name) +} + +func TestProjectsCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + tools.PrintResource(t, project) + + var iFalse bool = false + updateOpts := projects.UpdateOpts{ + Enabled: &iFalse, + } + + updatedProject, err := projects.Update(client, project.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, updatedProject) +} + +func TestProjectsDomain(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + var iTrue = true + createOpts := projects.CreateOpts{ + IsDomain: &iTrue, + } + + projectDomain, err := CreateProject(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, projectDomain.ID) + + tools.PrintResource(t, projectDomain) + + createOpts = projects.CreateOpts{ + DomainID: projectDomain.ID, + } + + project, err := CreateProject(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + tools.PrintResource(t, project) + + th.AssertEquals(t, project.DomainID, projectDomain.ID) + + var iFalse = false + updateOpts := projects.UpdateOpts{ + Enabled: &iFalse, + } + + _, err = projects.Update(client, projectDomain.ID, updateOpts).Extract() + th.AssertNoErr(t, err) +} + +func TestProjectsNested(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + projectMain, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, projectMain.ID) + + tools.PrintResource(t, projectMain) + + createOpts := projects.CreateOpts{ + ParentID: projectMain.ID, + } + + project, err := CreateProject(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + tools.PrintResource(t, project) + + th.AssertEquals(t, project.ParentID, projectMain.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/regions_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/regions_test.go new file mode 100644 index 00000000..f44a65be --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/regions_test.go @@ -0,0 +1,96 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/regions" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestRegionsList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + listOpts := regions.ListOpts{ + ParentRegionID: "RegionOne", + } + + allPages, err := regions.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allRegions, err := regions.ExtractRegions(allPages) + th.AssertNoErr(t, err) + + for _, region := range allRegions { + tools.PrintResource(t, region) + } +} + +func TestRegionsGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allPages, err := regions.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allRegions, err := regions.ExtractRegions(allPages) + th.AssertNoErr(t, err) + + region := allRegions[0] + p, err := regions.Get(client, region.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, p) + + th.AssertEquals(t, region.ID, p.ID) +} + +func TestRegionsCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := regions.CreateOpts{ + ID: "testregion", + Description: "Region for testing", + Extra: map[string]interface{}{ + "email": "testregion@example.com", + }, + } + + // Create region in the default domain + region, err := CreateRegion(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteRegion(t, client, region.ID) + + tools.PrintResource(t, region) + tools.PrintResource(t, region.Extra) + + updateOpts := regions.UpdateOpts{ + Description: "Region A for testing", + /* + // Due to a bug in Keystone, the Extra column of the Region table + // is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933 + // The following lines should be uncommented once the fix is merged. + + Extra: map[string]interface{}{ + "email": "testregionA@example.com", + }, + */ + } + + newRegion, err := regions.Update(client, region.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newRegion) + tools.PrintResource(t, newRegion.Extra) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/roles_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/roles_test.go new file mode 100644 index 00000000..52867f66 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/roles_test.go @@ -0,0 +1,633 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/domains" + "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestRolesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + listOpts := roles.ListOpts{ + DomainID: "default", + } + + allPages, err := roles.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + for _, role := range allRoles { + tools.PrintResource(t, role) + } +} + +func TestRolesGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + p, err := roles.Get(client, role.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, p) +} + +func TestRolesCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := roles.CreateOpts{ + Name: "testrole", + Extra: map[string]interface{}{ + "description": "test role description", + }, + } + + // Create Role in the default domain + role, err := CreateRole(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteRole(t, client, role.ID) + + tools.PrintResource(t, role) + tools.PrintResource(t, role.Extra) + + var listOpts roles.ListOpts + allPages, err := roles.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, r := range allRoles { + tools.PrintResource(t, r) + tools.PrintResource(t, r.Extra) + + if r.Name == role.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "TEST", + } + + allPages, err = roles.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err = roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + found = false + for _, r := range allRoles { + tools.PrintResource(t, r) + tools.PrintResource(t, r.Extra) + + if r.Name == role.Name { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "foo", + } + + allPages, err = roles.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err = roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + found = false + for _, r := range allRoles { + tools.PrintResource(t, r) + tools.PrintResource(t, r.Extra) + + if r.Name == role.Name { + found = true + } + } + + th.AssertEquals(t, found, false) + + updateOpts := roles.UpdateOpts{ + Extra: map[string]interface{}{ + "description": "updated test role description", + }, + } + + newRole, err := roles.Update(client, role.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newRole) + tools.PrintResource(t, newRole.Extra) + + th.AssertEquals(t, newRole.Extra["description"], "updated test role description") +} + +func TestRoleListAssignmentForUserOnProject(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + t.Logf("Attempting to assign a role %s to a user %s on a project %s", + role.Name, user.Name, project.Name) + + assignOpts := roles.AssignOpts{ + UserID: user.ID, + ProjectID: project.ID, + } + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a user %s on a project %s", + role.Name, user.Name, project.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + UserID: user.ID, + ProjectID: project.ID, + }) + + listAssignmentsOnResourceOpts := roles.ListAssignmentsOnResourceOpts{ + UserID: user.ID, + ProjectID: project.ID, + } + allPages, err := roles.ListAssignmentsOnResource(client, listAssignmentsOnResourceOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of user %s on project %s:", user.Name, project.Name) + var found bool + for _, _role := range allRoles { + tools.PrintResource(t, _role) + + if _role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRoleListAssignmentForUserOnDomain(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + domain, err := CreateDomain(t, client, &domains.CreateOpts{ + Enabled: gophercloud.Disabled, + }) + th.AssertNoErr(t, err) + defer DeleteDomain(t, client, domain.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + t.Logf("Attempting to assign a role %s to a user %s on a domain %s", + role.Name, user.Name, domain.Name) + + assignOpts := roles.AssignOpts{ + UserID: user.ID, + DomainID: domain.ID, + } + + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a user %s on a domain %s", + role.Name, user.Name, domain.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + UserID: user.ID, + DomainID: domain.ID, + }) + + listAssignmentsOnResourceOpts := roles.ListAssignmentsOnResourceOpts{ + UserID: user.ID, + DomainID: domain.ID, + } + allPages, err := roles.ListAssignmentsOnResource(client, listAssignmentsOnResourceOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of user %s on domain %s:", user.Name, domain.Name) + var found bool + for _, _role := range allRoles { + tools.PrintResource(t, _role) + + if _role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRoleListAssignmentForGroupOnProject(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + group, err := CreateGroup(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + t.Logf("Attempting to assign a role %s to a group %s on a project %s", + role.Name, group.Name, project.Name) + + assignOpts := roles.AssignOpts{ + GroupID: group.ID, + ProjectID: project.ID, + } + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a group %s on a project %s", + role.Name, group.Name, project.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + GroupID: group.ID, + ProjectID: project.ID, + }) + + listAssignmentsOnResourceOpts := roles.ListAssignmentsOnResourceOpts{ + GroupID: group.ID, + ProjectID: project.ID, + } + allPages, err := roles.ListAssignmentsOnResource(client, listAssignmentsOnResourceOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of group %s on project %s:", group.Name, project.Name) + var found bool + for _, _role := range allRoles { + tools.PrintResource(t, _role) + + if _role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRoleListAssignmentForGroupOnDomain(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + domain, err := CreateDomain(t, client, &domains.CreateOpts{ + Enabled: gophercloud.Disabled, + }) + th.AssertNoErr(t, err) + defer DeleteDomain(t, client, domain.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + group, err := CreateGroup(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + t.Logf("Attempting to assign a role %s to a group %s on a domain %s", + role.Name, group.Name, domain.Name) + + assignOpts := roles.AssignOpts{ + GroupID: group.ID, + DomainID: domain.ID, + } + + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a group %s on a domain %s", + role.Name, group.Name, domain.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + GroupID: group.ID, + DomainID: domain.ID, + }) + + listAssignmentsOnResourceOpts := roles.ListAssignmentsOnResourceOpts{ + GroupID: group.ID, + DomainID: domain.ID, + } + allPages, err := roles.ListAssignmentsOnResource(client, listAssignmentsOnResourceOpts).AllPages() + th.AssertNoErr(t, err) + + allRoles, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of group %s on domain %s:", group.Name, domain.Name) + var found bool + for _, _role := range allRoles { + tools.PrintResource(t, _role) + + if _role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRolesAssignToUserOnProject(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + t.Logf("Attempting to assign a role %s to a user %s on a project %s", + role.Name, user.Name, project.Name) + + assignOpts := roles.AssignOpts{ + UserID: user.ID, + ProjectID: project.ID, + } + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a user %s on a project %s", + role.Name, user.Name, project.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + UserID: user.ID, + ProjectID: project.ID, + }) + + lao := roles.ListAssignmentsOpts{ + RoleID: role.ID, + ScopeProjectID: project.ID, + UserID: user.ID, + } + + allPages, err := roles.ListAssignments(client, lao).AllPages() + th.AssertNoErr(t, err) + + allRoleAssignments, err := roles.ExtractRoleAssignments(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of user %s on project %s:", user.Name, project.Name) + var found bool + for _, roleAssignment := range allRoleAssignments { + tools.PrintResource(t, roleAssignment) + + if roleAssignment.Role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRolesAssignToUserOnDomain(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + domain, err := CreateDomain(t, client, &domains.CreateOpts{ + Enabled: gophercloud.Disabled, + }) + th.AssertNoErr(t, err) + defer DeleteDomain(t, client, domain.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + user, err := CreateUser(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + t.Logf("Attempting to assign a role %s to a user %s on a domain %s", + role.Name, user.Name, domain.Name) + + assignOpts := roles.AssignOpts{ + UserID: user.ID, + DomainID: domain.ID, + } + + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a user %s on a domain %s", + role.Name, user.Name, domain.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + UserID: user.ID, + DomainID: domain.ID, + }) + + lao := roles.ListAssignmentsOpts{ + RoleID: role.ID, + ScopeDomainID: domain.ID, + UserID: user.ID, + } + + allPages, err := roles.ListAssignments(client, lao).AllPages() + th.AssertNoErr(t, err) + + allRoleAssignments, err := roles.ExtractRoleAssignments(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of user %s on domain %s:", user.Name, domain.Name) + var found bool + for _, roleAssignment := range allRoleAssignments { + tools.PrintResource(t, roleAssignment) + + if roleAssignment.Role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRolesAssignToGroupOnDomain(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + domain, err := CreateDomain(t, client, &domains.CreateOpts{ + Enabled: gophercloud.Disabled, + }) + th.AssertNoErr(t, err) + defer DeleteDomain(t, client, domain.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + group, err := CreateGroup(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + t.Logf("Attempting to assign a role %s to a group %s on a domain %s", + role.Name, group.Name, domain.Name) + + assignOpts := roles.AssignOpts{ + GroupID: group.ID, + DomainID: domain.ID, + } + + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a group %s on a domain %s", + role.Name, group.Name, domain.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + GroupID: group.ID, + DomainID: domain.ID, + }) + + lao := roles.ListAssignmentsOpts{ + RoleID: role.ID, + ScopeDomainID: domain.ID, + GroupID: group.ID, + } + + allPages, err := roles.ListAssignments(client, lao).AllPages() + th.AssertNoErr(t, err) + + allRoleAssignments, err := roles.ExtractRoleAssignments(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of group %s on domain %s:", group.Name, domain.Name) + var found bool + for _, roleAssignment := range allRoleAssignments { + tools.PrintResource(t, roleAssignment) + + if roleAssignment.Role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestRolesAssignToGroupOnProject(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + role, err := FindRole(t, client) + th.AssertNoErr(t, err) + + group, err := CreateGroup(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + t.Logf("Attempting to assign a role %s to a group %s on a project %s", + role.Name, group.Name, project.Name) + + assignOpts := roles.AssignOpts{ + GroupID: group.ID, + ProjectID: project.ID, + } + err = roles.Assign(client, role.ID, assignOpts).ExtractErr() + th.AssertNoErr(t, err) + + t.Logf("Successfully assigned a role %s to a group %s on a project %s", + role.Name, group.Name, project.Name) + + defer UnassignRole(t, client, role.ID, &roles.UnassignOpts{ + GroupID: group.ID, + ProjectID: project.ID, + }) + + lao := roles.ListAssignmentsOpts{ + RoleID: role.ID, + ScopeProjectID: project.ID, + GroupID: group.ID, + } + + allPages, err := roles.ListAssignments(client, lao).AllPages() + th.AssertNoErr(t, err) + + allRoleAssignments, err := roles.ExtractRoleAssignments(allPages) + th.AssertNoErr(t, err) + + t.Logf("Role assignments of group %s on project %s:", group.Name, project.Name) + var found bool + for _, roleAssignment := range allRoleAssignments { + tools.PrintResource(t, roleAssignment) + + if roleAssignment.Role.ID == role.ID { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/service_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/service_test.go new file mode 100644 index 00000000..7e072ce3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/service_test.go @@ -0,0 +1,78 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/services" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestServicesList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + listOpts := services.ListOpts{ + ServiceType: "identity", + } + + allPages, err := services.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allServices, err := services.ExtractServices(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, service := range allServices { + tools.PrintResource(t, service) + + if service.Type == "identity" { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestServicesCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := services.CreateOpts{ + Type: "testing", + Extra: map[string]interface{}{ + "email": "testservice@example.com", + }, + } + + // Create service in the default domain + service, err := CreateService(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteService(t, client, service.ID) + + tools.PrintResource(t, service) + tools.PrintResource(t, service.Extra) + + updateOpts := services.UpdateOpts{ + Type: "testing2", + Extra: map[string]interface{}{ + "description": "Test Users", + "email": "thetestservice@example.com", + }, + } + + newService, err := services.Update(client, service.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newService) + tools.PrintResource(t, newService.Extra) + + th.AssertEquals(t, newService.Extra["description"], "Test Users") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/token_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/token_test.go new file mode 100644 index 00000000..ff6e91d4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/token_test.go @@ -0,0 +1,49 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTokensGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + ao, err := openstack.AuthOptionsFromEnv() + th.AssertNoErr(t, err) + + authOptions := tokens.AuthOptions{ + Username: ao.Username, + Password: ao.Password, + DomainName: "default", + } + + token, err := tokens.Create(client, &authOptions).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, token) + + catalog, err := tokens.Get(client, token.ID).ExtractServiceCatalog() + th.AssertNoErr(t, err) + tools.PrintResource(t, catalog) + + user, err := tokens.Get(client, token.ID).ExtractUser() + th.AssertNoErr(t, err) + tools.PrintResource(t, user) + + roles, err := tokens.Get(client, token.ID).ExtractRoles() + th.AssertNoErr(t, err) + tools.PrintResource(t, roles) + + project, err := tokens.Get(client, token.ID).ExtractProject() + th.AssertNoErr(t, err) + tools.PrintResource(t, project) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/users_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/users_test.go new file mode 100644 index 00000000..5bf2fcb5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3/users_test.go @@ -0,0 +1,334 @@ +// +build acceptance + +package v3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" + "github.com/gophercloud/gophercloud/openstack/identity/v3/users" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestUsersList(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + var iTrue bool = true + listOpts := users.ListOpts{ + Enabled: &iTrue, + } + + allPages, err := users.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allUsers, err := users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, user := range allUsers { + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + if user.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "dmi", + } + + allPages, err = users.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allUsers, err = users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + + found = false + for _, user := range allUsers { + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + if user.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, true) + + listOpts.Filters = map[string]string{ + "name__contains": "foo", + } + + allPages, err = users.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allUsers, err = users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + + found = false + for _, user := range allUsers { + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + if user.Name == "admin" { + found = true + } + } + + th.AssertEquals(t, found, false) +} + +func TestUsersGet(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allPages, err := users.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allUsers, err := users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + + user := allUsers[0] + p, err := users.Get(client, user.ID).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, p) + + th.AssertEquals(t, user.Name, p.Name) +} + +func TestUserCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + project, err := CreateProject(t, client, nil) + th.AssertNoErr(t, err) + defer DeleteProject(t, client, project.ID) + + tools.PrintResource(t, project) + + createOpts := users.CreateOpts{ + DefaultProjectID: project.ID, + Password: "foobar", + DomainID: "default", + Options: map[users.Option]interface{}{ + users.IgnorePasswordExpiry: true, + users.MultiFactorAuthRules: []interface{}{ + []string{"password", "totp"}, + []string{"password", "custom-auth-method"}, + }, + }, + Extra: map[string]interface{}{ + "email": "jsmith@example.com", + }, + } + + user, err := CreateUser(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + iFalse := false + updateOpts := users.UpdateOpts{ + Enabled: &iFalse, + Options: map[users.Option]interface{}{ + users.MultiFactorAuthRules: nil, + }, + Extra: map[string]interface{}{ + "disabled_reason": "DDOS", + }, + } + + newUser, err := users.Update(client, user.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + + tools.PrintResource(t, newUser) + tools.PrintResource(t, newUser.Extra) + + th.AssertEquals(t, newUser.Extra["disabled_reason"], "DDOS") +} + +func TestUserChangePassword(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := users.CreateOpts{ + Password: "secretsecret", + DomainID: "default", + } + + user, err := CreateUser(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + changePasswordOpts := users.ChangePasswordOpts{ + OriginalPassword: "secretsecret", + Password: "new_secretsecret", + } + err = users.ChangePassword(client, user.ID, changePasswordOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUsersGroups(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + createOpts := users.CreateOpts{ + Password: "foobar", + DomainID: "default", + } + + user, err := CreateUser(t, client, &createOpts) + th.AssertNoErr(t, err) + defer DeleteUser(t, client, user.ID) + + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + createGroupOpts := groups.CreateOpts{ + Name: "testgroup", + DomainID: "default", + } + + // Create Group in the default domain + group, err := CreateGroup(t, client, &createGroupOpts) + th.AssertNoErr(t, err) + defer DeleteGroup(t, client, group.ID) + + tools.PrintResource(t, group) + tools.PrintResource(t, group.Extra) + + err = users.AddToGroup(client, group.ID, user.ID).ExtractErr() + th.AssertNoErr(t, err) + + allGroupPages, err := users.ListGroups(client, user.ID).AllPages() + th.AssertNoErr(t, err) + + allGroups, err := groups.ExtractGroups(allGroupPages) + th.AssertNoErr(t, err) + + var found bool + for _, g := range allGroups { + tools.PrintResource(t, g) + tools.PrintResource(t, g.Extra) + + if g.ID == group.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + found = false + allUserPages, err := users.ListInGroup(client, group.ID, nil).AllPages() + th.AssertNoErr(t, err) + + allUsers, err := users.ExtractUsers(allUserPages) + th.AssertNoErr(t, err) + + for _, u := range allUsers { + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + if u.ID == user.ID { + found = true + } + } + + th.AssertEquals(t, found, true) + + ok, err := users.IsMemberOfGroup(client, group.ID, user.ID).Extract() + if err != nil { + t.Fatalf("Unable to check whether user belongs to group: %v", err) + } + if !ok { + t.Fatalf("User %s is expected to be a member of group %s", user.ID, group.ID) + } + + err = users.RemoveFromGroup(client, group.ID, user.ID).ExtractErr() + th.AssertNoErr(t, err) + + allGroupPages, err = users.ListGroups(client, user.ID).AllPages() + th.AssertNoErr(t, err) + + allGroups, err = groups.ExtractGroups(allGroupPages) + th.AssertNoErr(t, err) + + found = false + for _, g := range allGroups { + tools.PrintResource(t, g) + tools.PrintResource(t, g.Extra) + + if g.ID == group.ID { + found = true + } + } + + th.AssertEquals(t, found, false) + + found = false + allUserPages, err = users.ListInGroup(client, group.ID, nil).AllPages() + th.AssertNoErr(t, err) + + allUsers, err = users.ExtractUsers(allUserPages) + th.AssertNoErr(t, err) + + for _, u := range allUsers { + tools.PrintResource(t, user) + tools.PrintResource(t, user.Extra) + + if u.ID == user.ID { + found = true + } + } + + th.AssertEquals(t, found, false) + +} + +func TestUsersListProjects(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewIdentityV3Client() + th.AssertNoErr(t, err) + + allUserPages, err := users.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allUsers, err := users.ExtractUsers(allUserPages) + th.AssertNoErr(t, err) + + user := allUsers[0] + + allProjectPages, err := users.ListProjects(client, user.ID).AllPages() + th.AssertNoErr(t, err) + + allProjects, err := projects.ExtractProjects(allProjectPages) + th.AssertNoErr(t, err) + + for _, project := range allProjects { + tools.PrintResource(t, project) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/images_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/images_test.go new file mode 100644 index 00000000..9c6cf32a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/images_test.go @@ -0,0 +1,140 @@ +// +build acceptance imageservice images + +package v2 + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestImagesListEachPage(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + listOpts := images.ListOpts{ + Limit: 1, + } + + pager := images.List(client, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + images, err := images.ExtractImages(page) + if err != nil { + t.Fatalf("Unable to extract images: %v", err) + } + + for _, image := range images { + tools.PrintResource(t, image) + tools.PrintResource(t, image.Properties) + } + + return true, nil + }) +} + +func TestImagesListAllPages(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + image, err := CreateEmptyImage(t, client) + th.AssertNoErr(t, err) + defer DeleteImage(t, client, image) + + listOpts := images.ListOpts{} + + allPages, err := images.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allImages, err := images.ExtractImages(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, i := range allImages { + tools.PrintResource(t, i) + tools.PrintResource(t, i.Properties) + + if i.Name == image.Name { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestImagesListByDate(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + date := time.Date(2014, 1, 1, 1, 1, 1, 0, time.UTC) + listOpts := images.ListOpts{ + Limit: 1, + CreatedAtQuery: &images.ImageDateQuery{ + Date: date, + Filter: images.FilterGTE, + }, + } + + allPages, err := images.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allImages, err := images.ExtractImages(allPages) + th.AssertNoErr(t, err) + + if len(allImages) == 0 { + t.Fatalf("Query resulted in no results") + } + + for _, image := range allImages { + tools.PrintResource(t, image) + tools.PrintResource(t, image.Properties) + } + + date = time.Date(2049, 1, 1, 1, 1, 1, 0, time.UTC) + listOpts = images.ListOpts{ + Limit: 1, + CreatedAtQuery: &images.ImageDateQuery{ + Date: date, + Filter: images.FilterGTE, + }, + } + + allPages, err = images.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allImages, err = images.ExtractImages(allPages) + th.AssertNoErr(t, err) + + if len(allImages) > 0 { + t.Fatalf("Expected 0 images, got %d", len(allImages)) + } +} + +func TestImagesFilter(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + image, err := CreateEmptyImage(t, client) + th.AssertNoErr(t, err) + defer DeleteImage(t, client, image) + + listOpts := images.ListOpts{ + Tags: []string{"foo", "bar"}, + ContainerFormat: "bare", + DiskFormat: "qcow2", + } + + allPages, err := images.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allImages, err := images.ExtractImages(allPages) + th.AssertNoErr(t, err) + + if len(allImages) == 0 { + t.Fatalf("Query resulted in no results") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/imageservice.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/imageservice.go index 8aaeeb74..f61500e6 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/imageservice.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/imageservice.go @@ -8,6 +8,8 @@ import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/acceptance/tools" "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks" + th "github.com/gophercloud/gophercloud/testhelper" ) // CreateEmptyImage will create an image, but with no actual image data. @@ -31,6 +33,7 @@ func CreateEmptyImage(t *testing.T, client *gophercloud.ServiceClient) (*images. Properties: map[string]string{ "architecture": "x86_64", }, + Tags: []string{"foo", "bar", "baz"}, } image, err := images.Create(client, createOpts).Extract() @@ -38,8 +41,16 @@ func CreateEmptyImage(t *testing.T, client *gophercloud.ServiceClient) (*images. return image, err } - t.Logf("Created image %s: %#v", name, image) - return image, nil + newImage, err := images.Get(client, image.ID).Extract() + if err != nil { + return image, err + } + + t.Logf("Created image %s: %#v", name, newImage) + + th.CheckEquals(t, newImage.Name, name) + th.CheckEquals(t, newImage.Properties["architecture"], "x86_64") + return newImage, nil } // DeleteImage deletes an image. @@ -53,3 +64,34 @@ func DeleteImage(t *testing.T, client *gophercloud.ServiceClient, image *images. t.Logf("Deleted image: %s", image.ID) } + +// ImportImageURL contains an URL of a test image that can be imported. +const ImportImageURL = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img" + +// CreateTask will create a task to import the CirrOS image. +// An error will be returned if a task couldn't be created. +func CreateTask(t *testing.T, client *gophercloud.ServiceClient, imageURL string) (*tasks.Task, error) { + t.Logf("Attempting to create an Imageservice import task with image: %s", imageURL) + opts := tasks.CreateOpts{ + Type: "import", + Input: map[string]interface{}{ + "image_properties": map[string]interface{}{ + "container_format": "bare", + "disk_format": "raw", + }, + "import_from_format": "raw", + "import_from": imageURL, + }, + } + task, err := tasks.Create(client, opts).Extract() + if err != nil { + return nil, err + } + + newTask, err := tasks.Get(client, task.ID).Extract() + if err != nil { + return nil, err + } + + return newTask, nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/tasks_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/tasks_test.go new file mode 100644 index 00000000..1e0fbf3f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/tasks_test.go @@ -0,0 +1,63 @@ +// +build acceptance imageservice tasks + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTasksListEachPage(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + listOpts := tasks.ListOpts{ + Limit: 1, + } + + pager := tasks.List(client, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + tasks, err := tasks.ExtractTasks(page) + th.AssertNoErr(t, err) + + for _, task := range tasks { + tools.PrintResource(t, task) + } + + return true, nil + }) +} + +func TestTasksListAllPages(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + listOpts := tasks.ListOpts{} + + allPages, err := tasks.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allTasks, err := tasks.ExtractTasks(allPages) + th.AssertNoErr(t, err) + + for _, i := range allTasks { + tools.PrintResource(t, i) + } +} + +func TestTaskCreate(t *testing.T) { + client, err := clients.NewImageServiceV2Client() + th.AssertNoErr(t, err) + + task, err := CreateTask(t, client, ImportImageURL) + if err != nil { + t.Fatalf("Unable to create an Imageservice task: %v", err) + } + + tools.PrintResource(t, task) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/acls_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/acls_test.go new file mode 100644 index 00000000..54a123a2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/acls_test.go @@ -0,0 +1,103 @@ +// +build acceptance keymanager acls + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestACLCRUD(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + payload := tools.RandomString("SUPERSECRET-", 8) + secret, err := CreateSecretWithPayload(t, client, payload) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + user := tools.RandomString("", 32) + users := []string{user} + iFalse := false + setOpts := acls.SetOpts{ + Type: "read", + Users: &users, + ProjectAccess: &iFalse, + } + + aclRef, err := acls.SetSecretACL(client, secretID, setOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, aclRef) + defer func() { + err := acls.DeleteSecretACL(client, secretID).ExtractErr() + th.AssertNoErr(t, err) + acl, err := acls.GetSecretACL(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + }() + + acl, err := acls.GetSecretACL(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + tools.PrintResource(t, (*acl)["read"].Created) + th.AssertEquals(t, len((*acl)["read"].Users), 1) + th.AssertEquals(t, (*acl)["read"].ProjectAccess, false) + + newUsers := []string{} + updateOpts := acls.SetOpts{ + Type: "read", + Users: &newUsers, + } + + aclRef, err = acls.UpdateSecretACL(client, secretID, updateOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, aclRef) + + acl, err = acls.GetSecretACL(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + tools.PrintResource(t, (*acl)["read"].Created) + th.AssertEquals(t, len((*acl)["read"].Users), 0) + th.AssertEquals(t, (*acl)["read"].ProjectAccess, false) + + container, err := CreateGenericContainer(t, client, secret) + th.AssertNoErr(t, err) + containerID, err := ParseID(container.ContainerRef) + th.AssertNoErr(t, err) + defer DeleteContainer(t, client, containerID) + + aclRef, err = acls.SetContainerACL(client, containerID, setOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, aclRef) + defer func() { + err := acls.DeleteContainerACL(client, containerID).ExtractErr() + th.AssertNoErr(t, err) + acl, err := acls.GetContainerACL(client, containerID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + }() + + acl, err = acls.GetContainerACL(client, containerID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + tools.PrintResource(t, (*acl)["read"].Created) + th.AssertEquals(t, len((*acl)["read"].Users), 1) + th.AssertEquals(t, (*acl)["read"].ProjectAccess, false) + + aclRef, err = acls.UpdateContainerACL(client, containerID, updateOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, aclRef) + + acl, err = acls.GetContainerACL(client, containerID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, acl) + tools.PrintResource(t, (*acl)["read"].Created) + th.AssertEquals(t, len((*acl)["read"].Users), 0) + th.AssertEquals(t, (*acl)["read"].ProjectAccess, false) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/containers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/containers_test.go new file mode 100644 index 00000000..2b5f4d01 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/containers_test.go @@ -0,0 +1,188 @@ +// +build acceptance keymanager containers + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestGenericContainersCRUD(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + payload := tools.RandomString("SUPERSECRET-", 8) + secret, err := CreateSecretWithPayload(t, client, payload) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + container, err := CreateGenericContainer(t, client, secret) + th.AssertNoErr(t, err) + containerID, err := ParseID(container.ContainerRef) + th.AssertNoErr(t, err) + defer DeleteContainer(t, client, containerID) + + allPages, err := containers.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allContainers, err := containers.ExtractContainers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allContainers { + if v.ContainerRef == container.ContainerRef { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestCertificateContainer(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + pass := tools.RandomString("", 16) + priv, cert, err := CreateCertificate(t, pass) + th.AssertNoErr(t, err) + + private, err := CreatePrivateSecret(t, client, priv) + th.AssertNoErr(t, err) + secretID, err := ParseID(private.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Private Payload: %s", string(payload)) + + certificate, err := CreateCertificateSecret(t, client, cert) + th.AssertNoErr(t, err) + secretID, err = ParseID(certificate.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err = secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Certificate Payload: %s", string(payload)) + + passphrase, err := CreatePassphraseSecret(t, client, pass) + th.AssertNoErr(t, err) + secretID, err = ParseID(passphrase.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err = secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Passphrase Payload: %s", string(payload)) + + container, err := CreateCertificateContainer(t, client, passphrase, private, certificate) + th.AssertNoErr(t, err) + containerID, err := ParseID(container.ContainerRef) + defer DeleteContainer(t, client, containerID) +} + +func TestRSAContainer(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + pass := tools.RandomString("", 16) + priv, pub, err := CreateRSAKeyPair(t, pass) + th.AssertNoErr(t, err) + + private, err := CreatePrivateSecret(t, client, priv) + th.AssertNoErr(t, err) + secretID, err := ParseID(private.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Private Payload: %s", string(payload)) + + public, err := CreatePublicSecret(t, client, pub) + th.AssertNoErr(t, err) + secretID, err = ParseID(public.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err = secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Public Payload: %s", string(payload)) + + passphrase, err := CreatePassphraseSecret(t, client, pass) + th.AssertNoErr(t, err) + secretID, err = ParseID(passphrase.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err = secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Passphrase Payload: %s", string(payload)) + + container, err := CreateRSAContainer(t, client, passphrase, private, public) + th.AssertNoErr(t, err) + containerID, err := ParseID(container.ContainerRef) + defer DeleteContainer(t, client, containerID) +} + +func TestContainerConsumersCRUD(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + payload := tools.RandomString("SUPERSECRET-", 8) + secret, err := CreateSecretWithPayload(t, client, payload) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + container, err := CreateGenericContainer(t, client, secret) + th.AssertNoErr(t, err) + containerID, err := ParseID(container.ContainerRef) + th.AssertNoErr(t, err) + defer DeleteContainer(t, client, containerID) + + consumerName := tools.RandomString("CONSUMER-", 8) + consumerCreateOpts := containers.CreateConsumerOpts{ + Name: consumerName, + URL: "http://example.com", + } + + container, err = containers.CreateConsumer(client, containerID, consumerCreateOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, container.Consumers) + th.AssertEquals(t, len(container.Consumers), 1) + defer func() { + deleteOpts := containers.DeleteConsumerOpts{ + Name: consumerName, + URL: "http://example.com", + } + + container, err := containers.DeleteConsumer(client, containerID, deleteOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, len(container.Consumers), 0) + }() + + allPages, err := containers.ListConsumers(client, containerID, nil).AllPages() + th.AssertNoErr(t, err) + + allConsumers, err := containers.ExtractConsumers(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allConsumers { + if v.Name == consumerName { + found = true + } + } + + th.AssertEquals(t, found, true) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/keymanager.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/keymanager.go new file mode 100644 index 00000000..99a85f96 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/keymanager.go @@ -0,0 +1,713 @@ +package v1 + +import ( + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "crypto/x509/pkix" + "encoding/asn1" + "encoding/base64" + "encoding/pem" + "fmt" + "math/big" + "strings" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +// CreateAsymmetric Order will create a random asymmetric order. +// An error will be returned if the order could not be created. +func CreateAsymmetricOrder(t *testing.T, client *gophercloud.ServiceClient) (*orders.Order, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create order %s", name) + + expiration := time.Date(2049, 1, 1, 1, 1, 1, 0, time.UTC) + createOpts := orders.CreateOpts{ + Type: orders.AsymmetricOrder, + Meta: orders.MetaOpts{ + Name: name, + Algorithm: "rsa", + BitLength: 2048, + Mode: "cbc", + Expiration: &expiration, + }, + } + + order, err := orders.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + orderID, err := ParseID(order.OrderRef) + if err != nil { + return nil, err + } + + err = WaitForOrder(client, orderID) + th.AssertNoErr(t, err) + + order, err = orders.Get(client, orderID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, order) + tools.PrintResource(t, order.Meta.Expiration) + + th.AssertEquals(t, order.Meta.Name, name) + th.AssertEquals(t, order.Type, "asymmetric") + + return order, nil +} + +// CreateCertificateContainer will create a random certificate container. +// An error will be returned if the container could not be created. +func CreateCertificateContainer(t *testing.T, client *gophercloud.ServiceClient, passphrase, private, certificate *secrets.Secret) (*containers.Container, error) { + containerName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create container %s", containerName) + + createOpts := containers.CreateOpts{ + Type: containers.CertificateContainer, + Name: containerName, + SecretRefs: []containers.SecretRef{ + { + Name: "certificate", + SecretRef: certificate.SecretRef, + }, + { + Name: "private_key", + SecretRef: private.SecretRef, + }, + { + Name: "private_key_passphrase", + SecretRef: passphrase.SecretRef, + }, + }, + } + + container, err := containers.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created container: %s", container.ContainerRef) + + containerID, err := ParseID(container.ContainerRef) + if err != nil { + return nil, err + } + + container, err = containers.Get(client, containerID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, container) + + th.AssertEquals(t, container.Name, containerName) + th.AssertEquals(t, container.Type, "certificate") + + return container, nil +} + +// CreateKeyOrder will create a random key order. +// An error will be returned if the order could not be created. +func CreateKeyOrder(t *testing.T, client *gophercloud.ServiceClient) (*orders.Order, error) { + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create order %s", name) + + expiration := time.Date(2049, 1, 1, 1, 1, 1, 0, time.UTC) + createOpts := orders.CreateOpts{ + Type: orders.KeyOrder, + Meta: orders.MetaOpts{ + Name: name, + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Expiration: &expiration, + }, + } + + order, err := orders.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + orderID, err := ParseID(order.OrderRef) + if err != nil { + return nil, err + } + + order, err = orders.Get(client, orderID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, order) + tools.PrintResource(t, order.Meta.Expiration) + + th.AssertEquals(t, order.Meta.Name, name) + th.AssertEquals(t, order.Type, "key") + + return order, nil +} + +// CreateRSAContainer will create a random RSA container. +// An error will be returned if the container could not be created. +func CreateRSAContainer(t *testing.T, client *gophercloud.ServiceClient, passphrase, private, public *secrets.Secret) (*containers.Container, error) { + containerName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create container %s", containerName) + + createOpts := containers.CreateOpts{ + Type: containers.RSAContainer, + Name: containerName, + SecretRefs: []containers.SecretRef{ + { + Name: "public_key", + SecretRef: public.SecretRef, + }, + { + Name: "private_key", + SecretRef: private.SecretRef, + }, + { + Name: "private_key_passphrase", + SecretRef: passphrase.SecretRef, + }, + }, + } + + container, err := containers.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created container: %s", container.ContainerRef) + + containerID, err := ParseID(container.ContainerRef) + if err != nil { + return nil, err + } + + container, err = containers.Get(client, containerID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, container) + + th.AssertEquals(t, container.Name, containerName) + th.AssertEquals(t, container.Type, "rsa") + + return container, nil +} + +// CreateCertificateSecret will create a random certificate secret. An error +// will be returned if the secret could not be created. +func CreateCertificateSecret(t *testing.T, client *gophercloud.ServiceClient, cert []byte) (*secrets.Secret, error) { + b64Cert := base64.StdEncoding.EncodeToString(cert) + + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create public key %s", name) + + createOpts := secrets.CreateOpts{ + Name: name, + SecretType: secrets.CertificateSecret, + Payload: b64Cert, + PayloadContentType: "application/octet-stream", + PayloadContentEncoding: "base64", + Algorithm: "rsa", + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, name) + th.AssertEquals(t, secret.Algorithm, "rsa") + + return secret, nil +} + +// CreateEmptySecret will create a random secret with no payload. An error will +// be returned if the secret could not be created. +func CreateEmptySecret(t *testing.T, client *gophercloud.ServiceClient) (*secrets.Secret, error) { + secretName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create secret %s", secretName) + + createOpts := secrets.CreateOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Name: secretName, + SecretType: secrets.OpaqueSecret, + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, secretName) + th.AssertEquals(t, secret.Algorithm, "aes") + + return secret, nil +} + +// CreateGenericContainer will create a random generic container with a +// specified secret. An error will be returned if the container could not +// be created. +func CreateGenericContainer(t *testing.T, client *gophercloud.ServiceClient, secret *secrets.Secret) (*containers.Container, error) { + containerName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create container %s", containerName) + + createOpts := containers.CreateOpts{ + Type: containers.GenericContainer, + Name: containerName, + SecretRefs: []containers.SecretRef{ + { + Name: secret.Name, + SecretRef: secret.SecretRef, + }, + }, + } + + container, err := containers.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created container: %s", container.ContainerRef) + + containerID, err := ParseID(container.ContainerRef) + if err != nil { + return nil, err + } + + container, err = containers.Get(client, containerID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, container) + + th.AssertEquals(t, container.Name, containerName) + th.AssertEquals(t, container.Type, "generic") + + return container, nil +} + +// CreatePassphraseSecret will create a random passphrase secret. +// An error will be returned if the secret could not be created. +func CreatePassphraseSecret(t *testing.T, client *gophercloud.ServiceClient, passphrase string) (*secrets.Secret, error) { + secretName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create secret %s", secretName) + + createOpts := secrets.CreateOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Name: secretName, + Payload: passphrase, + PayloadContentType: "text/plain", + SecretType: secrets.PassphraseSecret, + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, secretName) + th.AssertEquals(t, secret.Algorithm, "aes") + + return secret, nil +} + +// CreatePublicSecret will create a random public secret. An error +// will be returned if the secret could not be created. +func CreatePublicSecret(t *testing.T, client *gophercloud.ServiceClient, pub []byte) (*secrets.Secret, error) { + b64Cert := base64.StdEncoding.EncodeToString(pub) + + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create public key %s", name) + + createOpts := secrets.CreateOpts{ + Name: name, + SecretType: secrets.PublicSecret, + Payload: b64Cert, + PayloadContentType: "application/octet-stream", + PayloadContentEncoding: "base64", + Algorithm: "rsa", + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, name) + th.AssertEquals(t, secret.Algorithm, "rsa") + + return secret, nil +} + +// CreatePrivateSecret will create a random private secret. An error +// will be returned if the secret could not be created. +func CreatePrivateSecret(t *testing.T, client *gophercloud.ServiceClient, priv []byte) (*secrets.Secret, error) { + b64Cert := base64.StdEncoding.EncodeToString(priv) + + name := tools.RandomString("TESTACC-", 8) + t.Logf("Attempting to create public key %s", name) + + createOpts := secrets.CreateOpts{ + Name: name, + SecretType: secrets.PrivateSecret, + Payload: b64Cert, + PayloadContentType: "application/octet-stream", + PayloadContentEncoding: "base64", + Algorithm: "rsa", + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, name) + th.AssertEquals(t, secret.Algorithm, "rsa") + + return secret, nil +} + +// CreateSecretWithPayload will create a random secret with a given payload. +// An error will be returned if the secret could not be created. +func CreateSecretWithPayload(t *testing.T, client *gophercloud.ServiceClient, payload string) (*secrets.Secret, error) { + secretName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create secret %s", secretName) + + createOpts := secrets.CreateOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Name: secretName, + Payload: payload, + PayloadContentType: "text/plain", + SecretType: secrets.OpaqueSecret, + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, secretName) + th.AssertEquals(t, secret.Algorithm, "aes") + + return secret, nil +} + +// CreateSymmetricSecret will create a random symmetric secret. An error +// will be returned if the secret could not be created. +func CreateSymmetricSecret(t *testing.T, client *gophercloud.ServiceClient) (*secrets.Secret, error) { + name := tools.RandomString("TESTACC-", 8) + key := tools.RandomString("", 256) + b64Key := base64.StdEncoding.EncodeToString([]byte(key)) + + t.Logf("Attempting to create symmetric key %s", name) + + createOpts := secrets.CreateOpts{ + Name: name, + SecretType: secrets.SymmetricSecret, + Payload: b64Key, + PayloadContentType: "application/octet-stream", + PayloadContentEncoding: "base64", + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + return nil, err + } + + t.Logf("Successfully created secret: %s", secret.SecretRef) + + secretID, err := ParseID(secret.SecretRef) + if err != nil { + return nil, err + } + + secret, err = secrets.Get(client, secretID).Extract() + if err != nil { + return nil, err + } + + tools.PrintResource(t, secret) + + th.AssertEquals(t, secret.Name, name) + th.AssertEquals(t, secret.Algorithm, "aes") + + return secret, nil +} + +// DeleteContainer will delete a container. A fatal error will occur if the +// container could not be deleted. This works best when used as a deferred +// function. +func DeleteContainer(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete container %s", id) + + err := containers.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Could not delete container: %s", err) + } + + t.Logf("Successfully deleted container %s", id) +} + +// DeleteOrder will delete an order. A fatal error will occur if the +// order could not be deleted. This works best when used as a deferred +// function. +func DeleteOrder(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete order %s", id) + + err := orders.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Could not delete order: %s", err) + } + + t.Logf("Successfully deleted order %s", id) +} + +// DeleteSecret will delete a secret. A fatal error will occur if the secret +// could not be deleted. This works best when used as a deferred function. +func DeleteSecret(t *testing.T, client *gophercloud.ServiceClient, id string) { + t.Logf("Attempting to delete secret %s", id) + + err := secrets.Delete(client, id).ExtractErr() + if err != nil { + t.Fatalf("Could not delete secret: %s", err) + } + + t.Logf("Successfully deleted secret %s", id) +} + +func ParseID(ref string) (string, error) { + parts := strings.Split(ref, "/") + if len(parts) < 2 { + return "", fmt.Errorf("Could not parse %s", ref) + } + + return parts[len(parts)-1], nil +} + +// CreateCertificate will create a random certificate. A fatal error will +// be returned if creation failed. +// https://golang.org/src/crypto/tls/generate_cert.go +func CreateCertificate(t *testing.T, passphrase string) ([]byte, []byte, error) { + key, err := rsa.GenerateKey(rand.Reader, 2048) + if err != nil { + return nil, nil, err + } + + block := &pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: x509.MarshalPKCS1PrivateKey(key), + } + + if passphrase != "" { + block, err = x509.EncryptPEMBlock(rand.Reader, block.Type, block.Bytes, []byte(passphrase), x509.PEMCipherAES256) + if err != nil { + return nil, nil, err + } + } + + keyPem := pem.EncodeToMemory(block) + + serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) + serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) + if err != nil { + return nil, nil, err + } + + tpl := x509.Certificate{ + SerialNumber: serialNumber, + Subject: pkix.Name{ + Organization: []string{"Some Org"}, + }, + NotBefore: time.Now(), + NotAfter: time.Now().AddDate(5, 0, 0), + BasicConstraintsValid: true, + } + + cert, err := x509.CreateCertificate(rand.Reader, &tpl, &tpl, &key.PublicKey, key) + if err != nil { + return nil, nil, err + } + + certPem := pem.EncodeToMemory(&pem.Block{ + Type: "CERTIFICATE", + Bytes: cert, + }) + + return keyPem, certPem, nil +} + +// CreateRSAKeyPair will create a random RSA key pair. An error will be +// returned if the pair could not be created. +func CreateRSAKeyPair(t *testing.T, passphrase string) ([]byte, []byte, error) { + key, err := rsa.GenerateKey(rand.Reader, 2048) + if err != nil { + return nil, nil, err + } + + block := &pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: x509.MarshalPKCS1PrivateKey(key), + } + + if passphrase != "" { + block, err = x509.EncryptPEMBlock(rand.Reader, block.Type, block.Bytes, []byte(passphrase), x509.PEMCipherAES256) + if err != nil { + return nil, nil, err + } + } + + keyPem := pem.EncodeToMemory(block) + + asn1Bytes, err := asn1.Marshal(key.PublicKey) + if err != nil { + return nil, nil, err + } + + block = &pem.Block{ + Type: "RSA PUBLIC KEY", + Bytes: asn1Bytes, + } + + pubPem := pem.EncodeToMemory(block) + + return keyPem, pubPem, nil +} + +func WaitForOrder(client *gophercloud.ServiceClient, orderID string) error { + return tools.WaitFor(func() (bool, error) { + order, err := orders.Get(client, orderID).Extract() + if err != nil { + return false, err + } + + if order.SecretRef != "" { + return true, nil + } + + if order.ContainerRef != "" { + return true, nil + } + + if order.Status == "ERROR" { + return false, fmt.Errorf("Order %s in ERROR state", orderID) + } + + return false, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/orders_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/orders_test.go new file mode 100644 index 00000000..de44debe --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/orders_test.go @@ -0,0 +1,84 @@ +// +build acceptance keymanager orders + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestOrdersCRUD(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + order, err := CreateKeyOrder(t, client) + th.AssertNoErr(t, err) + orderID, err := ParseID(order.OrderRef) + th.AssertNoErr(t, err) + defer DeleteOrder(t, client, orderID) + + secretID, err := ParseID(order.SecretRef) + th.AssertNoErr(t, err) + + payloadOpts := secrets.GetPayloadOpts{ + PayloadContentType: "application/octet-stream", + } + payload, err := secrets.GetPayload(client, secretID, payloadOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, payload) + + allPages, err := orders.List(client, nil).AllPages() + th.AssertNoErr(t, err) + + allOrders, err := orders.ExtractOrders(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allOrders { + if v.OrderRef == order.OrderRef { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestOrdersAsymmetric(t *testing.T) { + clients.RequireAdmin(t) + + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + order, err := CreateAsymmetricOrder(t, client) + th.AssertNoErr(t, err) + orderID, err := ParseID(order.OrderRef) + th.AssertNoErr(t, err) + defer DeleteOrder(t, client, orderID) + + containerID, err := ParseID(order.ContainerRef) + th.AssertNoErr(t, err) + + container, err := containers.Get(client, containerID).Extract() + th.AssertNoErr(t, err) + + for _, v := range container.SecretRefs { + secretID, err := ParseID(v.SecretRef) + th.AssertNoErr(t, err) + + payloadOpts := secrets.GetPayloadOpts{ + PayloadContentType: "application/octet-stream", + } + + payload, err := secrets.GetPayload(client, secretID, payloadOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/secrets_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/secrets_test.go new file mode 100644 index 00000000..dd00e569 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/keymanager/v1/secrets_test.go @@ -0,0 +1,242 @@ +// +build acceptance keymanager secrets + +package v1 + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestSecretsCRUD(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + payload := tools.RandomString("SUPERSECRET-", 8) + secret, err := CreateSecretWithPayload(t, client, payload) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + // Test payload retrieval + actual, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, payload, string(actual)) + + // Test listing secrets + createdQuery := &secrets.DateQuery{ + Date: time.Date(2049, 6, 7, 1, 2, 3, 0, time.UTC), + Filter: secrets.DateFilterLT, + } + + listOpts := secrets.ListOpts{ + CreatedQuery: createdQuery, + } + + allPages, err := secrets.List(client, listOpts).AllPages() + th.AssertNoErr(t, err) + + allSecrets, err := secrets.ExtractSecrets(allPages) + th.AssertNoErr(t, err) + + var found bool + for _, v := range allSecrets { + if v.SecretRef == secret.SecretRef { + found = true + } + } + + th.AssertEquals(t, found, true) +} + +func TestSecretsDelayedPayload(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + secret, err := CreateEmptySecret(t, client) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload := tools.RandomString("SUPERSECRET-", 8) + updateOpts := secrets.UpdateOpts{ + ContentType: "text/plain", + Payload: payload, + } + + err = secrets.Update(client, secretID, updateOpts).ExtractErr() + th.AssertNoErr(t, err) + + // Test payload retrieval + actual, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, payload, string(actual)) +} + +func TestSecretsMetadataCRUD(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + payload := tools.RandomString("SUPERSECRET-", 8) + secret, err := CreateSecretWithPayload(t, client, payload) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + // Create some metadata + createOpts := secrets.MetadataOpts{ + "foo": "bar", + "something": "something else", + } + + ref, err := secrets.CreateMetadata(client, secretID, createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ref["metadata_ref"], secret.SecretRef+"/metadata") + + // Get the metadata + metadata, err := secrets.GetMetadata(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, metadata) + th.AssertEquals(t, metadata["foo"], "bar") + th.AssertEquals(t, metadata["something"], "something else") + + // Add a single metadatum + metadatumOpts := secrets.MetadatumOpts{ + Key: "bar", + Value: "baz", + } + + err = secrets.CreateMetadatum(client, secretID, metadatumOpts).ExtractErr() + th.AssertNoErr(t, err) + + metadata, err = secrets.GetMetadata(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, metadata) + th.AssertEquals(t, len(metadata), 3) + th.AssertEquals(t, metadata["foo"], "bar") + th.AssertEquals(t, metadata["something"], "something else") + th.AssertEquals(t, metadata["bar"], "baz") + + // Update a metadatum + metadatumOpts.Key = "foo" + metadatumOpts.Value = "foo" + + metadatum, err := secrets.UpdateMetadatum(client, secretID, metadatumOpts).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, metadatum) + th.AssertDeepEquals(t, metadatum.Key, "foo") + th.AssertDeepEquals(t, metadatum.Value, "foo") + + metadata, err = secrets.GetMetadata(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, metadata) + th.AssertEquals(t, len(metadata), 3) + th.AssertEquals(t, metadata["foo"], "foo") + th.AssertEquals(t, metadata["something"], "something else") + th.AssertEquals(t, metadata["bar"], "baz") + + // Delete a metadatum + err = secrets.DeleteMetadatum(client, secretID, "foo").ExtractErr() + th.AssertNoErr(t, err) + + metadata, err = secrets.GetMetadata(client, secretID).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, metadata) + th.AssertEquals(t, len(metadata), 2) + th.AssertEquals(t, metadata["something"], "something else") + th.AssertEquals(t, metadata["bar"], "baz") +} + +func TestSymmetricSecret(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + secret, err := CreateSymmetricSecret(t, client) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) +} + +func TestCertificateSecret(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + pass := tools.RandomString("", 16) + cert, _, err := CreateCertificate(t, pass) + th.AssertNoErr(t, err) + + secret, err := CreateCertificateSecret(t, client, cert) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) +} + +func TestPrivateSecret(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + pass := tools.RandomString("", 16) + priv, _, err := CreateCertificate(t, pass) + th.AssertNoErr(t, err) + + secret, err := CreatePrivateSecret(t, client, priv) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) +} + +func TestPublicSecret(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + _, pub, err := CreateRSAKeyPair(t, "") + th.AssertNoErr(t, err) + + secret, err := CreatePublicSecret(t, client, pub) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) +} + +func TestPassphraseSecret(t *testing.T) { + client, err := clients.NewKeyManagerV1Client() + th.AssertNoErr(t, err) + + pass := tools.RandomString("", 16) + secret, err := CreatePassphraseSecret(t, client, pass) + th.AssertNoErr(t, err) + secretID, err := ParseID(secret.SecretRef) + th.AssertNoErr(t, err) + defer DeleteSecret(t, client, secretID) + + payload, err := secrets.GetPayload(client, secretID, nil).Extract() + th.AssertNoErr(t, err) + tools.PrintResource(t, string(payload)) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/l7policies_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/l7policies_test.go new file mode 100644 index 00000000..d6f09258 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/l7policies_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking loadbalancer l7policies + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" +) + +func TestL7PoliciesList(t *testing.T) { + client, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + allPages, err := l7policies.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list l7policies: %v", err) + } + + allL7Policies, err := l7policies.ExtractL7Policies(allPages) + if err != nil { + t.Fatalf("Unable to extract l7policies: %v", err) + } + + for _, policy := range allL7Policies { + tools.PrintResource(t, policy) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/listeners_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/listeners_test.go new file mode 100644 index 00000000..f6436765 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/listeners_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking loadbalancer listeners + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" +) + +func TestListenersList(t *testing.T) { + client, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + allPages, err := listeners.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list listeners: %v", err) + } + + allListeners, err := listeners.ExtractListeners(allPages) + if err != nil { + t.Fatalf("Unable to extract listeners: %v", err) + } + + for _, listener := range allListeners { + tools.PrintResource(t, listener) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancer.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancer.go new file mode 100644 index 00000000..c15dd068 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancer.go @@ -0,0 +1,397 @@ +package v2 + +import ( + "fmt" + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" +) + +const loadbalancerActiveTimeoutSeconds = 300 +const loadbalancerDeleteTimeoutSeconds = 300 + +// CreateListener will create a listener for a given load balancer on a random +// port with a random name. An error will be returned if the listener could not +// be created. +func CreateListener(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*listeners.Listener, error) { + listenerName := tools.RandomString("TESTACCT-", 8) + listenerPort := tools.RandomInt(1, 100) + + t.Logf("Attempting to create listener %s on port %d", listenerName, listenerPort) + + createOpts := listeners.CreateOpts{ + Name: listenerName, + LoadbalancerID: lb.ID, + Protocol: "TCP", + ProtocolPort: listenerPort, + } + + listener, err := listeners.Create(client, createOpts).Extract() + if err != nil { + return listener, err + } + + t.Logf("Successfully created listener %s", listenerName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return listener, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return listener, nil +} + +// CreateLoadBalancer will create a load balancer with a random name on a given +// subnet. An error will be returned if the loadbalancer could not be created. +func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetID string) (*loadbalancers.LoadBalancer, error) { + lbName := tools.RandomString("TESTACCT-", 8) + + t.Logf("Attempting to create loadbalancer %s on subnet %s", lbName, subnetID) + + createOpts := loadbalancers.CreateOpts{ + Name: lbName, + VipSubnetID: subnetID, + AdminStateUp: gophercloud.Enabled, + } + + lb, err := loadbalancers.Create(client, createOpts).Extract() + if err != nil { + return lb, err + } + + t.Logf("Successfully created loadbalancer %s on subnet %s", lbName, subnetID) + t.Logf("Waiting for loadbalancer %s to become active", lbName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return lb, err + } + + t.Logf("LoadBalancer %s is active", lbName) + + return lb, nil +} + +// CreateMember will create a member with a random name, port, address, and +// weight. An error will be returned if the member could not be created. +func CreateMember(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool, subnetID, subnetCIDR string) (*pools.Member, error) { + memberName := tools.RandomString("TESTACCT-", 8) + memberPort := tools.RandomInt(100, 1000) + memberWeight := tools.RandomInt(1, 10) + + cidrParts := strings.Split(subnetCIDR, "/") + subnetParts := strings.Split(cidrParts[0], ".") + memberAddress := fmt.Sprintf("%s.%s.%s.%d", subnetParts[0], subnetParts[1], subnetParts[2], tools.RandomInt(10, 100)) + + t.Logf("Attempting to create member %s", memberName) + + createOpts := pools.CreateMemberOpts{ + Name: memberName, + ProtocolPort: memberPort, + Weight: memberWeight, + Address: memberAddress, + SubnetID: subnetID, + } + + t.Logf("Member create opts: %#v", createOpts) + + member, err := pools.CreateMember(client, pool.ID, createOpts).Extract() + if err != nil { + return member, err + } + + t.Logf("Successfully created member %s", memberName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return member, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return member, nil +} + +// CreateMonitor will create a monitor with a random name for a specific pool. +// An error will be returned if the monitor could not be created. +func CreateMonitor(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool) (*monitors.Monitor, error) { + monitorName := tools.RandomString("TESTACCT-", 8) + + t.Logf("Attempting to create monitor %s", monitorName) + + createOpts := monitors.CreateOpts{ + PoolID: pool.ID, + Name: monitorName, + Delay: 10, + Timeout: 5, + MaxRetries: 5, + Type: "PING", + } + + monitor, err := monitors.Create(client, createOpts).Extract() + if err != nil { + return monitor, err + } + + t.Logf("Successfully created monitor: %s", monitorName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return monitor, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return monitor, nil +} + +// CreatePool will create a pool with a random name with a specified listener +// and loadbalancer. An error will be returned if the pool could not be +// created. +func CreatePool(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*pools.Pool, error) { + poolName := tools.RandomString("TESTACCT-", 8) + + t.Logf("Attempting to create pool %s", poolName) + + createOpts := pools.CreateOpts{ + Name: poolName, + Protocol: pools.ProtocolTCP, + LoadbalancerID: lb.ID, + LBMethod: pools.LBMethodLeastConnections, + } + + pool, err := pools.Create(client, createOpts).Extract() + if err != nil { + return pool, err + } + + t.Logf("Successfully created pool %s", poolName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return pool, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return pool, nil +} + +// CreateL7Policy will create a l7 policy with a random name with a specified listener +// and loadbalancer. An error will be returned if the l7 policy could not be +// created. +func CreateL7Policy(t *testing.T, client *gophercloud.ServiceClient, listener *listeners.Listener, lb *loadbalancers.LoadBalancer) (*l7policies.L7Policy, error) { + policyName := tools.RandomString("TESTACCT-", 8) + + t.Logf("Attempting to create l7 policy %s", policyName) + + createOpts := l7policies.CreateOpts{ + Name: policyName, + ListenerID: listener.ID, + Action: l7policies.ActionRedirectToURL, + RedirectURL: "http://www.example.com", + } + + policy, err := l7policies.Create(client, createOpts).Extract() + if err != nil { + return policy, err + } + + t.Logf("Successfully created l7 policy %s", policyName) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return policy, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return policy, nil +} + +// CreateL7Rule creates a l7 rule for specified l7 policy. +func CreateL7Rule(t *testing.T, client *gophercloud.ServiceClient, policyID string, lb *loadbalancers.LoadBalancer) (*l7policies.Rule, error) { + t.Logf("Attempting to create l7 rule for policy %s", policyID) + + createOpts := l7policies.CreateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeStartWith, + Value: "/api", + } + + rule, err := l7policies.CreateRule(client, policyID, createOpts).Extract() + if err != nil { + return rule, err + } + + t.Logf("Successfully created l7 rule for policy %s", policyID) + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + return rule, fmt.Errorf("Timed out waiting for loadbalancer to become active") + } + + return rule, nil +} + +// DeleteL7Policy will delete a specified l7 policy. A fatal error will occur if +// the l7 policy could not be deleted. This works best when used as a deferred +// function. +func DeleteL7Policy(t *testing.T, client *gophercloud.ServiceClient, lbID, policyID string) { + t.Logf("Attempting to delete l7 policy %s", policyID) + + if err := l7policies.Delete(client, policyID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete l7 policy: %v", err) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted l7 policy %s", policyID) +} + +// DeleteL7Rule will delete a specified l7 rule. A fatal error will occur if +// the l7 rule could not be deleted. This works best when used as a deferred +// function. +func DeleteL7Rule(t *testing.T, client *gophercloud.ServiceClient, lbID, policyID, ruleID string) { + t.Logf("Attempting to delete l7 rule %s", ruleID) + + if err := l7policies.DeleteRule(client, policyID, ruleID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete l7 rule: %v", err) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted l7 rule %s", ruleID) +} + +// DeleteListener will delete a specified listener. A fatal error will occur if +// the listener could not be deleted. This works best when used as a deferred +// function. +func DeleteListener(t *testing.T, client *gophercloud.ServiceClient, lbID, listenerID string) { + t.Logf("Attempting to delete listener %s", listenerID) + + if err := listeners.Delete(client, listenerID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete listener: %v", err) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted listener %s", listenerID) +} + +// DeleteMember will delete a specified member. A fatal error will occur if the +// member could not be deleted. This works best when used as a deferred +// function. +func DeleteMember(t *testing.T, client *gophercloud.ServiceClient, lbID, poolID, memberID string) { + t.Logf("Attempting to delete member %s", memberID) + + if err := pools.DeleteMember(client, poolID, memberID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete member: %s", memberID) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted member %s", memberID) +} + +// DeleteLoadBalancer will delete a specified loadbalancer. A fatal error will +// occur if the loadbalancer could not be deleted. This works best when used +// as a deferred function. +func DeleteLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, lbID string) { + t.Logf("Attempting to delete loadbalancer %s", lbID) + + deleteOpts := loadbalancers.DeleteOpts{ + Cascade: false, + } + + if err := loadbalancers.Delete(client, lbID, deleteOpts).ExtractErr(); err != nil { + t.Fatalf("Unable to delete loadbalancer: %v", err) + } + + t.Logf("Waiting for loadbalancer %s to delete", lbID) + + if err := WaitForLoadBalancerState(client, lbID, "DELETED", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Loadbalancer did not delete in time.") + } + + t.Logf("Successfully deleted loadbalancer %s", lbID) +} + +// CascadeDeleteLoadBalancer will perform a cascading delete on a loadbalancer. +// A fatal error will occur if the loadbalancer could not be deleted. This works +// best when used as a deferred function. +func CascadeDeleteLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, lbID string) { + t.Logf("Attempting to cascade delete loadbalancer %s", lbID) + + deleteOpts := loadbalancers.DeleteOpts{ + Cascade: true, + } + + if err := loadbalancers.Delete(client, lbID, deleteOpts).ExtractErr(); err != nil { + t.Fatalf("Unable to cascade delete loadbalancer: %v", err) + } + + t.Logf("Waiting for loadbalancer %s to cascade delete", lbID) + + if err := WaitForLoadBalancerState(client, lbID, "DELETED", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Loadbalancer did not delete in time.") + } + + t.Logf("Successfully deleted loadbalancer %s", lbID) +} + +// DeleteMonitor will delete a specified monitor. A fatal error will occur if +// the monitor could not be deleted. This works best when used as a deferred +// function. +func DeleteMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID, monitorID string) { + t.Logf("Attempting to delete monitor %s", monitorID) + + if err := monitors.Delete(client, monitorID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete monitor: %v", err) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted monitor %s", monitorID) +} + +// DeletePool will delete a specified pool. A fatal error will occur if the +// pool could not be deleted. This works best when used as a deferred function. +func DeletePool(t *testing.T, client *gophercloud.ServiceClient, lbID, poolID string) { + t.Logf("Attempting to delete pool %s", poolID) + + if err := pools.Delete(client, poolID).ExtractErr(); err != nil { + t.Fatalf("Unable to delete pool: %v", err) + } + + if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + t.Logf("Successfully deleted pool %s", poolID) +} + +// WaitForLoadBalancerState will wait until a loadbalancer reaches a given state. +func WaitForLoadBalancerState(client *gophercloud.ServiceClient, lbID, status string, secs int) error { + return gophercloud.WaitFor(secs, func() (bool, error) { + current, err := loadbalancers.Get(client, lbID).Extract() + if err != nil { + if httpStatus, ok := err.(gophercloud.ErrDefault404); ok { + if httpStatus.Actual == 404 { + if status == "DELETED" { + return true, nil + } + } + } + return false, err + } + + if current.ProvisioningStatus == status { + return true, nil + } + + return false, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go new file mode 100644 index 00000000..6fd0f5f0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go @@ -0,0 +1,394 @@ +// +build acceptance networking loadbalancer loadbalancers + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" +) + +func TestLoadbalancersList(t *testing.T) { + client, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + allPages, err := loadbalancers.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list loadbalancers: %v", err) + } + + allLoadbalancers, err := loadbalancers.ExtractLoadBalancers(allPages) + if err != nil { + t.Fatalf("Unable to extract loadbalancers: %v", err) + } + + for _, lb := range allLoadbalancers { + tools.PrintResource(t, lb) + } +} + +func TestLoadbalancersCRUD(t *testing.T) { + netClient, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a networking client: %v", err) + } + + lbClient, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + network, err := networking.CreateNetwork(t, netClient) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, netClient, network.ID) + + subnet, err := networking.CreateSubnet(t, netClient, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, netClient, subnet.ID) + + lb, err := CreateLoadBalancer(t, lbClient, subnet.ID) + if err != nil { + t.Fatalf("Unable to create loadbalancer: %v", err) + } + defer DeleteLoadBalancer(t, lbClient, lb.ID) + + newLB, err := loadbalancers.Get(lbClient, lb.ID).Extract() + if err != nil { + t.Fatalf("Unable to get loadbalancer: %v", err) + } + + tools.PrintResource(t, newLB) + + // Because of the time it takes to create a loadbalancer, + // this test will include some other resources. + + // Listener + listener, err := CreateListener(t, lbClient, lb) + if err != nil { + t.Fatalf("Unable to create listener: %v", err) + } + defer DeleteListener(t, lbClient, lb.ID, listener.ID) + + updateListenerOpts := listeners.UpdateOpts{ + Description: "Some listener description", + } + _, err = listeners.Update(lbClient, listener.ID, updateListenerOpts).Extract() + if err != nil { + t.Fatalf("Unable to update listener") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newListener, err := listeners.Get(lbClient, listener.ID).Extract() + if err != nil { + t.Fatalf("Unable to get listener") + } + + tools.PrintResource(t, newListener) + + // L7 policy + policy, err := CreateL7Policy(t, lbClient, listener, lb) + if err != nil { + t.Fatalf("Unable to create l7 policy: %v", err) + } + defer DeleteL7Policy(t, lbClient, lb.ID, policy.ID) + + newDescription := "New l7 policy description" + updateL7policyOpts := l7policies.UpdateOpts{ + Description: &newDescription, + } + _, err = l7policies.Update(lbClient, policy.ID, updateL7policyOpts).Extract() + if err != nil { + t.Fatalf("Unable to update l7 policy") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newPolicy, err := l7policies.Get(lbClient, policy.ID).Extract() + if err != nil { + t.Fatalf("Unable to get l7 policy: %v", err) + } + + tools.PrintResource(t, newPolicy) + + // L7 rule + rule, err := CreateL7Rule(t, lbClient, newPolicy.ID, lb) + if err != nil { + t.Fatalf("Unable to create l7 rule: %v", err) + } + defer DeleteL7Rule(t, lbClient, lb.ID, policy.ID, rule.ID) + + allPages, err := l7policies.ListRules(lbClient, policy.ID, l7policies.ListRulesOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to get l7 rules: %v", err) + } + allRules, err := l7policies.ExtractRules(allPages) + if err != nil { + t.Fatalf("Unable to extract l7 rules: %v", err) + } + for _, rule := range allRules { + tools.PrintResource(t, rule) + } + + updateL7ruleOpts := l7policies.UpdateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeRegex, + Value: "/images/special*", + } + _, err = l7policies.UpdateRule(lbClient, policy.ID, rule.ID, updateL7ruleOpts).Extract() + if err != nil { + t.Fatalf("Unable to update l7 rule: %v", err) + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newRule, err := l7policies.GetRule(lbClient, newPolicy.ID, rule.ID).Extract() + if err != nil { + t.Fatalf("Unable to get l7 rule: %v", err) + } + + tools.PrintResource(t, newRule) + + // Pool + pool, err := CreatePool(t, lbClient, lb) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, lbClient, lb.ID, pool.ID) + + updatePoolOpts := pools.UpdateOpts{ + Description: "Some pool description", + } + _, err = pools.Update(lbClient, pool.ID, updatePoolOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newPool, err := pools.Get(lbClient, pool.ID).Extract() + if err != nil { + t.Fatalf("Unable to get pool") + } + + tools.PrintResource(t, newPool) + + // Member + member, err := CreateMember(t, lbClient, lb, newPool, subnet.ID, subnet.CIDR) + if err != nil { + t.Fatalf("Unable to create member: %v", err) + } + defer DeleteMember(t, lbClient, lb.ID, pool.ID, member.ID) + + newWeight := tools.RandomInt(11, 100) + updateMemberOpts := pools.UpdateMemberOpts{ + Weight: newWeight, + } + _, err = pools.UpdateMember(lbClient, pool.ID, member.ID, updateMemberOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMember, err := pools.GetMember(lbClient, pool.ID, member.ID).Extract() + if err != nil { + t.Fatalf("Unable to get member") + } + + tools.PrintResource(t, newMember) + + // Monitor + monitor, err := CreateMonitor(t, lbClient, lb, newPool) + if err != nil { + t.Fatalf("Unable to create monitor: %v", err) + } + defer DeleteMonitor(t, lbClient, lb.ID, monitor.ID) + + newDelay := tools.RandomInt(20, 30) + updateMonitorOpts := monitors.UpdateOpts{ + Delay: newDelay, + } + _, err = monitors.Update(lbClient, monitor.ID, updateMonitorOpts).Extract() + if err != nil { + t.Fatalf("Unable to update monitor") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMonitor, err := monitors.Get(lbClient, monitor.ID).Extract() + if err != nil { + t.Fatalf("Unable to get monitor") + } + + tools.PrintResource(t, newMonitor) + +} + +func TestLoadbalancersCascadeCRUD(t *testing.T) { + netClient, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a networking client: %v", err) + } + + lbClient, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + network, err := networking.CreateNetwork(t, netClient) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, netClient, network.ID) + + subnet, err := networking.CreateSubnet(t, netClient, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, netClient, subnet.ID) + + lb, err := CreateLoadBalancer(t, lbClient, subnet.ID) + if err != nil { + t.Fatalf("Unable to create loadbalancer: %v", err) + } + defer CascadeDeleteLoadBalancer(t, lbClient, lb.ID) + + newLB, err := loadbalancers.Get(lbClient, lb.ID).Extract() + if err != nil { + t.Fatalf("Unable to get loadbalancer: %v", err) + } + + tools.PrintResource(t, newLB) + + // Because of the time it takes to create a loadbalancer, + // this test will include some other resources. + + // Listener + listener, err := CreateListener(t, lbClient, lb) + if err != nil { + t.Fatalf("Unable to create listener: %v", err) + } + + updateListenerOpts := listeners.UpdateOpts{ + Description: "Some listener description", + } + _, err = listeners.Update(lbClient, listener.ID, updateListenerOpts).Extract() + if err != nil { + t.Fatalf("Unable to update listener") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newListener, err := listeners.Get(lbClient, listener.ID).Extract() + if err != nil { + t.Fatalf("Unable to get listener") + } + + tools.PrintResource(t, newListener) + + // Pool + pool, err := CreatePool(t, lbClient, lb) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + + updatePoolOpts := pools.UpdateOpts{ + Description: "Some pool description", + } + _, err = pools.Update(lbClient, pool.ID, updatePoolOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newPool, err := pools.Get(lbClient, pool.ID).Extract() + if err != nil { + t.Fatalf("Unable to get pool") + } + + tools.PrintResource(t, newPool) + + // Member + member, err := CreateMember(t, lbClient, lb, newPool, subnet.ID, subnet.CIDR) + if err != nil { + t.Fatalf("Unable to create member: %v", err) + } + + newWeight := tools.RandomInt(11, 100) + updateMemberOpts := pools.UpdateMemberOpts{ + Weight: newWeight, + } + _, err = pools.UpdateMember(lbClient, pool.ID, member.ID, updateMemberOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMember, err := pools.GetMember(lbClient, pool.ID, member.ID).Extract() + if err != nil { + t.Fatalf("Unable to get member") + } + + tools.PrintResource(t, newMember) + + // Monitor + monitor, err := CreateMonitor(t, lbClient, lb, newPool) + if err != nil { + t.Fatalf("Unable to create monitor: %v", err) + } + + newDelay := tools.RandomInt(20, 30) + updateMonitorOpts := monitors.UpdateOpts{ + Delay: newDelay, + } + _, err = monitors.Update(lbClient, monitor.ID, updateMonitorOpts).Extract() + if err != nil { + t.Fatalf("Unable to update monitor") + } + + if err := WaitForLoadBalancerState(lbClient, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMonitor, err := monitors.Get(lbClient, monitor.ID).Extract() + if err != nil { + t.Fatalf("Unable to get monitor") + } + + tools.PrintResource(t, newMonitor) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/monitors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/monitors_test.go new file mode 100644 index 00000000..93688fdb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/monitors_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking loadbalancer monitors + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" +) + +func TestMonitorsList(t *testing.T) { + client, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + allPages, err := monitors.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list monitors: %v", err) + } + + allMonitors, err := monitors.ExtractMonitors(allPages) + if err != nil { + t.Fatalf("Unable to extract monitors: %v", err) + } + + for _, monitor := range allMonitors { + tools.PrintResource(t, monitor) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pkg.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pkg.go new file mode 100644 index 00000000..5ec3cc8e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pkg.go @@ -0,0 +1 @@ +package v2 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pools_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pools_test.go new file mode 100644 index 00000000..f7ec2a4a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/loadbalancer/v2/pools_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking loadbalancer pools + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" +) + +func TestPoolsList(t *testing.T) { + client, err := clients.NewLoadBalancerV2Client() + if err != nil { + t.Fatalf("Unable to create a loadbalancer client: %v", err) + } + + allPages, err := pools.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list pools: %v", err) + } + + allPools, err := pools.ExtractPools(allPages) + if err != nil { + t.Fatalf("Unable to extract pools: %v", err) + } + + for _, pool := range allPools { + tools.PrintResource(t, pool) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/claims_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/claims_test.go new file mode 100644 index 00000000..4ffb9229 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/claims_test.go @@ -0,0 +1,63 @@ +// +build acceptance messaging claims + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/claims" +) + +func TestCRUDClaim(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734c" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + + client, err = clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + for i := 0; i < 3; i++ { + CreateMessage(t, client, createdQueueName) + } + + clientID = "3381af92-2b9e-11e3-b191-7186130073dd" + claimedMessages, err := CreateClaim(t, client, createdQueueName) + claimIDs, _ := ExtractIDs(claimedMessages) + + tools.PrintResource(t, claimedMessages) + + updateOpts := claims.UpdateOpts{ + TTL: 600, + Grace: 500, + } + + for _, claimID := range claimIDs { + t.Logf("Attempting to update claim: %s", claimID) + updateErr := claims.Update(client, createdQueueName, claimID, updateOpts).ExtractErr() + + if updateErr != nil { + t.Fatalf("Unable to update claim %s: %v", claimID, err) + } else { + t.Logf("Successfully updated claim: %s", claimID) + } + + updatedClaim, getErr := GetClaim(t, client, createdQueueName, claimID) + if getErr != nil { + t.Fatalf("Unable to retrieve claim %s: %v", claimID, getErr) + } + + tools.PrintResource(t, updatedClaim) + DeleteClaim(t, client, createdQueueName, claimID) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/message_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/message_test.go new file mode 100644 index 00000000..f3c55811 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/message_test.go @@ -0,0 +1,301 @@ +// +build acceptance messaging messages + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/messages" + "github.com/gophercloud/gophercloud/pagination" +) + +func TestListMessages(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + for i := 0; i < 3; i++ { + CreateMessage(t, client, createdQueueName) + } + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + client, err = clients.NewMessagingV2Client(clientID) + + listOpts := messages.ListOpts{} + + pager := messages.List(client, createdQueueName, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := messages.ExtractMessages(page) + if err != nil { + t.Fatalf("Unable to extract messages: %v", err) + } + + for _, message := range allMessages { + tools.PrintResource(t, message) + } + + return true, nil + }) +} + +func TestCreateMessages(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734c" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + CreateMessage(t, client, createdQueueName) +} + +func TestGetMessages(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + CreateMessage(t, client, createdQueueName) + CreateMessage(t, client, createdQueueName) + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + client, err = clients.NewMessagingV2Client(clientID) + + listOpts := messages.ListOpts{} + + var messageIDs []string + + pager := messages.List(client, createdQueueName, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := messages.ExtractMessages(page) + if err != nil { + t.Fatalf("Unable to extract messages: %v", err) + } + + for _, message := range allMessages { + messageIDs = append(messageIDs, message.ID) + } + + return true, nil + }) + + getMessageOpts := messages.GetMessagesOpts{ + IDs: messageIDs, + } + t.Logf("Attempting to get messages from queue %s with ids: %v", createdQueueName, messageIDs) + messagesList, err := messages.GetMessages(client, createdQueueName, getMessageOpts).Extract() + if err != nil { + t.Fatalf("Unable to get messages from queue: %s", createdQueueName) + } + + tools.PrintResource(t, messagesList) +} + +func TestGetMessage(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + CreateMessage(t, client, createdQueueName) + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + client, err = clients.NewMessagingV2Client(clientID) + + listOpts := messages.ListOpts{} + + var messageIDs []string + + pager := messages.List(client, createdQueueName, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := messages.ExtractMessages(page) + if err != nil { + t.Fatalf("Unable to extract messages: %v", err) + } + + for _, message := range allMessages { + messageIDs = append(messageIDs, message.ID) + } + + return true, nil + }) + + for _, messageID := range messageIDs { + t.Logf("Attempting to get message from queue %s: %s", createdQueueName, messageID) + message, getErr := messages.Get(client, createdQueueName, messageID).Extract() + if getErr != nil { + t.Fatalf("Unable to get message from queue %s: %s", createdQueueName, messageID) + } + tools.PrintResource(t, message) + } +} + +func TestDeleteMessagesIDs(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + CreateMessage(t, client, createdQueueName) + CreateMessage(t, client, createdQueueName) + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + + client, err = clients.NewMessagingV2Client(clientID) + + listOpts := messages.ListOpts{} + + var messageIDs []string + + pager := messages.List(client, createdQueueName, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := messages.ExtractMessages(page) + if err != nil { + t.Fatalf("Unable to extract messages: %v", err) + } + + for _, message := range allMessages { + messageIDs = append(messageIDs, message.ID) + tools.PrintResource(t, message) + } + + return true, nil + }) + + deleteOpts := messages.DeleteMessagesOpts{ + IDs: messageIDs, + } + + t.Logf("Attempting to delete messages: %v", messageIDs) + deleteErr := messages.DeleteMessages(client, createdQueueName, deleteOpts).ExtractErr() + if deleteErr != nil { + t.Fatalf("Unable to delete messages: %v", deleteErr) + } + + t.Logf("Attempting to list messages.") + messageList, err := ListMessages(t, client, createdQueueName) + + if len(messageList) > 0 { + t.Fatalf("Did not delete all specified messages in the queue.") + } +} + +func TestDeleteMessagesPop(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + for i := 0; i < 5; i++ { + CreateMessage(t, client, createdQueueName) + } + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + + client, err = clients.NewMessagingV2Client(clientID) + + messageList, err := ListMessages(t, client, createdQueueName) + + messagesNumber := len(messageList) + popNumber := 3 + + PopOpts := messages.PopMessagesOpts{ + Pop: popNumber, + } + + t.Logf("Attempting to Pop last %v messages.", popNumber) + popMessages, deleteErr := messages.PopMessages(client, createdQueueName, PopOpts).Extract() + if deleteErr != nil { + t.Fatalf("Unable to Pop messages: %v", deleteErr) + } + + tools.PrintResource(t, popMessages) + + messageList, err = ListMessages(t, client, createdQueueName) + if len(messageList) != messagesNumber-popNumber { + t.Fatalf("Unable to Pop specified number of messages.") + } +} + +func TestDeleteMessage(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-718613007343" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + CreateMessage(t, client, createdQueueName) + + // Use a different client/clientID in order to see messages on the Queue + clientID = "3381af92-2b9e-11e3-b191-71861300734d" + client, err = clients.NewMessagingV2Client(clientID) + + listOpts := messages.ListOpts{} + + var messageIDs []string + + pager := messages.List(client, createdQueueName, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := messages.ExtractMessages(page) + if err != nil { + t.Fatalf("Unable to extract messages: %v", err) + } + + for _, message := range allMessages { + messageIDs = append(messageIDs, message.ID) + } + + return true, nil + }) + + for _, messageID := range messageIDs { + t.Logf("Attempting to delete message from queue %s: %s", createdQueueName, messageID) + deleteOpts := messages.DeleteOpts{} + deleteErr := messages.Delete(client, createdQueueName, messageID, deleteOpts).ExtractErr() + if deleteErr != nil { + t.Fatalf("Unable to delete message from queue %s: %s", createdQueueName, messageID) + } else { + t.Logf("Successfully deleted message: %s", messageID) + } + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/messaging.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/messaging.go new file mode 100644 index 00000000..f782770b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/messaging.go @@ -0,0 +1,173 @@ +package v2 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/claims" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/messages" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/queues" + "github.com/gophercloud/gophercloud/pagination" +) + +func CreateQueue(t *testing.T, client *gophercloud.ServiceClient) (string, error) { + queueName := tools.RandomString("ACPTTEST", 5) + + t.Logf("Attempting to create Queue: %s", queueName) + + createOpts := queues.CreateOpts{ + QueueName: queueName, + MaxMessagesPostSize: 262143, + DefaultMessageTTL: 3700, + DefaultMessageDelay: 25, + DeadLetterQueueMessagesTTL: 3500, + MaxClaimCount: 10, + Extra: map[string]interface{}{"description": "Test Queue for Gophercloud acceptance tests."}, + } + + createErr := queues.Create(client, createOpts).ExtractErr() + if createErr != nil { + t.Fatalf("Unable to create Queue: %v", createErr) + } + + GetQueue(t, client, queueName) + + t.Logf("Created Queue: %s", queueName) + return queueName, nil +} + +func DeleteQueue(t *testing.T, client *gophercloud.ServiceClient, queueName string) { + t.Logf("Attempting to delete Queue: %s", queueName) + err := queues.Delete(client, queueName).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete Queue %s: %v", queueName, err) + } + + t.Logf("Deleted Queue: %s", queueName) +} + +func GetQueue(t *testing.T, client *gophercloud.ServiceClient, queueName string) (queues.QueueDetails, error) { + t.Logf("Attempting to get Queue: %s", queueName) + queue, err := queues.Get(client, queueName).Extract() + if err != nil { + t.Fatalf("Unable to get Queue %s: %v", queueName, err) + } + return queue, nil +} + +func CreateShare(t *testing.T, client *gophercloud.ServiceClient, queueName string) (queues.QueueShare, error) { + t.Logf("Attempting to create share for queue: %s", queueName) + + shareOpts := queues.ShareOpts{ + Paths: []queues.SharePath{queues.PathMessages}, + Methods: []queues.ShareMethod{queues.MethodPost}, + } + + share, err := queues.Share(client, queueName, shareOpts).Extract() + + return share, err +} + +func CreateMessage(t *testing.T, client *gophercloud.ServiceClient, queueName string) (messages.ResourceList, error) { + t.Logf("Attempting to add message to Queue: %s", queueName) + createOpts := messages.BatchCreateOpts{ + messages.CreateOpts{ + TTL: 300, + Body: map[string]interface{}{"Key": tools.RandomString("ACPTTEST", 8)}, + }, + } + + resource, err := messages.Create(client, queueName, createOpts).Extract() + if err != nil { + t.Fatalf("Unable to add message to queue %s: %v", queueName, err) + } else { + t.Logf("Successfully added message to queue: %s", queueName) + } + + return resource, err +} + +func ListMessages(t *testing.T, client *gophercloud.ServiceClient, queueName string) ([]messages.Message, error) { + listOpts := messages.ListOpts{} + var allMessages []messages.Message + var listErr error + + t.Logf("Attempting to list messages on queue: %s", queueName) + pager := messages.List(client, queueName, listOpts) + err := pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, listErr = messages.ExtractMessages(page) + if listErr != nil { + t.Fatalf("Unable to extract messages: %v", listErr) + } + + for _, message := range allMessages { + tools.PrintResource(t, message) + } + + return true, nil + }) + return allMessages, err +} + +func CreateClaim(t *testing.T, client *gophercloud.ServiceClient, queueName string) ([]claims.Messages, error) { + createOpts := claims.CreateOpts{} + + t.Logf("Attempting to create claim on queue: %s", queueName) + claimedMessages, err := claims.Create(client, queueName, createOpts).Extract() + tools.PrintResource(t, claimedMessages) + if err != nil { + t.Fatalf("Unable to create claim: %v", err) + } + + return claimedMessages, err +} + +func GetClaim(t *testing.T, client *gophercloud.ServiceClient, queueName string, claimID string) (*claims.Claim, error) { + t.Logf("Attempting to get claim: %s", claimID) + claim, err := claims.Get(client, queueName, claimID).Extract() + if err != nil { + t.Fatalf("Unable to get claim: %s", claimID) + } + + return claim, err +} + +func DeleteClaim(t *testing.T, client *gophercloud.ServiceClient, queueName string, claimID string) error { + t.Logf("Attempting to delete claim: %s", claimID) + err := claims.Delete(client, queueName, claimID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete claim: %s", claimID) + } + t.Logf("Sucessfully deleted claim: %s", claimID) + + return err +} + +func ExtractIDs(claim []claims.Messages) ([]string, []string) { + var claimIDs []string + var messageID []string + + for _, msg := range claim { + parts := strings.Split(msg.Href, "?claim_id=") + if len(parts) == 2 { + pieces := strings.Split(parts[0], "/") + if len(pieces) > 0 { + messageID = append(messageID, pieces[len(pieces)-1]) + } + claimIDs = append(claimIDs, parts[1]) + } + } + encountered := map[string]bool{} + for v := range claimIDs { + encountered[claimIDs[v]] = true + } + + var uniqueClaimIDs []string + + for key := range encountered { + uniqueClaimIDs = append(uniqueClaimIDs, key) + } + return uniqueClaimIDs, messageID +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/queue_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/queue_test.go new file mode 100644 index 00000000..166f46e8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/messaging/v2/queue_test.go @@ -0,0 +1,154 @@ +// +build acceptance messaging queues + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/messaging/v2/queues" + "github.com/gophercloud/gophercloud/pagination" +) + +func TestCRUDQueues(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734d" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + createdQueue, err := queues.Get(client, createdQueueName).Extract() + + tools.PrintResource(t, createdQueue) + tools.PrintResource(t, createdQueue.Extra) + + updateOpts := queues.BatchUpdateOpts{ + queues.UpdateOpts{ + Op: "replace", + Path: "/metadata/_max_claim_count", + Value: 15, + }, + queues.UpdateOpts{ + Op: "replace", + Path: "/metadata/description", + Value: "Updated description for queues acceptance test.", + }, + } + + t.Logf("Attempting to update Queue: %s", createdQueueName) + updateResult, updateErr := queues.Update(client, createdQueueName, updateOpts).Extract() + if updateErr != nil { + t.Fatalf("Unable to update Queue %s: %v", createdQueueName, updateErr) + } + + updatedQueue, err := GetQueue(t, client, createdQueueName) + + tools.PrintResource(t, updateResult) + tools.PrintResource(t, updatedQueue) + tools.PrintResource(t, updatedQueue.Extra) +} + +func TestListQueues(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734d" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + firstQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, firstQueueName) + + secondQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, secondQueueName) + + listOpts := queues.ListOpts{ + Limit: 10, + Detailed: true, + } + + pager := queues.List(client, listOpts) + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allQueues, err := queues.ExtractQueues(page) + if err != nil { + t.Fatalf("Unable to extract Queues: %v", err) + } + + for _, queue := range allQueues { + tools.PrintResource(t, queue) + } + + return true, nil + }) +} + +func TestStatQueue(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734c" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + createdQueueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, createdQueueName) + + queueStats, err := queues.GetStats(client, createdQueueName).Extract() + if err != nil { + t.Fatalf("Unable to stat queue: %v", err) + } + + tools.PrintResource(t, queueStats) +} + +func TestShare(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734c" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + queueName, err := CreateQueue(t, client) + if err != nil { + t.Logf("Unable to create queue for share.") + } + defer DeleteQueue(t, client, queueName) + + t.Logf("Attempting to create share for queue: %s", queueName) + share, shareErr := CreateShare(t, client, queueName) + if shareErr != nil { + t.Fatalf("Unable to create share: %v", shareErr) + } + + tools.PrintResource(t, share) +} + +func TestPurge(t *testing.T) { + clientID := "3381af92-2b9e-11e3-b191-71861300734c" + + client, err := clients.NewMessagingV2Client(clientID) + if err != nil { + t.Fatalf("Unable to create a messaging service client: %v", err) + } + + queueName, err := CreateQueue(t, client) + defer DeleteQueue(t, client, queueName) + + purgeOpts := queues.PurgeOpts{ + ResourceTypes: []queues.PurgeResource{ + queues.ResourceMessages, + }, + } + + t.Logf("Attempting to purge queue: %s", queueName) + purgeErr := queues.Purge(client, queueName, purgeOpts).ExtractErr() + if purgeErr != nil { + t.Fatalf("Unable to purge queue %s: %v", queueName, purgeErr) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/apiversion_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/apiversion_test.go new file mode 100644 index 00000000..c6f8f261 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/apiversion_test.go @@ -0,0 +1,53 @@ +// +build acceptance networking + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions" +) + +func TestAPIVersionsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := apiversions.ListVersions(client).AllPages() + if err != nil { + t.Fatalf("Unable to list api versions: %v", err) + } + + allAPIVersions, err := apiversions.ExtractAPIVersions(allPages) + if err != nil { + t.Fatalf("Unable to extract api versions: %v", err) + } + + for _, apiVersion := range allAPIVersions { + tools.PrintResource(t, apiVersion) + } +} + +func TestAPIResourcesList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := apiversions.ListVersionResources(client, "v2.0").AllPages() + if err != nil { + t.Fatalf("Unable to list api version reosources: %v", err) + } + + allVersionResources, err := apiversions.ExtractVersionResources(allPages) + if err != nil { + t.Fatalf("Unable to extract version resources: %v", err) + } + + for _, versionResource := range allVersionResources { + tools.PrintResource(t, versionResource) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extension_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extension_test.go new file mode 100644 index 00000000..5609e852 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extension_test.go @@ -0,0 +1,46 @@ +// +build acceptance networking extensions + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/common/extensions" +) + +func TestExtensionsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := extensions.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to list extensions: %v", err) + } + + allExtensions, err := extensions.ExtractExtensions(allPages) + if err != nil { + t.Fatalf("Unable to extract extensions: %v", err) + } + + for _, extension := range allExtensions { + tools.PrintResource(t, extension) + } +} + +func TestExtensionGet(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + extension, err := extensions.Get(client, "router").Extract() + if err != nil { + t.Fatalf("Unable to get extension port-security: %v", err) + } + + tools.PrintResource(t, extension) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/firewall_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/firewall_test.go new file mode 100644 index 00000000..89d378ee --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/firewall_test.go @@ -0,0 +1,212 @@ +// +build acceptance networking fwaas + +package fwaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + layer3 "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion" +) + +func TestFirewallList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := firewalls.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list firewalls: %v", err) + } + + allFirewalls, err := firewalls.ExtractFirewalls(allPages) + if err != nil { + t.Fatalf("Unable to extract firewalls: %v", err) + } + + for _, firewall := range allFirewalls { + tools.PrintResource(t, firewall) + } +} + +func TestFirewallCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + router, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router.ID) + + rule, err := CreateRule(t, client) + if err != nil { + t.Fatalf("Unable to create rule: %v", err) + } + defer DeleteRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + policy, err := CreatePolicy(t, client, rule.ID) + if err != nil { + t.Fatalf("Unable to create policy: %v", err) + } + defer DeletePolicy(t, client, policy.ID) + + tools.PrintResource(t, policy) + + firewall, err := CreateFirewall(t, client, policy.ID) + if err != nil { + t.Fatalf("Unable to create firewall: %v", err) + } + defer DeleteFirewall(t, client, firewall.ID) + + tools.PrintResource(t, firewall) + + updateOpts := firewalls.UpdateOpts{ + PolicyID: policy.ID, + Description: "Some firewall description", + } + + _, err = firewalls.Update(client, firewall.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update firewall: %v", err) + } + + newFirewall, err := firewalls.Get(client, firewall.ID).Extract() + if err != nil { + t.Fatalf("Unable to get firewall: %v", err) + } + + tools.PrintResource(t, newFirewall) +} + +func TestFirewallCRUDRouter(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + router, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router.ID) + + rule, err := CreateRule(t, client) + if err != nil { + t.Fatalf("Unable to create rule: %v", err) + } + defer DeleteRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + policy, err := CreatePolicy(t, client, rule.ID) + if err != nil { + t.Fatalf("Unable to create policy: %v", err) + } + defer DeletePolicy(t, client, policy.ID) + + tools.PrintResource(t, policy) + + firewall, err := CreateFirewallOnRouter(t, client, policy.ID, router.ID) + if err != nil { + t.Fatalf("Unable to create firewall: %v", err) + } + defer DeleteFirewall(t, client, firewall.ID) + + tools.PrintResource(t, firewall) + + router2, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router2.ID) + + firewallUpdateOpts := firewalls.UpdateOpts{ + PolicyID: policy.ID, + Description: "Some firewall description", + } + + updateOpts := routerinsertion.UpdateOptsExt{ + firewallUpdateOpts, + []string{router2.ID}, + } + + _, err = firewalls.Update(client, firewall.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update firewall: %v", err) + } + + newFirewall, err := firewalls.Get(client, firewall.ID).Extract() + if err != nil { + t.Fatalf("Unable to get firewall: %v", err) + } + + tools.PrintResource(t, newFirewall) +} + +func TestFirewallCRUDRemoveRouter(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + router, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router.ID) + + rule, err := CreateRule(t, client) + if err != nil { + t.Fatalf("Unable to create rule: %v", err) + } + defer DeleteRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + policy, err := CreatePolicy(t, client, rule.ID) + if err != nil { + t.Fatalf("Unable to create policy: %v", err) + } + defer DeletePolicy(t, client, policy.ID) + + tools.PrintResource(t, policy) + + firewall, err := CreateFirewallOnRouter(t, client, policy.ID, router.ID) + if err != nil { + t.Fatalf("Unable to create firewall: %v", err) + } + defer DeleteFirewall(t, client, firewall.ID) + + tools.PrintResource(t, firewall) + + firewallUpdateOpts := firewalls.UpdateOpts{ + PolicyID: policy.ID, + Description: "Some firewall description", + } + + updateOpts := routerinsertion.UpdateOptsExt{ + firewallUpdateOpts, + []string{}, + } + + _, err = firewalls.Update(client, firewall.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update firewall: %v", err) + } + + newFirewall, err := firewalls.Get(client, firewall.ID).Extract() + if err != nil { + t.Fatalf("Unable to get firewall: %v", err) + } + + tools.PrintResource(t, newFirewall) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/policy_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/policy_test.go new file mode 100644 index 00000000..3220d821 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/policy_test.go @@ -0,0 +1,71 @@ +// +build acceptance networking fwaas + +package fwaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" +) + +func TestPolicyList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := policies.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list policies: %v", err) + } + + allPolicies, err := policies.ExtractPolicies(allPages) + if err != nil { + t.Fatalf("Unable to extract policies: %v", err) + } + + for _, policy := range allPolicies { + tools.PrintResource(t, policy) + } +} + +func TestPolicyCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + rule, err := CreateRule(t, client) + if err != nil { + t.Fatalf("Unable to create rule: %v", err) + } + defer DeleteRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + policy, err := CreatePolicy(t, client, rule.ID) + if err != nil { + t.Fatalf("Unable to create policy: %v", err) + } + defer DeletePolicy(t, client, policy.ID) + + tools.PrintResource(t, policy) + + updateOpts := policies.UpdateOpts{ + Description: "Some policy description", + } + + _, err = policies.Update(client, policy.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update policy: %v", err) + } + + newPolicy, err := policies.Get(client, policy.ID).Extract() + if err != nil { + t.Fatalf("Unable to get policy: %v", err) + } + + tools.PrintResource(t, newPolicy) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/rule_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/rule_test.go new file mode 100644 index 00000000..4521a60b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/fwaas/rule_test.go @@ -0,0 +1,64 @@ +// +build acceptance networking fwaas + +package fwaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" +) + +func TestRuleList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := rules.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list rules: %v", err) + } + + allRules, err := rules.ExtractRules(allPages) + if err != nil { + t.Fatalf("Unable to extract rules: %v", err) + } + + for _, rule := range allRules { + tools.PrintResource(t, rule) + } +} + +func TestRuleCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + rule, err := CreateRule(t, client) + if err != nil { + t.Fatalf("Unable to create rule: %v", err) + } + defer DeleteRule(t, client, rule.ID) + + tools.PrintResource(t, rule) + + ruleDescription := "Some rule description" + updateOpts := rules.UpdateOpts{ + Description: &ruleDescription, + } + + _, err = rules.Update(client, rule.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update rule: %v", err) + } + + newRule, err := rules.Get(client, rule.ID).Extract() + if err != nil { + t.Fatalf("Unable to get rule: %v", err) + } + + tools.PrintResource(t, newRule) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/floatingips_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/floatingips_test.go new file mode 100644 index 00000000..3d2073c1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/floatingips_test.go @@ -0,0 +1,147 @@ +// +build acceptance networking layer3 floatingips + +package layer3 + +import ( + "os" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" +) + +func TestLayer3FloatingIPsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + listOpts := floatingips.ListOpts{ + Status: "DOWN", + } + allPages, err := floatingips.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list floating IPs: %v", err) + } + + allFIPs, err := floatingips.ExtractFloatingIPs(allPages) + if err != nil { + t.Fatalf("Unable to extract floating IPs: %v", err) + } + + for _, fip := range allFIPs { + tools.PrintResource(t, fip) + } +} + +func TestLayer3FloatingIPsCreateDelete(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatalf("Unable to get choices: %v", err) + } + + netid, err := networks.IDFromName(client, choices.NetworkName) + if err != nil { + t.Fatalf("Unable to find network id: %v", err) + } + + subnet, err := networking.CreateSubnet(t, client, netid) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + router, err := CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer DeleteRouter(t, client, router.ID) + + port, err := networking.CreatePort(t, client, netid, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + + _, err = CreateRouterInterface(t, client, port.ID, router.ID) + if err != nil { + t.Fatalf("Unable to create router interface: %v", err) + } + defer DeleteRouterInterface(t, client, port.ID, router.ID) + + fip, err := CreateFloatingIP(t, client, choices.ExternalNetworkID, port.ID) + if err != nil { + t.Fatalf("Unable to create floating IP: %v", err) + } + defer DeleteFloatingIP(t, client, fip.ID) + + newFip, err := floatingips.Get(client, fip.ID).Extract() + if err != nil { + t.Fatalf("Unable to get floating ip: %v", err) + } + + tools.PrintResource(t, newFip) + + // Disassociate the floating IP + updateOpts := floatingips.UpdateOpts{ + PortID: nil, + } + + newFip, err = floatingips.Update(client, fip.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to disassociate floating IP: %v", err) + } +} + +func TestLayer3FloatingIPsCreateDeleteBySubnetID(t *testing.T) { + username := os.Getenv("OS_USERNAME") + if username != "admin" { + t.Skip("must be admin to run this test") + } + + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatalf("Unable to get choices: %v", err) + } + + listOpts := subnets.ListOpts{ + NetworkID: choices.ExternalNetworkID, + } + + subnetPages, err := subnets.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list subnets: %v", err) + } + + allSubnets, err := subnets.ExtractSubnets(subnetPages) + if err != nil { + t.Fatalf("Unable to extract subnets: %v", err) + } + + createOpts := floatingips.CreateOpts{ + FloatingNetworkID: choices.ExternalNetworkID, + SubnetID: allSubnets[0].ID, + } + + fip, err := floatingips.Create(client, createOpts).Extract() + if err != nil { + t.Fatalf("Unable to create floating IP: %v", err) + } + + tools.PrintResource(t, fip) + + DeleteFloatingIP(t, client, fip.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/routers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/routers_test.go new file mode 100644 index 00000000..4be922e9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/routers_test.go @@ -0,0 +1,119 @@ +// +build acceptance networking layer3 router + +package layer3 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" +) + +func TestLayer3RouterList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + listOpts := routers.ListOpts{} + allPages, err := routers.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list routers: %v", err) + } + + allRouters, err := routers.ExtractRouters(allPages) + if err != nil { + t.Fatalf("Unable to extract routers: %v", err) + } + + for _, router := range allRouters { + tools.PrintResource(t, router) + } +} + +func TestLayer3ExternalRouterCreateDelete(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + router, err := CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer DeleteRouter(t, client, router.ID) + + tools.PrintResource(t, router) + + newName := tools.RandomString("TESTACC-", 8) + updateOpts := routers.UpdateOpts{ + Name: newName, + } + + _, err = routers.Update(client, router.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update router: %v", err) + } + + newRouter, err := routers.Get(client, router.ID).Extract() + if err != nil { + t.Fatalf("Unable to get router: %v", err) + } + + tools.PrintResource(t, newRouter) +} + +func TestLayer3RouterInterface(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a compute client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatalf("Unable to get choices: %v", err) + } + + netid, err := networks.IDFromName(client, choices.NetworkName) + if err != nil { + t.Fatalf("Unable to find network id: %v", err) + } + + subnet, err := networking.CreateSubnet(t, client, netid) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + router, err := CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer DeleteRouter(t, client, router.ID) + + aiOpts := routers.AddInterfaceOpts{ + SubnetID: subnet.ID, + } + + iface, err := routers.AddInterface(client, router.ID, aiOpts).Extract() + if err != nil { + t.Fatalf("Failed to add interface to router: %v", err) + } + + tools.PrintResource(t, router) + tools.PrintResource(t, iface) + + riOpts := routers.RemoveInterfaceOpts{ + SubnetID: subnet.ID, + } + + _, err = routers.RemoveInterface(client, router.ID, riOpts).Extract() + if err != nil { + t.Fatalf("Failed to remove interface from router: %v", err) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/members_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/members_test.go new file mode 100644 index 00000000..75dec839 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/members_test.go @@ -0,0 +1,83 @@ +// +build acceptance networking lbaas member + +package lbaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members" +) + +func TestMembersList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := members.List(client, members.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to list members: %v", err) + } + + allMembers, err := members.ExtractMembers(allPages) + if err != nil { + t.Fatalf("Unable to extract members: %v", err) + } + + for _, member := range allMembers { + tools.PrintResource(t, member) + } +} + +func TestMembersCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + pool, err := CreatePool(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, client, pool.ID) + + member, err := CreateMember(t, client, pool.ID) + if err != nil { + t.Fatalf("Unable to create member: %v", err) + } + defer DeleteMember(t, client, member.ID) + + tools.PrintResource(t, member) + + updateOpts := members.UpdateOpts{ + AdminStateUp: gophercloud.Enabled, + } + + _, err = members.Update(client, member.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update member: %v") + } + + newMember, err := members.Get(client, member.ID).Extract() + if err != nil { + t.Fatalf("Unable to get member: %v") + } + + tools.PrintResource(t, newMember) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/monitors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/monitors_test.go new file mode 100644 index 00000000..56b413af --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/monitors_test.go @@ -0,0 +1,63 @@ +// +build acceptance networking lbaas monitors + +package lbaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors" +) + +func TestMonitorsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := monitors.List(client, monitors.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to list monitors: %v", err) + } + + allMonitors, err := monitors.ExtractMonitors(allPages) + if err != nil { + t.Fatalf("Unable to extract monitors: %v", err) + } + + for _, monitor := range allMonitors { + tools.PrintResource(t, monitor) + } +} + +func TestMonitorsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + monitor, err := CreateMonitor(t, client) + if err != nil { + t.Fatalf("Unable to create monitor: %v", err) + } + defer DeleteMonitor(t, client, monitor.ID) + + tools.PrintResource(t, monitor) + + updateOpts := monitors.UpdateOpts{ + Delay: 999, + } + + _, err = monitors.Update(client, monitor.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update monitor: %v") + } + + newMonitor, err := monitors.Get(client, monitor.ID).Extract() + if err != nil { + t.Fatalf("Unable to get monitor: %v") + } + + tools.PrintResource(t, newMonitor) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/pools_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/pools_test.go new file mode 100644 index 00000000..b53237c0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/pools_test.go @@ -0,0 +1,118 @@ +// +build acceptance networking lbaas pool + +package lbaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools" +) + +func TestPoolsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := pools.List(client, pools.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to list pools: %v", err) + } + + allPools, err := pools.ExtractPools(allPages) + if err != nil { + t.Fatalf("Unable to extract pools: %v", err) + } + + for _, pool := range allPools { + tools.PrintResource(t, pool) + } +} + +func TestPoolsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + pool, err := CreatePool(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, client, pool.ID) + + tools.PrintResource(t, pool) + + updateOpts := pools.UpdateOpts{ + LBMethod: pools.LBMethodLeastConnections, + } + + _, err = pools.Update(client, pool.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool: %v") + } + + newPool, err := pools.Get(client, pool.ID).Extract() + if err != nil { + t.Fatalf("Unable to get pool: %v") + } + + tools.PrintResource(t, newPool) +} + +func TestPoolsMonitors(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + pool, err := CreatePool(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, client, pool.ID) + + monitor, err := CreateMonitor(t, client) + if err != nil { + t.Fatalf("Unable to create monitor: %v", err) + } + defer DeleteMonitor(t, client, monitor.ID) + + t.Logf("Associating monitor %s with pool %s", monitor.ID, pool.ID) + if res := pools.AssociateMonitor(client, pool.ID, monitor.ID); res.Err != nil { + t.Fatalf("Unable to associate monitor to pool") + } + + t.Logf("Disassociating monitor %s with pool %s", monitor.ID, pool.ID) + if res := pools.DisassociateMonitor(client, pool.ID, monitor.ID); res.Err != nil { + t.Fatalf("Unable to disassociate monitor from pool") + } + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/vips_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/vips_test.go new file mode 100644 index 00000000..a63dc63c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas/vips_test.go @@ -0,0 +1,83 @@ +// +build acceptance networking lbaas vip + +package lbaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips" +) + +func TestVIPsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := vips.List(client, vips.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to list vips: %v", err) + } + + allVIPs, err := vips.ExtractVIPs(allPages) + if err != nil { + t.Fatalf("Unable to extract vips: %v", err) + } + + for _, vip := range allVIPs { + tools.PrintResource(t, vip) + } +} + +func TestVIPsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + pool, err := CreatePool(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, client, pool.ID) + + vip, err := CreateVIP(t, client, subnet.ID, pool.ID) + if err != nil { + t.Fatalf("Unable to create vip: %v", err) + } + defer DeleteVIP(t, client, vip.ID) + + tools.PrintResource(t, vip) + + connLimit := 100 + updateOpts := vips.UpdateOpts{ + ConnLimit: &connLimit, + } + + _, err = vips.Update(client, vip.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update vip: %v") + } + + newVIP, err := vips.Get(client, vip.ID).Extract() + if err != nil { + t.Fatalf("Unable to get vip: %v") + } + + tools.PrintResource(t, newVIP) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/listeners_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/listeners_test.go new file mode 100644 index 00000000..2d2dd036 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/listeners_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking lbaas_v2 listeners + +package lbaas_v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" +) + +func TestListenersList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := listeners.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list listeners: %v", err) + } + + allListeners, err := listeners.ExtractListeners(allPages) + if err != nil { + t.Fatalf("Unable to extract listeners: %v", err) + } + + for _, listener := range allListeners { + tools.PrintResource(t, listener) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/loadbalancers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/loadbalancers_test.go new file mode 100644 index 00000000..650eb2cc --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/loadbalancers_test.go @@ -0,0 +1,178 @@ +// +build acceptance networking lbaas_v2 loadbalancers + +package lbaas_v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" +) + +func TestLoadbalancersList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := loadbalancers.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list loadbalancers: %v", err) + } + + allLoadbalancers, err := loadbalancers.ExtractLoadBalancers(allPages) + if err != nil { + t.Fatalf("Unable to extract loadbalancers: %v", err) + } + + for _, lb := range allLoadbalancers { + tools.PrintResource(t, lb) + } +} + +func TestLoadbalancersCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + lb, err := CreateLoadBalancer(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create loadbalancer: %v", err) + } + defer DeleteLoadBalancer(t, client, lb.ID) + + newLB, err := loadbalancers.Get(client, lb.ID).Extract() + if err != nil { + t.Fatalf("Unable to get loadbalancer: %v", err) + } + + tools.PrintResource(t, newLB) + + // Because of the time it takes to create a loadbalancer, + // this test will include some other resources. + + // Listener + listener, err := CreateListener(t, client, lb) + if err != nil { + t.Fatalf("Unable to create listener: %v", err) + } + defer DeleteListener(t, client, lb.ID, listener.ID) + + updateListenerOpts := listeners.UpdateOpts{ + Description: "Some listener description", + } + _, err = listeners.Update(client, listener.ID, updateListenerOpts).Extract() + if err != nil { + t.Fatalf("Unable to update listener") + } + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newListener, err := listeners.Get(client, listener.ID).Extract() + if err != nil { + t.Fatalf("Unable to get listener") + } + + tools.PrintResource(t, newListener) + + // Pool + pool, err := CreatePool(t, client, lb) + if err != nil { + t.Fatalf("Unable to create pool: %v", err) + } + defer DeletePool(t, client, lb.ID, pool.ID) + + updatePoolOpts := pools.UpdateOpts{ + Description: "Some pool description", + } + _, err = pools.Update(client, pool.ID, updatePoolOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newPool, err := pools.Get(client, pool.ID).Extract() + if err != nil { + t.Fatalf("Unable to get pool") + } + + tools.PrintResource(t, newPool) + + // Member + member, err := CreateMember(t, client, lb, newPool, subnet.ID, subnet.CIDR) + if err != nil { + t.Fatalf("Unable to create member: %v", err) + } + defer DeleteMember(t, client, lb.ID, pool.ID, member.ID) + + newWeight := tools.RandomInt(11, 100) + updateMemberOpts := pools.UpdateMemberOpts{ + Weight: newWeight, + } + _, err = pools.UpdateMember(client, pool.ID, member.ID, updateMemberOpts).Extract() + if err != nil { + t.Fatalf("Unable to update pool") + } + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMember, err := pools.GetMember(client, pool.ID, member.ID).Extract() + if err != nil { + t.Fatalf("Unable to get member") + } + + tools.PrintResource(t, newMember) + + // Monitor + monitor, err := CreateMonitor(t, client, lb, newPool) + if err != nil { + t.Fatalf("Unable to create monitor: %v", err) + } + defer DeleteMonitor(t, client, lb.ID, monitor.ID) + + newDelay := tools.RandomInt(20, 30) + updateMonitorOpts := monitors.UpdateOpts{ + Delay: newDelay, + } + _, err = monitors.Update(client, monitor.ID, updateMonitorOpts).Extract() + if err != nil { + t.Fatalf("Unable to update monitor") + } + + if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { + t.Fatalf("Timed out waiting for loadbalancer to become active") + } + + newMonitor, err := monitors.Get(client, monitor.ID).Extract() + if err != nil { + t.Fatalf("Unable to get monitor") + } + + tools.PrintResource(t, newMonitor) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/monitors_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/monitors_test.go new file mode 100644 index 00000000..b3123707 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/monitors_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking lbaas_v2 monitors + +package lbaas_v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" +) + +func TestMonitorsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := monitors.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list monitors: %v", err) + } + + allMonitors, err := monitors.ExtractMonitors(allPages) + if err != nil { + t.Fatalf("Unable to extract monitors: %v", err) + } + + for _, monitor := range allMonitors { + tools.PrintResource(t, monitor) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/pools_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/pools_test.go new file mode 100644 index 00000000..b4f55a0f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/lbaas_v2/pools_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking lbaas_v2 pools + +package lbaas_v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" +) + +func TestPoolsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := pools.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list pools: %v", err) + } + + allPools, err := pools.ExtractPools(allPages) + if err != nil { + t.Fatalf("Unable to extract pools: %v", err) + } + + for _, pool := range allPools { + tools.PrintResource(t, pool) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/networkipavailabilities_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/networkipavailabilities_test.go new file mode 100644 index 00000000..f141d204 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/networkipavailabilities_test.go @@ -0,0 +1,32 @@ +// +build acceptance networking networkipavailabilities + +package networkipavailabilities + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities" +) + +func TestNetworkIPAvailabilityList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := networkipavailabilities.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list network IP availabilities: %v", err) + } + + allAvailabilities, err := networkipavailabilities.ExtractNetworkIPAvailabilities(allPages) + if err != nil { + t.Fatalf("Unable to extract network IP availabilities: %v", err) + } + + for _, availability := range allAvailabilities { + tools.PrintResource(t, availability) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/pkg.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/pkg.go new file mode 100644 index 00000000..7399a405 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/networkipavailabilities/pkg.go @@ -0,0 +1 @@ +package networkipavailabilities diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go new file mode 100644 index 00000000..6ce20592 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go @@ -0,0 +1,57 @@ +// +build acceptance networking + +package portsbinding + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" +) + +func TestPortsbindingCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + // Define a host + hostID := "localhost" + + // Create port + port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer networking.DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Update port + newPortName := tools.RandomString("TESTACC-", 8) + updateOpts := ports.UpdateOpts{ + Name: newPortName, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/provider_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/provider_test.go new file mode 100644 index 00000000..44726ce2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/provider_test.go @@ -0,0 +1,34 @@ +// +build acceptance networking provider + +package extensions + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" +) + +func TestNetworksProviderCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a network + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + getResult := networks.Get(client, network.ID) + newNetwork, err := getResult.Extract() + if err != nil { + t.Fatalf("Unable to extract network: %v", err) + } + + tools.PrintResource(t, newNetwork) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/qos/ruletypes/ruletypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/qos/ruletypes/ruletypes_test.go new file mode 100644 index 00000000..e14844b5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/qos/ruletypes/ruletypes_test.go @@ -0,0 +1,31 @@ +package ruletypes + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes" +) + +func TestListRuleTypes(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + return + } + + page, err := ruletypes.ListRuleTypes(client).AllPages() + if err != nil { + t.Fatalf("Failed to list rule types pages: %v", err) + return + } + + ruleTypes, err := ruletypes.ExtractRuleTypes(page) + if err != nil { + t.Fatalf("Failed to list rule types: %v", err) + return + } + + tools.PrintResource(t, ruleTypes) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/pkg.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/pkg.go new file mode 100644 index 00000000..f682aeab --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/pkg.go @@ -0,0 +1 @@ +package rbacpolicies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies.go new file mode 100644 index 00000000..46903dff --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies.go @@ -0,0 +1,43 @@ +package rbacpolicies + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" +) + +// CreateRBACPolicy will create a rbac-policy. An error will be returned if the +// rbac-policy could not be created. +func CreateRBACPolicy(t *testing.T, client *gophercloud.ServiceClient, tenantID, networkID string) (*rbacpolicies.RBACPolicy, error) { + createOpts := rbacpolicies.CreateOpts{ + Action: rbacpolicies.ActionAccessShared, + ObjectType: "network", + TargetTenant: tenantID, + ObjectID: networkID, + } + + t.Logf("Trying to create rbac_policy") + + rbacPolicy, err := rbacpolicies.Create(client, createOpts).Extract() + if err != nil { + return rbacPolicy, err + } + + t.Logf("Successfully created rbac_policy") + return rbacPolicy, nil +} + +// DeleteRBACPolicy will delete a rbac-policy with a specified ID. A fatal error will +// occur if the delete was not successful. This works best when used as a +// deferred function. +func DeleteRBACPolicy(t *testing.T, client *gophercloud.ServiceClient, rbacPolicyID string) { + t.Logf("Trying to delete rbac_policy: %s", rbacPolicyID) + + err := rbacpolicies.Delete(client, rbacPolicyID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete rbac_policy %s: %v", rbacPolicyID, err) + } + + t.Logf("Deleted rbac_policy: %s", rbacPolicyID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies_test.go new file mode 100644 index 00000000..db838d28 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/rbacpolicies/rbacpolicies_test.go @@ -0,0 +1,113 @@ +// +build acceptance + +package rbacpolicies + +import ( + "os" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + projects "github.com/gophercloud/gophercloud/acceptance/openstack/identity/v3" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" +) + +func TestRBACPolicyCRUD(t *testing.T) { + username := os.Getenv("OS_USERNAME") + if username != "admin" { + t.Skip("must be admin to run this test") + } + + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a network + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + tools.PrintResource(t, network) + + identityClient, err := clients.NewIdentityV3Client() + if err != nil { + t.Fatalf("Unable to obtain an identity client: %v") + } + + // Create a project/tenant + project, err := projects.CreateProject(t, identityClient, nil) + if err != nil { + t.Fatalf("Unable to create project: %v", err) + } + defer projects.DeleteProject(t, identityClient, project.ID) + + tools.PrintResource(t, project) + + // Create a rbac-policy + rbacPolicy, err := CreateRBACPolicy(t, client, project.ID, network.ID) + if err != nil { + t.Fatalf("Unable to create rbac-policy: %v", err) + } + defer DeleteRBACPolicy(t, client, rbacPolicy.ID) + + tools.PrintResource(t, rbacPolicy) + + // Create another project/tenant for rbac-update + project2, err := projects.CreateProject(t, identityClient, nil) + if err != nil { + t.Fatalf("Unable to create project2: %v", err) + } + defer projects.DeleteProject(t, identityClient, project2.ID) + + tools.PrintResource(t, project2) + + // Update a rbac-policy + updateOpts := rbacpolicies.UpdateOpts{ + TargetTenant: project2.ID, + } + + _, err = rbacpolicies.Update(client, rbacPolicy.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update rbac-policy: %v", err) + } + + // Get the rbac-policy by ID + t.Logf("Get rbac_policy by ID") + newrbacPolicy, err := rbacpolicies.Get(client, rbacPolicy.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve rbac policy: %v", err) + } + + tools.PrintResource(t, newrbacPolicy) +} + +func TestRBACPolicyList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + type rbacPolicy struct { + rbacpolicies.RBACPolicy + } + + var allRBACPolicies []rbacPolicy + + allPages, err := rbacpolicies.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list rbac policies: %v", err) + } + + err = rbacpolicies.ExtractRBACPolicesInto(allPages, &allRBACPolicies) + if err != nil { + t.Fatalf("Unable to extract rbac policies: %v", err) + } + + for _, rbacpolicy := range allRBACPolicies { + tools.PrintResource(t, rbacpolicy) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/security_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/security_test.go new file mode 100644 index 00000000..3810a420 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/security_test.go @@ -0,0 +1,105 @@ +// +build acceptance networking security + +package extensions + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" +) + +func TestSecurityGroupsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + listOpts := groups.ListOpts{} + allPages, err := groups.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list groups: %v", err) + } + + allGroups, err := groups.ExtractGroups(allPages) + if err != nil { + t.Fatalf("Unable to extract groups: %v", err) + } + + for _, group := range allGroups { + tools.PrintResource(t, group) + } +} + +func TestSecurityGroupsCreateUpdateDelete(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + group, err := CreateSecurityGroup(t, client) + if err != nil { + t.Fatalf("Unable to create security group: %v", err) + } + defer DeleteSecurityGroup(t, client, group.ID) + + rule, err := CreateSecurityGroupRule(t, client, group.ID) + if err != nil { + t.Fatalf("Unable to create security group rule: %v", err) + } + defer DeleteSecurityGroupRule(t, client, rule.ID) + + tools.PrintResource(t, group) + + updateOpts := groups.UpdateOpts{ + Description: "A security group", + } + + newGroup, err := groups.Update(client, group.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update security group: %v", err) + } + + tools.PrintResource(t, newGroup) +} + +func TestSecurityGroupsPort(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + network, err := networking.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networking.DeleteNetwork(t, client, network.ID) + + subnet, err := networking.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networking.DeleteSubnet(t, client, subnet.ID) + + group, err := CreateSecurityGroup(t, client) + if err != nil { + t.Fatalf("Unable to create security group: %v", err) + } + defer DeleteSecurityGroup(t, client, group.ID) + + rule, err := CreateSecurityGroupRule(t, client, group.ID) + if err != nil { + t.Fatalf("Unable to create security group rule: %v", err) + } + defer DeleteSecurityGroupRule(t, client, rule.ID) + + port, err := CreatePortWithSecurityGroup(t, client, network.ID, subnet.ID, group.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer networking.DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools_test.go new file mode 100644 index 00000000..bdef6e67 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools_test.go @@ -0,0 +1,65 @@ +// +build acceptance networking subnetpools + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" +) + +func TestSubnetPoolsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a subnetpool + subnetPool, err := CreateSubnetPool(t, client) + if err != nil { + t.Fatalf("Unable to create a subnetpool: %v", err) + } + defer DeleteSubnetPool(t, client, subnetPool.ID) + + tools.PrintResource(t, subnetPool) + + newName := tools.RandomString("TESTACC-", 8) + updateOpts := &subnetpools.UpdateOpts{ + Name: newName, + } + + _, err = subnetpools.Update(client, subnetPool.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update the subnetpool: %v", err) + } + + newSubnetPool, err := subnetpools.Get(client, subnetPool.ID).Extract() + if err != nil { + t.Fatalf("Unable to get subnetpool: %v", err) + } + + tools.PrintResource(t, newSubnetPool) +} + +func TestSubnetPoolsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := subnetpools.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list subnetpools: %v", err) + } + + allSubnetPools, err := subnetpools.ExtractSubnetPools(allPages) + if err != nil { + t.Fatalf("Unable to extract subnetpools: %v", err) + } + + for _, subnetpool := range allSubnetPools { + tools.PrintResource(t, subnetpool) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/group_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/group_test.go new file mode 100644 index 00000000..853065d2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/group_test.go @@ -0,0 +1,65 @@ +// +build acceptance networking vpnaas + +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups" +) + +func TestGroupList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := endpointgroups.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list endpoint groups: %v", err) + } + + allGroups, err := endpointgroups.ExtractEndpointGroups(allPages) + if err != nil { + t.Fatalf("Unable to extract endpoint groups: %v", err) + } + + for _, group := range allGroups { + tools.PrintResource(t, group) + } +} + +func TestGroupCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + group, err := CreateEndpointGroup(t, client) + if err != nil { + t.Fatalf("Unable to create Endpoint group: %v", err) + } + defer DeleteEndpointGroup(t, client, group.ID) + tools.PrintResource(t, group) + + newGroup, err := endpointgroups.Get(client, group.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve Endpoint group: %v", err) + } + tools.PrintResource(t, newGroup) + + updatedName := "updatedname" + updatedDescription := "updated description" + updateOpts := endpointgroups.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + } + updatedGroup, err := endpointgroups.Update(client, group.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update endpoint group: %v", err) + } + tools.PrintResource(t, updatedGroup) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ikepolicy_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ikepolicy_test.go new file mode 100644 index 00000000..2efa1e1b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ikepolicy_test.go @@ -0,0 +1,69 @@ +// +build acceptance networking vpnaas + +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies" +) + +func TestIKEPolicyList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := ikepolicies.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list IKE policies: %v", err) + } + + allPolicies, err := ikepolicies.ExtractPolicies(allPages) + if err != nil { + t.Fatalf("Unable to extract IKE policies: %v", err) + } + + for _, policy := range allPolicies { + tools.PrintResource(t, policy) + } +} + +func TestIKEPolicyCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + policy, err := CreateIKEPolicy(t, client) + if err != nil { + t.Fatalf("Unable to create IKE policy: %v", err) + } + defer DeleteIKEPolicy(t, client, policy.ID) + + tools.PrintResource(t, policy) + + newPolicy, err := ikepolicies.Get(client, policy.ID).Extract() + if err != nil { + t.Fatalf("Unable to get IKE policy: %v", err) + } + tools.PrintResource(t, newPolicy) + + updatedName := "updatedname" + updatedDescription := "updated policy" + updateOpts := ikepolicies.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + Lifetime: &ikepolicies.LifetimeUpdateOpts{ + Value: 7000, + }, + } + updatedPolicy, err := ikepolicies.Update(client, policy.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update IKE policy: %v", err) + } + tools.PrintResource(t, updatedPolicy) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ipsecpolicy_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ipsecpolicy_test.go new file mode 100644 index 00000000..2fdee7dd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/ipsecpolicy_test.go @@ -0,0 +1,63 @@ +// +build acceptance networking vpnaas + +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies" +) + +func TestIPSecPolicyList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := ipsecpolicies.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list IPSec policies: %v", err) + } + + allPolicies, err := ipsecpolicies.ExtractPolicies(allPages) + if err != nil { + t.Fatalf("Unable to extract policies: %v", err) + } + + for _, policy := range allPolicies { + tools.PrintResource(t, policy) + } +} + +func TestIPSecPolicyCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + policy, err := CreateIPSecPolicy(t, client) + if err != nil { + t.Fatalf("Unable to create IPSec policy: %v", err) + } + defer DeleteIPSecPolicy(t, client, policy.ID) + tools.PrintResource(t, policy) + + updatedDescription := "Updated policy description" + updateOpts := ipsecpolicies.UpdateOpts{ + Description: &updatedDescription, + } + + policy, err = ipsecpolicies.Update(client, policy.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update IPSec policy: %v", err) + } + tools.PrintResource(t, policy) + + newPolicy, err := ipsecpolicies.Get(client, policy.ID).Extract() + if err != nil { + t.Fatalf("Unable to get IPSec policy: %v", err) + } + tools.PrintResource(t, newPolicy) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/service_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/service_test.go new file mode 100644 index 00000000..f88aa761 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/service_test.go @@ -0,0 +1,60 @@ +// +build acceptance networking fwaas + +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + layer3 "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services" +) + +func TestServiceList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := services.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list services: %v", err) + } + + allServices, err := services.ExtractServices(allPages) + if err != nil { + t.Fatalf("Unable to extract services: %v", err) + } + + for _, service := range allServices { + tools.PrintResource(t, service) + } +} + +func TestServiceCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + router, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router.ID) + + service, err := CreateService(t, client, router.ID) + if err != nil { + t.Fatalf("Unable to create service: %v", err) + } + defer DeleteService(t, client, service.ID) + + newService, err := services.Get(client, service.ID).Extract() + if err != nil { + t.Fatalf("Unable to get service: %v", err) + } + + tools.PrintResource(t, service) + tools.PrintResource(t, newService) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/siteconnection_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/siteconnection_test.go new file mode 100644 index 00000000..5bf75607 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/siteconnection_test.go @@ -0,0 +1,125 @@ +// +build acceptance networking vpnaas + +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + networks "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2" + layer3 "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" + + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections" +) + +func TestConnectionList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := siteconnections.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list IPSec site connections: %v", err) + } + + allConnections, err := siteconnections.ExtractConnections(allPages) + if err != nil { + t.Fatalf("Unable to extract IPSec site connections: %v", err) + } + + for _, connection := range allConnections { + tools.PrintResource(t, connection) + } +} + +func TestConnectionCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := networks.CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer networks.DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := networks.CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer networks.DeleteSubnet(t, client, subnet.ID) + + router, err := layer3.CreateExternalRouter(t, client) + if err != nil { + t.Fatalf("Unable to create router: %v", err) + } + defer layer3.DeleteRouter(t, client, router.ID) + + // Link router and subnet + aiOpts := routers.AddInterfaceOpts{ + SubnetID: subnet.ID, + } + + _, err = routers.AddInterface(client, router.ID, aiOpts).Extract() + if err != nil { + t.Fatalf("Failed to add interface to router: %v", err) + } + defer func() { + riOpts := routers.RemoveInterfaceOpts{ + SubnetID: subnet.ID, + } + routers.RemoveInterface(client, router.ID, riOpts) + }() + + // Create all needed resources for the connection + service, err := CreateService(t, client, router.ID) + if err != nil { + t.Fatalf("Unable to create service: %v", err) + } + defer DeleteService(t, client, service.ID) + + ikepolicy, err := CreateIKEPolicy(t, client) + if err != nil { + t.Fatalf("Unable to create IKE policy: %v", err) + } + defer DeleteIKEPolicy(t, client, ikepolicy.ID) + + ipsecpolicy, err := CreateIPSecPolicy(t, client) + if err != nil { + t.Fatalf("Unable to create IPSec Policy: %v", err) + } + defer DeleteIPSecPolicy(t, client, ipsecpolicy.ID) + + peerEPGroup, err := CreateEndpointGroup(t, client) + if err != nil { + t.Fatalf("Unable to create Endpoint Group with CIDR endpoints: %v", err) + } + defer DeleteEndpointGroup(t, client, peerEPGroup.ID) + + localEPGroup, err := CreateEndpointGroupWithSubnet(t, client, subnet.ID) + if err != nil { + t.Fatalf("Unable to create Endpoint Group with subnet endpoints: %v", err) + } + defer DeleteEndpointGroup(t, client, localEPGroup.ID) + + conn, err := CreateSiteConnection(t, client, ikepolicy.ID, ipsecpolicy.ID, service.ID, peerEPGroup.ID, localEPGroup.ID) + if err != nil { + t.Fatalf("Unable to create IPSec Site Connection: %v", err) + } + defer DeleteSiteConnection(t, client, conn.ID) + + newConnection, err := siteconnections.Get(client, conn.ID).Extract() + if err != nil { + t.Fatalf("Unable to get connection: %v", err) + } + + tools.PrintResource(t, conn) + tools.PrintResource(t, newConnection) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go new file mode 100644 index 00000000..2194a4c7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go @@ -0,0 +1,258 @@ +package vpnaas + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections" +) + +// CreateService will create a Service with a random name and a specified router ID +// An error will be returned if the service could not be created. +func CreateService(t *testing.T, client *gophercloud.ServiceClient, routerID string) (*services.Service, error) { + serviceName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create service %s", serviceName) + + iTrue := true + createOpts := services.CreateOpts{ + Name: serviceName, + AdminStateUp: &iTrue, + RouterID: routerID, + } + service, err := services.Create(client, createOpts).Extract() + if err != nil { + return service, err + } + + t.Logf("Successfully created service %s", serviceName) + + return service, nil +} + +// DeleteService will delete a service with a specified ID. A fatal error +// will occur if the delete was not successful. This works best when used as +// a deferred function. +func DeleteService(t *testing.T, client *gophercloud.ServiceClient, serviceID string) { + t.Logf("Attempting to delete service: %s", serviceID) + + err := services.Delete(client, serviceID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete service %s: %v", serviceID, err) + } + + t.Logf("Service deleted: %s", serviceID) +} + +// CreateIPSecPolicy will create an IPSec Policy with a random name and given +// rule. An error will be returned if the rule could not be created. +func CreateIPSecPolicy(t *testing.T, client *gophercloud.ServiceClient) (*ipsecpolicies.Policy, error) { + policyName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create IPSec policy %s", policyName) + + createOpts := ipsecpolicies.CreateOpts{ + Name: policyName, + } + + policy, err := ipsecpolicies.Create(client, createOpts).Extract() + if err != nil { + return policy, err + } + + t.Logf("Successfully created IPSec policy %s", policyName) + + return policy, nil +} + +// CreateIKEPolicy will create an IKE Policy with a random name and given +// rule. An error will be returned if the policy could not be created. +func CreateIKEPolicy(t *testing.T, client *gophercloud.ServiceClient) (*ikepolicies.Policy, error) { + policyName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create IKE policy %s", policyName) + + createOpts := ikepolicies.CreateOpts{ + Name: policyName, + EncryptionAlgorithm: ikepolicies.EncryptionAlgorithm3DES, + PFS: ikepolicies.PFSGroup5, + } + + policy, err := ikepolicies.Create(client, createOpts).Extract() + if err != nil { + return policy, err + } + + t.Logf("Successfully created IKE policy %s", policyName) + + return policy, nil +} + +// DeleteIPSecPolicy will delete an IPSec policy with a specified ID. A fatal error will +// occur if the delete was not successful. This works best when used as a +// deferred function. +func DeleteIPSecPolicy(t *testing.T, client *gophercloud.ServiceClient, policyID string) { + t.Logf("Attempting to delete IPSec policy: %s", policyID) + + err := ipsecpolicies.Delete(client, policyID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete IPSec policy %s: %v", policyID, err) + } + + t.Logf("Deleted IPSec policy: %s", policyID) +} + +// DeleteIKEPolicy will delete an IKE policy with a specified ID. A fatal error will +// occur if the delete was not successful. This works best when used as a +// deferred function. +func DeleteIKEPolicy(t *testing.T, client *gophercloud.ServiceClient, policyID string) { + t.Logf("Attempting to delete policy: %s", policyID) + + err := ikepolicies.Delete(client, policyID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete IKE policy %s: %v", policyID, err) + } + + t.Logf("Deleted IKE policy: %s", policyID) +} + +// CreateEndpointGroup will create an endpoint group with a random name. +// An error will be returned if the group could not be created. +func CreateEndpointGroup(t *testing.T, client *gophercloud.ServiceClient) (*endpointgroups.EndpointGroup, error) { + groupName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create group %s", groupName) + + createOpts := endpointgroups.CreateOpts{ + Name: groupName, + Type: endpointgroups.TypeCIDR, + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + } + group, err := endpointgroups.Create(client, createOpts).Extract() + if err != nil { + return group, err + } + + t.Logf("Successfully created group %s", groupName) + + return group, nil +} + +// CreateEndpointGroupWithCIDR will create an endpoint group with a random name and a specified CIDR. +// An error will be returned if the group could not be created. +func CreateEndpointGroupWithCIDR(t *testing.T, client *gophercloud.ServiceClient, cidr string) (*endpointgroups.EndpointGroup, error) { + groupName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create group %s", groupName) + + createOpts := endpointgroups.CreateOpts{ + Name: groupName, + Type: endpointgroups.TypeCIDR, + Endpoints: []string{ + cidr, + }, + } + group, err := endpointgroups.Create(client, createOpts).Extract() + if err != nil { + return group, err + } + + t.Logf("Successfully created group %s", groupName) + t.Logf("%v", group) + + return group, nil +} + +// DeleteEndpointGroup will delete an Endpoint group with a specified ID. A fatal error will +// occur if the delete was not successful. This works best when used as a +// deferred function. +func DeleteEndpointGroup(t *testing.T, client *gophercloud.ServiceClient, epGroupID string) { + t.Logf("Attempting to delete endpoint group: %s", epGroupID) + + err := endpointgroups.Delete(client, epGroupID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete endpoint group %s: %v", epGroupID, err) + } + + t.Logf("Deleted endpoint group: %s", epGroupID) + +} + +// CreateEndpointGroupWithSubnet will create an endpoint group with a random name. +// An error will be returned if the group could not be created. +func CreateEndpointGroupWithSubnet(t *testing.T, client *gophercloud.ServiceClient, subnetID string) (*endpointgroups.EndpointGroup, error) { + groupName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create group %s", groupName) + + createOpts := endpointgroups.CreateOpts{ + Name: groupName, + Type: endpointgroups.TypeSubnet, + Endpoints: []string{ + subnetID, + }, + } + group, err := endpointgroups.Create(client, createOpts).Extract() + if err != nil { + return group, err + } + + t.Logf("Successfully created group %s", groupName) + + return group, nil +} + +// CreateSiteConnection will create an IPSec site connection with a random name and specified +// IKE policy, IPSec policy, service, peer EP group and local EP Group. +// An error will be returned if the connection could not be created. +func CreateSiteConnection(t *testing.T, client *gophercloud.ServiceClient, ikepolicyID string, ipsecpolicyID string, serviceID string, peerEPGroupID string, localEPGroupID string) (*siteconnections.Connection, error) { + connectionName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create IPSec site connection %s", connectionName) + + createOpts := siteconnections.CreateOpts{ + Name: connectionName, + PSK: "secret", + Initiator: siteconnections.InitiatorBiDirectional, + AdminStateUp: gophercloud.Enabled, + IPSecPolicyID: ipsecpolicyID, + PeerEPGroupID: peerEPGroupID, + IKEPolicyID: ikepolicyID, + VPNServiceID: serviceID, + LocalEPGroupID: localEPGroupID, + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + MTU: 1500, + } + connection, err := siteconnections.Create(client, createOpts).Extract() + if err != nil { + return connection, err + } + + t.Logf("Successfully created IPSec Site Connection %s", connectionName) + + return connection, nil +} + +// DeleteSiteConnection will delete an IPSec site connection with a specified ID. A fatal error will +// occur if the delete was not successful. This works best when used as a +// deferred function. +func DeleteSiteConnection(t *testing.T, client *gophercloud.ServiceClient, siteConnectionID string) { + t.Logf("Attempting to delete site connection: %s", siteConnectionID) + + err := siteconnections.Delete(client, siteConnectionID).ExtractErr() + if err != nil { + t.Fatalf("Unable to delete site connection %s: %v", siteConnectionID, err) + } + + t.Logf("Deleted site connection: %s", siteConnectionID) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networking.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networking.go index bc463dde..2abf4f91 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networking.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networking.go @@ -6,6 +6,8 @@ import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" @@ -31,6 +33,32 @@ func CreateNetwork(t *testing.T, client *gophercloud.ServiceClient) (*networks.N return network, nil } +// CreateNetworkWithoutPortSecurity will create a network without port security. +// An error will be returned if the network could not be created. +func CreateNetworkWithoutPortSecurity(t *testing.T, client *gophercloud.ServiceClient) (*networks.Network, error) { + networkName := tools.RandomString("TESTACC-", 8) + networkCreateOpts := networks.CreateOpts{ + Name: networkName, + AdminStateUp: gophercloud.Enabled, + } + + iFalse := false + createOpts := portsecurity.NetworkCreateOptsExt{ + CreateOptsBuilder: networkCreateOpts, + PortSecurityEnabled: &iFalse, + } + + t.Logf("Attempting to create network: %s", networkName) + + network, err := networks.Create(client, createOpts).Extract() + if err != nil { + return network, err + } + + t.Logf("Successfully created network.") + return network, nil +} + // CreatePort will create a port on the specified subnet. An error will be // returned if the port could not be created. func CreatePort(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*ports.Port, error) { @@ -99,6 +127,45 @@ func CreatePortWithNoSecurityGroup(t *testing.T, client *gophercloud.ServiceClie return newPort, nil } +// CreatePortWithoutPortSecurity will create a port without port security on the +// specified subnet. An error will be returned if the port could not be created. +func CreatePortWithoutPortSecurity(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*ports.Port, error) { + portName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create port: %s", portName) + + portCreateOpts := ports.CreateOpts{ + NetworkID: networkID, + Name: portName, + AdminStateUp: gophercloud.Enabled, + FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, + } + + iFalse := false + createOpts := portsecurity.PortCreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + PortSecurityEnabled: &iFalse, + } + + port, err := ports.Create(client, createOpts).Extract() + if err != nil { + return port, err + } + + if err := WaitForPortToCreate(client, port.ID, 60); err != nil { + return port, err + } + + newPort, err := ports.Get(client, port.ID).Extract() + if err != nil { + return newPort, err + } + + t.Logf("Successfully created port: %s", portName) + + return newPort, nil +} + // CreateSubnet will create a subnet on the specified Network ID. An error // will be returned if the subnet could not be created. func CreateSubnet(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*subnets.Subnet, error) { @@ -188,6 +255,56 @@ func CreateSubnetWithNoGateway(t *testing.T, client *gophercloud.ServiceClient, return subnet, nil } +// CreateSubnetWithSubnetPool will create a subnet associated with the provided subnetpool on the specified Network ID. +// An error will be returned if the subnet or the subnetpool could not be created. +func CreateSubnetWithSubnetPool(t *testing.T, client *gophercloud.ServiceClient, networkID string, subnetPoolID string) (*subnets.Subnet, error) { + subnetName := tools.RandomString("TESTACC-", 8) + subnetOctet := tools.RandomInt(1, 250) + subnetCIDR := fmt.Sprintf("10.%d.0.0/24", subnetOctet) + createOpts := subnets.CreateOpts{ + NetworkID: networkID, + CIDR: subnetCIDR, + IPVersion: 4, + Name: subnetName, + EnableDHCP: gophercloud.Disabled, + SubnetPoolID: subnetPoolID, + } + + t.Logf("Attempting to create subnet: %s", subnetName) + + subnet, err := subnets.Create(client, createOpts).Extract() + if err != nil { + return subnet, err + } + + t.Logf("Successfully created subnet.") + return subnet, nil +} + +// CreateSubnetWithSubnetPoolNoCIDR will create a subnet associated with the +// provided subnetpool on the specified Network ID. +// An error will be returned if the subnet or the subnetpool could not be created. +func CreateSubnetWithSubnetPoolNoCIDR(t *testing.T, client *gophercloud.ServiceClient, networkID string, subnetPoolID string) (*subnets.Subnet, error) { + subnetName := tools.RandomString("TESTACC-", 8) + createOpts := subnets.CreateOpts{ + NetworkID: networkID, + IPVersion: 4, + Name: subnetName, + EnableDHCP: gophercloud.Disabled, + SubnetPoolID: subnetPoolID, + } + + t.Logf("Attempting to create subnet: %s", subnetName) + + subnet, err := subnets.Create(client, createOpts).Extract() + if err != nil { + return subnet, err + } + + t.Logf("Successfully created subnet.") + return subnet, nil +} + // DeleteNetwork will delete a network with a specified ID. A fatal error will // occur if the delete was not successful. This works best when used as a // deferred function. @@ -244,3 +361,53 @@ func WaitForPortToCreate(client *gophercloud.ServiceClient, portID string, secs return false, nil }) } + +// PortWithExtraDHCPOpts represents a port with extra DHCP options configuration. +type PortWithExtraDHCPOpts struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt +} + +// CreatePortWithExtraDHCPOpts will create a port with DHCP options on the +// specified subnet. An error will be returned if the port could not be created. +func CreatePortWithExtraDHCPOpts(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*PortWithExtraDHCPOpts, error) { + portName := tools.RandomString("TESTACC-", 8) + + t.Logf("Attempting to create port: %s", portName) + + portCreateOpts := ports.CreateOpts{ + NetworkID: networkID, + Name: portName, + AdminStateUp: gophercloud.Enabled, + FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, + } + + createOpts := extradhcpopts.CreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + ExtraDHCPOpts: []extradhcpopts.CreateExtraDHCPOpt{ + { + OptName: "test_option_1", + OptValue: "test_value_1", + }, + }, + } + port := &PortWithExtraDHCPOpts{} + + err := ports.Create(client, createOpts).ExtractInto(port) + if err != nil { + return nil, err + } + + if err := WaitForPortToCreate(client, port.ID, 60); err != nil { + return nil, err + } + + err = ports.Get(client, port.ID).ExtractInto(port) + if err != nil { + return port, err + } + + t.Logf("Successfully created port: %s", portName) + + return port, nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go new file mode 100644 index 00000000..d7300a35 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go @@ -0,0 +1,179 @@ +// +build acceptance networking + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestNetworksList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + type networkWithExt struct { + networks.Network + portsecurity.PortSecurityExt + } + + var allNetworks []networkWithExt + + allPages, err := networks.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list networks: %v", err) + } + + err = networks.ExtractNetworksInto(allPages, &allNetworks) + if err != nil { + t.Fatalf("Unable to extract networks: %v", err) + } + + for _, network := range allNetworks { + tools.PrintResource(t, network) + } +} + +func TestNetworksExternalList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + choices, err := clients.AcceptanceTestChoicesFromEnv() + if err != nil { + t.Fatalf("Unable to fetch environment information: %s", err) + } + + type networkWithExt struct { + networks.Network + external.NetworkExternalExt + } + + var allNetworks []networkWithExt + + iTrue := true + networkListOpts := networks.ListOpts{ + ID: choices.ExternalNetworkID, + } + listOpts := external.ListOptsExt{ + ListOptsBuilder: networkListOpts, + External: &iTrue, + } + + allPages, err := networks.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list networks: %v", err) + } + + err = networks.ExtractNetworksInto(allPages, &allNetworks) + if err != nil { + t.Fatalf("Unable to extract networks: %v", err) + } + + var found bool + for _, network := range allNetworks { + if network.External == true && network.ID == choices.ExternalNetworkID { + found = true + } + } + + th.AssertEquals(t, found, true) + + iFalse := false + networkListOpts = networks.ListOpts{ + ID: choices.ExternalNetworkID, + } + listOpts = external.ListOptsExt{ + ListOptsBuilder: networkListOpts, + External: &iFalse, + } + + allPages, err = networks.List(client, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list networks: %v", err) + } + + v, err := networks.ExtractNetworks(allPages) + th.AssertEquals(t, len(v), 0) +} + +func TestNetworksCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + tools.PrintResource(t, network) + + newName := tools.RandomString("TESTACC-", 8) + updateOpts := &networks.UpdateOpts{ + Name: newName, + } + + _, err = networks.Update(client, network.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update network: %v", err) + } + + newNetwork, err := networks.Get(client, network.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve network: %v", err) + } + + tools.PrintResource(t, newNetwork) +} + +func TestNetworksPortSecurityCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a network without port security + network, err := CreateNetworkWithoutPortSecurity(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + var networkWithExtensions struct { + networks.Network + portsecurity.PortSecurityExt + } + + err = networks.Get(client, network.ID).ExtractInto(&networkWithExtensions) + if err != nil { + t.Fatalf("Unable to retrieve network: %v", err) + } + + tools.PrintResource(t, networkWithExtensions) + + iTrue := true + networkUpdateOpts := networks.UpdateOpts{} + updateOpts := portsecurity.NetworkUpdateOptsExt{ + UpdateOptsBuilder: networkUpdateOpts, + PortSecurityEnabled: &iTrue, + } + + err = networks.Update(client, network.ID, updateOpts).ExtractInto(&networkWithExtensions) + if err != nil { + t.Fatalf("Unable to update network: %v", err) + } + + tools.PrintResource(t, networkWithExtensions) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/ports_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/ports_test.go new file mode 100644 index 00000000..5b820d7e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/ports_test.go @@ -0,0 +1,466 @@ +// +build acceptance networking + +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + extensions "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" +) + +func TestPortsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := ports.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list ports: %v", err) + } + + allPorts, err := ports.ExtractPorts(allPages) + if err != nil { + t.Fatalf("Unable to extract ports: %v", err) + } + + for _, port := range allPorts { + tools.PrintResource(t, port) + } +} + +func TestPortsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePort(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + if len(port.SecurityGroups) != 1 { + t.Logf("WARNING: Port did not have a default security group applied") + } + + tools.PrintResource(t, port) + + // Update port + newPortName := tools.RandomString("TESTACC-", 8) + updateOpts := ports.UpdateOpts{ + Name: newPortName, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) +} + +func TestPortsRemoveSecurityGroups(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePort(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Create a Security Group + group, err := extensions.CreateSecurityGroup(t, client) + if err != nil { + t.Fatalf("Unable to create security group: %v", err) + } + defer extensions.DeleteSecurityGroup(t, client, group.ID) + + // Add the group to the port + updateOpts := ports.UpdateOpts{ + SecurityGroups: &[]string{group.ID}, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + // Remove the group + updateOpts = ports.UpdateOpts{ + SecurityGroups: &[]string{}, + } + newPort, err = ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) + + if len(newPort.SecurityGroups) > 0 { + t.Fatalf("Unable to remove security group from port") + } +} + +func TestPortsDontAlterSecurityGroups(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create a Security Group + group, err := extensions.CreateSecurityGroup(t, client) + if err != nil { + t.Fatalf("Unable to create security group: %v", err) + } + defer extensions.DeleteSecurityGroup(t, client, group.ID) + + // Create port + port, err := CreatePort(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Add the group to the port + updateOpts := ports.UpdateOpts{ + SecurityGroups: &[]string{group.ID}, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + // Update the port again + updateOpts = ports.UpdateOpts{ + Name: "some_port", + } + newPort, err = ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) + + if len(newPort.SecurityGroups) == 0 { + t.Fatalf("Port had security group updated") + } +} + +func TestPortsWithNoSecurityGroup(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePortWithNoSecurityGroup(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + if len(port.SecurityGroups) != 0 { + t.Fatalf("Port was created with security groups") + } +} + +func TestPortsRemoveAddressPair(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePort(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Add an address pair to the port + updateOpts := ports.UpdateOpts{ + AllowedAddressPairs: &[]ports.AddressPair{ + ports.AddressPair{IPAddress: "192.168.255.10", MACAddress: "aa:bb:cc:dd:ee:ff"}, + }, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + // Remove the address pair + updateOpts = ports.UpdateOpts{ + AllowedAddressPairs: &[]ports.AddressPair{}, + } + newPort, err = ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) + + if len(newPort.AllowedAddressPairs) > 0 { + t.Fatalf("Unable to remove the address pair") + } +} + +func TestPortsDontUpdateAllowedAddressPairs(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePort(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Add an address pair to the port + updateOpts := ports.UpdateOpts{ + AllowedAddressPairs: &[]ports.AddressPair{ + ports.AddressPair{IPAddress: "192.168.255.10", MACAddress: "aa:bb:cc:dd:ee:ff"}, + }, + } + newPort, err := ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) + + // Remove the address pair + updateOpts = ports.UpdateOpts{ + Name: "some_port", + } + newPort, err = ports.Update(client, port.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) + + if len(newPort.AllowedAddressPairs) == 0 { + t.Fatalf("Address Pairs were removed") + } +} + +func TestPortsPortSecurityCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create port + port, err := CreatePortWithoutPortSecurity(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + defer DeletePort(t, client, port.ID) + + var portWithExt struct { + ports.Port + portsecurity.PortSecurityExt + } + + err = ports.Get(client, port.ID).ExtractInto(&portWithExt) + if err != nil { + t.Fatalf("Unable to create port: %v", err) + } + + tools.PrintResource(t, portWithExt) + + iTrue := true + portUpdateOpts := ports.UpdateOpts{} + updateOpts := portsecurity.PortUpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + PortSecurityEnabled: &iTrue, + } + + err = ports.Update(client, port.ID, updateOpts).ExtractInto(&portWithExt) + if err != nil { + t.Fatalf("Unable to update port: %v", err) + } + + tools.PrintResource(t, portWithExt) +} + +func TestPortsWithExtraDHCPOptsCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create a Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create a network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create a Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create a subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + // Create a port with extra DHCP options. + port, err := CreatePortWithExtraDHCPOpts(t, client, network.ID, subnet.ID) + if err != nil { + t.Fatalf("Unable to create a port: %v", err) + } + defer DeletePort(t, client, port.ID) + + tools.PrintResource(t, port) + + // Update the port with extra DHCP options. + newPortName := tools.RandomString("TESTACC-", 8) + portUpdateOpts := ports.UpdateOpts{ + Name: newPortName, + } + + existingOpt := port.ExtraDHCPOpts[0] + newOptValue := "test_value_2" + + updateOpts := extradhcpopts.UpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + ExtraDHCPOpts: []extradhcpopts.UpdateExtraDHCPOpt{ + { + OptName: existingOpt.OptName, + OptValue: nil, + }, + { + OptName: "test_option_2", + OptValue: &newOptValue, + }, + }, + } + + newPort := &PortWithExtraDHCPOpts{} + err = ports.Update(client, port.ID, updateOpts).ExtractInto(newPort) + if err != nil { + t.Fatalf("Could not update port: %v", err) + } + + tools.PrintResource(t, newPort) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/subnets_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/subnets_test.go new file mode 100644 index 00000000..6eb46074 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/subnets_test.go @@ -0,0 +1,227 @@ +// +build acceptance networking + +package v2 + +import ( + "fmt" + "strings" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + subnetpools "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" +) + +func TestSubnetsList(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + allPages, err := subnets.List(client, nil).AllPages() + if err != nil { + t.Fatalf("Unable to list subnets: %v", err) + } + + allSubnets, err := subnets.ExtractSubnets(allPages) + if err != nil { + t.Fatalf("Unable to extract subnets: %v", err) + } + + for _, subnet := range allSubnets { + tools.PrintResource(t, subnet) + } +} + +func TestSubnetCRUD(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnet(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + // Update Subnet + newSubnetName := tools.RandomString("TESTACC-", 8) + updateOpts := subnets.UpdateOpts{ + Name: newSubnetName, + } + _, err = subnets.Update(client, subnet.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update subnet: %v", err) + } + + // Get subnet + newSubnet, err := subnets.Get(client, subnet.ID).Extract() + if err != nil { + t.Fatalf("Unable to get subnet: %v", err) + } + + tools.PrintResource(t, newSubnet) +} + +func TestSubnetsDefaultGateway(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnetWithDefaultGateway(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + if subnet.GatewayIP == "" { + t.Fatalf("A default gateway was not created.") + } + + var noGateway = "" + updateOpts := subnets.UpdateOpts{ + GatewayIP: &noGateway, + } + + newSubnet, err := subnets.Update(client, subnet.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update subnet") + } + + if newSubnet.GatewayIP != "" { + t.Fatalf("Gateway was not updated correctly") + } +} + +func TestSubnetsNoGateway(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create Subnet + subnet, err := CreateSubnetWithNoGateway(t, client, network.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + if subnet.GatewayIP != "" { + t.Fatalf("A gateway exists when it shouldn't.") + } + + subnetParts := strings.Split(subnet.CIDR, ".") + newGateway := fmt.Sprintf("%s.%s.%s.1", subnetParts[0], subnetParts[1], subnetParts[2]) + updateOpts := subnets.UpdateOpts{ + GatewayIP: &newGateway, + } + + newSubnet, err := subnets.Update(client, subnet.ID, updateOpts).Extract() + if err != nil { + t.Fatalf("Unable to update subnet") + } + + if newSubnet.GatewayIP == "" { + t.Fatalf("Gateway was not updated correctly") + } +} + +func TestSubnetsWithSubnetPool(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create SubnetPool + subnetPool, err := subnetpools.CreateSubnetPool(t, client) + if err != nil { + t.Fatalf("Unable to create subnet pool: %v", err) + } + defer subnetpools.DeleteSubnetPool(t, client, subnetPool.ID) + + // Create Subnet + subnet, err := CreateSubnetWithSubnetPool(t, client, network.ID, subnetPool.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + if subnet.GatewayIP == "" { + t.Fatalf("A subnet pool was not associated.") + } +} + +func TestSubnetsWithSubnetPoolNoCIDR(t *testing.T) { + client, err := clients.NewNetworkV2Client() + if err != nil { + t.Fatalf("Unable to create a network client: %v", err) + } + + // Create Network + network, err := CreateNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create network: %v", err) + } + defer DeleteNetwork(t, client, network.ID) + + // Create SubnetPool + subnetPool, err := subnetpools.CreateSubnetPool(t, client) + if err != nil { + t.Fatalf("Unable to create subnet pool: %v", err) + } + defer subnetpools.DeleteSubnetPool(t, client, subnetPool.ID) + + // Create Subnet + subnet, err := CreateSubnetWithSubnetPoolNoCIDR(t, client, network.ID, subnetPool.ID) + if err != nil { + t.Fatalf("Unable to create subnet: %v", err) + } + defer DeleteSubnet(t, client, subnet.ID) + + tools.PrintResource(t, subnet) + + if subnet.GatewayIP == "" { + t.Fatalf("A subnet pool was not associated.") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/accounts_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/accounts_test.go new file mode 100644 index 00000000..bb9745f8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/accounts_test.go @@ -0,0 +1,55 @@ +// +build acceptance + +package v1 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestAccounts(t *testing.T) { + client, err := clients.NewObjectStorageV1Client() + if err != nil { + t.Fatalf("Unable to create client: %v", err) + } + + // Update an account's metadata. + metadata := map[string]string{ + "Gophercloud-Test": "accounts", + } + updateres := accounts.Update(client, accounts.UpdateOpts{Metadata: metadata}) + t.Logf("Update Account Response: %+v\n", updateres) + updateHeaders, err := updateres.Extract() + th.AssertNoErr(t, err) + t.Logf("Update Account Response Headers: %+v\n", updateHeaders) + + // Defer the deletion of the metadata set above. + defer func() { + tempMap := make(map[string]string) + for k := range metadata { + tempMap[k] = "" + } + updateres = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap}) + th.AssertNoErr(t, updateres.Err) + }() + + // Extract the custom metadata from the 'Get' response. + res := accounts.Get(client, nil) + + h, err := res.Extract() + th.AssertNoErr(t, err) + t.Logf("Get Account Response Headers: %+v\n", h) + + am, err := res.ExtractMetadata() + th.AssertNoErr(t, err) + for k := range metadata { + if am[k] != metadata[strings.Title(k)] { + t.Errorf("Expected custom metadata with key: %s", k) + return + } + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/containers_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/containers_test.go new file mode 100644 index 00000000..2b031941 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/containers_test.go @@ -0,0 +1,150 @@ +// +build acceptance + +package v1 + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +// numContainers is the number of containers to create for testing. +var numContainers = 2 + +func TestContainers(t *testing.T) { + client, err := clients.NewObjectStorageV1Client() + if err != nil { + t.Fatalf("Unable to create client: %v", err) + } + + // Create a slice of random container names. + cNames := make([]string, numContainers) + for i := 0; i < numContainers; i++ { + cNames[i] = tools.RandomString("gophercloud-test-container-", 8) + } + + // Create numContainers containers. + for i := 0; i < len(cNames); i++ { + res := containers.Create(client, cNames[i], nil) + th.AssertNoErr(t, res.Err) + } + // Delete the numContainers containers after function completion. + defer func() { + for i := 0; i < len(cNames); i++ { + res := containers.Delete(client, cNames[i]) + th.AssertNoErr(t, res.Err) + } + }() + + // List the numContainer names that were just created. To just list those, + // the 'prefix' parameter is used. + err = containers.List(client, &containers.ListOpts{Full: true, Prefix: "gophercloud-test-container-"}).EachPage(func(page pagination.Page) (bool, error) { + containerList, err := containers.ExtractInfo(page) + th.AssertNoErr(t, err) + + for _, n := range containerList { + t.Logf("Container: Name [%s] Count [%d] Bytes [%d]", + n.Name, n.Count, n.Bytes) + } + + return true, nil + }) + th.AssertNoErr(t, err) + + // List the info for the numContainer containers that were created. + err = containers.List(client, &containers.ListOpts{Full: false, Prefix: "gophercloud-test-container-"}).EachPage(func(page pagination.Page) (bool, error) { + containerList, err := containers.ExtractNames(page) + th.AssertNoErr(t, err) + for _, n := range containerList { + t.Logf("Container: Name [%s]", n) + } + + return true, nil + }) + th.AssertNoErr(t, err) + + // Update one of the numContainer container metadata. + metadata := map[string]string{ + "Gophercloud-Test": "containers", + } + + updateres := containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: metadata}) + th.AssertNoErr(t, updateres.Err) + // After the tests are done, delete the metadata that was set. + defer func() { + tempMap := make(map[string]string) + for k := range metadata { + tempMap[k] = "" + } + res := containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: tempMap}) + th.AssertNoErr(t, res.Err) + }() + + // Retrieve a container's metadata. + getOpts := containers.GetOpts{ + Newest: true, + } + + cm, err := containers.Get(client, cNames[0], getOpts).ExtractMetadata() + th.AssertNoErr(t, err) + for k := range metadata { + if cm[k] != metadata[strings.Title(k)] { + t.Errorf("Expected custom metadata with key: %s", k) + } + } +} + +func TestListAllContainers(t *testing.T) { + client, err := clients.NewObjectStorageV1Client() + if err != nil { + t.Fatalf("Unable to create client: %v", err) + } + + numContainers := 20 + + // Create a slice of random container names. + cNames := make([]string, numContainers) + for i := 0; i < numContainers; i++ { + cNames[i] = tools.RandomString("gophercloud-test-container-", 8) + } + + // Create numContainers containers. + for i := 0; i < len(cNames); i++ { + res := containers.Create(client, cNames[i], nil) + th.AssertNoErr(t, res.Err) + } + // Delete the numContainers containers after function completion. + defer func() { + for i := 0; i < len(cNames); i++ { + res := containers.Delete(client, cNames[i]) + th.AssertNoErr(t, res.Err) + } + }() + + // List all the numContainer names that were just created. To just list those, + // the 'prefix' parameter is used. + allPages, err := containers.List(client, &containers.ListOpts{Full: true, Limit: 5, Prefix: "gophercloud-test-container-"}).AllPages() + th.AssertNoErr(t, err) + containerInfoList, err := containers.ExtractInfo(allPages) + th.AssertNoErr(t, err) + for _, n := range containerInfoList { + t.Logf("Container: Name [%s] Count [%d] Bytes [%d]", + n.Name, n.Count, n.Bytes) + } + th.AssertEquals(t, numContainers, len(containerInfoList)) + + // List the info for all the numContainer containers that were created. + allPages, err = containers.List(client, &containers.ListOpts{Full: false, Limit: 2, Prefix: "gophercloud-test-container-"}).AllPages() + th.AssertNoErr(t, err) + containerNamesList, err := containers.ExtractNames(allPages) + th.AssertNoErr(t, err) + for _, n := range containerNamesList { + t.Logf("Container: Name [%s]", n) + } + th.AssertEquals(t, numContainers, len(containerNamesList)) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/objects_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/objects_test.go new file mode 100644 index 00000000..ed3def62 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/objectstorage/v1/objects_test.go @@ -0,0 +1,263 @@ +// +build acceptance + +package v1 + +import ( + "bytes" + "strings" + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" + th "github.com/gophercloud/gophercloud/testhelper" +) + +// numObjects is the number of objects to create for testing. +var numObjects = 2 + +func TestObjects(t *testing.T) { + client, err := clients.NewObjectStorageV1Client() + if err != nil { + t.Fatalf("Unable to create client: %v", err) + } + + // Make a slice of length numObjects to hold the random object names. + oNames := make([]string, numObjects) + for i := 0; i < len(oNames); i++ { + oNames[i] = tools.RandomString("test-object-", 8) + } + + // Create a container to hold the test objects. + cName := tools.RandomString("test-container-", 8) + header, err := containers.Create(client, cName, nil).Extract() + th.AssertNoErr(t, err) + t.Logf("Create object headers: %+v\n", header) + + // Defer deletion of the container until after testing. + defer func() { + res := containers.Delete(client, cName) + th.AssertNoErr(t, res.Err) + }() + + // Create a slice of buffers to hold the test object content. + oContents := make([]*bytes.Buffer, numObjects) + for i := 0; i < numObjects; i++ { + oContents[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10))) + createOpts := objects.CreateOpts{ + Content: oContents[i], + } + res := objects.Create(client, cName, oNames[i], createOpts) + th.AssertNoErr(t, res.Err) + } + // Delete the objects after testing. + defer func() { + for i := 0; i < numObjects; i++ { + res := objects.Delete(client, cName, oNames[i], nil) + th.AssertNoErr(t, res.Err) + } + }() + + // List all created objects + listOpts := objects.ListOpts{ + Full: true, + Prefix: "test-object-", + } + + allPages, err := objects.List(client, cName, listOpts).AllPages() + if err != nil { + t.Fatalf("Unable to list objects: %v", err) + } + + ons, err := objects.ExtractNames(allPages) + if err != nil { + t.Fatalf("Unable to extract objects: %v", err) + } + th.AssertEquals(t, len(ons), len(oNames)) + + ois, err := objects.ExtractInfo(allPages) + if err != nil { + t.Fatalf("Unable to extract object info: %v", err) + } + th.AssertEquals(t, len(ois), len(oNames)) + + // Copy the contents of one object to another. + copyOpts := objects.CopyOpts{ + Destination: cName + "/" + oNames[1], + } + copyres := objects.Copy(client, cName, oNames[0], copyOpts) + th.AssertNoErr(t, copyres.Err) + + // Download one of the objects that was created above. + downloadres := objects.Download(client, cName, oNames[0], nil) + th.AssertNoErr(t, downloadres.Err) + + o1Content, err := downloadres.ExtractContent() + th.AssertNoErr(t, err) + + // Download the another object that was create above. + downloadOpts := objects.DownloadOpts{ + Newest: true, + } + downloadres = objects.Download(client, cName, oNames[1], downloadOpts) + th.AssertNoErr(t, downloadres.Err) + o2Content, err := downloadres.ExtractContent() + th.AssertNoErr(t, err) + + // Compare the two object's contents to test that the copy worked. + th.AssertEquals(t, string(o2Content), string(o1Content)) + + // Update an object's metadata. + metadata := map[string]string{ + "Gophercloud-Test": "objects", + } + + updateOpts := objects.UpdateOpts{ + Metadata: metadata, + } + updateres := objects.Update(client, cName, oNames[0], updateOpts) + th.AssertNoErr(t, updateres.Err) + + // Delete the object's metadata after testing. + defer func() { + tempMap := make(map[string]string) + for k := range metadata { + tempMap[k] = "" + } + res := objects.Update(client, cName, oNames[0], &objects.UpdateOpts{Metadata: tempMap}) + th.AssertNoErr(t, res.Err) + }() + + // Retrieve an object's metadata. + getOpts := objects.GetOpts{ + Newest: true, + } + om, err := objects.Get(client, cName, oNames[0], getOpts).ExtractMetadata() + th.AssertNoErr(t, err) + for k := range metadata { + if om[k] != metadata[strings.Title(k)] { + t.Errorf("Expected custom metadata with key: %s", k) + return + } + } +} + +func TestObjectsListSubdir(t *testing.T) { + client, err := clients.NewObjectStorageV1Client() + if err != nil { + t.Fatalf("Unable to create client: %v", err) + } + + // Create a random subdirectory name. + cSubdir1 := tools.RandomString("test-subdir-", 8) + cSubdir2 := tools.RandomString("test-subdir-", 8) + + // Make a slice of length numObjects to hold the random object names. + oNames1 := make([]string, numObjects) + for i := 0; i < len(oNames1); i++ { + oNames1[i] = cSubdir1 + "/" + tools.RandomString("test-object-", 8) + } + + oNames2 := make([]string, numObjects) + for i := 0; i < len(oNames2); i++ { + oNames2[i] = cSubdir2 + "/" + tools.RandomString("test-object-", 8) + } + + // Create a container to hold the test objects. + cName := tools.RandomString("test-container-", 8) + _, err = containers.Create(client, cName, nil).Extract() + th.AssertNoErr(t, err) + + // Defer deletion of the container until after testing. + defer func() { + t.Logf("Deleting container %s", cName) + res := containers.Delete(client, cName) + th.AssertNoErr(t, res.Err) + }() + + // Create a slice of buffers to hold the test object content. + oContents1 := make([]*bytes.Buffer, numObjects) + for i := 0; i < numObjects; i++ { + oContents1[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10))) + createOpts := objects.CreateOpts{ + Content: oContents1[i], + } + res := objects.Create(client, cName, oNames1[i], createOpts) + th.AssertNoErr(t, res.Err) + } + // Delete the objects after testing. + defer func() { + for i := 0; i < numObjects; i++ { + t.Logf("Deleting object %s", oNames1[i]) + res := objects.Delete(client, cName, oNames1[i], nil) + th.AssertNoErr(t, res.Err) + } + }() + + oContents2 := make([]*bytes.Buffer, numObjects) + for i := 0; i < numObjects; i++ { + oContents2[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10))) + createOpts := objects.CreateOpts{ + Content: oContents2[i], + } + res := objects.Create(client, cName, oNames2[i], createOpts) + th.AssertNoErr(t, res.Err) + } + // Delete the objects after testing. + defer func() { + for i := 0; i < numObjects; i++ { + t.Logf("Deleting object %s", oNames2[i]) + res := objects.Delete(client, cName, oNames2[i], nil) + th.AssertNoErr(t, res.Err) + } + }() + + listOpts := objects.ListOpts{ + Full: true, + Delimiter: "/", + } + + allPages, err := objects.List(client, cName, listOpts).AllPages() + if err != nil { + t.Fatal(err) + } + + allObjects, err := objects.ExtractNames(allPages) + if err != nil { + t.Fatal(err) + } + + t.Logf("%#v\n", allObjects) + expected := []string{cSubdir1, cSubdir2} + for _, e := range expected { + var valid bool + for _, a := range allObjects { + if e+"/" == a { + valid = true + } + } + if !valid { + t.Fatalf("could not find %s in results", e) + } + } + + listOpts = objects.ListOpts{ + Full: true, + Delimiter: "/", + Prefix: cSubdir2, + } + + allPages, err = objects.List(client, cName, listOpts).AllPages() + if err != nil { + t.Fatal(err) + } + + allObjects, err = objects.ExtractNames(allPages) + if err != nil { + t.Fatal(err) + } + + th.AssertEquals(t, allObjects[0], cSubdir2+"/") + t.Logf("%#v\n", allObjects) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/buildinfo_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/buildinfo_test.go new file mode 100644 index 00000000..1b486629 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/buildinfo_test.go @@ -0,0 +1,20 @@ +// +build acceptance + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestBuildInfo(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + bi, err := buildinfo.Get(client).Extract() + th.AssertNoErr(t, err) + t.Logf("retrieved build info: %+v\n", bi) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackevents_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackevents_test.go new file mode 100644 index 00000000..4be4bf67 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackevents_test.go @@ -0,0 +1,68 @@ +// +build acceptance + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestStackEvents(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + stackName := "postman_stack_2" + resourceName := "hello_world" + var eventID string + + createOpts := stacks.CreateOpts{ + Name: stackName, + Template: template, + Timeout: 5, + } + stack, err := stacks.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("Created stack: %+v\n", stack) + defer func() { + err := stacks.Delete(client, stackName, stack.ID).ExtractErr() + th.AssertNoErr(t, err) + t.Logf("Deleted stack (%s)", stackName) + }() + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "CREATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + err = stackevents.List(client, stackName, stack.ID, nil).EachPage(func(page pagination.Page) (bool, error) { + events, err := stackevents.ExtractEvents(page) + th.AssertNoErr(t, err) + t.Logf("listed events: %+v\n", events) + eventID = events[0].ID + return false, nil + }) + th.AssertNoErr(t, err) + + err = stackevents.ListResourceEvents(client, stackName, stack.ID, resourceName, nil).EachPage(func(page pagination.Page) (bool, error) { + resourceEvents, err := stackevents.ExtractEvents(page) + th.AssertNoErr(t, err) + t.Logf("listed resource events: %+v\n", resourceEvents) + return false, nil + }) + th.AssertNoErr(t, err) + + event, err := stackevents.Get(client, stackName, stack.ID, resourceName, eventID).Extract() + th.AssertNoErr(t, err) + t.Logf("retrieved event: %+v\n", event) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackresources_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackresources_test.go new file mode 100644 index 00000000..50a0f063 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stackresources_test.go @@ -0,0 +1,62 @@ +// +build acceptance + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestStackResources(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + stackName := "postman_stack_2" + + createOpts := stacks.CreateOpts{ + Name: stackName, + Template: template, + Timeout: 5, + } + stack, err := stacks.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("Created stack: %+v\n", stack) + defer func() { + err := stacks.Delete(client, stackName, stack.ID).ExtractErr() + th.AssertNoErr(t, err) + t.Logf("Deleted stack (%s)", stackName) + }() + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "CREATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + resourceName := "hello_world" + resource, err := stackresources.Get(client, stackName, stack.ID, resourceName).Extract() + th.AssertNoErr(t, err) + t.Logf("Got stack resource: %+v\n", resource) + + metadata, err := stackresources.Metadata(client, stackName, stack.ID, resourceName).Extract() + th.AssertNoErr(t, err) + t.Logf("Got stack resource metadata: %+v\n", metadata) + + err = stackresources.List(client, stackName, stack.ID, stackresources.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + resources, err := stackresources.ExtractResources(page) + th.AssertNoErr(t, err) + t.Logf("resources: %+v\n", resources) + return false, nil + }) + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacks_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacks_test.go new file mode 100644 index 00000000..c87cc5d0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacks_test.go @@ -0,0 +1,153 @@ +// +build acceptance + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestStacks(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + stackName1 := "gophercloud-test-stack-2" + createOpts := stacks.CreateOpts{ + Name: stackName1, + Template: template, + Timeout: 5, + } + stack, err := stacks.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("Created stack: %+v\n", stack) + defer func() { + err := stacks.Delete(client, stackName1, stack.ID).ExtractErr() + th.AssertNoErr(t, err) + t.Logf("Deleted stack (%s)", stackName1) + }() + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "CREATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + updateOpts := stacks.UpdateOpts{ + Template: template, + Timeout: 20, + } + err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr() + th.AssertNoErr(t, err) + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "UPDATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + t.Logf("Updated stack") + + err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { + stackList, err := stacks.ExtractStacks(page) + th.AssertNoErr(t, err) + + t.Logf("Got stack list: %+v\n", stackList) + + return true, nil + }) + th.AssertNoErr(t, err) + + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("Got stack: %+v\n", getStack) + + abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("Abandonded stack %+v\n", abandonedStack) + th.AssertNoErr(t, err) +} + +// Test using the updated interface +func TestStacksNewTemplateFormat(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + stackName1 := "gophercloud-test-stack-2" + templateOpts := new(osStacks.Template) + templateOpts.Bin = []byte(template) + createOpts := osStacks.CreateOpts{ + Name: stackName1, + TemplateOpts: templateOpts, + Timeout: 5, + } + stack, err := stacks.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("Created stack: %+v\n", stack) + defer func() { + err := stacks.Delete(client, stackName1, stack.ID).ExtractErr() + th.AssertNoErr(t, err) + t.Logf("Deleted stack (%s)", stackName1) + }() + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "CREATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + updateOpts := osStacks.UpdateOpts{ + TemplateOpts: templateOpts, + Timeout: 20, + } + err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr() + th.AssertNoErr(t, err) + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "UPDATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + t.Logf("Updated stack") + + err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { + stackList, err := osStacks.ExtractStacks(page) + th.AssertNoErr(t, err) + + t.Logf("Got stack list: %+v\n", stackList) + + return true, nil + }) + th.AssertNoErr(t, err) + + getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("Got stack: %+v\n", getStack) + + abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("Abandonded stack %+v\n", abandonedStack) + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacktemplates_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacktemplates_test.go new file mode 100644 index 00000000..9992e0c0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/orchestration/v1/stacktemplates_test.go @@ -0,0 +1,75 @@ +// +build acceptance + +package v1 + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestStackTemplates(t *testing.T) { + // Create a provider client for making the HTTP requests. + // See common.go in this directory for more information. + client := newClient(t) + + stackName := "postman_stack_2" + + createOpts := stacks.CreateOpts{ + Name: stackName, + Template: template, + Timeout: 5, + } + stack, err := stacks.Create(client, createOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("Created stack: %+v\n", stack) + defer func() { + err := stacks.Delete(client, stackName, stack.ID).ExtractErr() + th.AssertNoErr(t, err) + t.Logf("Deleted stack (%s)", stackName) + }() + err = gophercloud.WaitFor(60, func() (bool, error) { + getStack, err := stacks.Get(client, stackName, stack.ID).Extract() + if err != nil { + return false, err + } + if getStack.Status == "CREATE_COMPLETE" { + return true, nil + } + return false, nil + }) + + tmpl, err := stacktemplates.Get(client, stackName, stack.ID).Extract() + th.AssertNoErr(t, err) + t.Logf("retrieved template: %+v\n", tmpl) + + validateOpts := osStacktemplates.ValidateOpts{ + Template: `{"heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string", + }, + }, + "resources": { + "hello_world": { + "type": "OS::Nova::Server", + "properties": { + "key_name": "heat_key", + "flavor": { + "get_param": "flavor", + }, + "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", + "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n", + }, + }, + }, + }`} + validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract() + th.AssertNoErr(t, err) + t.Logf("validated template: %+v\n", validatedTemplate) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/availabilityzones_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/availabilityzones_test.go new file mode 100644 index 00000000..8841160a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/availabilityzones_test.go @@ -0,0 +1,29 @@ +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones" +) + +func TestAvailabilityZonesList(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + allPages, err := availabilityzones.List(client).AllPages() + if err != nil { + t.Fatalf("Unable to list availability zones: %v", err) + } + + zones, err := availabilityzones.ExtractAvailabilityZones(allPages) + if err != nil { + t.Fatalf("Unable to extract availability zones: %v", err) + } + + if len(zones) == 0 { + t.Fatal("At least one availability zone was expected to be found") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go new file mode 100644 index 00000000..ecf8cc9a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go @@ -0,0 +1,142 @@ +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" +) + +func TestSecurityServiceCreateDelete(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + securityService, err := CreateSecurityService(t, client) + if err != nil { + t.Fatalf("Unable to create security service: %v", err) + } + + newSecurityService, err := securityservices.Get(client, securityService.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve the security service: %v", err) + } + + if newSecurityService.Name != securityService.Name { + t.Fatalf("Security service name was expeted to be: %s", securityService.Name) + } + + PrintSecurityService(t, securityService) + + defer DeleteSecurityService(t, client, securityService) +} + +func TestSecurityServiceList(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + allPages, err := securityservices.List(client, securityservices.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve security services: %v", err) + } + + allSecurityServices, err := securityservices.ExtractSecurityServices(allPages) + if err != nil { + t.Fatalf("Unable to extract security services: %v", err) + } + + for _, securityService := range allSecurityServices { + PrintSecurityService(t, &securityService) + } +} + +// The test creates 2 security services and verifies that only the one(s) with +// a particular name are being listed +func TestSecurityServiceListFiltering(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + securityService, err := CreateSecurityService(t, client) + if err != nil { + t.Fatalf("Unable to create security service: %v", err) + } + defer DeleteSecurityService(t, client, securityService) + + securityService, err = CreateSecurityService(t, client) + if err != nil { + t.Fatalf("Unable to create security service: %v", err) + } + defer DeleteSecurityService(t, client, securityService) + + options := securityservices.ListOpts{ + Name: securityService.Name, + } + + allPages, err := securityservices.List(client, options).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve security services: %v", err) + } + + allSecurityServices, err := securityservices.ExtractSecurityServices(allPages) + if err != nil { + t.Fatalf("Unable to extract security services: %v", err) + } + + for _, listedSecurityService := range allSecurityServices { + if listedSecurityService.Name != securityService.Name { + t.Fatalf("The name of the security service was expected to be %s", securityService.Name) + } + PrintSecurityService(t, &listedSecurityService) + } +} + +// Create a security service and update the name and description. Get the security +// service and verify that the name and description have been updated +func TestSecurityServiceUpdate(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + securityService, err := CreateSecurityService(t, client) + if err != nil { + t.Fatalf("Unable to create security service: %v", err) + } + + options := securityservices.UpdateOpts{ + Name: "NewName", + Description: "New security service description", + Type: "ldap", + } + + _, err = securityservices.Update(client, securityService.ID, options).Extract() + if err != nil { + t.Errorf("Unable to update the security service: %v", err) + } + + newSecurityService, err := securityservices.Get(client, securityService.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve the security service: %v", err) + } + + if newSecurityService.Name != options.Name { + t.Fatalf("Security service name was expeted to be: %s", options.Name) + } + + if newSecurityService.Description != options.Description { + t.Fatalf("Security service description was expeted to be: %s", options.Description) + } + + if newSecurityService.Type != options.Type { + t.Fatalf("Security service type was expected to be: %s", options.Type) + } + + PrintSecurityService(t, securityService) + + defer DeleteSecurityService(t, client, securityService) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go new file mode 100644 index 00000000..7bf760f8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go @@ -0,0 +1,223 @@ +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestShareNetworkCreateDestroy(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + shareNetwork, err := CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + + newShareNetwork, err := sharenetworks.Get(client, shareNetwork.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve shareNetwork: %v", err) + } + + if newShareNetwork.Name != shareNetwork.Name { + t.Fatalf("Share network name was expeted to be: %s", shareNetwork.Name) + } + + PrintShareNetwork(t, shareNetwork) + + defer DeleteShareNetwork(t, client, shareNetwork) +} + +// Create a share network and update the name and description. Get the share +// network and verify that the name and description have been updated +func TestShareNetworkUpdate(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + shareNetwork, err := CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + + expectedShareNetwork, err := sharenetworks.Get(client, shareNetwork.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve shareNetwork: %v", err) + } + + options := sharenetworks.UpdateOpts{ + Name: "NewName", + Description: "New share network description", + } + + expectedShareNetwork.Name = options.Name + expectedShareNetwork.Description = options.Description + + _, err = sharenetworks.Update(client, shareNetwork.ID, options).Extract() + if err != nil { + t.Errorf("Unable to update shareNetwork: %v", err) + } + + updatedShareNetwork, err := sharenetworks.Get(client, shareNetwork.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve shareNetwork: %v", err) + } + + // Update time has to be set in order to get the assert equal to pass + expectedShareNetwork.UpdatedAt = updatedShareNetwork.UpdatedAt + + th.CheckDeepEquals(t, expectedShareNetwork, updatedShareNetwork) + + PrintShareNetwork(t, shareNetwork) + + defer DeleteShareNetwork(t, client, shareNetwork) +} + +func TestShareNetworkListDetail(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + allPages, err := sharenetworks.ListDetail(client, sharenetworks.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve share networks: %v", err) + } + + allShareNetworks, err := sharenetworks.ExtractShareNetworks(allPages) + if err != nil { + t.Fatalf("Unable to extract share networks: %v", err) + } + + for _, shareNetwork := range allShareNetworks { + PrintShareNetwork(t, &shareNetwork) + } +} + +// The test creates 2 shared networks and verifies that only the one(s) with +// a particular name are being listed +func TestShareNetworkListFiltering(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + shareNetwork, err := CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + defer DeleteShareNetwork(t, client, shareNetwork) + + shareNetwork, err = CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + defer DeleteShareNetwork(t, client, shareNetwork) + + options := sharenetworks.ListOpts{ + Name: shareNetwork.Name, + } + + allPages, err := sharenetworks.ListDetail(client, options).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve share networks: %v", err) + } + + allShareNetworks, err := sharenetworks.ExtractShareNetworks(allPages) + if err != nil { + t.Fatalf("Unable to extract share networks: %v", err) + } + + for _, listedShareNetwork := range allShareNetworks { + if listedShareNetwork.Name != shareNetwork.Name { + t.Fatalf("The name of the share network was expected to be %s", shareNetwork.Name) + } + PrintShareNetwork(t, &listedShareNetwork) + } +} + +func TestShareNetworkListPagination(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + shareNetwork, err := CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + defer DeleteShareNetwork(t, client, shareNetwork) + + shareNetwork, err = CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + defer DeleteShareNetwork(t, client, shareNetwork) + + count := 0 + + err = sharenetworks.ListDetail(client, sharenetworks.ListOpts{Offset: 0, Limit: 1}).EachPage(func(page pagination.Page) (bool, error) { + count++ + _, err := sharenetworks.ExtractShareNetworks(page) + if err != nil { + t.Fatalf("Failed to extract share networks: %v", err) + return false, err + } + + return true, nil + }) + if err != nil { + t.Fatalf("Unable to retrieve share networks: %v", err) + } + + if count < 2 { + t.Fatal("Expected to get at least 2 pages") + } + +} + +func TestShareNetworkAddRemoveSecurityService(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + securityService, err := CreateSecurityService(t, client) + if err != nil { + t.Fatalf("Unable to create security service: %v", err) + } + defer DeleteSecurityService(t, client, securityService) + + shareNetwork, err := CreateShareNetwork(t, client) + if err != nil { + t.Fatalf("Unable to create share network: %v", err) + } + defer DeleteShareNetwork(t, client, shareNetwork) + + options := sharenetworks.AddSecurityServiceOpts{ + SecurityServiceID: securityService.ID, + } + + _, err = sharenetworks.AddSecurityService(client, shareNetwork.ID, options).Extract() + if err != nil { + t.Errorf("Unable to add security service: %v", err) + } + + removeOptions := sharenetworks.RemoveSecurityServiceOpts{ + SecurityServiceID: securityService.ID, + } + + _, err = sharenetworks.RemoveSecurityService(client, shareNetwork.ID, removeOptions).Extract() + if err != nil { + t.Errorf("Unable to remove security service: %v", err) + } + + PrintShareNetwork(t, shareNetwork) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares.go index 82f2f8d1..0bd55089 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares.go @@ -43,6 +43,41 @@ func CreateShare(t *testing.T, client *gophercloud.ServiceClient) (*shares.Share return share, nil } +// ListShares lists all shares that belong to this tenant's project. +// An error will be returned if the shares could not be listed.. +func ListShares(t *testing.T, client *gophercloud.ServiceClient) ([]shares.Share, error) { + r, err := shares.ListDetail(client, &shares.ListOpts{}).AllPages() + if err != nil { + return nil, err + } + + return shares.ExtractShares(r) +} + +// GrantAccess will grant access to an existing share. A fatal error will occur if +// this operation fails. +func GrantAccess(t *testing.T, client *gophercloud.ServiceClient, share *shares.Share) (*shares.AccessRight, error) { + return shares.GrantAccess(client, share.ID, shares.GrantAccessOpts{ + AccessType: "ip", + AccessTo: "0.0.0.0/32", + AccessLevel: "r", + }).Extract() +} + +// RevokeAccess will revoke an exisiting access of a share. A fatal error will occur +// if this operation fails. +func RevokeAccess(t *testing.T, client *gophercloud.ServiceClient, share *shares.Share, accessRight *shares.AccessRight) error { + return shares.RevokeAccess(client, share.ID, shares.RevokeAccessOpts{ + AccessID: accessRight.ID, + }).ExtractErr() +} + +// GetAccessRightsSlice will retrieve all access rules assigned to a share. +// A fatal error will occur if this operation fails. +func GetAccessRightsSlice(t *testing.T, client *gophercloud.ServiceClient, share *shares.Share) ([]shares.AccessRight, error) { + return shares.ListAccessRights(client, share.ID).Extract() +} + // DeleteShare will delete a share. A fatal error will occur if the share // failed to be deleted. This works best when used as a deferred function. func DeleteShare(t *testing.T, client *gophercloud.ServiceClient, share *shares.Share) { @@ -64,6 +99,16 @@ func PrintShare(t *testing.T, share *shares.Share) { t.Logf("Share %s", string(asJSON)) } +// PrintAccessRight prints contents of an access rule +func PrintAccessRight(t *testing.T, accessRight *shares.AccessRight) { + asJSON, err := json.MarshalIndent(accessRight, "", " ") + if err != nil { + t.Logf("Cannot print access rule") + } + + t.Logf("Access rule %s", string(asJSON)) +} + func waitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { return gophercloud.WaitFor(secs, func() (bool, error) { current, err := shares.Get(c, id).Extract() diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares_test.go new file mode 100644 index 00000000..7aea6d0e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/shares_test.go @@ -0,0 +1,110 @@ +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" +) + +func TestShareCreate(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a sharedfs client: %v", err) + } + + share, err := CreateShare(t, client) + if err != nil { + t.Fatalf("Unable to create a share: %v", err) + } + + defer DeleteShare(t, client, share) + + created, err := shares.Get(client, share.ID).Extract() + if err != nil { + t.Errorf("Unable to retrieve share: %v", err) + } + PrintShare(t, created) +} + +func TestShareListDetail(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a sharedfs client: %v", err) + } + + share, err := CreateShare(t, client) + if err != nil { + t.Fatalf("Unable to create a share: %v", err) + } + + defer DeleteShare(t, client, share) + + ss, err := ListShares(t, client) + if err != nil { + t.Fatalf("Unable to list shares: %v", err) + } + + for i := range ss { + PrintShare(t, &ss[i]) + } +} + +func TestGrantAndRevokeAccess(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a sharedfs client: %v", err) + } + + share, err := CreateShare(t, client) + if err != nil { + t.Fatalf("Unable to create a share: %v", err) + } + + defer DeleteShare(t, client, share) + + accessRight, err := GrantAccess(t, client, share) + if err != nil { + t.Fatalf("Unable to grant access: %v", err) + } + + PrintAccessRight(t, accessRight) + + if err = RevokeAccess(t, client, share, accessRight); err != nil { + t.Fatalf("Unable to revoke access: %v", err) + } +} + +func TestListAccessRights(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a sharedfs client: %v", err) + } + + share, err := CreateShare(t, client) + if err != nil { + t.Fatalf("Unable to create a share: %v", err) + } + + defer DeleteShare(t, client, share) + + _, err = GrantAccess(t, client, share) + if err != nil { + t.Fatalf("Unable to grant access: %v", err) + } + + rs, err := GetAccessRightsSlice(t, client, share) + if err != nil { + t.Fatalf("Unable to retrieve list of access rules for share %s: %v", share.ID, err) + } + + if len(rs) != 1 { + t.Fatalf("Unexpected number of access rules for share %s: got %d, expected 1", share.ID, len(rs)) + } + + t.Logf("Share %s has %d access rule(s):", share.ID, len(rs)) + + for _, r := range rs { + PrintAccessRight(t, &r) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go new file mode 100644 index 00000000..9efe0359 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go @@ -0,0 +1,162 @@ +package v2 + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/clients" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes" +) + +func TestShareTypeCreateDestroy(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + shareType, err := CreateShareType(t, client) + if err != nil { + t.Fatalf("Unable to create share type: %v", err) + } + + PrintShareType(t, shareType) + + defer DeleteShareType(t, client, shareType) +} + +func TestShareTypeList(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + allPages, err := sharetypes.List(client, sharetypes.ListOpts{}).AllPages() + if err != nil { + t.Fatalf("Unable to retrieve share types: %v", err) + } + + allShareTypes, err := sharetypes.ExtractShareTypes(allPages) + if err != nil { + t.Fatalf("Unable to extract share types: %v", err) + } + + for _, shareType := range allShareTypes { + PrintShareType(t, &shareType) + } +} + +func TestShareTypeGetDefault(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create a shared file system client: %v", err) + } + + shareType, err := sharetypes.GetDefault(client).Extract() + if err != nil { + t.Fatalf("Unable to retrieve the default share type: %v", err) + } + + PrintShareType(t, shareType) +} + +func TestShareTypeExtraSpecs(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + shareType, err := CreateShareType(t, client) + if err != nil { + t.Fatalf("Unable to create share type: %v", err) + } + + options := sharetypes.SetExtraSpecsOpts{ + ExtraSpecs: map[string]interface{}{"my_new_key": "my_value"}, + } + + _, err = sharetypes.SetExtraSpecs(client, shareType.ID, options).Extract() + if err != nil { + t.Fatalf("Unable to set extra specs for Share type: %s", shareType.Name) + } + + extraSpecs, err := sharetypes.GetExtraSpecs(client, shareType.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve share type: %s", shareType.Name) + } + + if extraSpecs["driver_handles_share_servers"] != "True" { + t.Fatal("driver_handles_share_servers was expected to be true") + } + + if extraSpecs["my_new_key"] != "my_value" { + t.Fatal("my_new_key was expected to be equal to my_value") + } + + err = sharetypes.UnsetExtraSpecs(client, shareType.ID, "my_new_key").ExtractErr() + if err != nil { + t.Fatalf("Unable to unset extra specs for Share type: %s", shareType.Name) + } + + extraSpecs, err = sharetypes.GetExtraSpecs(client, shareType.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve share type: %s", shareType.Name) + } + + if _, ok := extraSpecs["my_new_key"]; ok { + t.Fatalf("my_new_key was expected to be unset for Share type: %s", shareType.Name) + } + + PrintShareType(t, shareType) + + defer DeleteShareType(t, client, shareType) +} + +func TestShareTypeAccess(t *testing.T) { + client, err := clients.NewSharedFileSystemV2Client() + if err != nil { + t.Fatalf("Unable to create shared file system client: %v", err) + } + + shareType, err := CreateShareType(t, client) + if err != nil { + t.Fatalf("Unable to create share type: %v", err) + } + + options := sharetypes.AccessOpts{ + Project: "9e3a5a44e0134445867776ef53a37605", + } + + err = sharetypes.AddAccess(client, shareType.ID, options).ExtractErr() + if err != nil { + t.Fatalf("Unable to add a new access to a share type: %v", err) + } + + access, err := sharetypes.ShowAccess(client, shareType.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve the access details for a share type: %v", err) + } + + expected := []sharetypes.ShareTypeAccess{{ShareTypeID: shareType.ID, ProjectID: options.Project}} + + if access[0] != expected[0] { + t.Fatal("Share type access is not the same than expected") + } + + err = sharetypes.RemoveAccess(client, shareType.ID, options).ExtractErr() + if err != nil { + t.Fatalf("Unable to remove an access from a share type: %v", err) + } + + access, err = sharetypes.ShowAccess(client, shareType.ID).Extract() + if err != nil { + t.Fatalf("Unable to retrieve the access details for a share type: %v", err) + } + + if len(access) > 0 { + t.Fatalf("No access should be left for the share type: %s", shareType.Name) + } + + PrintShareType(t, shareType) + + defer DeleteShareType(t, client, shareType) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/auth_options.go b/discovery/vendor/github.com/gophercloud/gophercloud/auth_options.go index 42114700..5e693585 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/auth_options.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/auth_options.go @@ -81,6 +81,17 @@ type AuthOptions struct { // TokenID allows users to authenticate (possibly as another user) with an // authentication token ID. TokenID string `json:"-"` + + // Scope determines the scoping of the authentication request. + Scope *AuthScope `json:"-"` +} + +// AuthScope allows a created token to be limited to a specific domain or project. +type AuthScope struct { + ProjectID string + ProjectName string + DomainID string + DomainName string } // ToTokenV2CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder @@ -263,85 +274,83 @@ func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]interface{}) (map[s } func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) { - - var scope struct { - ProjectID string - ProjectName string - DomainID string - DomainName string - } - - if opts.TenantID != "" { - scope.ProjectID = opts.TenantID - } else { - if opts.TenantName != "" { - scope.ProjectName = opts.TenantName - scope.DomainID = opts.DomainID - scope.DomainName = opts.DomainName + // For backwards compatibility. + // If AuthOptions.Scope was not set, try to determine it. + // This works well for common scenarios. + if opts.Scope == nil { + opts.Scope = new(AuthScope) + if opts.TenantID != "" { + opts.Scope.ProjectID = opts.TenantID + } else { + if opts.TenantName != "" { + opts.Scope.ProjectName = opts.TenantName + opts.Scope.DomainID = opts.DomainID + opts.Scope.DomainName = opts.DomainName + } } } - if scope.ProjectName != "" { + if opts.Scope.ProjectName != "" { // ProjectName provided: either DomainID or DomainName must also be supplied. // ProjectID may not be supplied. - if scope.DomainID == "" && scope.DomainName == "" { + if opts.Scope.DomainID == "" && opts.Scope.DomainName == "" { return nil, ErrScopeDomainIDOrDomainName{} } - if scope.ProjectID != "" { + if opts.Scope.ProjectID != "" { return nil, ErrScopeProjectIDOrProjectName{} } - if scope.DomainID != "" { + if opts.Scope.DomainID != "" { // ProjectName + DomainID return map[string]interface{}{ "project": map[string]interface{}{ - "name": &scope.ProjectName, - "domain": map[string]interface{}{"id": &scope.DomainID}, + "name": &opts.Scope.ProjectName, + "domain": map[string]interface{}{"id": &opts.Scope.DomainID}, }, }, nil } - if scope.DomainName != "" { + if opts.Scope.DomainName != "" { // ProjectName + DomainName return map[string]interface{}{ "project": map[string]interface{}{ - "name": &scope.ProjectName, - "domain": map[string]interface{}{"name": &scope.DomainName}, + "name": &opts.Scope.ProjectName, + "domain": map[string]interface{}{"name": &opts.Scope.DomainName}, }, }, nil } - } else if scope.ProjectID != "" { + } else if opts.Scope.ProjectID != "" { // ProjectID provided. ProjectName, DomainID, and DomainName may not be provided. - if scope.DomainID != "" { + if opts.Scope.DomainID != "" { return nil, ErrScopeProjectIDAlone{} } - if scope.DomainName != "" { + if opts.Scope.DomainName != "" { return nil, ErrScopeProjectIDAlone{} } // ProjectID return map[string]interface{}{ "project": map[string]interface{}{ - "id": &scope.ProjectID, + "id": &opts.Scope.ProjectID, }, }, nil - } else if scope.DomainID != "" { + } else if opts.Scope.DomainID != "" { // DomainID provided. ProjectID, ProjectName, and DomainName may not be provided. - if scope.DomainName != "" { + if opts.Scope.DomainName != "" { return nil, ErrScopeDomainIDOrDomainName{} } // DomainID return map[string]interface{}{ "domain": map[string]interface{}{ - "id": &scope.DomainID, + "id": &opts.Scope.DomainID, }, }, nil - } else if scope.DomainName != "" { + } else if opts.Scope.DomainName != "" { // DomainName return map[string]interface{}{ "domain": map[string]interface{}{ - "name": &scope.DomainName, + "name": &opts.Scope.DomainName, }, }, nil } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/FAQ.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/FAQ.md similarity index 100% rename from discovery/vendor/github.com/gophercloud/gophercloud/FAQ.md rename to discovery/vendor/github.com/gophercloud/gophercloud/docs/FAQ.md diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/MIGRATING.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/MIGRATING.md similarity index 95% rename from discovery/vendor/github.com/gophercloud/gophercloud/MIGRATING.md rename to discovery/vendor/github.com/gophercloud/gophercloud/docs/MIGRATING.md index aa383c9c..ef1a2bb9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/MIGRATING.md +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/MIGRATING.md @@ -16,7 +16,7 @@ * `servers.Reboot` now requires a `servers.RebootOpts` struct: ```golang - rebootOpts := &servers.RebootOpts{ + rebootOpts := servers.RebootOpts{ Type: servers.SoftReboot, } res := servers.Reboot(client, server.ID, rebootOpts) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/STYLEGUIDE.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/STYLEGUIDE.md similarity index 100% rename from discovery/vendor/github.com/gophercloud/gophercloud/STYLEGUIDE.md rename to discovery/vendor/github.com/gophercloud/gophercloud/docs/STYLEGUIDE.md diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/assets/openlab.png b/discovery/vendor/github.com/gophercloud/gophercloud/docs/assets/openlab.png similarity index 100% rename from discovery/vendor/github.com/gophercloud/gophercloud/assets/openlab.png rename to discovery/vendor/github.com/gophercloud/gophercloud/docs/assets/openlab.png diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/assets/vexxhost.png b/discovery/vendor/github.com/gophercloud/gophercloud/docs/assets/vexxhost.png similarity index 100% rename from discovery/vendor/github.com/gophercloud/gophercloud/assets/vexxhost.png rename to discovery/vendor/github.com/gophercloud/gophercloud/docs/assets/vexxhost.png diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/doc.go new file mode 100644 index 00000000..bbf39c54 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/doc.go @@ -0,0 +1,13 @@ +/* +Package NAME manages and retrieves RESOURCE in the OpenStack SERVICE Service. + +Example to List RESOURCE + +Example to Create a RESOURCE + +Example to Update a RESOURCE + +Example to Delete a RESOURCE + +*/ +package RESOURCE diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/requests.go new file mode 100644 index 00000000..1c4bb4d3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/requests.go @@ -0,0 +1,105 @@ +package RESOURCE + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request +type ListOptsBuilder interface { + ToResourceListQuery() (string, error) +} + +// ListOpts provides options to filter the List results. +type ListOpts struct { +} + +// ToResourceListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToResourceListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List retrieves a list of RESOURCES. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToResourceListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ResourcePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves details of a RESOURCE. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} + +// CreateOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateOptsBuilder interface { + ToResourceCreateMap() (map[string]interface{}, error) +} + +// CreateOpts provides options used to create a RESOURCE. +type CreateOpts struct { +} + +// ToResourceCreateMap formats a CreateOpts into a create request. +func (opts CreateOpts) ToResourceCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "resource") +} + +// Create creates a new RESOURCE. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToResourceCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// Delete deletes a RESOURCE. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to +// the Update request. +type UpdateOptsBuilder interface { + ToResourceUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents parameters to update a RESOURCE. +type UpdateOpts struct { +} + +// ToUpdateCreateMap formats a UpdateOpts into an update request. +func (opts UpdateOpts) ToResourceUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "resource") +} + +// Update modifies the attributes of a RESOURCE. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToResourceUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/results.go new file mode 100644 index 00000000..88272e1e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/results.go @@ -0,0 +1,83 @@ +package RESOURCE + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// RESOURCE represents... +type Resource struct { +} + +type commonResult struct { + gophercloud.Result +} + +// GetResult is the response from a Get operation. Call its Extract method +// to interpret it as a RESOURCE. +type GetResult struct { + commonResult +} + +// CreateResult is the response from a Create operation. Call its Extract method +// to interpret it as a RESOURCE. +type CreateResult struct { + commonResult +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult is the result of an Update request. Call its Extract method to +// interpret it as a RESOURCE. +type UpdateResult struct { + commonResult +} + +// ResourcePage is a single page of RESOURCE results. +type ResourcePage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of RESOURCES contains any results. +func (r ResourcePage) IsEmpty() (bool, error) { + resources, err := ExtractResources(r) + return len(resources) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r ResourcePage) NextPageURL() (string, error) { + var s struct { + Links struct { + Next string `json:"next"` + Previous string `json:"previous"` + } `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Links.Next, err +} + +// ExtractResources returns a slice of Resources contained in a single page of +// results. +func ExtractResources(r pagination.Page) ([]Resource, error) { + var s struct { + Resources []Resource `json:"resources"` + } + err := (r.(ResourcePage)).ExtractInto(&s) + return s.Resources, err +} + +// Extract interprets any commonResult as a Resource. +func (r commonResult) Extract() (*Resource, error) { + var s struct { + Resource *Resource `json:"resource"` + } + err := r.ExtractInto(&s) + return s.Resource, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/fixtures.go new file mode 100644 index 00000000..66e2a202 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/fixtures.go @@ -0,0 +1,118 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/service/vN/resources" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListResult provides a single page of RESOURCE results. +const ListResult = ` +{ +} +` + +// GetResult provides a Get result. +const GetResult = ` +{ +} +` + +// CreateRequest provides the input to a Create request. +const CreateRequest = ` +{ +} +` + +// UpdateRequest provides the input to as Update request. +const UpdateRequest = ` +{ +} +` + +// UpdateResult provides an update result. +const UpdateResult = ` +{ +} +` + +// FirstResource is the first resource in the List request. +var FirstResource = resources.Resource{} + +// SecondResource is the second resource in the List request. +var SecondResource = resources.Resource{} + +// SecondResourceUpdated is how SecondResource should look after an Update. +var SecondResourceUpdated = resources.Resource{} + +// ExpectedResourcesSlice is the slice of resources expected to be returned from ListResult. +var ExpectedResourcesSlice = []resources.Resource{FirstResource, SecondResource} + +// HandleListResourceSuccessfully creates an HTTP handler at `/resources` on the +// test handler mux that responds with a list of two resources. +func HandleListResourceSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/resources", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResult) + }) +} + +// HandleGetResourceSuccessfully creates an HTTP handler at `/resources` on the +// test handler mux that responds with a single resource. +func HandleGetResourceSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResult) + }) +} + +// HandleCreateResourceSuccessfully creates an HTTP handler at `/resources` on the +// test handler mux that tests resource creation. +func HandleCreateResourceSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/resources", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateRequest) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, GetResult) + }) +} + +// HandleDeleteResourceSuccessfully creates an HTTP handler at `/resources` on the +// test handler mux that tests resource deletion. +func HandleDeleteResourceSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleUpdateResourceSuccessfully creates an HTTP handler at `/resources` on the +// test handler mux that tests resource update. +func HandleUpdateResourceSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, UpdateRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, UpdateResult) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/requests_test.go new file mode 100644 index 00000000..22f97a22 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/testing/requests_test.go @@ -0,0 +1,89 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/service/vN/resources" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListResources(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListResourcesSuccessfully(t) + + count := 0 + err := resources.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := resources.ExtractResources(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedResourcesSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestListResourcesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListResourcesSuccessfully(t) + + allPages, err := resources.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := resources.ExtractResources(allPages) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedResourcesSlice, actual) +} + +func TestGetResource(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetResourceSuccessfully(t) + + actual, err := resources.Get(client.ServiceClient(), "9fe1d3").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, SecondResource, *actual) +} + +func TestCreateResource(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateResourceSuccessfully(t) + + createOpts := resources.CreateOpts{ + Name: "resource two", + } + + actual, err := resources.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, SecondResource, *actual) +} + +func TestDeleteResource(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteResourceSuccessfully(t) + + res := resources.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateResource(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateResourceSuccessfully(t) + + updateOpts := resources.UpdateOpts{ + Description: "Staging Resource", + } + + actual, err := resources.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, SecondResourceUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/urls.go new file mode 100644 index 00000000..603b8124 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/.template/urls.go @@ -0,0 +1,23 @@ +package RESOURCE + +import "github.com/gophercloud/gophercloud" + +func listURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("resource") +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("resource", id) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("resource") +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("resource", id) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("resource", id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/README.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/README.md new file mode 100644 index 00000000..14950b2b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/README.md @@ -0,0 +1,12 @@ +Contributor Tutorial +==================== + +This tutorial is to help new contributors become familiar with the processes +used by the Gophercloud team when adding a new feature or fixing a bug. + +While we have a defined process for working on Gophercloud, we're very mindful +that everyone is new to this in the beginning. Please reach out for help or ask +for clarification if needed. No question is ever "dumb" or not worth our time +answering. + +To begin, go to [Step 1](step-01-introduction.md). diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-01-introduction.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-01-introduction.md new file mode 100644 index 00000000..d806143d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-01-introduction.md @@ -0,0 +1,16 @@ +Step 1: Read Our Guides +======================== + +There are two introductory guides you should read before proceeding: + +* [CONTRIBUTING](/.github/CONTRIBUTING.md): The Contributing guide is a detailed + document which describes the different ways you can contribute to Gophercloud + and how to get started. This tutorial you're reading is very similar to that + guide, but presented in a different way. We still recommend you read it over. + +* [STYLE](/docs/STYLEGUIDE.md): The Style Guide documents coding conventions used + in the Gophercloud project. + +--- + +When you've finished reading those guides, proceed to [Step 2](step-02-issues.md). diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-02-issues.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-02-issues.md new file mode 100644 index 00000000..a3ae2a23 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-02-issues.md @@ -0,0 +1,124 @@ +Step 2: Create an Issue +======================== + +Every patch / Pull Request requires a corresponding issue. If you're fixing +a bug for an existing issue, then there's no need to create a new issue. + +However, if no prior issue exists, you must create an issue. + +Reporting a Bug +--------------- + +When reporting a bug, please try to provide as much information as you +can. + +The following issues are good examples for reporting a bug: + +* https://github.com/gophercloud/gophercloud/issues/108 +* https://github.com/gophercloud/gophercloud/issues/212 +* https://github.com/gophercloud/gophercloud/issues/424 +* https://github.com/gophercloud/gophercloud/issues/588 +* https://github.com/gophercloud/gophercloud/issues/629 +* https://github.com/gophercloud/gophercloud/issues/647 + +Feature Request +--------------- + +If you've noticed that a feature is missing from Gophercloud, you'll also +need to create an issue before doing any work. This is start a discussion about +whether or not the feature should be included in Gophercloud. We don't want to +want to see you put in hours of work only to learn that the feature is out of +scope of the project. + +Feature requests can come in different forms: + +### Adding a Feature to Gophercloud Core + +The "core" of Gophercloud is the code which supports API requests and +responses: pagination, error handling, building request bodies, and parsing +response bodies are all examples of core code. + +Modifications to core will usually have the most amount of discussion than +other requests since a change to core will affect _all_ of Gophercloud. + +The following issues are examples of core change discussions: + +* https://github.com/gophercloud/gophercloud/issues/310 +* https://github.com/gophercloud/gophercloud/issues/613 +* https://github.com/gophercloud/gophercloud/issues/729 +* https://github.com/gophercloud/gophercloud/issues/713 + +### Adding a Missing Field + +If you've found a missing field in an existing struct, submit an issue to +request having it added. These kinds of issues are pretty easy to report +and resolve. + +You should also provide a link to the actual service's Python code which +defines the missing field. + +The following issues are examples of missing fields: + +* https://github.com/gophercloud/gophercloud/issues/620 +* https://github.com/gophercloud/gophercloud/issues/621 +* https://github.com/gophercloud/gophercloud/issues/658 + +There's one situation which can make adding fields more difficult: if the field +is part of an API extension rather than the base API itself. An example of this +can be seen in [this](https://github.com/gophercloud/gophercloud/issues/749) +issue. + +Here, a user reported fields missing in the `Get` function of +`networking/v2/networks`. The fields reported missing weren't missing at all, +they're just part of various Networking extensions located in +`networking/v2/extensions`. + +### Adding a Missing API Call + +If you've found a missing API action, create an issue with details of +the action. For example: + +* https://github.com/gophercloud/gophercloud/issues/715 +* https://github.com/gophercloud/gophercloud/issues/719 + +You'll want to make sure the API call is part of the upstream OpenStack project +and not an extension created by a third-party or vendor. Gophercloud only +supports the OpenStack projects proper. + +### Adding a Missing API Suite + +Adding support to a missing suite of API calls will require more than one Pull +Request. However, you can use a single issue for all PRs. + +Examples of issues which track the addition of a missing API suite are: + +* https://github.com/gophercloud/gophercloud/issues/539 +* https://github.com/gophercloud/gophercloud/issues/555 +* https://github.com/gophercloud/gophercloud/issues/571 +* https://github.com/gophercloud/gophercloud/issues/583 +* https://github.com/gophercloud/gophercloud/issues/605 + +Note how the issue breaks down the implementation by request types (Create, +Update, Delete, Get, List). + +Also note how these issues provide links to the service's Python code. These +links are not required for _issues_, but it's usually a good idea to provide +them, anyway. These links _are required_ for PRs and that will be covered in +detail in a later step of this tutorial. + +### Adding a Missing OpenStack Project + +These kinds of feature additions are large undertakings. Adding support for +an entire OpenStack project is something the Gophercloud team very much +appreciates, but you should be prepared for several weeks of work and +interaction with the Gophercloud team. + +An example of how to create an issue for an entire project can be seen +here: + +* https://github.com/gophercloud/gophercloud/issues/723 + +--- + +With all of the above in mind, proceed to [Step 3](step-03-code-hunting.md) to +learn about Code Hunting. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-03-code-hunting.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-03-code-hunting.md new file mode 100644 index 00000000..f773eec0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-03-code-hunting.md @@ -0,0 +1,104 @@ +Step 3: Code Hunting +==================== + +If you plan to submit a feature or bug fix to Gophercloud, you must be +able to prove your code correctly works with the OpenStack service in +question. + +Let's use the following issue as an example: +[https://github.com/gophercloud/gophercloud/issues/621](https://github.com/gophercloud/gophercloud/issues/621). +In this issue, there's a request being made to add support for +`availability_zone_hints` to the `networking/v2/networks` package. +Meaning, we want to change: + +```go +type Network struct { + ID string `json:"id"` + Name string `json:"name"` + AdminStateUp bool `json:"admin_state_up"` + Status string `json:"status"` + Subnets []string `json:"subnets"` + TenantID string `json:"tenant_id"` + Shared bool `json:"shared"` +} +``` + +to look like + +```go +type Network struct { + ID string `json:"id"` + Name string `json:"name"` + AdminStateUp bool `json:"admin_state_up"` + Status string `json:"status"` + Subnets []string `json:"subnets"` + TenantID string `json:"tenant_id"` + Shared bool `json:"shared"` + + AvailabilityZoneHints []string `json:"availability_zone_hints"` +} +``` + +We need to be sure that `availability_zone_hints` is a field which really does +exist in the OpenStack Neutron project and it's not a field which was added as +a customization to a single OpenStack cloud. + +In addition, we need to ensure that `availability_zone_hints` is really a +`[]string` and not a different kind of type. + +One way of verifying this is through the [OpenStack API reference +documentation](https://developer.openstack.org/api-ref/network/v2/). +However, the API docs might either be incorrect or they might not provide all of +the details we need to know in order to ensure this field is added correctly. + +> Note: when we say the API docs might be incorrect, we are _not_ implying +> that the API docs aren't useful or that the contributors who work on the API +> docs are wrong. OpenStack moves fast. Typos happen. Forgetting to update +> documentation happens. + +Since the OpenStack service itself correctly accepts and processes the fields, +the best source of information on how the field works is in the service code +itself. + +Continuing on with using #621 as an example, we can find the definition of +`availability_zone_hints` in the following piece of code: + +https://github.com/openstack/neutron/blob/8e9959725eda4063a318b4ba6af1e3494cad9e35/neutron/objects/network.py#L191 + +The above code confirms that `availability_zone_hints` is indeed part of the +`Network` object and that its type is a list of strings (`[]string`). + +This example is a best-case situation: the code is relatively easy to find +and it's simple to understand. However, there will be times when proving the +implementation in the service code is difficult. Make no mistake, this is _not_ +fun work. This can sometimes be more difficult than writing the actual patch +for Gophercloud. However, this is an essential step to ensuring the feature +or bug fix is correctly added to Gophercloud. + +Examples of good code hunting can be seen here: + +* https://github.com/gophercloud/gophercloud/issues/539 +* https://github.com/gophercloud/gophercloud/issues/555 +* https://github.com/gophercloud/gophercloud/issues/571 +* https://github.com/gophercloud/gophercloud/issues/583 +* https://github.com/gophercloud/gophercloud/issues/605 + +Code Hunting Tips +----------------- + +OpenStack projects differ from one to another. Code is organized in different +ways. However, the following tips should be useful across all projects. + +* The logic which implements Create and Delete actions is usually either located + in the "model" or "controller" portion of the code. + +* Use Github's search box to search for the exact field you're working on. + Review all results to gain a good understanding of everywhere the field is + used. + +* When adding a field, look for an object model or a schema of some sort. + +--- + +Proceed to [Step 4](step-04-acceptance-testing.md) to learn about Acceptance +Testing. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-04-acceptance-testing.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-04-acceptance-testing.md new file mode 100644 index 00000000..fe827174 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-04-acceptance-testing.md @@ -0,0 +1,27 @@ +Step 4: Acceptance Testing +========================== + +If we haven't started working on the feature or bug fix, why are we talking +about Acceptance Testing now? + +Before you implement a feature or bug fix, you _must_ be able to test your code +in a working OpenStack environment. Please do not submit code which you have +only tested with offline unit tests. + +Blindly submitting code is dangerous to the Gophercloud project. Developers +from all over the world use Gophercloud in many different projects. If you +submit code which is untested, it can cause these projects to break or become +unstable. + +And, to be frank, submitting untested code will inevitably cause someone else +to have to spend time fixing it. + +If you don't have an OpenStack environment to test with, we have lots of +documentation [here](/acceptance) to help you build your own small OpenStack +environment for testing. + +--- + +Once you've confirmed you are able to test your code, proceed to +[Step 5](step-05-pull-requests.md) to (finally!) start working on a Pull +Request. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-05-pull-requests.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-05-pull-requests.md new file mode 100644 index 00000000..cb340a92 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-05-pull-requests.md @@ -0,0 +1,189 @@ +Step 5: Writing the Code +======================== + +At this point, you should have: + +- [x] Identified a feature or bug fix +- [x] Opened an Issue about it +- [x] Located the project's service code which validates the feature or fix +- [x] Have an OpenStack environment available to test with + +Now it's time to write the actual code! We recommend reading over the +[CONTRIBUTING](/.github/CONTRIBUTING.md) guide again as a refresh. Notably +the [Getting Started](/.github/CONTRIBUTING.md#getting-started) section will +help you set up a `git` repository correctly. + +We encourage you to browse the existing Gophercloud code to find examples +of similar implementations. It would be a _very_ rare occurrence for you +to be implementing something that hasn't already been done. + +Use the existing packages as templates and mirror the style, naming, and +logic. + +Types of Pull Requests +---------------------- + +The amount of changes you plan to make will determine how much code you should +submit as Pull Requests. + +### A Single Bug Fix + +If you're implementing a single bug fix, then creating one `git` branch and +submitting one Pull Request is fine. + +### Adding a Single Field + +If you're adding a single field, then a single Pull Request is also fine. See +[#662](https://github.com/gophercloud/gophercloud/pull/662) as an example of +this. + +If you plan to add more than one missing field, you will need to open a Pull +Request for _each_ field. + +### Adding a Single API Call + +Single API calls can also be submitted as a single Pull Request. See +[#722](https://github.com/gophercloud/gophercloud/pull/722) as an example of +this. + +### Adding a Suite of API Calls + +If you're adding support for a "suite" of API calls (meaning: Create, Update, +Delete, Get), then you will need to create one Pull Request for _each_ call. + +The following Pull Requests are good examples of how to do this: + +* https://github.com/gophercloud/gophercloud/pull/584 +* https://github.com/gophercloud/gophercloud/pull/586 +* https://github.com/gophercloud/gophercloud/pull/587 +* https://github.com/gophercloud/gophercloud/pull/594 + +You can also use the provided [template](/docs/contributor-tutorial/.template) +as it contains a lot of the repeated boiler plate code seen in each resource. +However, please make sure to thoroughly review and edit it as needed. +Leaving templated portions in-place might be interpreted as rushing through +the work and will require further rounds of review to fix. + +### Adding an Entire OpenStack Project + +To add an entire OpenStack project, you must break each set of API calls into +individual Pull Requests. Implementing an entire project can be thought of as +implementing multiple API suites. + +An example of this can be seen from the Pull Requests referenced in +[#723](https://github.com/gophercloud/gophercloud/issues/723). + +What to Include in a Pull Request +--------------------------------- + +Each Pull Request should contain the following: + +1. The actual Go code to implement the feature or bug fix +2. Unit tests +3. Acceptance tests +4. Documentation + +Whether you want to bundle all of the above into a single commit or multiple +commits is up to you. Use your preferred style. + +### Unit Tests + +Unit tests should provide basic validation that your code works as intended. + +Please do not use JSON fixtures from the API reference documentation. Please +generate your own fixtures using the OpenStack environment you're +[testing](step-04-acceptance-testing.md) with. + +### Acceptance Tests + +Since unit tests are not run against an actual OpenStack environment, +acceptance tests can arguably be more important. The acceptance tests that you +include in your Pull Request should confirm that your implemented code works +as intended with an actual OpenStack environment. + +### Documentation + +All documentation in Gophercloud is done through in-line `godoc`. Please make +sure to document all fields, functions, and methods appropriately. In addition, +each package has a `doc.go` file which should be created or amended with +details of your Pull Request, where appropriate. + +Dealing with Related Pull Requests +---------------------------------- + +If you plan to open more than one Pull Request, it's only natural that code +from one Pull Request will be dependent on code from the prior Pull Request. + +There are two methods of handling this: + +### Create Independent Pull Requests + +With this method, each Pull Request has all of the code to fully implement +the code in question. Each Pull Request can be merged in any order because +it's self contained. + +Use the following `git` workflow to implement this method: + +```shell +$ git checkout master +$ git pull +$ git checkout -b identityv3-regions-create +$ (write your code) +$ git add . +$ git commit -m "Implementing Regions Create" + +$ git checkout master +$ git checkout -b identityv3-regions-update +$ (write your code) +$ git add . +$ git commit -m "Implementing Regions Update" +``` + +Advantages of this Method: + +* Pull Requests can be merged in any order +* Additional commits to one Pull Request are independent of other Pull Requests + +Disadvantages of this Method: + +* There will be _a lot_ of duplicate code in each Pull Request +* You will have to rebase all other Pull Requests and resolve a good amount of + merge conflicts. + +### Create a Chain of Pull Requests + +With this method, each Pull Request is based off of a previous Pull Request. +Pull Requests will have to be merged in a specific order since there is a +defined relationship. + +Use the following `git` workflow to implement this method: + +```shell +$ git checkout master +$ git pull +$ git checkout -b identityv3-regions-create +$ (write your code) +$ git add . +$ git commit -m "Implementing Regions Create" + +$ git checkout -b identityv3-regions-update +$ (write your code) +$ git add . +$ git commit -m "Implementing Regions Update" +``` + +Advantages of this Method: + +* Each Pull Request becomes smaller since you are building off of the last + +Disadvantages of this Method: + +* If a Pull Request requires changes, you will have to rebase _all_ child + Pull Requests based off of the parent. + +The choice of method is up to you. + +--- + +Once you have your code written, submit a Pull Request to Gophercloud and +proceed to [Step 6](step-06-code-review.md). diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-06-code-review.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-06-code-review.md new file mode 100644 index 00000000..ac3b6880 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-06-code-review.md @@ -0,0 +1,93 @@ +Step 6: Code Review +=================== + +Once you've submitted a Pull Request, three things will happen automatically: + +1. Travis-CI will run a set of simple tests: + + a. Unit Tests + + b. Code Formatting checks + + c. `go vet` checks + +2. Coveralls will run a coverage test. +3. [OpenLab](https://openlabtesting.org/) will run acceptance tests. + +Depending on the results of the above, you might need to make additional +changes to your code. + +While you're working on the finishing touches to your code, it is helpful +to add a `[wip]` tag to the title of your Pull Request. + +You are most welcomed to take as much time as you need to work on your Pull +Request. As well, take advantage of the automatic testing that is done to +each commit. + +### Travis-CI + +If Travis reports code formatting issues, please make sure to run `gofmt` on all +of your code. Travis will also report errors with unit tests, so you should +ensure those are fixed, too. + +### Coveralls + +If Coveralls reports a decrease in test coverage, check and make sure you have +provided unit tests. A decrease in test coverage is _sometimes_ unavoidable and +ignorable. + +### OpenLab + +OpenLab does not yet run a full suite of acceptance tests, so it's possible +that the acceptance tests you've included were not run. When this happens, +a core member for Gophercloud will run the tests manually. + +There are times when a core reviewer does not have access to the resources +required to run the acceptance tests. When this happens, it is essential +that you've run them yourself (See [Step 4](step-04.md)). + +Request a Code Review +--------------------- + +When you feel your Pull Request is ready for review, please leave a comment +requesting a code review. If you don't explicitly ask for a code review, a +core member might not know the Pull Request is ready for review. + +Additionally, if there are parts of your implementation that you are unsure +about, please ask for help. We're more than happy to provide advice. + +During the code review process, a core member will review the code you've +submitted and either request changes or request additional information. +Generally these requests fall under the following categories: + +1. Code which needs to be reformatted (See our [Style Guide](/docs/STYLEGUIDE.md) + for conventions used. + +2. Requests for additional information about the validity of something. This + might happen because the included supporting service code URLs don't have + enough information. + +3. Missing unit tests or acceptance tests. + +Submitting Changes +------------------ + +If a code review requires changes to be submitted, please do not squash your +commits. Please only add new commits to the Pull Request. This is to help the +code reviewer see only the changes that were made. + +It's Never Personal +------------------- + +Code review is a healthy exercise where a new set of eyes can sometimes spot +items forgotten by the author. + +Please don't take change requests personally. Our intention is to ensure the +code is correct before merging. + +--- + +Once the code has been reviewed and approved, a core member will merge your +Pull Request. + +Please proceed to [Step 7](step-07-congratulations.md). diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-07-congratulations.md b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-07-congratulations.md new file mode 100644 index 00000000..e14b7941 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/docs/contributor-tutorial/step-07-congratulations.md @@ -0,0 +1,9 @@ +Step 7: Congratulations! +======================== + +At this point your code is merged and you've either fixed a bug or added a new +feature to Gophercloud! + +We completely understand that this has been a long process. We appreciate your +patience as well as the time you have taken for working on this. You've made +Gophercloud a better project with your work. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/errors.go index 88fd2ac6..a5fa68d6 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/errors.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/errors.go @@ -1,6 +1,9 @@ package gophercloud -import "fmt" +import ( + "fmt" + "strings" +) // BaseError is an error type that all other error types embed. type BaseError struct { @@ -43,6 +46,33 @@ func (e ErrInvalidInput) Error() string { return e.choseErrString() } +// ErrMissingEnvironmentVariable is the error when environment variable is required +// in a particular situation but not provided by the user +type ErrMissingEnvironmentVariable struct { + BaseError + EnvironmentVariable string +} + +func (e ErrMissingEnvironmentVariable) Error() string { + e.DefaultErrString = fmt.Sprintf("Missing environment variable [%s]", e.EnvironmentVariable) + return e.choseErrString() +} + +// ErrMissingAnyoneOfEnvironmentVariables is the error when anyone of the environment variables +// is required in a particular situation but not provided by the user +type ErrMissingAnyoneOfEnvironmentVariables struct { + BaseError + EnvironmentVariables []string +} + +func (e ErrMissingAnyoneOfEnvironmentVariables) Error() string { + e.DefaultErrString = fmt.Sprintf( + "Missing one of the following environment variables [%s]", + strings.Join(e.EnvironmentVariables, ", "), + ) + return e.choseErrString() +} + // ErrUnexpectedResponseCode is returned by the Request method when a response code other than // those listed in OkCodes is encountered. type ErrUnexpectedResponseCode struct { @@ -72,6 +102,11 @@ type ErrDefault401 struct { ErrUnexpectedResponseCode } +// ErrDefault403 is the default error type returned on a 403 HTTP response code. +type ErrDefault403 struct { + ErrUnexpectedResponseCode +} + // ErrDefault404 is the default error type returned on a 404 HTTP response code. type ErrDefault404 struct { ErrUnexpectedResponseCode @@ -103,11 +138,22 @@ type ErrDefault503 struct { } func (e ErrDefault400) Error() string { - return "Invalid request due to incorrect syntax or missing required parameters." + e.DefaultErrString = fmt.Sprintf( + "Bad request with: [%s %s], error message: %s", + e.Method, e.URL, e.Body, + ) + return e.choseErrString() } func (e ErrDefault401) Error() string { return "Authentication failed" } +func (e ErrDefault403) Error() string { + e.DefaultErrString = fmt.Sprintf( + "Request forbidden: [%s %s], error message: %s", + e.Method, e.URL, e.Body, + ) + return e.choseErrString() +} func (e ErrDefault404) Error() string { return "Resource not found" } @@ -141,6 +187,12 @@ type Err401er interface { Error401(ErrUnexpectedResponseCode) error } +// Err403er is the interface resource error types implement to override the error message +// from a 403 error. +type Err403er interface { + Error403(ErrUnexpectedResponseCode) error +} + // Err404er is the interface resource error types implement to override the error message // from a 404 error. type Err404er interface { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/internal/testing/util_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/internal/testing/util_test.go new file mode 100644 index 00000000..12fd172b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/internal/testing/util_test.go @@ -0,0 +1,42 @@ +package testing + +import ( + "reflect" + "testing" + + "github.com/gophercloud/gophercloud/internal" +) + +func TestRemainingKeys(t *testing.T) { + type User struct { + UserID string `json:"user_id"` + Username string `json:"username"` + Location string `json:"-"` + CreatedAt string `json:"-"` + Status string + IsAdmin bool + } + + userResponse := map[string]interface{}{ + "user_id": "abcd1234", + "username": "jdoe", + "location": "Hawaii", + "created_at": "2017-06-08T02:49:03.000000", + "status": "active", + "is_admin": "true", + "custom_field": "foo", + } + + expected := map[string]interface{}{ + "created_at": "2017-06-08T02:49:03.000000", + "is_admin": "true", + "custom_field": "foo", + } + + actual := internal.RemainingKeys(User{}, userResponse) + + isEqual := reflect.DeepEqual(expected, actual) + if !isEqual { + t.Fatalf("expected %s but got %s", expected, actual) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go index b5482ba8..994b5550 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go @@ -50,17 +50,23 @@ func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) { } if authURL == "" { - err := gophercloud.ErrMissingInput{Argument: "authURL"} + err := gophercloud.ErrMissingEnvironmentVariable{ + EnvironmentVariable: "OS_AUTH_URL", + } return nilOptions, err } if username == "" && userID == "" { - err := gophercloud.ErrMissingInput{Argument: "username"} + err := gophercloud.ErrMissingAnyoneOfEnvironmentVariables{ + EnvironmentVariables: []string{"OS_USERNAME", "OS_USERID"}, + } return nilOptions, err } if password == "" { - err := gophercloud.ErrMissingInput{Argument: "password"} + err := gophercloud.ErrMissingEnvironmentVariable{ + EnvironmentVariable: "OS_PASSWORD", + } return nilOptions, err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/doc.go new file mode 100644 index 00000000..109f78f5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/doc.go @@ -0,0 +1,42 @@ +/* +Package quotasets enables retrieving and managing Block Storage quotas. + +Example to Get a Quota Set + + quotaset, err := quotasets.Get(blockStorageClient, "project-id").Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", quotaset) + +Example to Get Quota Set Usage + + quotaset, err := quotasets.GetUsage(blockStorageClient, "project-id").Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", quotaset) + +Example to Update a Quota Set + + updateOpts := quotasets.UpdateOpts{ + Volumes: gophercloud.IntToPointer(100), + } + + quotaset, err := quotasets.Update(blockStorageClient, "project-id", updateOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", quotaset) + +Example to Delete a Quota Set + + err := quotasets.Delete(blockStorageClient, "project-id").ExtractErr() + if err != nil { + panic(err) + } +*/ +package quotasets diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/requests.go new file mode 100644 index 00000000..c89b4e35 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/requests.go @@ -0,0 +1,94 @@ +package quotasets + +import ( + "fmt" + + "github.com/gophercloud/gophercloud" +) + +// Get returns public data about a previously created QuotaSet. +func Get(client *gophercloud.ServiceClient, projectID string) (r GetResult) { + _, r.Err = client.Get(getURL(client, projectID), &r.Body, nil) + return +} + +// GetDefaults returns public data about the project's default block storage quotas. +func GetDefaults(client *gophercloud.ServiceClient, projectID string) (r GetResult) { + _, r.Err = client.Get(getDefaultsURL(client, projectID), &r.Body, nil) + return +} + +// GetUsage returns detailed public data about a previously created QuotaSet. +func GetUsage(client *gophercloud.ServiceClient, projectID string) (r GetUsageResult) { + u := fmt.Sprintf("%s?usage=true", getURL(client, projectID)) + _, r.Err = client.Get(u, &r.Body, nil) + return +} + +// Updates the quotas for the given projectID and returns the new QuotaSet. +func Update(client *gophercloud.ServiceClient, projectID string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToBlockStorageQuotaUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(updateURL(client, projectID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return r +} + +// UpdateOptsBuilder enables extensins to add parameters to the update request. +type UpdateOptsBuilder interface { + // Extra specific name to prevent collisions with interfaces for other quotas + // (e.g. neutron) + ToBlockStorageQuotaUpdateMap() (map[string]interface{}, error) +} + +// ToBlockStorageQuotaUpdateMap builds the update options into a serializable +// format. +func (opts UpdateOpts) ToBlockStorageQuotaUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "quota_set") +} + +// Options for Updating the quotas of a Tenant. +// All int-values are pointers so they can be nil if they are not needed. +// You can use gopercloud.IntToPointer() for convenience +type UpdateOpts struct { + // Volumes is the number of volumes that are allowed for each project. + Volumes *int `json:"volumes,omitempty"` + + // Snapshots is the number of snapshots that are allowed for each project. + Snapshots *int `json:"snapshots,omitempty"` + + // Gigabytes is the size (GB) of volumes and snapshots that are allowed for + // each project. + Gigabytes *int `json:"gigabytes,omitempty"` + + // PerVolumeGigabytes is the size (GB) of volumes and snapshots that are + // allowed for each project and the specifed volume type. + PerVolumeGigabytes *int `json:"per_volume_gigabytes,omitempty"` + + // Backups is the number of backups that are allowed for each project. + Backups *int `json:"backups,omitempty"` + + // BackupGigabytes is the size (GB) of backups that are allowed for each + // project. + BackupGigabytes *int `json:"backup_gigabytes,omitempty"` + + // Groups is the number of groups that are allowed for each project. + Groups *int `json:"groups,omitempty"` + + // Force will update the quotaset even if the quota has already been used + // and the reserved quota exceeds the new quota. + Force bool `json:"force,omitempty"` +} + +// Resets the quotas for the given tenant to their default values. +func Delete(client *gophercloud.ServiceClient, projectID string) (r DeleteResult) { + _, r.Err = client.Delete(updateURL(client, projectID), &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/results.go new file mode 100644 index 00000000..8ccfb5bf --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/results.go @@ -0,0 +1,165 @@ +package quotasets + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// QuotaSet is a set of operational limits that allow for control of block +// storage usage. +type QuotaSet struct { + // ID is project associated with this QuotaSet. + ID string `json:"id"` + + // Volumes is the number of volumes that are allowed for each project. + Volumes int `json:"volumes"` + + // Snapshots is the number of snapshots that are allowed for each project. + Snapshots int `json:"snapshots"` + + // Gigabytes is the size (GB) of volumes and snapshots that are allowed for + // each project. + Gigabytes int `json:"gigabytes"` + + // PerVolumeGigabytes is the size (GB) of volumes and snapshots that are + // allowed for each project and the specifed volume type. + PerVolumeGigabytes int `json:"per_volume_gigabytes"` + + // Backups is the number of backups that are allowed for each project. + Backups int `json:"backups"` + + // BackupGigabytes is the size (GB) of backups that are allowed for each + // project. + BackupGigabytes int `json:"backup_gigabytes"` +} + +// QuotaUsageSet represents details of both operational limits of block +// storage resources and the current usage of those resources. +type QuotaUsageSet struct { + // ID is the project ID associated with this QuotaUsageSet. + ID string `json:"id"` + + // Volumes is the volume usage information for this project, including + // in_use, limit, reserved and allocated attributes. Note: allocated + // attribute is available only when nested quota is enabled. + Volumes QuotaUsage `json:"volumes"` + + // Snapshots is the snapshot usage information for this project, including + // in_use, limit, reserved and allocated attributes. Note: allocated + // attribute is available only when nested quota is enabled. + Snapshots QuotaUsage `json:"snapshots"` + + // Gigabytes is the size (GB) usage information of volumes and snapshots + // for this project, including in_use, limit, reserved and allocated + // attributes. Note: allocated attribute is available only when nested + // quota is enabled. + Gigabytes QuotaUsage `json:"gigabytes"` + + // PerVolumeGigabytes is the size (GB) usage information for each volume, + // including in_use, limit, reserved and allocated attributes. Note: + // allocated attribute is available only when nested quota is enabled and + // only limit is meaningful here. + PerVolumeGigabytes QuotaUsage `json:"per_volume_gigabytes"` + + // Backups is the backup usage information for this project, including + // in_use, limit, reserved and allocated attributes. Note: allocated + // attribute is available only when nested quota is enabled. + Backups QuotaUsage `json:"backups"` + + // BackupGigabytes is the size (GB) usage information of backup for this + // project, including in_use, limit, reserved and allocated attributes. + // Note: allocated attribute is available only when nested quota is + // enabled. + BackupGigabytes QuotaUsage `json:"backup_gigabytes"` +} + +// QuotaUsage is a set of details about a single operational limit that allows +// for control of block storage usage. +type QuotaUsage struct { + // InUse is the current number of provisioned resources of the given type. + InUse int `json:"in_use"` + + // Allocated is the current number of resources of a given type allocated + // for use. It is only available when nested quota is enabled. + Allocated int `json:"allocated"` + + // Reserved is a transitional state when a claim against quota has been made + // but the resource is not yet fully online. + Reserved int `json:"reserved"` + + // Limit is the maximum number of a given resource that can be + // allocated/provisioned. This is what "quota" usually refers to. + Limit int `json:"limit"` +} + +// QuotaSetPage stores a single page of all QuotaSet results from a List call. +type QuotaSetPage struct { + pagination.SinglePageBase +} + +// IsEmpty determines whether or not a QuotaSetsetPage is empty. +func (r QuotaSetPage) IsEmpty() (bool, error) { + ks, err := ExtractQuotaSets(r) + return len(ks) == 0, err +} + +// ExtractQuotaSets interprets a page of results as a slice of QuotaSets. +func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) { + var s struct { + QuotaSets []QuotaSet `json:"quotas"` + } + err := (r.(QuotaSetPage)).ExtractInto(&s) + return s.QuotaSets, err +} + +type quotaResult struct { + gophercloud.Result +} + +// Extract is a method that attempts to interpret any QuotaSet resource response +// as a QuotaSet struct. +func (r quotaResult) Extract() (*QuotaSet, error) { + var s struct { + QuotaSet *QuotaSet `json:"quota_set"` + } + err := r.ExtractInto(&s) + return s.QuotaSet, err +} + +// GetResult is the response from a Get operation. Call its Extract method to +// interpret it as a QuotaSet. +type GetResult struct { + quotaResult +} + +// UpdateResult is the response from a Update operation. Call its Extract method +// to interpret it as a QuotaSet. +type UpdateResult struct { + quotaResult +} + +type quotaUsageResult struct { + gophercloud.Result +} + +// GetUsageResult is the response from a Get operation. Call its Extract +// method to interpret it as a QuotaSet. +type GetUsageResult struct { + quotaUsageResult +} + +// Extract is a method that attempts to interpret any QuotaUsageSet resource +// response as a set of QuotaUsageSet structs. +func (r quotaUsageResult) Extract() (QuotaUsageSet, error) { + var s struct { + QuotaUsageSet QuotaUsageSet `json:"quota_set"` + } + err := r.ExtractInto(&s) + return s.QuotaUsageSet, err +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr +// method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/doc.go new file mode 100644 index 00000000..30d864eb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/doc.go @@ -0,0 +1,2 @@ +// quotasets unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/fixtures.go new file mode 100644 index 00000000..fe1a5d88 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/fixtures.go @@ -0,0 +1,162 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const FirstTenantID = "555544443333222211110000ffffeeee" + +var getExpectedJSONBody = ` +{ + "quota_set" : { + "volumes" : 8, + "snapshots" : 9, + "gigabytes" : 10, + "per_volume_gigabytes" : 11, + "backups" : 12, + "backup_gigabytes" : 13 + } +}` + +var getExpectedQuotaSet = quotasets.QuotaSet{ + Volumes: 8, + Snapshots: 9, + Gigabytes: 10, + PerVolumeGigabytes: 11, + Backups: 12, + BackupGigabytes: 13, +} + +var getUsageExpectedJSONBody = ` +{ + "quota_set" : { + "id": "555544443333222211110000ffffeeee", + "volumes" : { + "in_use": 15, + "limit": 16, + "reserved": 17 + }, + "snapshots" : { + "in_use": 18, + "limit": 19, + "reserved": 20 + }, + "gigabytes" : { + "in_use": 21, + "limit": 22, + "reserved": 23 + }, + "per_volume_gigabytes" : { + "in_use": 24, + "limit": 25, + "reserved": 26 + }, + "backups" : { + "in_use": 27, + "limit": 28, + "reserved": 29 + }, + "backup_gigabytes" : { + "in_use": 30, + "limit": 31, + "reserved": 32 + } + } + } +}` + +var getUsageExpectedQuotaSet = quotasets.QuotaUsageSet{ + ID: FirstTenantID, + Volumes: quotasets.QuotaUsage{InUse: 15, Limit: 16, Reserved: 17}, + Snapshots: quotasets.QuotaUsage{InUse: 18, Limit: 19, Reserved: 20}, + Gigabytes: quotasets.QuotaUsage{InUse: 21, Limit: 22, Reserved: 23}, + PerVolumeGigabytes: quotasets.QuotaUsage{InUse: 24, Limit: 25, Reserved: 26}, + Backups: quotasets.QuotaUsage{InUse: 27, Limit: 28, Reserved: 29}, + BackupGigabytes: quotasets.QuotaUsage{InUse: 30, Limit: 31, Reserved: 32}, +} + +var fullUpdateExpectedJSONBody = ` +{ + "quota_set": { + "volumes": 8, + "snapshots": 9, + "gigabytes": 10, + "per_volume_gigabytes": 11, + "backups": 12, + "backup_gigabytes": 13 + } +}` + +var fullUpdateOpts = quotasets.UpdateOpts{ + Volumes: gophercloud.IntToPointer(8), + Snapshots: gophercloud.IntToPointer(9), + Gigabytes: gophercloud.IntToPointer(10), + PerVolumeGigabytes: gophercloud.IntToPointer(11), + Backups: gophercloud.IntToPointer(12), + BackupGigabytes: gophercloud.IntToPointer(13), +} + +var fullUpdateExpectedQuotaSet = quotasets.QuotaSet{ + Volumes: 8, + Snapshots: 9, + Gigabytes: 10, + PerVolumeGigabytes: 11, + Backups: 12, + BackupGigabytes: 13, +} + +var partialUpdateExpectedJSONBody = ` +{ + "quota_set": { + "volumes": 200, + "snapshots": 0, + "gigabytes": 0, + "per_volume_gigabytes": 0, + "backups": 0, + "backup_gigabytes": 0 + } +}` + +var partialUpdateOpts = quotasets.UpdateOpts{ + Volumes: gophercloud.IntToPointer(200), + Snapshots: gophercloud.IntToPointer(0), + Gigabytes: gophercloud.IntToPointer(0), + PerVolumeGigabytes: gophercloud.IntToPointer(0), + Backups: gophercloud.IntToPointer(0), + BackupGigabytes: gophercloud.IntToPointer(0), +} + +var partiualUpdateExpectedQuotaSet = quotasets.QuotaSet{Volumes: 200} + +// HandleSuccessfulRequest configures the test server to respond to an HTTP request. +func HandleSuccessfulRequest(t *testing.T, httpMethod, uriPath, jsonOutput string, uriQueryParams map[string]string) { + + th.Mux.HandleFunc(uriPath, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, httpMethod) + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + w.Header().Add("Content-Type", "application/json") + + if uriQueryParams != nil { + th.TestFormValues(t, r, uriQueryParams) + } + + fmt.Fprintf(w, jsonOutput) + }) +} + +// HandleDeleteSuccessfully tests quotaset deletion. +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusOK) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/requests_test.go new file mode 100644 index 00000000..922b8d33 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/testing/requests_test.go @@ -0,0 +1,80 @@ +package testing + +import ( + "errors" + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + uriQueryParms := map[string]string{} + HandleSuccessfulRequest(t, "GET", "/os-quota-sets/"+FirstTenantID, getExpectedJSONBody, uriQueryParms) + actual, err := quotasets.Get(client.ServiceClient(), FirstTenantID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &getExpectedQuotaSet, actual) +} + +func TestGetUsage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + uriQueryParms := map[string]string{"usage": "true"} + HandleSuccessfulRequest(t, "GET", "/os-quota-sets/"+FirstTenantID, getUsageExpectedJSONBody, uriQueryParms) + actual, err := quotasets.GetUsage(client.ServiceClient(), FirstTenantID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, getUsageExpectedQuotaSet, actual) +} + +func TestFullUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + uriQueryParms := map[string]string{} + HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, fullUpdateExpectedJSONBody, uriQueryParms) + actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, fullUpdateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &fullUpdateExpectedQuotaSet, actual) +} + +func TestPartialUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + uriQueryParms := map[string]string{} + HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, partialUpdateExpectedJSONBody, uriQueryParms) + actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, partialUpdateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &partiualUpdateExpectedQuotaSet, actual) +} + +type ErrorUpdateOpts quotasets.UpdateOpts + +func (opts ErrorUpdateOpts) ToBlockStorageQuotaUpdateMap() (map[string]interface{}, error) { + return nil, errors.New("This is an error") +} + +func TestErrorInToBlockStorageQuotaUpdateMap(t *testing.T) { + opts := &ErrorUpdateOpts{} + th.SetupHTTP() + defer th.TeardownHTTP() + HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, "", nil) + _, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract() + if err == nil { + t.Fatal("Error handling failed") + } +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := quotasets.Delete(client.ServiceClient(), FirstTenantID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/urls.go new file mode 100644 index 00000000..7d8e5ceb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets/urls.go @@ -0,0 +1,21 @@ +package quotasets + +import "github.com/gophercloud/gophercloud" + +const resourcePath = "os-quota-sets" + +func getURL(c *gophercloud.ServiceClient, projectID string) string { + return c.ServiceURL(resourcePath, projectID) +} + +func getDefaultsURL(c *gophercloud.ServiceClient, projectID string) string { + return c.ServiceURL(resourcePath, projectID, "defaults") +} + +func updateURL(c *gophercloud.ServiceClient, projectID string) string { + return getURL(c, projectID) +} + +func deleteURL(c *gophercloud.ServiceClient, projectID string) string { + return getURL(c, projectID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/results.go index 3da8f80c..9f536119 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/results.go @@ -23,7 +23,7 @@ type Capabilities struct { LocationInfo string `json:"location_info"` QoSSupport bool `json:"QoS_support"` ProvisionedCapacityGB float64 `json:"provisioned_capacity_gb"` - MaxOverSubscriptionRatio float64 `json:"max_over_subscription_ratio"` + MaxOverSubscriptionRatio string `json:"max_over_subscription_ratio"` ThinProvisioningSupport bool `json:"thin_provisioning_support"` ThickProvisioningSupport bool `json:"thick_provisioning_support"` TotalVolumes int64 `json:"total_volumes"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/testing/requests_test.go new file mode 100644 index 00000000..8a4ef518 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats/testing/requests_test.go @@ -0,0 +1,38 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats" + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListStoragePoolsDetail(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleStoragePoolsListSuccessfully(t) + + pages := 0 + err := schedulerstats.List(client.ServiceClient(), schedulerstats.ListOpts{Detail: true}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := schedulerstats.ExtractStoragePools(page) + testhelper.AssertNoErr(t, err) + + if len(actual) != 2 { + t.Fatalf("Expected 2 backends, got %d", len(actual)) + } + testhelper.CheckDeepEquals(t, StoragePoolFake1, actual[0]) + testhelper.CheckDeepEquals(t, StoragePoolFake2, actual[1]) + + return true, nil + }) + + testhelper.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services/testing/requests_test.go new file mode 100644 index 00000000..4178c236 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services/testing/requests_test.go @@ -0,0 +1,41 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services" + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListServices(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleListSuccessfully(t) + + pages := 0 + err := services.List(client.ServiceClient(), services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := services.ExtractServices(page) + if err != nil { + return false, err + } + + if len(actual) != 3 { + t.Fatalf("Expected 3 services, got %d", len(actual)) + } + testhelper.CheckDeepEquals(t, FirstFakeService, actual[0]) + testhelper.CheckDeepEquals(t, SecondFakeService, actual[1]) + testhelper.CheckDeepEquals(t, ThirdFakeService, actual[2]) + + return true, nil + }) + + testhelper.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go new file mode 100644 index 00000000..38fae478 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go @@ -0,0 +1,166 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestAttach(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockAttachResponse(t) + + options := &volumeactions.AttachOpts{ + MountPoint: "/mnt", + Mode: "rw", + InstanceUUID: "50902f4f-a974-46a0-85e9-7efc5e22dfdd", + } + err := volumeactions.Attach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestBeginDetaching(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockBeginDetachingResponse(t) + + err := volumeactions.BeginDetaching(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestDetach(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDetachResponse(t) + + err := volumeactions.Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", &volumeactions.DetachOpts{}).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUploadImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + MockUploadImageResponse(t) + options := &volumeactions.UploadImageOpts{ + ContainerFormat: "bare", + DiskFormat: "raw", + ImageName: "test", + Force: true, + } + + actual, err := volumeactions.UploadImage(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).Extract() + th.AssertNoErr(t, err) + + expected := volumeactions.VolumeImage{ + VolumeID: "cd281d77-8217-4830-be95-9528227c105c", + ContainerFormat: "bare", + DiskFormat: "raw", + Description: "", + ImageID: "ecb92d98-de08-45db-8235-bbafe317269c", + ImageName: "test", + Size: 5, + Status: "uploading", + UpdatedAt: time.Date(2017, 7, 17, 9, 29, 22, 0, time.UTC), + VolumeType: volumeactions.ImageVolumeType{ + ID: "b7133444-62f6-4433-8da3-70ac332229b7", + Name: "basic.ru-2a", + Description: "", + IsPublic: true, + ExtraSpecs: map[string]interface{}{"volume_backend_name": "basic.ru-2a"}, + QosSpecsID: "", + Deleted: false, + DeletedAt: time.Time{}, + CreatedAt: time.Date(2016, 5, 4, 8, 54, 14, 0, time.UTC), + UpdatedAt: time.Date(2016, 5, 4, 9, 15, 33, 0, time.UTC), + }, + } + th.AssertDeepEquals(t, expected, actual) +} + +func TestReserve(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockReserveResponse(t) + + err := volumeactions.Reserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUnreserve(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUnreserveResponse(t) + + err := volumeactions.Unreserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestInitializeConnection(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockInitializeConnectionResponse(t) + + options := &volumeactions.InitializeConnectionOpts{ + IP: "127.0.0.1", + Host: "stack", + Initiator: "iqn.1994-05.com.redhat:17cf566367d2", + Multipath: gophercloud.Disabled, + Platform: "x86_64", + OSType: "linux2", + } + _, err := volumeactions.InitializeConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).Extract() + th.AssertNoErr(t, err) +} + +func TestTerminateConnection(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockTerminateConnectionResponse(t) + + options := &volumeactions.TerminateConnectionOpts{ + IP: "127.0.0.1", + Host: "stack", + Initiator: "iqn.1994-05.com.redhat:17cf566367d2", + Multipath: gophercloud.Enabled, + Platform: "x86_64", + OSType: "linux2", + } + err := volumeactions.TerminateConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestExtendSize(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockExtendSizeResponse(t) + + options := &volumeactions.ExtendSizeOpts{ + NewSize: 3, + } + + err := volumeactions.ExtendSize(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestForceDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockForceDeleteResponse(t) + + res := volumeactions.ForceDelete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/noauth/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/noauth/testing/requests_test.go new file mode 100644 index 00000000..14080259 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/noauth/testing/requests_test.go @@ -0,0 +1,38 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/blockstorage/noauth" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestNoAuth(t *testing.T) { + ao := gophercloud.AuthOptions{ + Username: "user", + TenantName: "test", + } + provider, err := noauth.NewClient(ao) + th.AssertNoErr(t, err) + noauthClient, err := noauth.NewBlockStorageNoAuth(provider, noauth.EndpointOpts{ + CinderEndpoint: "http://cinder:8776/v2", + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, naTestResult.Endpoint, noauthClient.Endpoint) + th.AssertEquals(t, naTestResult.TokenID, noauthClient.TokenID) + + ao2 := gophercloud.AuthOptions{} + provider2, err := noauth.NewClient(ao2) + th.AssertNoErr(t, err) + noauthClient2, err := noauth.NewBlockStorageNoAuth(provider2, noauth.EndpointOpts{ + CinderEndpoint: "http://cinder:8776/v2/", + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, naResult.Endpoint, noauthClient2.Endpoint) + th.AssertEquals(t, naResult.TokenID, noauthClient2.TokenID) + + errTest, err := noauth.NewBlockStorageNoAuth(provider2, noauth.EndpointOpts{}) + _ = errTest + th.AssertEquals(t, errorResult, err.Error()) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions/testing/requests_test.go new file mode 100644 index 00000000..31034970 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions/testing/requests_test.go @@ -0,0 +1,64 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + apiversions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := apiversions.ExtractAPIVersions(page) + th.AssertNoErr(t, err) + + expected := []apiversions.APIVersion{ + { + ID: "v1.0", + Status: "CURRENT", + Updated: "2012-01-04T11:33:21Z", + }, + { + ID: "v2.0", + Status: "CURRENT", + Updated: "2012-11-21T11:33:21Z", + }, + } + + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertEquals(t, 1, count) +} + +func TestAPIInfo(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + actual, err := apiversions.Get(client.ServiceClient(), "v1").Extract() + th.AssertNoErr(t, err) + + expected := apiversions.APIVersion{ + ID: "v1.0", + Status: "CURRENT", + Updated: "2012-01-04T11:33:21Z", + } + + th.AssertEquals(t, actual.ID, expected.ID) + th.AssertEquals(t, actual.Status, expected.Status) + th.AssertEquals(t, actual.Updated, expected.Updated) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/requests.go index cb9d0d0e..fed1252a 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/requests.go @@ -130,7 +130,12 @@ func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMet func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/testing/requests_test.go new file mode 100644 index 00000000..f4056b5b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots/testing/requests_test.go @@ -0,0 +1,116 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := snapshots.ExtractSnapshots(page) + if err != nil { + t.Errorf("Failed to extract snapshots: %v", err) + return false, err + } + + expected := []snapshots.Snapshot{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "snapshot-001", + VolumeID: "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + Status: "available", + Size: 30, + CreatedAt: time.Date(2012, 2, 14, 20, 53, 7, 0, time.UTC), + Description: "Daily Backup", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "snapshot-002", + VolumeID: "76b8950a-8594-4e5b-8dce-0dfa9c696358", + Status: "available", + Size: 25, + CreatedAt: time.Date(2012, 2, 14, 20, 53, 8, 0, time.UTC), + Description: "Weekly Backup", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "snapshot-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := snapshots.CreateOpts{VolumeID: "1234", Name: "snapshot-001"} + n, err := snapshots.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.VolumeID, "1234") + th.AssertEquals(t, n.Name, "snapshot-001") + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestUpdateMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateMetadataResponse(t) + + expected := map[string]interface{}{"key": "v1"} + + options := &snapshots.UpdateMetadataOpts{ + Metadata: map[string]interface{}{ + "key": "v1", + }, + } + + actual, err := snapshots.UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, actual, expected) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := snapshots.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/requests.go index 566def51..52d738fa 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/requests.go @@ -139,7 +139,12 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/testing/requests_test.go new file mode 100644 index 00000000..c4ce23a7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/testing/requests_test.go @@ -0,0 +1,152 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := volumes.ExtractVolumes(page) + if err != nil { + t.Errorf("Failed to extract volumes: %v", err) + return false, err + } + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListAll(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := volumes.ExtractVolumes(allPages) + th.AssertNoErr(t, err) + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + }, + } + + th.CheckDeepEquals(t, expected, actual) + +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + actual, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + expected := &volumes.Volume{ + Status: "active", + Name: "vol-001", + Attachments: []map[string]interface{}{ + { + "attachment_id": "03987cd1-0ad5-40d1-9b2a-7cc48295d4fa", + "id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf", + "volume_id": "6c80f8ac-e3e2-480c-8e6e-f1db92fe4bfe", + "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f", + "host_name": "mitaka", + "device": "/", + }, + }, + AvailabilityZone: "us-east1", + Bootable: "false", + CreatedAt: time.Date(2012, 2, 14, 20, 53, 07, 0, time.UTC), + Description: "Another volume.", + VolumeType: "289da7f8-6440-407c-9fb4-7db01ec49164", + SnapshotID: "", + SourceVolID: "", + Metadata: map[string]string{ + "contents": "junk", + }, + ID: "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + Size: 30, + } + + th.AssertDeepEquals(t, expected, actual) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &volumes.CreateOpts{ + Size: 75, + AvailabilityZone: "us-east1", + } + n, err := volumes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Size, 4) + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateResponse(t) + + options := volumes.UpdateOpts{Name: "vol-002"} + v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract() + th.AssertNoErr(t, err) + th.CheckEquals(t, "vol-002", v.Name) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes/testing/requests_test.go new file mode 100644 index 00000000..42446151 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes/testing/requests_test.go @@ -0,0 +1,119 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + volumetypes.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := volumetypes.ExtractVolumeTypes(page) + if err != nil { + t.Errorf("Failed to extract volume types: %v", err) + return false, err + } + + expected := []volumetypes.VolumeType{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-type-001", + ExtraSpecs: map[string]interface{}{ + "capabilities": "gpu", + }, + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-type-002", + ExtraSpecs: map[string]interface{}{}, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + vt, err := volumetypes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, vt.ExtraSpecs, map[string]interface{}{"serverNumber": "2"}) + th.AssertEquals(t, vt.Name, "vol-type-001") + th.AssertEquals(t, vt.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/types", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "volume_type": { + "name": "vol-type-001" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "volume_type": { + "name": "vol-type-001", + "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" + } +} + `) + }) + + options := &volumetypes.CreateOpts{Name: "vol-type-001"} + n, err := volumetypes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Name, "vol-type-001") + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + w.WriteHeader(http.StatusAccepted) + }) + + err := volumetypes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/requests.go index dc707fd9..939e5020 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/requests.go @@ -142,7 +142,12 @@ func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMet func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/testing/requests_test.go new file mode 100644 index 00000000..1c44e52c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots/testing/requests_test.go @@ -0,0 +1,116 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := snapshots.ExtractSnapshots(page) + if err != nil { + t.Errorf("Failed to extract snapshots: %v", err) + return false, err + } + + expected := []snapshots.Snapshot{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "snapshot-001", + VolumeID: "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + Status: "available", + Size: 30, + CreatedAt: time.Date(2017, 5, 30, 3, 35, 3, 0, time.UTC), + Description: "Daily Backup", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "snapshot-002", + VolumeID: "76b8950a-8594-4e5b-8dce-0dfa9c696358", + Status: "available", + Size: 25, + CreatedAt: time.Date(2017, 5, 30, 3, 35, 3, 0, time.UTC), + Description: "Weekly Backup", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "snapshot-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := snapshots.CreateOpts{VolumeID: "1234", Name: "snapshot-001"} + n, err := snapshots.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.VolumeID, "1234") + th.AssertEquals(t, n.Name, "snapshot-001") + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestUpdateMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateMetadataResponse(t) + + expected := map[string]interface{}{"key": "v1"} + + options := &snapshots.UpdateMetadataOpts{ + Metadata: map[string]interface{}{ + "key": "v1", + }, + } + + actual, err := snapshots.UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, actual, expected) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := snapshots.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/requests.go index 2ec10ad5..b7977cbc 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/requests.go @@ -98,6 +98,19 @@ type ListOpts struct { // TenantID will filter by a specific tenant/project ID. // Setting AllTenants is required for this. TenantID string `q:"project_id"` + + // Comma-separated list of sort keys and optional sort directions in the + // form of [:]. + Sort string `q:"sort"` + + // Requests a page size of items. + Limit int `q:"limit"` + + // Used in conjunction with limit to return a slice of items. + Offset int `q:"offset"` + + // The ID of the last-seen item. + Marker string `q:"marker"` } // ToVolumeListQuery formats a ListOpts into a query string. @@ -118,7 +131,7 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa } return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return VolumePage{pagination.SinglePageBase(r)} + return VolumePage{pagination.LinkedPageBase{PageResult: r}} }) } @@ -161,7 +174,12 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/results.go index 674ec346..96572b01 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/results.go @@ -98,7 +98,7 @@ func (r *Volume) UnmarshalJSON(b []byte) error { // VolumePage is a pagination.pager that is returned from a call to the List function. type VolumePage struct { - pagination.SinglePageBase + pagination.LinkedPageBase } // IsEmpty returns true if a ListResult contains no Volumes. @@ -107,6 +107,19 @@ func (r VolumePage) IsEmpty() (bool, error) { return len(volumes) == 0, err } +// NextPageURL uses the response's embedded link reference to navigate to the +// next page of results. +func (r VolumePage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"volumes_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + // ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call. func ExtractVolumes(r pagination.Page) ([]Volume, error) { var s []Volume diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/testing/requests_test.go new file mode 100644 index 00000000..cd7dcf5e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes/testing/requests_test.go @@ -0,0 +1,257 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumetenants" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := volumes.ExtractVolumes(page) + if err != nil { + t.Errorf("Failed to extract volumes: %v", err) + return false, err + } + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + Attachments: []volumes.Attachment{{ + ServerID: "83ec2e3b-4321-422b-8706-a84185f52a0a", + AttachmentID: "05551600-a936-4d4a-ba42-79a037c1-c91a", + AttachedAt: time.Date(2016, 8, 6, 14, 48, 20, 0, time.UTC), + HostName: "foobar", + VolumeID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + Device: "/dev/vdc", + ID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + }}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{"foo": "bar"}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + Attachments: []volumes.Attachment{}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListAllWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + type VolumeWithExt struct { + volumes.Volume + volumetenants.VolumeTenantExt + } + + allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + var actual []VolumeWithExt + err = volumes.ExtractVolumesInto(allPages, &actual) + th.AssertNoErr(t, err) + th.AssertEquals(t, 2, len(actual)) + th.AssertEquals(t, "304dc00909ac4d0da6c62d816bcb3459", actual[0].TenantID) +} + +func TestListAll(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := volumes.ExtractVolumes(allPages) + th.AssertNoErr(t, err) + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + Attachments: []volumes.Attachment{{ + ServerID: "83ec2e3b-4321-422b-8706-a84185f52a0a", + AttachmentID: "05551600-a936-4d4a-ba42-79a037c1-c91a", + AttachedAt: time.Date(2016, 8, 6, 14, 48, 20, 0, time.UTC), + HostName: "foobar", + VolumeID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + Device: "/dev/vdc", + ID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + }}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{"foo": "bar"}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + Attachments: []volumes.Attachment{}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + } + + th.CheckDeepEquals(t, expected, actual) + +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "vol-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &volumes.CreateOpts{Size: 75, Name: "vol-001"} + n, err := volumes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Size, 75) + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateResponse(t) + + options := volumes.UpdateOpts{Name: "vol-002"} + v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract() + th.AssertNoErr(t, err) + th.CheckEquals(t, "vol-002", v.Name) +} + +func TestGetWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + var s struct { + volumes.Volume + volumetenants.VolumeTenantExt + } + err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&s) + th.AssertNoErr(t, err) + th.AssertEquals(t, "304dc00909ac4d0da6c62d816bcb3459", s.TenantID) + + err = volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(s) + if err == nil { + t.Errorf("Expected error when providing non-pointer struct") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/requests.go index 7df688ed..22531c9f 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/requests.go @@ -153,7 +153,12 @@ func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMet func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/testing/requests_test.go new file mode 100644 index 00000000..51231e30 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots/testing/requests_test.go @@ -0,0 +1,116 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := snapshots.ExtractSnapshots(page) + if err != nil { + t.Errorf("Failed to extract snapshots: %v", err) + return false, err + } + + expected := []snapshots.Snapshot{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "snapshot-001", + VolumeID: "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + Status: "available", + Size: 30, + CreatedAt: time.Date(2017, 5, 30, 3, 35, 3, 0, time.UTC), + Description: "Daily Backup", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "snapshot-002", + VolumeID: "76b8950a-8594-4e5b-8dce-0dfa9c696358", + Status: "available", + Size: 25, + CreatedAt: time.Date(2017, 5, 30, 3, 35, 3, 0, time.UTC), + Description: "Weekly Backup", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "snapshot-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := snapshots.CreateOpts{VolumeID: "1234", Name: "snapshot-001"} + n, err := snapshots.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.VolumeID, "1234") + th.AssertEquals(t, n.Name, "snapshot-001") + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestUpdateMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateMetadataResponse(t) + + expected := map[string]interface{}{"key": "v1"} + + options := &snapshots.UpdateMetadataOpts{ + Metadata: map[string]interface{}{ + "key": "v1", + }, + } + + actual, err := snapshots.UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, actual, expected) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := snapshots.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/requests.go index 43727409..b7977cbc 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/requests.go @@ -174,7 +174,12 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/testing/requests_test.go new file mode 100644 index 00000000..5a1e46b6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes/testing/requests_test.go @@ -0,0 +1,257 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumetenants" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + count := 0 + + volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := volumes.ExtractVolumes(page) + if err != nil { + t.Errorf("Failed to extract volumes: %v", err) + return false, err + } + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + Attachments: []volumes.Attachment{{ + ServerID: "83ec2e3b-4321-422b-8706-a84185f52a0a", + AttachmentID: "05551600-a936-4d4a-ba42-79a037c1-c91a", + AttachedAt: time.Date(2016, 8, 6, 14, 48, 20, 0, time.UTC), + HostName: "foobar", + VolumeID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + Device: "/dev/vdc", + ID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + }}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{"foo": "bar"}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + Attachments: []volumes.Attachment{}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListAllWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + type VolumeWithExt struct { + volumes.Volume + volumetenants.VolumeTenantExt + } + + allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + var actual []VolumeWithExt + err = volumes.ExtractVolumesInto(allPages, &actual) + th.AssertNoErr(t, err) + th.AssertEquals(t, 2, len(actual)) + th.AssertEquals(t, "304dc00909ac4d0da6c62d816bcb3459", actual[0].TenantID) +} + +func TestListAll(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := volumes.ExtractVolumes(allPages) + th.AssertNoErr(t, err) + + expected := []volumes.Volume{ + { + ID: "289da7f8-6440-407c-9fb4-7db01ec49164", + Name: "vol-001", + Attachments: []volumes.Attachment{{ + ServerID: "83ec2e3b-4321-422b-8706-a84185f52a0a", + AttachmentID: "05551600-a936-4d4a-ba42-79a037c1-c91a", + AttachedAt: time.Date(2016, 8, 6, 14, 48, 20, 0, time.UTC), + HostName: "foobar", + VolumeID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + Device: "/dev/vdc", + ID: "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75", + }}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{"foo": "bar"}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + { + ID: "96c3bda7-c82a-4f50-be73-ca7621794835", + Name: "vol-002", + Attachments: []volumes.Attachment{}, + AvailabilityZone: "nova", + Bootable: "false", + ConsistencyGroupID: "", + CreatedAt: time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC), + Description: "", + Encrypted: false, + Metadata: map[string]string{}, + Multiattach: false, + //TenantID: "304dc00909ac4d0da6c62d816bcb3459", + //ReplicationDriverData: "", + //ReplicationExtendedStatus: "", + ReplicationStatus: "disabled", + Size: 75, + SnapshotID: "", + SourceVolID: "", + Status: "available", + UserID: "ff1ce52c03ab433aaba9108c2e3ef541", + VolumeType: "lvmdriver-1", + }, + } + + th.CheckDeepEquals(t, expected, actual) + +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "vol-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &volumes.CreateOpts{Size: 75, Name: "vol-001"} + n, err := volumes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Size, 75) + th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateResponse(t) + + options := volumes.UpdateOpts{Name: "vol-002"} + v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract() + th.AssertNoErr(t, err) + th.CheckEquals(t, "vol-002", v.Name) +} + +func TestGetWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + var s struct { + volumes.Volume + volumetenants.VolumeTenantExt + } + err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&s) + th.AssertNoErr(t, err) + th.AssertEquals(t, "304dc00909ac4d0da6c62d816bcb3459", s.TenantID) + + err = volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(s) + if err == nil { + t.Errorf("Expected error when providing non-pointer struct") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes/testing/requests_test.go new file mode 100644 index 00000000..00c3e6ea --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes/testing/requests_test.go @@ -0,0 +1,118 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListAll(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + pages := 0 + err := volumetypes.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + pages++ + actual, err := volumetypes.ExtractVolumeTypes(page) + if err != nil { + return false, err + } + expected := []volumetypes.VolumeType{ + { + ID: "6685584b-1eac-4da6-b5c3-555430cf68ff", + Name: "SSD", + ExtraSpecs: map[string]string{"volume_backend_name": "lvmdriver-1"}, + IsPublic: true, + Description: "", + QosSpecID: "", + PublicAccess: true, + }, { + ID: "8eb69a46-df97-4e41-9586-9a40a7533803", + Name: "SATA", + ExtraSpecs: map[string]string{"volume_backend_name": "lvmdriver-1"}, + IsPublic: true, + Description: "", + QosSpecID: "", + PublicAccess: true, + }, + } + th.CheckDeepEquals(t, expected, actual) + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, pages, 1) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + v, err := volumetypes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, v.Name, "vol-type-001") + th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, v.ExtraSpecs["capabilities"], "gpu") + th.AssertEquals(t, v.QosSpecID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, v.PublicAccess, true) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + var isPublic = true + + options := &volumetypes.CreateOpts{ + Name: "test_type", + IsPublic: &isPublic, + Description: "test_type_desc", + ExtraSpecs: map[string]string{"capabilities": "gpu"}, + } + + n, err := volumetypes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Name, "test_type") + th.AssertEquals(t, n.Description, "test_type_desc") + th.AssertEquals(t, n.IsPublic, true) + th.AssertEquals(t, n.PublicAccess, true) + th.AssertEquals(t, n.ID, "6d0ff92a-0007-4780-9ece-acfe5876966a") + th.AssertEquals(t, n.ExtraSpecs["capabilities"], "gpu") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := volumetypes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateResponse(t) + + var isPublic = true + options := volumetypes.UpdateOpts{ + Name: "vol-type-002", + IsPublic: &isPublic, + } + + v, err := volumetypes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract() + th.AssertNoErr(t, err) + th.CheckEquals(t, "vol-type-002", v.Name) + th.CheckEquals(t, true, v.IsPublic) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/base/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/base/testing/requests_test.go new file mode 100644 index 00000000..9c9517e3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/base/testing/requests_test.go @@ -0,0 +1,46 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/cdn/v1/base" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetHomeDocument(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := base.Get(fake.ServiceClient()).Extract() + th.CheckNoErr(t, err) + + expected := base.HomeDocument{ + "resources": map[string]interface{}{ + "rel/cdn": map[string]interface{}{ + "href-template": "services{?marker,limit}", + "href-vars": map[string]interface{}{ + "marker": "param/marker", + "limit": "param/limit", + }, + "hints": map[string]interface{}{ + "allow": []interface{}{"GET"}, + "formats": map[string]interface{}{ + "application/json": map[string]interface{}{}, + }, + }, + }, + }, + } + th.CheckDeepEquals(t, expected, *actual) +} + +func TestPing(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePingSuccessfully(t) + + err := base.Ping(fake.ServiceClient()).ExtractErr() + th.CheckNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors/testing/requests_test.go new file mode 100644 index 00000000..bc4b1a50 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors/testing/requests_test.go @@ -0,0 +1,90 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListCDNFlavorsSuccessfully(t) + + count := 0 + + err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := flavors.ExtractFlavors(page) + if err != nil { + t.Errorf("Failed to extract flavors: %v", err) + return false, err + } + + expected := []flavors.Flavor{ + { + ID: "europe", + Providers: []flavors.Provider{ + { + Provider: "Fastly", + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "http://www.fastly.com", + Rel: "provider_url", + }, + }, + }, + }, + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "https://www.poppycdn.io/v1.0/flavors/europe", + Rel: "self", + }, + }, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetCDNFlavorSuccessfully(t) + + expected := &flavors.Flavor{ + ID: "asia", + Providers: []flavors.Provider{ + { + Provider: "ChinaCache", + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "http://www.chinacache.com", + Rel: "provider_url", + }, + }, + }, + }, + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "https://www.poppycdn.io/v1.0/flavors/asia", + Rel: "self", + }, + }, + } + + actual, err := flavors.Get(fake.ServiceClient(), "asia").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets/testing/requests_test.go new file mode 100644 index 00000000..ff2073bd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets/testing/requests_test.go @@ -0,0 +1,19 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteCDNAssetSuccessfully(t) + + err := serviceassets.Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", nil).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/services/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/services/testing/requests_test.go new file mode 100644 index 00000000..0abc98ef --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/cdn/v1/services/testing/requests_test.go @@ -0,0 +1,359 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/cdn/v1/services" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListCDNServiceSuccessfully(t) + + count := 0 + + err := services.List(fake.ServiceClient(), &services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := services.ExtractServices(page) + if err != nil { + t.Errorf("Failed to extract services: %v", err) + return false, err + } + + expected := []services.Service{ + { + ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", + Name: "mywebsite.com", + Domains: []services.Domain{ + { + Domain: "www.mywebsite.com", + }, + }, + Origins: []services.Origin{ + { + Origin: "mywebsite.com", + Port: 80, + SSL: false, + }, + }, + Caching: []services.CacheRule{ + { + Name: "default", + TTL: 3600, + }, + { + Name: "home", + TTL: 17200, + Rules: []services.TTLRule{ + { + Name: "index", + RequestURL: "/index.htm", + }, + }, + }, + { + Name: "images", + TTL: 12800, + Rules: []services.TTLRule{ + { + Name: "images", + RequestURL: "*.png", + }, + }, + }, + }, + Restrictions: []services.Restriction{ + { + Name: "website only", + Rules: []services.RestrictionRule{ + { + Name: "mywebsite.com", + Referrer: "www.mywebsite.com", + }, + }, + }, + }, + FlavorID: "asia", + Status: "deployed", + Errors: []services.Error{}, + Links: []gophercloud.Link{ + { + Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", + Rel: "self", + }, + { + Href: "mywebsite.com.cdn123.poppycdn.net", + Rel: "access_url", + }, + { + Href: "https://www.poppycdn.io/v1.0/flavors/asia", + Rel: "flavor", + }, + }, + }, + { + ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", + Name: "myothersite.com", + Domains: []services.Domain{ + { + Domain: "www.myothersite.com", + }, + }, + Origins: []services.Origin{ + { + Origin: "44.33.22.11", + Port: 80, + SSL: false, + }, + { + Origin: "77.66.55.44", + Port: 80, + SSL: false, + Rules: []services.OriginRule{ + { + Name: "videos", + RequestURL: "^/videos/*.m3u", + }, + }, + }, + }, + Caching: []services.CacheRule{ + { + Name: "default", + TTL: 3600, + }, + }, + Restrictions: []services.Restriction{}, + FlavorID: "europe", + Status: "deployed", + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", + Rel: "self", + }, + gophercloud.Link{ + Href: "myothersite.com.poppycdn.net", + Rel: "access_url", + }, + gophercloud.Link{ + Href: "https://www.poppycdn.io/v1.0/flavors/europe", + Rel: "flavor", + }, + }, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateCDNServiceSuccessfully(t) + + createOpts := services.CreateOpts{ + Name: "mywebsite.com", + Domains: []services.Domain{ + { + Domain: "www.mywebsite.com", + }, + { + Domain: "blog.mywebsite.com", + }, + }, + Origins: []services.Origin{ + { + Origin: "mywebsite.com", + Port: 80, + SSL: false, + }, + }, + Restrictions: []services.Restriction{ + { + Name: "website only", + Rules: []services.RestrictionRule{ + { + Name: "mywebsite.com", + Referrer: "www.mywebsite.com", + }, + }, + }, + }, + Caching: []services.CacheRule{ + { + Name: "default", + TTL: 3600, + }, + }, + FlavorID: "cdn", + } + + expected := "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" + actual, err := services.Create(fake.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, expected, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetCDNServiceSuccessfully(t) + + expected := &services.Service{ + ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", + Name: "mywebsite.com", + Domains: []services.Domain{ + { + Domain: "www.mywebsite.com", + Protocol: "http", + }, + }, + Origins: []services.Origin{ + { + Origin: "mywebsite.com", + Port: 80, + SSL: false, + }, + }, + Caching: []services.CacheRule{ + { + Name: "default", + TTL: 3600, + }, + { + Name: "home", + TTL: 17200, + Rules: []services.TTLRule{ + { + Name: "index", + RequestURL: "/index.htm", + }, + }, + }, + { + Name: "images", + TTL: 12800, + Rules: []services.TTLRule{ + { + Name: "images", + RequestURL: "*.png", + }, + }, + }, + }, + Restrictions: []services.Restriction{ + { + Name: "website only", + Rules: []services.RestrictionRule{ + { + Name: "mywebsite.com", + Referrer: "www.mywebsite.com", + }, + }, + }, + }, + FlavorID: "cdn", + Status: "deployed", + Errors: []services.Error{}, + Links: []gophercloud.Link{ + { + Href: "https://global.cdn.api.rackspacecloud.com/v1.0/110011/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", + Rel: "self", + }, + { + Href: "blog.mywebsite.com.cdn1.raxcdn.com", + Rel: "access_url", + }, + { + Href: "https://global.cdn.api.rackspacecloud.com/v1.0/110011/flavors/cdn", + Rel: "flavor", + }, + }, + } + + actual, err := services.Get(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestSuccessfulUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateCDNServiceSuccessfully(t) + + expected := "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" + ops := services.UpdateOpts{ + // Append a single Domain + services.Append{Value: services.Domain{Domain: "appended.mocksite4.com"}}, + // Insert a single Domain + services.Insertion{ + Index: 4, + Value: services.Domain{Domain: "inserted.mocksite4.com"}, + }, + // Bulk addition + services.Append{ + Value: services.DomainList{ + {Domain: "bulkadded1.mocksite4.com"}, + {Domain: "bulkadded2.mocksite4.com"}, + }, + }, + // Replace a single Origin + services.Replacement{ + Index: 2, + Value: services.Origin{Origin: "44.33.22.11", Port: 80, SSL: false}, + }, + // Bulk replace Origins + services.Replacement{ + Index: 0, // Ignored + Value: services.OriginList{ + {Origin: "44.33.22.11", Port: 80, SSL: false}, + {Origin: "55.44.33.22", Port: 443, SSL: true}, + }, + }, + // Remove a single CacheRule + services.Removal{ + Index: 8, + Path: services.PathCaching, + }, + // Bulk removal + services.Removal{ + All: true, + Path: services.PathCaching, + }, + // Service name replacement + services.NameReplacement{ + NewName: "differentServiceName", + }, + } + + actual, err := services.Update(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", ops).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, expected, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteCDNServiceSuccessfully(t) + + err := services.Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/client.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/client.go index 5a52e579..0859d9cb 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/client.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/client.go @@ -2,10 +2,7 @@ package openstack import ( "fmt" - "net/url" "reflect" - "regexp" - "strings" "github.com/gophercloud/gophercloud" tokens2 "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" @@ -38,21 +35,11 @@ A basic example of using this would be: client, err := openstack.NewIdentityV3(provider, gophercloud.EndpointOpts{}) */ func NewClient(endpoint string) (*gophercloud.ProviderClient, error) { - u, err := url.Parse(endpoint) + base, err := utils.BaseEndpoint(endpoint) if err != nil { return nil, err } - u.RawQuery, u.Fragment = "", "" - - var base string - versionRe := regexp.MustCompile("v[0-9.]+/?") - if version := versionRe.FindString(u.Path); version != "" { - base = strings.Replace(u.String(), version, "", -1) - } else { - base = u.String() - } - endpoint = gophercloud.NormalizeURL(endpoint) base = gophercloud.NormalizeURL(base) @@ -287,11 +274,17 @@ func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp // Ensure endpoint still has a suffix of v3. // This is because EndpointLocator might have found a versionless - // endpoint and requests will fail unless targeted at /v3. - if !strings.HasSuffix(endpoint, "v3/") { - endpoint = endpoint + "v3/" + // endpoint or the published endpoint is still /v2.0. In both + // cases, we need to fix the endpoint to point to /v3. + base, err := utils.BaseEndpoint(endpoint) + if err != nil { + return nil, err } + base = gophercloud.NormalizeURL(base) + + endpoint = base + "v3/" + return &gophercloud.ServiceClient{ ProviderClient: client, Endpoint: endpoint, @@ -394,3 +387,36 @@ func NewLoadBalancerV2(client *gophercloud.ProviderClient, eo gophercloud.Endpoi sc.ResourceBase = sc.Endpoint + "v2.0/" return sc, err } + +// NewClusteringV1 creates a ServiceClient that may be used with the v1 clustering +// package. +func NewClusteringV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + return initClientOpts(client, eo, "clustering") +} + +// NewMessagingV2 creates a ServiceClient that may be used with the v2 messaging +// service. +func NewMessagingV2(client *gophercloud.ProviderClient, clientID string, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + sc, err := initClientOpts(client, eo, "messaging") + sc.MoreHeaders = map[string]string{"Client-ID": clientID} + return sc, err +} + +// NewContainerV1 creates a ServiceClient that may be used with v1 container package +func NewContainerV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + return initClientOpts(client, eo, "container") +} + +// NewKeyManagerV1 creates a ServiceClient that may be used with the v1 key +// manager service. +func NewKeyManagerV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + sc, err := initClientOpts(client, eo, "key-manager") + sc.ResourceBase = sc.Endpoint + "v1/" + return sc, err +} + +// NewContainerInfraV1 creates a ServiceClient that may be used with the v1 container infra management +// package. +func NewContainerInfraV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + return initClientOpts(client, eo, "container-infra") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/doc.go new file mode 100644 index 00000000..2312a512 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/doc.go @@ -0,0 +1,33 @@ +/* +Package actions provides listing and retrieving of senlin actions for the +OpenStack Clustering Service. + +Example to List Actions + + opts := actions.ListOpts{ + Limit: 5, + } + + err = actions.List(serviceClient, opts).EachPage(func(page pagination.Page) (bool, error) { + actionInfos, err := actions.ExtractActions(page) + if err != nil { + return false, err + } + + for _, actionInfo := range actionInfos { + fmt.Println("%+v\n", actionInfo) + } + return true, nil + }) + +Example to Get an Action + + actionID := "edce3528-864f-41fb-8759-f4707925cc09" + action, err := actions.Get(serviceClient, actionID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("Action %+v: ", action) +*/ +package actions diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/requests.go new file mode 100644 index 00000000..f1a4f43f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/requests.go @@ -0,0 +1,51 @@ +package actions + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToActionListQuery() (string, error) +} + +// ListOpts represents options used to list actions. +type ListOpts struct { + Limit int `q:"limit"` + Marker string `q:"marker"` + Sort string `q:"sort"` + GlobalProject *bool `q:"global_project"` + Name string `q:"name"` + Target string `q:"target"` + Action string `q:"action"` + Status string `q:"status"` +} + +// ToClusterListQuery builds a query string from ListOpts. +func (opts ListOpts) ToActionListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of actions. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToActionListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ActionPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves details of a single action. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/results.go new file mode 100644 index 00000000..ca03a4b7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/results.go @@ -0,0 +1,106 @@ +package actions + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Action represents a detailed Action. +type Action struct { + Action string `json:"action"` + Cause string `json:"cause"` + CreatedAt time.Time `json:"-"` + Data map[string]interface{} `json:"data"` + DependedBy []string `json:"depended_by"` + DependsOn []string `json:"depends_on"` + StartTime float64 `json:"start_time"` + EndTime float64 `json:"end_time"` + ID string `json:"id"` + Inputs map[string]interface{} `json:"inputs"` + Interval int `json:"interval"` + Name string `json:"name"` + Outputs map[string]interface{} `json:"outputs"` + Owner string `json:"owner"` + Project string `json:"project"` + Status string `json:"status"` + StatusReason string `json:"status_reason"` + Target string `json:"target"` + Timeout int `json:"timeout"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Action) UnmarshalJSON(b []byte) error { + type tmp Action + var s struct { + tmp + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + *r = Action(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(time.RFC3339, s.CreatedAt) + if err != nil { + return err + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(time.RFC3339, s.UpdatedAt) + if err != nil { + return err + } + } + + return nil +} + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult-based result as an Action. +func (r commonResult) Extract() (*Action, error) { + var s struct { + Action *Action `json:"action"` + } + err := r.ExtractInto(&s) + return s.Action, err +} + +// GetResult is the response of a Get operations. Call its Extract method to +// interpret it as an Action. +type GetResult struct { + commonResult +} + +// ActionPage contains a single page of all actions from a List call. +type ActionPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines if a ActionPage contains any results. +func (r ActionPage) IsEmpty() (bool, error) { + actions, err := ExtractActions(r) + return len(actions) == 0, err +} + +// ExtractActions returns a slice of Actions from the List operation. +func ExtractActions(r pagination.Page) ([]Action, error) { + var s struct { + Actions []Action `json:"actions"` + } + err := (r.(ActionPage)).ExtractInto(&s) + return s.Actions, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/doc.go new file mode 100644 index 00000000..ffecf4d8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_actions_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/fixtures.go new file mode 100644 index 00000000..4709b7c5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/fixtures.go @@ -0,0 +1,166 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/actions" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ListResponse = ` +{ + "actions": [ + { + "action": "NODE_DELETE", + "cause": "RPC Request", + "created_at": "2015-11-04T05:21:41Z", + "data": {}, + "depended_by": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "depends_on": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "end_time": 1425550000.0, + "id": "edce3528-864f-41fb-8759-f4707925cc09", + "inputs": {}, + "interval": -1, + "name": "node_delete_f0de9b9c", + "outputs": {}, + "owner": null, + "project": "f1fe61dcda2f4618a14c10dc7abc214d", + "start_time": 1425550000.0, + "status": "SUCCEEDED", + "status_reason": "Action completed successfully.", + "target": "f0de9b9c-6d48-4a46-af21-2ca8607777fe", + "timeout": 3600, + "updated_at": "2016-11-04T05:21:41Z", + "user": "8bcd2cdca7684c02afc9e4f2fc0f0c79" + }, + { + "action": "NODE_DELETE", + "cause": "RPC Request", + "created_at": null, + "data": {}, + "depended_by": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "depends_on": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "end_time": 1425550000.0, + "id": "edce3528-864f-41fb-8759-f4707925cc09", + "inputs": {}, + "interval": -1, + "name": "node_delete_f0de9b9c", + "outputs": {}, + "owner": null, + "project": "f1fe61dcda2f4618a14c10dc7abc214d", + "start_time": 1425550000.0, + "status": "SUCCEEDED", + "status_reason": "Action completed successfully.", + "target": "f0de9b9c-6d48-4a46-af21-2ca8607777fe", + "timeout": 3600, + "updated_at": "", + "user": "8bcd2cdca7684c02afc9e4f2fc0f0c79" + } + ] +} +` + +const GetResponse = ` +{ + "action": { + "action": "NODE_DELETE", + "cause": "RPC Request", + "created_at": "2015-11-04T05:21:41Z", + "data": {}, + "depended_by": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "depends_on": ["ef67fe80-6547-40f2-ba1b-83e950aa38df"], + "end_time": 1425550000.0, + "id": "edce3528-864f-41fb-8759-f4707925cc09", + "inputs": {}, + "interval": -1, + "name": "node_delete_f0de9b9c", + "outputs": {}, + "owner": null, + "project": "f1fe61dcda2f4618a14c10dc7abc214d", + "start_time": 1425550000.0, + "status": "SUCCEEDED", + "status_reason": "Action completed successfully.", + "target": "f0de9b9c-6d48-4a46-af21-2ca8607777fe", + "timeout": 3600, + "updated_at": "2016-11-04T05:21:41Z", + "user": "8bcd2cdca7684c02afc9e4f2fc0f0c79" + } +} +` + +var ExpectedAction1 = actions.Action{ + Action: "NODE_DELETE", + Cause: "RPC Request", + CreatedAt: time.Date(2015, 11, 4, 5, 21, 41, 0, time.UTC), + Data: map[string]interface{}{}, + DependedBy: []string{"ef67fe80-6547-40f2-ba1b-83e950aa38df"}, + DependsOn: []string{"ef67fe80-6547-40f2-ba1b-83e950aa38df"}, + EndTime: 1425550000.0, + ID: "edce3528-864f-41fb-8759-f4707925cc09", + Inputs: make(map[string]interface{}), + Interval: -1, + Name: "node_delete_f0de9b9c", + Outputs: make(map[string]interface{}), + Owner: "", + Project: "f1fe61dcda2f4618a14c10dc7abc214d", + StartTime: 1425550000.0, + Status: "SUCCEEDED", + StatusReason: "Action completed successfully.", + Target: "f0de9b9c-6d48-4a46-af21-2ca8607777fe", + Timeout: 3600, + UpdatedAt: time.Date(2016, 11, 4, 5, 21, 41, 0, time.UTC), + User: "8bcd2cdca7684c02afc9e4f2fc0f0c79", +} + +var ExpectedAction2 = actions.Action{ + Action: "NODE_DELETE", + Cause: "RPC Request", + CreatedAt: time.Time{}, + Data: map[string]interface{}{}, + DependedBy: []string{"ef67fe80-6547-40f2-ba1b-83e950aa38df"}, + DependsOn: []string{"ef67fe80-6547-40f2-ba1b-83e950aa38df"}, + EndTime: 1425550000.0, + ID: "edce3528-864f-41fb-8759-f4707925cc09", + Inputs: make(map[string]interface{}), + Interval: -1, + Name: "node_delete_f0de9b9c", + Outputs: make(map[string]interface{}), + Owner: "", + Project: "f1fe61dcda2f4618a14c10dc7abc214d", + StartTime: 1425550000.0, + Status: "SUCCEEDED", + StatusReason: "Action completed successfully.", + Target: "f0de9b9c-6d48-4a46-af21-2ca8607777fe", + Timeout: 3600, + UpdatedAt: time.Time{}, + User: "8bcd2cdca7684c02afc9e4f2fc0f0c79", +} + +var ExpectedActions = []actions.Action{ExpectedAction1, ExpectedAction2} + +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResponse) + }) +} + +func HandleGetSuccessfully(t *testing.T, id string) { + th.Mux.HandleFunc("/v1/actions/"+id, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/requests_test.go new file mode 100644 index 00000000..6a4e5f15 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/testing/requests_test.go @@ -0,0 +1,44 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/actions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListActions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + pageCount := 0 + err := actions.List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + pageCount++ + actual, err := actions.ExtractActions(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedActions, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + + if pageCount != 1 { + t.Errorf("Expected 1 page, got %d", pageCount) + } +} + +func TestGetAction(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t, ExpectedAction1.ID) + + actual, err := actions.Get(fake.ServiceClient(), ExpectedAction1.ID).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedAction1, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/urls.go new file mode 100644 index 00000000..3288cc80 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/actions/urls.go @@ -0,0 +1,22 @@ +package actions + +import "github.com/gophercloud/gophercloud" + +var apiVersion = "v1" +var apiName = "actions" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func idURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/doc.go new file mode 100644 index 00000000..f731fb53 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/doc.go @@ -0,0 +1,227 @@ +/* +Package clusters provides information and interaction with the clusters through +the OpenStack Clustering service. + +Example to Create a Cluster + + createOpts := clusters.CreateOpts{ + Name: "test-cluster", + DesiredCapacity: 1, + ProfileID: "b7b870ee-d3c5-4a93-b9d7-846c53b2c2da", + } + + cluster, err := clusters.Create(serviceClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Get a Cluster + + clusterName := "cluster123" + cluster, err := clusters.Get(serviceClient, clusterName).Extract() + if err != nil { + panic(err) + } + fmt.Printf("%+v\n", cluster) + +Example to List Clusters + + listOpts := clusters.ListOpts{ + Name: "testcluster", + } + + allPages, err := clusters.ListDetail(serviceClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allClusters, err := clusters.ExtractClusters(allPages) + if err != nil { + panic(err) + } + + for _, cluster := range allClusters { + fmt.Printf("%+v\n", cluster) + } + +Example to Update a Cluster + + updateOpts := clusters.UpdateOpts{ + Name: "testcluster", + ProfileID: "b7b870ee-d3c5-4a93-b9d7-846c53b2c2da", + } + + clusterID := "7d85f602-a948-4a30-afd4-e84f47471c15" + cluster, err := clusters.Update(serviceClient, clusterName, opts).Extract() + if err != nil { + panic(err) + } + fmt.Printf("%+v\n", cluster) + +Example to Delete a Cluster + + clusterID := "dc6d336e3fc4c0a951b5698cd1236ee" + err := clusters.Delete(serviceClient, clusterID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Resize a Cluster + + number := 1 + maxSize := 5 + minSize := 1 + minStep := 1 + strict := true + + resizeOpts := clusters.ResizeOpts{ + AdjustmentType: clusters.ChangeInCapacityAdjustment, + Number: number, + MaxSize: &maxSize, + MinSize: &minSize, + MinStep: &minStep, + Strict: &strict, + } + + actionID, err := clusters.Resize(client, clusterName, resizeOpts).Extract() + if err != nil { + t.Fatalf("Unable to resize cluster: %v", err) + } + fmt.Println("Resize actionID", actionID) + +Example to ScaleIn a Cluster + + count := 2 + scaleInOpts := clusters.ScaleInOpts{ + Count: &count, + } + clusterID: "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + + action, err := clusters.ScaleIn(computeClient, clusterID, scaleInOpts).Extract() + if err != nil { + panic(err) + } + +Example to ScaleOut a cluster + + scaleOutOpts := clusters.ScaleOutOpts{ + Count: 2, + } + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + + actionID, err := clusters.ScaleOut(computeClient, clusterID, scaleOutOpts).Extract() + if err != nil { + panic(err) + } + +Example to List Policies for a Cluster + + clusterID := "7d85f602-a948-4a30-afd4-e84f47471c15" + allPages, err := clusters.ListPolicies(serviceClient, clusterID, nil).AllPages() + if err != nil { + panic(err) + } + + allClusterPolicies, err := clusters.ExtractClusterPolicies(allPages) + if err != nil { + panic(err) + } + + for _, clusterPolicy := range allClusterPolicies { + fmt.Printf("%+v\n", clusterPolicy) + } + +Example to Get a Cluster Policy + + clusterID := "7d85f602-a948-4a30-afd4-e84f47471c15" + profileID := "714fe676-a08f-4196-b7af-61d52eeded15" + clusterPolicy, err := clusterpolicies.Get(serviceCLient, clusterID, profileID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", clusterPolicy) + +Example to Attach a Policy to a Cluster + + enabled := true + attachPolicyOpts := clusters.AttachPolicyOpts{ + PolicyID: "policy-123", + Enabled: &enabled, + } + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + actionID, err := clusters.AttachPolicy(serviceClient, clusterID, attachPolicyOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Println("Attach Policy actionID", actionID) + +Example to Detach a Policy to Cluster + + detachpolicyOpts := clusters.DetachPolicyOpts{ + PolicyID: "policy-123", + } + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + actionID, err := clusters.DetachPolicy(serviceClient, clusterID, detachpolicyOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Println("Update Policy actionID", actionID) + +Example to Update a Policy to a Cluster + + enabled := true + updatePolicyOpts := clusters.UpdatePolicyOpts{ + PolicyID: "policy-123", + Enabled: &enabled, + } + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + actionID, err := clusters.UpdatePolicy(serviceClient, clusterID, updatePolicyOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Println("Attach Policy actionID", actionID) + +Example to Recover a Cluster + + check := true + checkCapacity := true + recoverOpts := clusters.RecoverOpts{ + Operation: clusters.RebuildRecovery, + Check: &check, + CheckCapacity: &checkCapacity, + } + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + actionID, err := clusters.Recover(computeClient, clusterID, recoverOpts).Extract() + if err != nil { + panic(err) + } + fmt.Println("action=", actionID) + +Example to Check a Cluster + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + action, err := clusters.Check(computeClient, clusterID).Extract() + if err != nil { + panic(err) + } + +Example to Complete Life Cycle + + clusterID := "b7b870e3-d3c5-4a93-b9d7-846c53b2c2da" + lifecycleOpts := clusters.CompleteLifecycleOpts{LifecycleActionTokenID: "2b827124-69e1-496e-9484-33ca769fe4df"} + + action, err := clusters.CompleteLifecycle(computeClient, clusterID, lifecycleOpts).Extract() + if err != nil { + panic(err) + } + +*/ +package clusters diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/requests.go new file mode 100644 index 00000000..2c97e202 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/requests.go @@ -0,0 +1,525 @@ +package clusters + +import ( + "fmt" + "net/http" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// AdjustmentType represents valid values for resizing a cluster. +type AdjustmentType string + +const ( + ExactCapacityAdjustment AdjustmentType = "EXACT_CAPACITY" + ChangeInCapacityAdjustment AdjustmentType = "CHANGE_IN_CAPACITY" + ChangeInPercentageAdjustment AdjustmentType = "CHANGE_IN_PERCENTAGE" +) + +// RecoveryAction represents valid values for recovering a cluster. +type RecoveryAction string + +const ( + RebootRecovery RecoveryAction = "REBOOT" + RebuildRecovery RecoveryAction = "REBUILD" + RecreateRecovery RecoveryAction = "RECREATE" +) + +// CreateOptsBuilder allows extensions to add additional parameters +// to the Create request. +type CreateOptsBuilder interface { + ToClusterCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options used to create a cluster. +type CreateOpts struct { + Name string `json:"name" required:"true"` + DesiredCapacity int `json:"desired_capacity"` + ProfileID string `json:"profile_id" required:"true"` + MinSize *int `json:"min_size,omitempty"` + Timeout int `json:"timeout,omitempty"` + MaxSize int `json:"max_size,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Config map[string]interface{} `json:"config,omitempty"` +} + +// ToClusterCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "cluster") +} + +// Create requests the creation of a new cluster. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToClusterCreateMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// Get retrieves details of a single cluster. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + var result *http.Response + result, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request. +type ListOptsBuilder interface { + ToClusterListQuery() (string, error) +} + +// ListOpts represents options to list clusters. +type ListOpts struct { + Limit int `q:"limit"` + Marker string `q:"marker"` + Sort string `q:"sort"` + GlobalProject *bool `q:"global_project"` + Name string `q:"name,omitempty"` + Status string `q:"status,omitempty"` +} + +// ToClusterListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToClusterListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of clusters. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToClusterListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ClusterPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToClusterUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options to update a cluster. +type UpdateOpts struct { + Config string `json:"config,omitempty"` + Name string `json:"name,omitempty"` + ProfileID string `json:"profile_id,omitempty"` + Timeout *int `json:"timeout,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + ProfileOnly *bool `json:"profile_only,omitempty"` +} + +// ToClusterUpdateMap assembles a request body based on the contents of +// UpdateOpts. +func (opts UpdateOpts) ToClusterUpdateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "cluster") + if err != nil { + return nil, err + } + return b, nil +} + +// Update will update an existing cluster. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToClusterUpdateMap() + if err != nil { + r.Err = err + return r + } + + var result *http.Response + result, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 202}, + }) + + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Delete deletes the specified cluster ID. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + var result *http.Response + result, r.Err = client.Delete(deleteURL(client, id), nil) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// ResizeOptsBuilder allows extensions to add additional parameters to the +// resize request. +type ResizeOptsBuilder interface { + ToClusterResizeMap() (map[string]interface{}, error) +} + +// ResizeOpts represents options for resizing a cluster. +type ResizeOpts struct { + AdjustmentType AdjustmentType `json:"adjustment_type,omitempty"` + Number interface{} `json:"number,omitempty"` + MinSize *int `json:"min_size,omitempty"` + MaxSize *int `json:"max_size,omitempty"` + MinStep *int `json:"min_step,omitempty"` + Strict *bool `json:"strict,omitempty"` +} + +// ToClusterResizeMap constructs a request body from ResizeOpts. +func (opts ResizeOpts) ToClusterResizeMap() (map[string]interface{}, error) { + if opts.AdjustmentType != "" && opts.Number == nil { + return nil, fmt.Errorf("Number field MUST NOT be empty when AdjustmentType field used") + } + + switch opts.Number.(type) { + case nil, int, int32, int64: + // Valid type. Always allow + case float32, float64: + if opts.AdjustmentType != ChangeInPercentageAdjustment { + return nil, fmt.Errorf("Only ChangeInPercentageAdjustment allows float value for Number field") + } + default: + return nil, fmt.Errorf("Number field must be either int, float, or omitted") + } + + return gophercloud.BuildRequestBody(opts, "resize") +} + +func Resize(client *gophercloud.ServiceClient, id string, opts ResizeOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterResizeMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ScaleInOptsBuilder allows extensions to add additional parameters to the +// ScaleIn request. +type ScaleInOptsBuilder interface { + ToClusterScaleInMap() (map[string]interface{}, error) +} + +// ScaleInOpts represents options used to scale-in a cluster. +type ScaleInOpts struct { + Count *int `json:"count,omitempty"` +} + +// ToClusterScaleInMap constructs a request body from ScaleInOpts. +func (opts ScaleInOpts) ToClusterScaleInMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "scale_in") +} + +// ScaleIn will reduce the capacity of a cluster. +func ScaleIn(client *gophercloud.ServiceClient, id string, opts ScaleInOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterScaleInMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ScaleOutOptsBuilder allows extensions to add additional parameters to the +// ScaleOut request. +type ScaleOutOptsBuilder interface { + ToClusterScaleOutMap() (map[string]interface{}, error) +} + +// ScaleOutOpts represents options used to scale-out a cluster. +type ScaleOutOpts struct { + Count int `json:"count,omitempty"` +} + +// ToClusterScaleOutMap constructs a request body from ScaleOutOpts. +func (opts ScaleOutOpts) ToClusterScaleOutMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "scale_out") +} + +// ScaleOut will increase the capacity of a cluster. +func ScaleOut(client *gophercloud.ServiceClient, id string, opts ScaleOutOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterScaleOutMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// AttachPolicyOptsBuilder allows extensions to add additional parameters to the +// AttachPolicy request. +type AttachPolicyOptsBuilder interface { + ToClusterAttachPolicyMap() (map[string]interface{}, error) +} + +// PolicyOpts params +type AttachPolicyOpts struct { + PolicyID string `json:"policy_id" required:"true"` + Enabled *bool `json:"enabled,omitempty"` +} + +// ToClusterAttachPolicyMap constructs a request body from AttachPolicyOpts. +func (opts AttachPolicyOpts) ToClusterAttachPolicyMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "policy_attach") +} + +// Attach Policy will attach a policy to a cluster. +func AttachPolicy(client *gophercloud.ServiceClient, id string, opts AttachPolicyOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterAttachPolicyMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// UpdatePolicyOptsBuilder allows extensions to add additional parameters to the +// UpdatePolicy request. +type UpdatePolicyOptsBuilder interface { + ToClusterUpdatePolicyMap() (map[string]interface{}, error) +} + +// UpdatePolicyOpts represents options used to update a cluster policy. +type UpdatePolicyOpts struct { + PolicyID string `json:"policy_id" required:"true"` + Enabled *bool `json:"enabled,omitempty" required:"true"` +} + +// ToClusterUpdatePolicyMap constructs a request body from UpdatePolicyOpts. +func (opts UpdatePolicyOpts) ToClusterUpdatePolicyMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "policy_update") +} + +// UpdatePolicy will update a cluster's policy. +func UpdatePolicy(client *gophercloud.ServiceClient, id string, opts UpdatePolicyOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterUpdatePolicyMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// DetachPolicyOptsBuilder allows extensions to add additional parameters to the +// DetachPolicy request. +type DetachPolicyOptsBuilder interface { + ToClusterDetachPolicyMap() (map[string]interface{}, error) +} + +// DetachPolicyOpts represents options used to detach a policy from a cluster. +type DetachPolicyOpts struct { + PolicyID string `json:"policy_id" required:"true"` +} + +// ToClusterDetachPolicyMap constructs a request body from DetachPolicyOpts. +func (opts DetachPolicyOpts) ToClusterDetachPolicyMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "policy_detach") +} + +// DetachPolicy will detach a policy from a cluster. +func DetachPolicy(client *gophercloud.ServiceClient, id string, opts DetachPolicyOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterDetachPolicyMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ListPolicyOptsBuilder allows extensions to add additional parameters to the +// ListPolicies request. +type ListPoliciesOptsBuilder interface { + ToClusterPoliciesListQuery() (string, error) +} + +// ListPoliciesOpts represents options to list a cluster's policies. +type ListPoliciesOpts struct { + Enabled *bool `q:"enabled"` + Name string `q:"policy_name"` + Type string `q:"policy_type"` + Sort string `q:"sort"` +} + +// ToClusterPoliciesListQuery formats a ListOpts into a query string. +func (opts ListPoliciesOpts) ToClusterPoliciesListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListPolicies instructs OpenStack to provide a list of policies for a cluster. +func ListPolicies(client *gophercloud.ServiceClient, clusterID string, opts ListPoliciesOptsBuilder) pagination.Pager { + url := listPoliciesURL(client, clusterID) + if opts != nil { + query, err := opts.ToClusterPoliciesListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ClusterPolicyPage{pagination.SinglePageBase(r)} + }) +} + +// GetPolicy retrieves details of a cluster policy. +func GetPolicy(client *gophercloud.ServiceClient, clusterID string, policyID string) (r GetPolicyResult) { + _, r.Err = client.Get(getPolicyURL(client, clusterID, policyID), &r.Body, nil) + return +} + +// RecoverOptsBuilder allows extensions to add additional parameters to the +// Recover request. +type RecoverOptsBuilder interface { + ToClusterRecoverMap() (map[string]interface{}, error) +} + +// RecoverOpts represents options used to recover a cluster. +type RecoverOpts struct { + Operation RecoveryAction `json:"operation,omitempty"` + Check *bool `json:"check,omitempty"` + CheckCapacity *bool `json:"check_capacity,omitempty"` +} + +// ToClusterRecovermap constructs a request body from RecoverOpts. +func (opts RecoverOpts) ToClusterRecoverMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "recover") +} + +// Recover implements cluster recover request. +func Recover(client *gophercloud.ServiceClient, id string, opts RecoverOptsBuilder) (r ActionResult) { + b, err := opts.ToClusterRecoverMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// Check will perform a health check on a cluster. +func Check(client *gophercloud.ServiceClient, id string) (r ActionResult) { + b := map[string]interface{}{ + "check": map[string]interface{}{}, + } + + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ToClusterCompleteLifecycleMap constructs a request body from CompleteLifecycleOpts. +func (opts CompleteLifecycleOpts) ToClusterCompleteLifecycleMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "complete_lifecycle") +} + +type CompleteLifecycleOpts struct { + LifecycleActionTokenID string `json:"lifecycle_action_token" required:"true"` +} + +func CompleteLifecycle(client *gophercloud.ServiceClient, id string, opts CompleteLifecycleOpts) (r ActionResult) { + b, err := opts.ToClusterCompleteLifecycleMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/results.go new file mode 100644 index 00000000..b9d7aa2b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/results.go @@ -0,0 +1,201 @@ +package clusters + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Cluster represents an OpenStack Clustering cluster. +type Cluster struct { + Config map[string]interface{} `json:"config"` + CreatedAt time.Time `json:"-"` + Data map[string]interface{} `json:"data"` + Dependents map[string]interface{} `json:"dependents"` + DesiredCapacity int `json:"desired_capacity"` + Domain string `json:"domain"` + ID string `json:"id"` + InitAt time.Time `json:"-"` + MaxSize int `json:"max_size"` + Metadata map[string]interface{} `json:"metadata"` + MinSize int `json:"min_size"` + Name string `json:"name"` + Nodes []string `json:"nodes"` + Policies []string `json:"policies"` + ProfileID string `json:"profile_id"` + ProfileName string `json:"profile_name"` + Project string `json:"project"` + Status string `json:"status"` + StatusReason string `json:"status_reason"` + Timeout int `json:"timeout"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Cluster) UnmarshalJSON(b []byte) error { + type tmp Cluster + var s struct { + tmp + CreatedAt string `json:"created_at"` + InitAt string `json:"init_at"` + UpdatedAt string `json:"updated_at"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Cluster(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(gophercloud.RFC3339Milli, s.CreatedAt) + if err != nil { + return err + } + } + + if s.InitAt != "" { + r.InitAt, err = time.Parse(gophercloud.RFC3339Milli, s.InitAt) + if err != nil { + return err + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(gophercloud.RFC3339Milli, s.UpdatedAt) + if err != nil { + return err + } + } + + return nil +} + +// ClusterPolicy represents and OpenStack Clustering cluster policy. +type ClusterPolicy struct { + ClusterID string `json:"cluster_id"` + ClusterName string `json:"cluster_name"` + Enabled bool `json:"enabled"` + ID string `json:"id"` + PolicyID string `json:"policy_id"` + PolicyName string `json:"policy_name"` + PolicyType string `json:"policy_type"` +} + +// Action represents an OpenStack Clustering action. +type Action struct { + Action string `json:"action"` +} + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult-based result as a Cluster. +func (r commonResult) Extract() (*Cluster, error) { + var s struct { + Cluster *Cluster `json:"cluster"` + } + + err := r.ExtractInto(&s) + return s.Cluster, err +} + +// CreateResult is the response of a Create operations. Call its Extract method +// to interpret it as a Cluster. +type CreateResult struct { + commonResult +} + +// GetResult is the response of a Get operations. Call its Extract method to +// interpret it as a Cluster. +type GetResult struct { + commonResult +} + +// UpdateResult is the response of a Update operations. Call its Extract method +// to interpret it as a Cluster. +type UpdateResult struct { + commonResult +} + +// GetPolicyResult is the response of a Get operations. Call its Extract method +// to interpret it as a ClusterPolicy. +type GetPolicyResult struct { + gophercloud.Result +} + +// Extract interprets a GetPolicyResult as a ClusterPolicy. +func (r GetPolicyResult) Extract() (*ClusterPolicy, error) { + var s struct { + ClusterPolicy *ClusterPolicy `json:"cluster_policy"` + } + err := r.ExtractInto(&s) + return s.ClusterPolicy, err +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// ClusterPage contains a single page of all clusters from a List call. +type ClusterPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of Clusters contains any results. +func (page ClusterPage) IsEmpty() (bool, error) { + clusters, err := ExtractClusters(page) + return len(clusters) == 0, err +} + +// ClusterPolicyPage contains a single page of all policies from a List call +type ClusterPolicyPage struct { + pagination.SinglePageBase +} + +// IsEmpty determines whether or not a page of ClusterPolicies contains any +// results. +func (page ClusterPolicyPage) IsEmpty() (bool, error) { + clusterPolicies, err := ExtractClusterPolicies(page) + return len(clusterPolicies) == 0, err +} + +// ActionResult is the response of Senlin actions. Call its Extract method to +// obtain the Action ID of the action. +type ActionResult struct { + gophercloud.Result +} + +// Extract interprets any Action result as an Action. +func (r ActionResult) Extract() (string, error) { + var s struct { + Action string `json:"action"` + } + err := r.ExtractInto(&s) + return s.Action, err +} + +// ExtractClusters returns a slice of Clusters from the List operation. +func ExtractClusters(r pagination.Page) ([]Cluster, error) { + var s struct { + Clusters []Cluster `json:"clusters"` + } + err := (r.(ClusterPage)).ExtractInto(&s) + return s.Clusters, err +} + +// ExtractClusterPolicies returns a slice of ClusterPolicies from the +// ListClusterPolicies operation. +func ExtractClusterPolicies(r pagination.Page) ([]ClusterPolicy, error) { + var s struct { + ClusterPolicies []ClusterPolicy `json:"cluster_policies"` + } + err := (r.(ClusterPolicyPage)).ExtractInto(&s) + return s.ClusterPolicies, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/doc.go new file mode 100644 index 00000000..02215778 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_clusters_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/fixtures.go new file mode 100644 index 00000000..26c84821 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/fixtures.go @@ -0,0 +1,624 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ClusterResponse = ` +{ + "cluster": { + "config": {}, + "created_at": "2015-02-10T14:26:14Z", + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": "2015-02-10T15:26:14Z", + "max_size": 20, + "metadata": {}, + "min_size": 1, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": "2015-02-10T16:26:14Z", + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedCluster = clusters.Cluster{ + Config: map[string]interface{}{}, + CreatedAt: time.Date(2015, 2, 10, 14, 26, 14, 0, time.UTC), + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + DesiredCapacity: 3, + Domain: "", + ID: "7d85f602-a948-4a30-afd4-e84f47471c15", + InitAt: time.Date(2015, 2, 10, 15, 26, 14, 0, time.UTC), + MaxSize: 20, + Metadata: map[string]interface{}{}, + MinSize: 1, + Name: "cluster1", + Nodes: []string{ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac", + }, + Policies: []string{}, + ProfileID: "edc63d0a-2ca4-48fa-9854-27926da76a4a", + ProfileName: "mystack", + Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", + Status: "ACTIVE", + StatusReason: "Cluster scale-in succeeded", + Timeout: 3600, + UpdatedAt: time.Date(2015, 2, 10, 16, 26, 14, 0, time.UTC), + User: "5e5bf8027826429c96af157f68dc9072", +} + +const ClusterResponse_EmptyTime = ` +{ + "cluster": { + "config": {}, + "created_at": null, + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": null, + "max_size": 20, + "metadata": {}, + "min_size": 1, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": null, + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedCluster_EmptyTime = clusters.Cluster{ + Config: map[string]interface{}{}, + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + DesiredCapacity: 3, + Domain: "", + ID: "7d85f602-a948-4a30-afd4-e84f47471c15", + MaxSize: 20, + Metadata: map[string]interface{}{}, + MinSize: 1, + Name: "cluster1", + Nodes: []string{ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac", + }, + Policies: []string{}, + ProfileID: "edc63d0a-2ca4-48fa-9854-27926da76a4a", + ProfileName: "mystack", + Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", + Status: "ACTIVE", + StatusReason: "Cluster scale-in succeeded", + Timeout: 3600, + User: "5e5bf8027826429c96af157f68dc9072", +} + +const ClusterResponse_Metadata = ` +{ + "cluster": { + "config": {}, + "created_at": "2015-02-10T14:26:14Z", + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": "2015-02-10T15:26:14Z", + "max_size": 20, + "metadata": { + "test": { + "nil_interface": null, + "bool_value": false, + "string_value": "test_string", + "float_value": 123.3 + }, + "foo": "bar" + }, + "min_size": 1, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": "2015-02-10T16:26:14Z", + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedCluster_Metadata = clusters.Cluster{ + Config: map[string]interface{}{}, + CreatedAt: time.Date(2015, 2, 10, 14, 26, 14, 0, time.UTC), + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + DesiredCapacity: 3, + Domain: "", + ID: "7d85f602-a948-4a30-afd4-e84f47471c15", + InitAt: time.Date(2015, 2, 10, 15, 26, 14, 0, time.UTC), + MaxSize: 20, + MinSize: 1, + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Name: "cluster1", + Nodes: []string{ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac", + }, + Policies: []string{}, + ProfileID: "edc63d0a-2ca4-48fa-9854-27926da76a4a", + ProfileName: "mystack", + Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", + Status: "ACTIVE", + StatusReason: "Cluster scale-in succeeded", + Timeout: 3600, + UpdatedAt: time.Date(2015, 2, 10, 16, 26, 14, 0, time.UTC), + User: "5e5bf8027826429c96af157f68dc9072", +} + +const ListResponse = ` +{ + "clusters": [ + { + "config": {}, + "created_at": "2015-02-10T14:26:14Z", + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": "2015-02-10T15:26:14Z", + "max_size": 20, + "min_size": 1, + "metadata": {}, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": "2015-02-10T16:26:14Z", + "user": "5e5bf8027826429c96af157f68dc9072" + }, + { + "config": {}, + "created_at": null, + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": null, + "max_size": 20, + "metadata": {}, + "min_size": 1, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": null, + "user": "5e5bf8027826429c96af157f68dc9072" + } + ] +}` + +var ExpectedClusters = []clusters.Cluster{ExpectedCluster, ExpectedCluster_EmptyTime} + +const UpdateResponse = ` +{ + "cluster": { + "config": {}, + "created_at": "2015-02-10T14:26:14Z", + "data": {}, + "dependents": {}, + "desired_capacity": 4, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": "2015-02-10T15:26:14Z", + "max_size": -1, + "metadata": {}, + "min_size": 0, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "profile1", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": "2015-02-10T16:26:14Z", + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +const UpdateResponse_EmptyTime = ` +{ + "cluster": { + "config": {}, + "created_at": null, + "data": {}, + "dependents": {}, + "desired_capacity": 3, + "domain": null, + "id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "init_at": null, + "max_size": 20, + "metadata": {}, + "min_size": 1, + "name": "cluster1", + "nodes": [ + "b07c57c8-7ab2-47bf-bdf8-e894c0c601b9", + "ecc23d3e-bb68-48f8-8260-c9cf6bcb6e61", + "da1e9c87-e584-4626-a120-022da5062dac" + ], + "policies": [], + "profile_id": "edc63d0a-2ca4-48fa-9854-27926da76a4a", + "profile_name": "mystack", + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "status": "ACTIVE", + "status_reason": "Cluster scale-in succeeded", + "timeout": 3600, + "updated_at": null, + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +const ActionResponse = ` +{ + "action": "2a0ff107-e789-4660-a122-3816c43af703" +}` + +const ExpectedActionID = "2a0ff107-e789-4660-a122-3816c43af703" + +const ListPoliciesResult = `{ + "cluster_policies": [ + { + "cluster_id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "cluster_name": "cluster4", + "enabled": true, + "id": "06be3a1f-b238-4a96-a737-ceec5714087e", + "policy_id": "714fe676-a08f-4196-b7af-61d52eeded15", + "policy_name": "dp01", + "policy_type": "senlin.policy.deletion-1.0" + } + ] +}` + +var ExpectedClusterPolicy = clusters.ClusterPolicy{ + ClusterID: "7d85f602-a948-4a30-afd4-e84f47471c15", + ClusterName: "cluster4", + Enabled: true, + ID: "06be3a1f-b238-4a96-a737-ceec5714087e", + PolicyID: "714fe676-a08f-4196-b7af-61d52eeded15", + PolicyName: "dp01", + PolicyType: "senlin.policy.deletion-1.0", +} + +var ExpectedListPolicies = []clusters.ClusterPolicy{ExpectedClusterPolicy} + +const GetPolicyResponse = ` +{ + "cluster_policy": { + "cluster_id": "7d85f602-a948-4a30-afd4-e84f47471c15", + "cluster_name": "cluster4", + "enabled": true, + "id": "06be3a1f-b238-4a96-a737-ceec5714087e", + "policy_id": "714fe676-a08f-4196-b7af-61d52eeded15", + "policy_name": "dp01", + "policy_type": "senlin.policy.deletion-1.0" + } +}` + +func HandleCreateClusterSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", "req-781e9bdc-4163-46eb-91c9-786c53188bbb") + w.Header().Add("Location", "http://senlin.cloud.blizzard.net:8778/v1/actions/625628cd-f877-44be-bde0-fec79f84e13d") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse) + }) +} + +func HandleCreateClusterEmptyTimeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse_EmptyTime) + }) +} + +func HandleCreateClusterMetadataSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse_Metadata) + }) +} + +func HandleGetClusterSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse) + }) +} + +func HandleGetClusterEmptyTimeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse_EmptyTime) + }) +} + +func HandleListClusterSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ListResponse) + }) +} + +func HandleUpdateClusterSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/"+ExpectedCluster.ID, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ClusterResponse) + }) +} + +func HandleUpdateClusterEmptyTimeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/"+ExpectedCluster_EmptyTime.ID, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, UpdateResponse_EmptyTime) + }) +} + +func HandleDeleteClusterSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} + +func HandleResizeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleScaleInSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleScaleOutSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleListPoliciesSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ListPoliciesResult) + }) +} + +func HandleGetPolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/policies/714fe676-a08f-4196-b7af-61d52eeded15", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, GetPolicyResponse) + }) +} + +func HandleRecoverSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleAttachPolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleDetachPolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleUpdatePolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/7d85f602-a948-4a30-afd4-e84f47471c15/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleCheckSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ActionResponse) + }) +} + +func HandleLifecycleSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clusters/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", "req-781e9bdc-4163-46eb-91c9-786c53188bbb") + w.Header().Add("Location", "http://senlin.cloud.blizzard.net:8778/v1/actions/2a0ff107-e789-4660-a122-3816c43af703") + w.WriteHeader(http.StatusAccepted) + + fmt.Fprint(w, ActionResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/requests_test.go new file mode 100644 index 00000000..ba4f05a3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/testing/requests_test.go @@ -0,0 +1,428 @@ +package testing + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateCluster(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateClusterSuccessfully(t) + + minSize := 1 + opts := clusters.CreateOpts{ + Name: "cluster1", + DesiredCapacity: 3, + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + MinSize: &minSize, + MaxSize: 20, + Timeout: 3600, + Metadata: map[string]interface{}{}, + Config: map[string]interface{}{}, + } + + res := clusters.Create(fake.ServiceClient(), opts) + th.AssertNoErr(t, res.Err) + + location := res.Header.Get("Location") + th.AssertEquals(t, "http://senlin.cloud.blizzard.net:8778/v1/actions/625628cd-f877-44be-bde0-fec79f84e13d", location) + + locationFields := strings.Split(location, "actions/") + actionID := locationFields[1] + th.AssertEquals(t, "625628cd-f877-44be-bde0-fec79f84e13d", actionID) + + actual, err := res.Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster, *actual) +} + +func TestCreateClusterEmptyTime(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateClusterEmptyTimeSuccessfully(t) + + minSize := 1 + opts := clusters.CreateOpts{ + Name: "cluster1", + DesiredCapacity: 3, + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + MinSize: &minSize, + MaxSize: 20, + Timeout: 3600, + Metadata: map[string]interface{}{}, + Config: map[string]interface{}{}, + } + + actual, err := clusters.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster_EmptyTime, *actual) +} + +func TestCreateClusterMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateClusterMetadataSuccessfully(t) + + minSize := 1 + opts := clusters.CreateOpts{ + Name: "cluster1", + DesiredCapacity: 3, + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + MinSize: &minSize, + MaxSize: 20, + Timeout: 3600, + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Config: map[string]interface{}{}, + } + + actual, err := clusters.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster_Metadata, *actual) +} + +func TestGetCluster(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetClusterSuccessfully(t) + + actual, err := clusters.Get(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster, *actual) +} + +func TestGetClusterEmptyTime(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetClusterEmptyTimeSuccessfully(t) + + actual, err := clusters.Get(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster_EmptyTime, *actual) +} + +func TestListClusters(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListClusterSuccessfully(t) + + count := 0 + + clusters.List(fake.ServiceClient(), clusters.ListOpts{GlobalProject: new(bool)}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := clusters.ExtractClusters(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedClusters, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestUpdateCluster(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateClusterSuccessfully(t) + + updateOpts := clusters.UpdateOpts{ + Name: "cluster1", + ProfileID: "edc63d0a-2ca4-48fa-9854-27926da76a4a", + } + + actual, err := clusters.Update(fake.ServiceClient(), ExpectedCluster.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster, *actual) +} + +func TestUpdateClusterEmptyTime(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateClusterEmptyTimeSuccessfully(t) + + updateOpts := clusters.UpdateOpts{ + Name: "cluster1", + ProfileID: "edc63d0a-2ca4-48fa-9854-27926da76a4a", + } + + actual, err := clusters.Update(fake.ServiceClient(), ExpectedCluster_EmptyTime.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCluster_EmptyTime, *actual) +} + +func TestDeleteCluster(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteClusterSuccessfully(t) + + err := clusters.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestResizeCluster(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleResizeSuccessfully(t) + + maxSize := 5 + minSize := 1 + number := -2 + strict := true + opts := clusters.ResizeOpts{ + AdjustmentType: "CHANGE_IN_CAPACITY", + MaxSize: &maxSize, + MinSize: &minSize, + Number: number, + Strict: &strict, + } + + actionID, err := clusters.Resize(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15", opts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +// Test case for Number field having a float value +func TestResizeClusterNumberFloat(t *testing.T) { + maxSize := 5 + minSize := 1 + number := 100.0 + strict := true + opts := clusters.ResizeOpts{ + AdjustmentType: "CHANGE_IN_PERCENTAGE", + MaxSize: &maxSize, + MinSize: &minSize, + Number: number, + Strict: &strict, + } + + _, err := opts.ToClusterResizeMap() + th.AssertNoErr(t, err) +} + +// Test case for missing Number field. +func TestResizeClusterMissingNumber(t *testing.T) { + maxSize := 5 + minSize := 1 + strict := true + opts := clusters.ResizeOpts{ + MaxSize: &maxSize, + MinSize: &minSize, + Strict: &strict, + } + + _, err := opts.ToClusterResizeMap() + th.AssertNoErr(t, err) +} + +// Test case for missing Number field which is required when AdjustmentType is specified +func TestResizeClusterInvalidParamsMissingNumber(t *testing.T) { + maxSize := 5 + minSize := 1 + strict := true + opts := clusters.ResizeOpts{ + AdjustmentType: "CHANGE_IN_CAPACITY", + MaxSize: &maxSize, + MinSize: &minSize, + Strict: &strict, + } + + _, err := opts.ToClusterResizeMap() + isValid := err == nil + th.AssertEquals(t, false, isValid) +} + +// Test case for float Number field which is only valid for CHANGE_IN_PERCENTAGE. +func TestResizeClusterInvalidParamsNumberFloat(t *testing.T) { + maxSize := 5 + minSize := 1 + number := 100.0 + strict := true + opts := clusters.ResizeOpts{ + AdjustmentType: "CHANGE_IN_CAPACITY", + MaxSize: &maxSize, + MinSize: &minSize, + Number: number, + Strict: &strict, + } + + _, err := opts.ToClusterResizeMap() + isValid := err == nil + th.AssertEquals(t, false, isValid) +} + +func TestClusterScaleIn(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleScaleInSuccessfully(t) + + count := 5 + scaleOpts := clusters.ScaleInOpts{ + Count: &count, + } + actionID, err := clusters.ScaleIn(fake.ServiceClient(), "edce3528-864f-41fb-8759-f4707925cc09", scaleOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestListClusterPolicies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListPoliciesSuccessfully(t) + + pageCount := 0 + err := clusters.ListPolicies(fake.ServiceClient(), ExpectedClusterPolicy.ClusterID, clusters.ListPoliciesOpts{Name: "Test"}).EachPage(func(page pagination.Page) (bool, error) { + pageCount++ + actual, err := clusters.ExtractClusterPolicies(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedListPolicies, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, pageCount, 1) +} + +func TestGetClusterPolicies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetPolicySuccessfully(t) + + actual, err := clusters.GetPolicy(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15", "714fe676-a08f-4196-b7af-61d52eeded15").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedClusterPolicy, *actual) +} + +func TestClusterRecover(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleRecoverSuccessfully(t) + + recoverOpts := clusters.RecoverOpts{ + Operation: clusters.RebuildRecovery, + Check: new(bool), + CheckCapacity: new(bool), + } + actionID, err := clusters.Recover(fake.ServiceClient(), "edce3528-864f-41fb-8759-f4707925cc09", recoverOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestAttachPolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleAttachPolicySuccessfully(t) + + enabled := true + opts := clusters.AttachPolicyOpts{ + PolicyID: "policy1", + Enabled: &enabled, + } + actionID, err := clusters.AttachPolicy(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15", opts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestDetachPolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDetachPolicySuccessfully(t) + + opts := clusters.DetachPolicyOpts{ + PolicyID: "policy1", + } + actionID, err := clusters.DetachPolicy(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15", opts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestUpdatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdatePolicySuccessfully(t) + + enabled := true + opts := clusters.UpdatePolicyOpts{ + PolicyID: "policy1", + Enabled: &enabled, + } + actionID, err := clusters.UpdatePolicy(fake.ServiceClient(), "7d85f602-a948-4a30-afd4-e84f47471c15", opts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestClusterScaleOut(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleScaleOutSuccessfully(t) + + scaleOutOpts := clusters.ScaleOutOpts{ + Count: 5, + } + actionID, err := clusters.ScaleOut(fake.ServiceClient(), "edce3528-864f-41fb-8759-f4707925cc09", scaleOutOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestClusterCheck(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCheckSuccessfully(t) + + actionID, err := clusters.Check(fake.ServiceClient(), "edce3528-864f-41fb-8759-f4707925cc09").Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedActionID, actionID) +} + +func TestLifecycle(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleLifecycleSuccessfully(t) + + opts := clusters.CompleteLifecycleOpts{ + LifecycleActionTokenID: "976528c6-dcf6-4d8d-9f4c-588f4e675f29", + } + + res := clusters.CompleteLifecycle(fake.ServiceClient(), "edce3528-864f-41fb-8759-f4707925cc09", opts) + location := res.Header.Get("Location") + th.AssertEquals(t, "http://senlin.cloud.blizzard.net:8778/v1/actions/2a0ff107-e789-4660-a122-3816c43af703", location) + + actionID, err := res.Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, "2a0ff107-e789-4660-a122-3816c43af703", actionID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/urls.go new file mode 100644 index 00000000..a4e0db0c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/clusters/urls.go @@ -0,0 +1,46 @@ +package clusters + +import "github.com/gophercloud/gophercloud" + +var apiVersion = "v1" +var apiName = "clusters" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func idURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func actionURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id, "actions") +} + +func createURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func listPoliciesURL(client *gophercloud.ServiceClient, clusterID string) string { + return client.ServiceURL(apiVersion, apiName, clusterID, "policies") +} + +func getPolicyURL(client *gophercloud.ServiceClient, clusterID string, policyID string) string { + return client.ServiceURL(apiVersion, apiName, clusterID, "policies", policyID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/doc.go new file mode 100644 index 00000000..3257b8d1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/doc.go @@ -0,0 +1,74 @@ +/* +Package nodes provides information and interaction with the nodes through +the OpenStack Clustering service. + +Example to Create a Node + + opts := nodes.CreateOpts{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + Metadata: map[string]interface{}{}, + Name: "node-e395be1e-002", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + Role: "", + } + + node, err := nodes.Create(serviceClient, opts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("node", node) + +Example to List Nodes + + listOpts := nodes.ListOpts{ + Name: "testnode", + } + + allPages, err := nodes.List(serviceClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allNodes, err := nodes.ExtractNodes(allPages) + if err != nil { + panic(err) + } + + for _, node := range allNodes { + fmt.Printf("%+v\n", node) + } + +Example to Update a Node + + opts := nodes.UpdateOpts{ + Name: "new-node-name", + } + + nodeID := "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1" + node, err := nodes.Update(serviceClient, nodeID, opts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", node) + +Example to Delete a Node + + nodeID := "6dc6d336e3fc4c0a951b5698cd1236ee" + err := nodes.Delete(serviceClient, nodeID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Get a Node + + nodeID := "node123" + node, err := nodes.Get(serviceClient, nodeID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", node) +*/ +package nodes diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/requests.go new file mode 100644 index 00000000..98bbd6d7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/requests.go @@ -0,0 +1,146 @@ +package nodes + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToNodeCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options used to create a Node. +type CreateOpts struct { + Role string `json:"role,omitempty"` + ProfileID string `json:"profile_id" required:"true"` + ClusterID string `json:"cluster_id,omitempty"` + Name string `json:"name" required:"true"` + Metadata map[string]interface{} `json:"metadata,omitempty"` +} + +// ToNodeCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToNodeCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "node") +} + +// Create requests the creation of a new node. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToNodeCreateMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToNodeUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options used to update a Node. +type UpdateOpts struct { + Name string `json:"name,omitempty"` + ProfileID string `json:"profile_id,omitempty"` + Role string `json:"role,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` +} + +// ToClusterUpdateMap constructs a request body from UpdateOpts. +func (opts UpdateOpts) ToNodeUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "node") +} + +// Update requests the update of a node. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToNodeUpdateMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ListOptsBuilder allows extensions to add additional parmeters to the +// List request. +type ListOptsBuilder interface { + ToNodeListQuery() (string, error) +} + +// ListOpts represents options used to list nodes. +type ListOpts struct { + Limit int `q:"limit"` + Marker string `q:"marker"` + Sort string `q:"sort"` + GlobalProject *bool `q:"global_project"` + ClusterID string `q:"cluster_id"` + Name string `q:"name"` + Status string `q:"status"` +} + +// ToNodeListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToNodeListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of nodes. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToNodeListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return NodePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Delete deletes the specified node. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + var result *http.Response + result, r.Err = client.Delete(deleteURL(client, id), nil) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Get makes a request against senlin to get a details of a node type +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + var result *http.Response + result, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + if r.Err == nil { + r.Header = result.Header + } + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/results.go new file mode 100644 index 00000000..57987c27 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/results.go @@ -0,0 +1,129 @@ +package nodes + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Node represents an OpenStack clustering node. +type Node struct { + ClusterID string `json:"cluster_id"` + CreatedAt time.Time `json:"-"` + Data map[string]interface{} `json:"data"` + Dependents map[string]interface{} `json:"dependents"` + Domain string `json:"domain"` + ID string `json:"id"` + Index int `json:"index"` + InitAt time.Time `json:"-"` + Metadata map[string]interface{} `json:"metadata"` + Name string `json:"name"` + PhysicalID string `json:"physical_id"` + ProfileID string `json:"profile_id"` + ProfileName string `json:"profile_name"` + Project string `json:"project"` + Role string `json:"role"` + Status string `json:"status"` + StatusReason string `json:"status_reason"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Node) UnmarshalJSON(b []byte) error { + type tmp Node + var s struct { + tmp + CreatedAt string `json:"created_at"` + InitAt string `json:"init_at"` + UpdatedAt string `json:"updated_at"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Node(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(time.RFC3339, s.CreatedAt) + if err != nil { + return err + } + } + + if s.InitAt != "" { + r.InitAt, err = time.Parse(time.RFC3339, s.InitAt) + if err != nil { + return err + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(time.RFC3339, s.UpdatedAt) + if err != nil { + return err + } + } + + return nil +} + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult-based result as a Node. +func (r commonResult) Extract() (*Node, error) { + var s struct { + Node *Node `json:"node"` + } + err := r.ExtractInto(&s) + return s.Node, err +} + +// CreateResult is the result of a Create operation. Call its Extract +// method to intepret it as a Node. +type CreateResult struct { + commonResult +} + +// GetResult is the result of a Get operation. Call its Extract method to +// interpret it as a Node. +type GetResult struct { + commonResult +} + +// DeleteResult is the result from a Delete operation. Call ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult is the result of an Update operation. Call its Extract method +// to interpet it as a Node. +type UpdateResult struct { + commonResult +} + +// NodePage contains a single page of all nodes from a List call. +type NodePage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines if a NodePage contains any results. +func (page NodePage) IsEmpty() (bool, error) { + nodes, err := ExtractNodes(page) + return len(nodes) == 0, err +} + +// ExtractNodes returns a slice of Nodes from the List operation. +func ExtractNodes(r pagination.Page) ([]Node, error) { + var s struct { + Nodes []Node `json:"nodes"` + } + err := (r.(NodePage)).ExtractInto(&s) + return s.Nodes, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/doc.go new file mode 100644 index 00000000..cb76666d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_nodes_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/fixtures.go new file mode 100644 index 00000000..14ac6dbd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/fixtures.go @@ -0,0 +1,316 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const CreateResponse = `{ + "node": { + "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + "created_at": "2016-05-13T07:02:20Z", + "data": { + "internal_ports": [ + { + "network_id": "847e4f65-1ff1-42b1-9e74-74e6a109ad11", + "security_group_ids": ["8db277ab-1d98-4148-ba72-724721789427"], + "fixed_ips": [ + { + "subnet_id": "863b20c0-c011-4650-85c2-ad531f4570a4", + "ip_address": "10.63.177.162" + } + ], + "id": "43aa53d7-a70b-4f40-812f-4feecb687018", + "remove": true + } + ], + "placement": { + "zone": "nova" + } + }, + "dependents": {}, + "domain": "1235be1e-8d8e-43bb-bd6c-943eccf76a6d", + "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + "index": 2, + "init_at": "2016-05-13T08:02:04Z", + "metadata": { + "test": { + "nil_interface": null, + "bool_value": false, + "string_value": "test_string", + "float_value": 123.3 + }, + "foo": "bar" + }, + "name": "node-e395be1e-002", + "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", + "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + "profile_name": "pcirros", + "project": "eee0b7c083e84501bdd50fb269d2a10e", + "role": "", + "status": "ACTIVE", + "status_reason": "Creation succeeded", + "updated_at": null, + "user": "ab79b9647d074e46ac223a8fa297b846" + } +}` + +var ExpectedCreate = nodes.Node{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), + Data: map[string]interface{}{ + "internal_ports": []map[string]interface{}{ + { + "network_id": "847e4f65-1ff1-42b1-9e74-74e6a109ad11", + "security_group_ids": []interface{}{ + "8db277ab-1d98-4148-ba72-724721789427", + }, + "fixed_ips": []interface{}{ + map[string]interface{}{ + "subnet_id": "863b20c0-c011-4650-85c2-ad531f4570a4", + "ip_address": "10.63.177.162", + }, + }, + "id": "43aa53d7-a70b-4f40-812f-4feecb687018", + "remove": true, + }, + }, + "placement": map[string]interface{}{ + "zone": "nova", + }, + }, + Dependents: map[string]interface{}{}, + Domain: "1235be1e-8d8e-43bb-bd6c-943eccf76a6d", + ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + Index: 2, + InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Name: "node-e395be1e-002", + PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + ProfileName: "pcirros", + Project: "eee0b7c083e84501bdd50fb269d2a10e", + Role: "", + Status: "ACTIVE", + StatusReason: "Creation succeeded", + User: "ab79b9647d074e46ac223a8fa297b846", +} + +const ListResponse = ` +{ + "nodes": [ + { + "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + "created_at": "2016-05-13T07:02:20Z", + "data": {}, + "dependents": {}, + "domain": null, + "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + "index": 2, + "init_at": "2016-05-13T08:02:04Z", + "metadata": {}, + "name": "node-e395be1e-002", + "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", + "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + "profile_name": "pcirros", + "project": "eee0b7c083e84501bdd50fb269d2a10e", + "role": "", + "status": "ACTIVE", + "status_reason": "Creation succeeded", + "updated_at": "2016-05-13T09:02:04Z", + "user": "ab79b9647d074e46ac223a8fa297b846" } + ] +}` + +var ExpectedList1 = nodes.Node{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + Domain: "", + ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + Index: 2, + InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), + Metadata: map[string]interface{}{}, + Name: "node-e395be1e-002", + PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + ProfileName: "pcirros", + Project: "eee0b7c083e84501bdd50fb269d2a10e", + Role: "", + Status: "ACTIVE", + StatusReason: "Creation succeeded", + UpdatedAt: time.Date(2016, 5, 13, 9, 2, 4, 0, time.UTC), + User: "ab79b9647d074e46ac223a8fa297b846", +} + +var ExpectedList = []nodes.Node{ExpectedList1} + +const GetResponse = ` +{ + "node": { + "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + "created_at": "2016-05-13T07:02:20Z", + "data": {}, + "dependents": {}, + "domain": null, + "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + "index": 2, + "init_at": "2016-05-13T07:02:04Z", + "metadata": {"foo": "bar"}, + "name": "node-e395be1e-002", + "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", + "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + "profile_name": "pcirros", + "project": "eee0b7c083e84501bdd50fb269d2a10e", + "role": "", + "status": "ACTIVE", + "status_reason": "Creation succeeded", + "updated_at": "2016-05-13T07:02:20Z", + "user": "ab79b9647d074e46ac223a8fa297b846" + } +}` + +var ExpectedGet = nodes.Node{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + Domain: "", + ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + Index: 2, + InitAt: time.Date(2016, 5, 13, 7, 2, 4, 0, time.UTC), + Metadata: map[string]interface{}{"foo": "bar"}, + Name: "node-e395be1e-002", + PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + ProfileName: "pcirros", + Project: "eee0b7c083e84501bdd50fb269d2a10e", + Role: "", + Status: "ACTIVE", + StatusReason: "Creation succeeded", + UpdatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), + User: "ab79b9647d074e46ac223a8fa297b846", +} + +const UpdateResponse = ` +{ + "node": { + "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + "created_at": "2016-05-13T07:02:20Z", + "data": {}, + "dependents": {}, + "domain": null, + "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + "index": 2, + "init_at": "2016-05-13T08:02:04Z", + "metadata": {"foo":"bar"}, + "name": "node-e395be1e-002", + "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", + "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + "profile_name": "pcirros", + "project": "eee0b7c083e84501bdd50fb269d2a10e", + "role": "", + "status": "ACTIVE", + "status_reason": "Creation succeeded", + "updated_at": "2016-05-13T09:02:04Z", + "user": "ab79b9647d074e46ac223a8fa297b846" + } +}` + +var ExpectedUpdate = nodes.Node{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), + Data: map[string]interface{}{}, + Dependents: map[string]interface{}{}, + Domain: "", + ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", + Index: 2, + InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), + Metadata: map[string]interface{}{"foo": "bar"}, + Name: "node-e395be1e-002", + PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + ProfileName: "pcirros", + Project: "eee0b7c083e84501bdd50fb269d2a10e", + Role: "", + Status: "ACTIVE", + StatusReason: "Creation succeeded", + UpdatedAt: time.Date(2016, 5, 13, 9, 2, 4, 0, time.UTC), + User: "ab79b9647d074e46ac223a8fa297b846", +} + +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/nodes", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", "req-3791a089-9d46-4671-a3f9-55e95e55d2b4") + w.Header().Add("Location", "http://senlin.cloud.blizzard.net:8778/v1/actions/ffd94dd8-6266-4887-9a8c-5b78b72136da") + + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, CreateResponse) + }) +} + +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/nodes", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ListResponse) + }) +} + +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/nodes/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} + +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/nodes/573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, GetResponse) + }) +} + +func HandleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/nodes/82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, UpdateResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/requests_test.go new file mode 100644 index 00000000..1a8e72ad --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/testing/requests_test.go @@ -0,0 +1,105 @@ +package testing + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateNode(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateSuccessfully(t) + + createOpts := nodes.CreateOpts{ + ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", + Metadata: map[string]interface{}{ + "foo": "bar", + "test": map[string]interface{}{ + "nil_interface": interface{}(nil), + "float_value": float64(123.3), + "string_value": "test_string", + "bool_value": false, + }, + }, + Name: "node-e395be1e-002", + ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", + Role: "", + } + + res := nodes.Create(fake.ServiceClient(), createOpts) + th.AssertNoErr(t, res.Err) + + requestID := res.Header.Get("X-Openstack-Request-Id") + th.AssertEquals(t, "req-3791a089-9d46-4671-a3f9-55e95e55d2b4", requestID) + + location := res.Header.Get("Location") + th.AssertEquals(t, "http://senlin.cloud.blizzard.net:8778/v1/actions/ffd94dd8-6266-4887-9a8c-5b78b72136da", location) + + locationFields := strings.Split(location, "actions/") + actionID := locationFields[1] + th.AssertEquals(t, "ffd94dd8-6266-4887-9a8c-5b78b72136da", actionID) + + actual, err := res.Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCreate, *actual) +} + +func TestListNodes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + count := 0 + err := nodes.List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + actual, err := nodes.ExtractNodes(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedList, actual) + count++ + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestDeleteNode(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteSuccessfully(t) + + deleteResult := nodes.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee") + th.AssertNoErr(t, deleteResult.ExtractErr()) +} + +func TestGetNode(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t) + + actual, err := nodes.Get(fake.ServiceClient(), "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedGet, *actual) +} + +func TestUpdateNode(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateSuccessfully(t) + + nodeOpts := nodes.UpdateOpts{ + Name: "node-e395be1e-002", + } + actual, err := nodes.Update(fake.ServiceClient(), ExpectedUpdate.ID, nodeOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedUpdate, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/urls.go new file mode 100644 index 00000000..5479145d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes/urls.go @@ -0,0 +1,34 @@ +package nodes + +import "github.com/gophercloud/gophercloud" + +var apiVersion = "v1" +var apiName = "nodes" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func createURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func idURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/doc.go new file mode 100644 index 00000000..ffe75f6e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/doc.go @@ -0,0 +1,96 @@ +/* +Package policies provides information and interaction with the policies through +the OpenStack Clustering service. + +Example to List Policies + + listOpts := policies.ListOpts{ + Limit: 2, + } + + allPages, err := policies.List(clusteringClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allPolicies, err := policies.ExtractPolicies(allPages) + if err != nil { + panic(err) + } + + for _, policy := range allPolicies { + fmt.Printf("%+v\n", policy) + } + + +Example to Create a Policy + + opts := policies.CreateOpts{ + Name: "new_policy", + Spec: policies.Spec{ + Description: "new policy description", + Properties: map[string]interface{}{ + "hooks": map[string]interface{}{ + "type": "zaqar", + "params": map[string]interface{}{ + "queue": "my_zaqar_queue", + }, + "timeout": 10, + }, + }, + Type: "senlin.policy.deletion", + Version: "1.1", + }, + } + + createdPolicy, err := policies.Create(client, opts).Extract() + if err != nil { + panic(err) + } + +Example to Get a Policy + + policyName := "get_policy" + policyDetail, err := policies.Get(clusteringClient, policyName).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", policyDetail) + +Example to Update a Policy + + opts := policies.UpdateOpts{ + Name: "update_policy", + } + + updatePolicy, err := policies.Update(client, opts).Extract() + if err != nil { + panic(err) + } + +Example to Validate a Policy + + opts := policies.ValidateOpts{ + Spec: policies.Spec{ + Description: "new policy description", + Properties: map[string]interface{}{ + "hooks": map[string]interface{}{ + "type": "zaqar", + "params": map[string]interface{}{ + "queue": "my_zaqar_queue", + }, + "timeout": 10, + }, + }, + Type: "senlin.policy.deletion", + Version: "1.1", + }, + } + + validatePolicy, err := policies.Validate(client, opts).Extract() + if err != nil { + panic(err) + } +*/ +package policies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/requests.go new file mode 100644 index 00000000..f3e2ad24 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/requests.go @@ -0,0 +1,193 @@ +package policies + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToPolicyListQuery() (string, error) +} + +// ListOpts represents options used to list policies. +type ListOpts struct { + // Limit limits the number of Policies to return. + Limit int `q:"limit"` + + // Marker and Limit control paging. Marker instructs List where to start + // listing from. + Marker string `q:"marker"` + + // Sorts the response by one or more attribute and optional sort direction + // combinations. + Sort string `q:"sort"` + + // GlobalProject indicates whether to include resources for all projects or + // resources for the current project. + GlobalProject *bool `q:"global_project"` + + // Name to filter the response by the specified name property of the object. + Name string `q:"name"` + + // Filter the response by the specified type property of the object. + Type string `q:"type"` +} + +// ToPolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to retrieve a list of policies. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := policyListURL(client) + if opts != nil { + query, err := opts.ToPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + p := PolicyPage{pagination.MarkerPageBase{PageResult: r}} + p.MarkerPageBase.Owner = p + return p + }) +} + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToPolicyCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options used to create a policy. +type CreateOpts struct { + Name string `json:"name"` + Spec Spec `json:"spec"` +} + +// ToPolicyCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + return map[string]interface{}{"policy": b}, nil +} + +// Create makes a request against the API to create a policy +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPolicyCreateMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(policyCreateURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Delete makes a request against the API to delete a policy. +func Delete(client *gophercloud.ServiceClient, policyID string) (r DeleteResult) { + var result *http.Response + result, r.Err = client.Delete(policyDeleteURL(client, policyID), &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToPolicyUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options to update a policy. +type UpdateOpts struct { + Name string `json:"name,omitempty"` +} + +// ToPolicyUpdateMap constructs a request body from UpdateOpts. +func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "policy") +} + +// Update updates a specified policy. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + if r.Err == nil { + r.Header = result.Header + } + + return +} + +// ValidateOptsBuilder allows extensions to add additional parameters to the +// Validate request. +type ValidateOptsBuilder interface { + ToPolicyValidateMap() (map[string]interface{}, error) +} + +// ValidateOpts represents options used to validate a policy. +type ValidateOpts struct { + Spec Spec `json:"spec"` +} + +// ToPolicyValidateMap formats a CreateOpts into a body map. +func (opts ValidateOpts) ToPolicyValidateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "policy") +} + +// Validate policy will validate a specified policy. +func Validate(client *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) { + b, err := opts.ToPolicyValidateMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Post(validateURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201}, + }) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Get makes a request against the API to get details for a policy. +func Get(client *gophercloud.ServiceClient, policyTypeName string) (r GetResult) { + url := policyGetURL(client, policyTypeName) + + _, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/results.go new file mode 100644 index 00000000..ca5bf335 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/results.go @@ -0,0 +1,183 @@ +package policies + +import ( + "encoding/json" + "fmt" + "strconv" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Policy represents a clustering policy in the Openstack cloud. +type Policy struct { + CreatedAt time.Time `json:"-"` + Data map[string]interface{} `json:"data"` + Domain string `json:"domain"` + ID string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Spec Spec `json:"spec"` + Type string `json:"type"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Policy) UnmarshalJSON(b []byte) error { + type tmp Policy + var s struct { + tmp + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Policy(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(gophercloud.RFC3339MilliNoZ, s.CreatedAt) + if err != nil { + r.CreatedAt, err = time.Parse(time.RFC3339, s.CreatedAt) + if err != nil { + return err + } + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(gophercloud.RFC3339MilliNoZ, s.UpdatedAt) + if err != nil { + r.UpdatedAt, err = time.Parse(time.RFC3339, s.UpdatedAt) + if err != nil { + return err + } + } + } + + return nil +} + +// Spec represents an OpenStack clustering policy spec. +type Spec struct { + Description string `json:"description"` + Properties map[string]interface{} `json:"properties"` + Type string `json:"type"` + Version string `json:"version"` +} + +func (r *Spec) UnmarshalJSON(b []byte) error { + type tmp Spec + var s struct { + tmp + Version interface{} `json:"version"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Spec(s.tmp) + + switch t := s.Version.(type) { + case float64: + if t == 1 { + r.Version = fmt.Sprintf("%.1f", t) + } else { + r.Version = strconv.FormatFloat(t, 'f', -1, 64) + } + case string: + r.Version = t + } + + return nil +} + +// policyResult is the resposne of a base Policy result. +type policyResult struct { + gophercloud.Result +} + +// Extract interpets any policyResult-base result as a Policy. +func (r policyResult) Extract() (*Policy, error) { + var s struct { + Policy *Policy `json:"policy"` + } + err := r.ExtractInto(&s) + + return s.Policy, err +} + +// CreateResult is the result of an Update operation. Call its Extract +// method to interpret it as a Policy. +type CreateResult struct { + policyResult +} + +// GetResult is the result of a Get operation. Call its Extract method to +// interpret it as a Policy. +type GetResult struct { + policyResult +} + +// UpdateResult is the result of an Update operation. Call its Extract +// method to interpret it as a Policy. +type UpdateResult struct { + policyResult +} + +// ValidateResult is the result of a Validate operation. Call its Extract +// method to interpret it as a Policy. +type ValidateResult struct { + policyResult +} + +// DeleteResult is the result of a Delete operation. Call its Extract +// method to interpret it as a DeleteHeader. +type DeleteResult struct { + gophercloud.HeaderResult +} + +// DeleteHeader contains the delete information from a delete policy request. +type DeleteHeader struct { + RequestID string `json:"X-OpenStack-Request-ID"` +} + +func (r DeleteResult) Extract() (*DeleteHeader, error) { + var s *DeleteHeader + err := r.HeaderResult.ExtractInto(&s) + return s, err +} + +// PolicyPage contains a list page of all policies from a List call. +type PolicyPage struct { + pagination.MarkerPageBase +} + +// IsEmpty determines if a PolicyPage contains any results. +func (page PolicyPage) IsEmpty() (bool, error) { + policies, err := ExtractPolicies(page) + return len(policies) == 0, err +} + +// LastMarker returns the last policy ID in a ListResult. +func (r PolicyPage) LastMarker() (string, error) { + policies, err := ExtractPolicies(r) + if err != nil { + return "", err + } + if len(policies) == 0 { + return "", nil + } + return policies[len(policies)-1].ID, nil +} + +// ExtractPolicies returns a slice of Policies from the List operation. +func ExtractPolicies(r pagination.Page) ([]Policy, error) { + var s struct { + Policies []Policy `json:"policies"` + } + err := (r.(PolicyPage)).ExtractInto(&s) + return s.Policies, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/doc.go new file mode 100644 index 00000000..61bc1c3b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_policies_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/fixtures.go new file mode 100644 index 00000000..726fde98 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/fixtures.go @@ -0,0 +1,513 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policies" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const PolicyListBody1 = ` +{ + "policies": [ + { + "created_at": "2018-04-02T21:43:30.000000", + "data": {}, + "domain": null, + "id": "PolicyListBodyID1", + "name": "delpol", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": 60, + "reduce_desired_capacity": false + }, + "type": "senlin.policy.deletion", + "version": 1 + }, + "type": "senlin.policy.deletion-1.0", + "updated_at": "2018-04-02T00:19:12Z", + "user": "fe43e41739154b72818565e0d2580819" + } + ] +} +` + +const PolicyListBody2 = ` +{ + "policies": [ + { + "created_at": "2018-04-02T22:29:36.000000", + "data": {}, + "domain": null, + "id": "PolicyListBodyID2", + "name": "delpol2", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": 60, + "reduce_desired_capacity": false + }, + "type": "senlin.policy.deletion", + "version": "1.0" + }, + "type": "senlin.policy.deletion-1.0", + "updated_at": "2018-04-02T23:15:11.000000", + "user": "fe43e41739154b72818565e0d2580819" + } + ] +} +` + +const PolicyCreateBody = ` +{ + "policy": { + "created_at": "2018-04-04T00:18:36Z", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol4", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "hooks": { + "params": { + "queue": "zaqar_queue_name" + }, + "timeout": 180, + "type": "zaqar" + } + }, + "type": "senlin.policy.deletion", + "version": 1.1 + }, + "type": "senlin.policy.deletion-1.1", + "updated_at": null, + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyGetBody = ` +{ + "policy": { + "created_at": "2018-04-02T21:43:30.000000", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": 60, + "reduce_desired_capacity": false + }, + "type": "senlin.policy.deletion", + "version": 1 + }, + "type": "senlin.policy.deletion-1.0", + "updated_at": "2018-04-02T00:19:12Z", + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyUpdateBody = ` +{ + "policy": { + "created_at": "2018-04-02T21:43:30.000000", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol4", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "hooks": { + "params": { + "queue": "zaqar_queue_name" + }, + "timeout": 180, + "type": "zaqar" + } + }, + "type": "senlin.policy.deletion", + "version": 1.1 + }, + "type": "senlin.policy.deletion-1.1", + "updated_at": null, + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyBadUpdateBody = ` +{ + "policy": { + "created_at": "invalid", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol4", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "hooks": { + "params": { + "queue": "zaqar_queue_name" + }, + "timeout": 180, + "type": "zaqar" + } + }, + "type": "senlin.policy.deletion", + "version": 1.1 + }, + "type": "invalid", + "updated_at": null, + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyValidateBody = ` +{ + "policy": { + "created_at": "2018-04-02T21:43:30.000000", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol4", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "hooks": { + "params": { + "queue": "zaqar_queue_name" + }, + "timeout": 180, + "type": "zaqar" + } + }, + "type": "senlin.policy.deletion", + "version": 1.1 + }, + "type": "senlin.policy.deletion-1.1", + "updated_at": null, + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyBadValidateBody = ` +{ + "policy": { + "created_at": "invalid", + "data": {}, + "domain": null, + "id": "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + "name": "delpol4", + "project": "018cd0909fb44cd5bc9b7a3cd664920e", + "spec": { + "description": "A policy for choosing victim node(s) from a cluster for deletion.", + "properties": { + "hooks": { + "params": { + "queue": "zaqar_queue_name" + }, + "timeout": 180, + "type": "zaqar" + } + }, + "type": "senlin.policy.deletion", + "version": 1.1 + }, + "type": "invalid", + "updated_at": null, + "user": "fe43e41739154b72818565e0d2580819" + } +} +` + +const PolicyDeleteRequestID = "req-7328d1b0-9945-456f-b2cd-5166b77d14a8" +const PolicyIDtoUpdate = "b99b3ab4-3aa6-4fba-b827-69b88b9c544a" +const PolicyIDtoGet = "b99b3ab4-3aa6-4fba-b827-69b88b9c544a" +const PolicyIDtoDelete = "1" + +var ExpectedPolicy1 = policies.Policy{ + CreatedAt: time.Date(2018, 4, 2, 21, 43, 30, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "PolicyListBodyID1", + Name: "delpol", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": float64(60), + "reduce_desired_capacity": false, + }, + Type: "senlin.policy.deletion", + Version: "1.0", + }, + Type: "senlin.policy.deletion-1.0", + User: "fe43e41739154b72818565e0d2580819", + UpdatedAt: time.Date(2018, 4, 2, 0, 19, 12, 0, time.UTC), +} + +var ExpectedPolicy2 = policies.Policy{ + CreatedAt: time.Date(2018, 4, 2, 22, 29, 36, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "PolicyListBodyID2", + Name: "delpol2", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": float64(60), + "reduce_desired_capacity": false, + }, + Type: "senlin.policy.deletion", + Version: "1.0", + }, + Type: "senlin.policy.deletion-1.0", + User: "fe43e41739154b72818565e0d2580819", + UpdatedAt: time.Date(2018, 4, 2, 23, 15, 11, 0, time.UTC), +} + +var ExpectedPolicies = [][]policies.Policy{ + []policies.Policy{ExpectedPolicy1}, + []policies.Policy{ExpectedPolicy2}, +} + +var ExpectedCreatePolicy = policies.Policy{ + CreatedAt: time.Date(2018, 4, 4, 0, 18, 36, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + Name: "delpol4", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "hooks": map[string]interface{}{ + "params": map[string]interface{}{ + "queue": "zaqar_queue_name", + }, + "timeout": float64(180), + "type": "zaqar", + }, + }, + Type: "senlin.policy.deletion", + Version: "1.1", + }, + Type: "senlin.policy.deletion-1.1", + User: "fe43e41739154b72818565e0d2580819", +} + +var ExpectedGetPolicy = policies.Policy{ + CreatedAt: time.Date(2018, 4, 2, 21, 43, 30, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + Name: "delpol", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "criteria": "OLDEST_FIRST", + "destroy_after_deletion": true, + "grace_period": float64(60), + "reduce_desired_capacity": false, + }, + Type: "senlin.policy.deletion", + Version: "1.0", + }, + Type: "senlin.policy.deletion-1.0", + User: "fe43e41739154b72818565e0d2580819", + UpdatedAt: time.Date(2018, 4, 2, 0, 19, 12, 0, time.UTC), +} + +var ExpectedUpdatePolicy = policies.Policy{ + CreatedAt: time.Date(2018, 4, 2, 21, 43, 30, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + Name: "delpol4", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "hooks": map[string]interface{}{ + "params": map[string]interface{}{ + "queue": "zaqar_queue_name", + }, + "timeout": float64(180), + "type": "zaqar", + }, + }, + Type: "senlin.policy.deletion", + Version: "1.1", + }, + Type: "senlin.policy.deletion-1.1", + User: "fe43e41739154b72818565e0d2580819", +} + +var ExpectedValidatePolicy = policies.Policy{ + CreatedAt: time.Date(2018, 4, 2, 21, 43, 30, 0, time.UTC), + Data: map[string]interface{}{}, + Domain: "", + ID: "b99b3ab4-3aa6-4fba-b827-69b88b9c544a", + Name: "delpol4", + Project: "018cd0909fb44cd5bc9b7a3cd664920e", + + Spec: policies.Spec{ + Description: "A policy for choosing victim node(s) from a cluster for deletion.", + Properties: map[string]interface{}{ + "hooks": map[string]interface{}{ + "params": map[string]interface{}{ + "queue": "zaqar_queue_name", + }, + "timeout": float64(180), + "type": "zaqar", + }, + }, + Type: "senlin.policy.deletion", + Version: "1.1", + }, + Type: "senlin.policy.deletion-1.1", + User: "fe43e41739154b72818565e0d2580819", +} + +func HandlePolicyList(t *testing.T) { + th.Mux.HandleFunc("/v1/policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, PolicyListBody1) + case "PolicyListBodyID1": + fmt.Fprintf(w, PolicyListBody2) + case "PolicyListBodyID2": + fmt.Fprintf(w, `{"policies":[]}`) + default: + t.Fatalf("Unexpected marker: [%s]", marker) + } + }) +} + +func HandlePolicyCreate(t *testing.T) { + th.Mux.HandleFunc("/v1/policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, PolicyCreateBody) + }) +} + +func HandlePolicyDelete(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/"+PolicyIDtoDelete, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("X-OpenStack-Request-ID", PolicyDeleteRequestID) + w.WriteHeader(http.StatusNoContent) + }) +} + +func HandlePolicyGet(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/"+PolicyIDtoGet, + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyGetBody) + }) +} + +func HandlePolicyUpdate(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/"+PolicyIDtoUpdate, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyUpdateBody) + }) +} + +func HandleBadPolicyUpdate(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/"+PolicyIDtoUpdate, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyBadUpdateBody) + }) +} + +func HandlePolicyValidate(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/validate", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyValidateBody) + }) +} + +func HandleBadPolicyValidate(t *testing.T) { + th.Mux.HandleFunc("/v1/policies/validate", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyBadValidateBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/requests_test.go new file mode 100644 index 00000000..3f74bf0b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/testing/requests_test.go @@ -0,0 +1,147 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListPolicies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyList(t) + + listOpts := policies.ListOpts{ + Limit: 1, + } + + count := 0 + err := policies.List(fake.ServiceClient(), listOpts).EachPage(func(page pagination.Page) (bool, error) { + actual, err := policies.ExtractPolicies(page) + if err != nil { + t.Errorf("Failed to extract policies: %v", err) + return false, err + } + + th.AssertDeepEquals(t, ExpectedPolicies[count], actual) + count++ + + return true, nil + }) + + th.AssertNoErr(t, err) + + if count != 2 { + t.Errorf("Expected 2 pages, got %d", count) + } +} + +func TestCreatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyCreate(t) + + expected := ExpectedCreatePolicy + + opts := policies.CreateOpts{ + Name: ExpectedCreatePolicy.Name, + Spec: ExpectedCreatePolicy.Spec, + } + + actual, err := policies.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestDeletePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyDelete(t) + + actual, err := policies.Delete(fake.ServiceClient(), PolicyIDtoDelete).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, PolicyDeleteRequestID, actual.RequestID) +} + +func TestUpdatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyUpdate(t) + + expected := ExpectedUpdatePolicy + + opts := policies.UpdateOpts{ + Name: ExpectedUpdatePolicy.Name, + } + + actual, err := policies.Update(fake.ServiceClient(), PolicyIDtoUpdate, opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestBadUpdatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleBadPolicyUpdate(t) + + opts := policies.UpdateOpts{ + Name: ExpectedUpdatePolicy.Name, + } + + _, err := policies.Update(fake.ServiceClient(), PolicyIDtoUpdate, opts).Extract() + th.AssertEquals(t, false, err == nil) +} + +func TestValidatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyValidate(t) + + expected := ExpectedValidatePolicy + + opts := policies.ValidateOpts{ + Spec: ExpectedValidatePolicy.Spec, + } + + actual, err := policies.Validate(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &expected, actual) +} + +func TestBadValidatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleBadPolicyValidate(t) + + opts := policies.ValidateOpts{ + Spec: ExpectedValidatePolicy.Spec, + } + + _, err := policies.Validate(fake.ServiceClient(), opts).Extract() + th.AssertEquals(t, false, err == nil) +} + +func TestGetPolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyGet(t) + + actual, err := policies.Get(fake.ServiceClient(), PolicyIDtoGet).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedGetPolicy, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/urls.go new file mode 100644 index 00000000..d558ab0d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policies/urls.go @@ -0,0 +1,32 @@ +package policies + +import "github.com/gophercloud/gophercloud" + +const ( + apiVersion = "v1" + apiName = "policies" +) + +func policyListURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func policyCreateURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func policyDeleteURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(apiVersion, apiName, policyID) +} + +func policyGetURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(apiVersion, apiName, policyID) +} + +func updateURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(apiVersion, apiName, policyID) +} + +func validateURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName, "validate") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/doc.go new file mode 100644 index 00000000..2b1b6d68 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/doc.go @@ -0,0 +1,31 @@ +/* +Package policytypes lists all policy types and shows details for a policy type +from the OpenStack Clustering Service. + +Example to List Policy Types + + allPages, err := policytypes.List(clusteringClient).AllPages() + if err != nil { + panic(err) + } + + allPolicyTypes, err := actions.ExtractPolicyTypes(allPages) + if err != nil { + panic(err) + } + + for _, policyType := range allPolicyTypes { + fmt.Printf("%+v\n", policyType) + } + +Example to Get a Policy Type + + policyTypeName := "senlin.policy.affinity-1.0" + policyTypeDetail, err := policyTypes.Get(clusteringClient, policyTypeName).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", policyTypeDetail) +*/ +package policytypes diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/requests.go new file mode 100644 index 00000000..ca9a5a3b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/requests.go @@ -0,0 +1,26 @@ +package policytypes + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// List makes a request against the API to list policy types. +func List(client *gophercloud.ServiceClient) pagination.Pager { + url := policyTypeListURL(client) + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return PolicyTypePage{pagination.SinglePageBase(r)} + }) +} + +// Get makes a request against the API to get details for a policy type. +func Get(client *gophercloud.ServiceClient, policyTypeName string) (r GetResult) { + url := policyTypeGetURL(client, policyTypeName) + + _, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/results.go new file mode 100644 index 00000000..98c1e53c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/results.go @@ -0,0 +1,68 @@ +package policytypes + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// PolicyType represents a clustering policy type in the Openstack cloud. +type PolicyType struct { + Name string `json:"name"` + Version string `json:"version"` + SupportStatus map[string][]SupportStatusType `json:"support_status"` +} + +// SupportStatusType represents the support status information for a +// clustering policy type. +type SupportStatusType struct { + Status string `json:"status"` + Since string `json:"since"` +} + +// PolicyTypeDetail represents the detailed policy type information for a +// clustering policy type. +type PolicyTypeDetail struct { + Name string `json:"name"` + Schema map[string]interface{} `json:"schema"` + SupportStatus map[string][]SupportStatusType `json:"support_status,omitempty"` +} + +// policyTypeResult is the base result of a Policy Type operation. +type policyTypeResult struct { + gophercloud.Result +} + +// Extract interprets any policyTypeResult result as a PolicyTypeDetail. +func (r policyTypeResult) Extract() (*PolicyTypeDetail, error) { + var s struct { + PolicyType *PolicyTypeDetail `json:"policy_type"` + } + err := r.ExtractInto(&s) + return s.PolicyType, err +} + +// GetResult is the result of a Get operation. Call its Extract method to +// interpret it as a PolicyTypeDetail. +type GetResult struct { + policyTypeResult +} + +// PolicyTypePage contains a single page of all policy types from a List call. +type PolicyTypePage struct { + pagination.SinglePageBase +} + +// IsEmpty determines if a PolicyType contains any results. +func (page PolicyTypePage) IsEmpty() (bool, error) { + policyTypes, err := ExtractPolicyTypes(page) + return len(policyTypes) == 0, err +} + +// ExtractPolicyTypes returns a slice of PolicyTypes from a List operation. +func ExtractPolicyTypes(r pagination.Page) ([]PolicyType, error) { + var s struct { + PolicyTypes []PolicyType `json:"policy_types"` + } + err := (r.(PolicyTypePage)).ExtractInto(&s) + return s.PolicyTypes, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/doc.go new file mode 100644 index 00000000..5bd30a47 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_policytypes_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/fixtures.go new file mode 100644 index 00000000..2732dd9e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/fixtures.go @@ -0,0 +1,235 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const FakePolicyTypetoGet = "fake-policytype" + +const PolicyTypeBody = ` +{ + "policy_types": [ + { + "name": "senlin.policy.affinity", + "version": "1.0", + "support_status": { + "1.0": [ + { + "status": "SUPPORTED", + "since": "2016.10" + } + ] + } + }, + { + "name": "senlin.policy.health", + "version": "1.0", + "support_status": { + "1.0": [ + { + "status": "EXPERIMENTAL", + "since": "2016.10" + } + ] + } + }, + { + "name": "senlin.policy.scaling", + "version": "1.0", + "support_status": { + "1.0": [ + { + "status": "SUPPORTED", + "since": "2016.04" + } + ] + } + }, + { + "name": "senlin.policy.region_placement", + "version": "1.0", + "support_status": { + "1.0": [ + { + "status": "EXPERIMENTAL", + "since": "2016.04" + }, + { + "status": "SUPPORTED", + "since": "2016.10" + } + ] + } + } + ] +} +` + +const PolicyTypeDetailBody = ` +{ + "policy_type": { + "name": "senlin.policy.batch-1.0", + "schema": { + "max_batch_size": { + "default": -1, + "description": "Maximum number of nodes that will be updated in parallel.", + "required": false, + "type": "Integer", + "updatable": false + }, + "min_in_service": { + "default": 1, + "description": "Minimum number of nodes in service when performing updates.", + "required": false, + "type": "Integer", + "updatable": false + }, + "pause_time": { + "default": 60, + "description": "Interval in seconds between update batches if any.", + "required": false, + "type": "Integer", + "updatable": false + } + }, + "support_status": { + "1.0": [ + { + "status": "EXPERIMENTAL", + "since": "2017.02" + } + ] + } + } +} +` + +var ExpectedPolicyType1 = policytypes.PolicyType{ + Name: "senlin.policy.affinity", + Version: "1.0", + SupportStatus: map[string][]policytypes.SupportStatusType{ + "1.0": { + { + Status: "SUPPORTED", + Since: "2016.10", + }, + }, + }, +} + +var ExpectedPolicyType2 = policytypes.PolicyType{ + Name: "senlin.policy.health", + Version: "1.0", + SupportStatus: map[string][]policytypes.SupportStatusType{ + "1.0": { + { + Status: "EXPERIMENTAL", + Since: "2016.10", + }, + }, + }, +} + +var ExpectedPolicyType3 = policytypes.PolicyType{ + Name: "senlin.policy.scaling", + Version: "1.0", + SupportStatus: map[string][]policytypes.SupportStatusType{ + "1.0": { + { + Status: "SUPPORTED", + Since: "2016.04", + }, + }, + }, +} + +var ExpectedPolicyType4 = policytypes.PolicyType{ + Name: "senlin.policy.region_placement", + Version: "1.0", + SupportStatus: map[string][]policytypes.SupportStatusType{ + "1.0": { + { + Status: "EXPERIMENTAL", + Since: "2016.04", + }, + { + Status: "SUPPORTED", + Since: "2016.10", + }, + }, + }, +} + +var ExpectedPolicyTypes = []policytypes.PolicyType{ + ExpectedPolicyType1, + ExpectedPolicyType2, + ExpectedPolicyType3, + ExpectedPolicyType4, +} + +var ExpectedPolicyTypeDetail = &policytypes.PolicyTypeDetail{ + Name: "senlin.policy.batch-1.0", + Schema: map[string]interface{}{ + "max_batch_size": map[string]interface{}{ + "default": float64(-1), + "description": "Maximum number of nodes that will be updated in parallel.", + "required": false, + "type": "Integer", + "updatable": false, + }, + "min_in_service": map[string]interface{}{ + "default": float64(1), + "description": "Minimum number of nodes in service when performing updates.", + "required": false, + "type": "Integer", + "updatable": false, + }, + "pause_time": map[string]interface{}{ + "default": float64(60), + "description": "Interval in seconds between update batches if any.", + "required": false, + "type": "Integer", + "updatable": false, + }, + }, + SupportStatus: map[string][]policytypes.SupportStatusType{ + "1.0": []policytypes.SupportStatusType{ + { + Status: "EXPERIMENTAL", + Since: "2017.02", + }, + }, + }, +} + +func HandlePolicyTypeList(t *testing.T) { + th.Mux.HandleFunc("/v1/policy-types", + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyTypeBody) + }) +} + +func HandlePolicyTypeGet(t *testing.T) { + th.Mux.HandleFunc("/v1/policy-types/"+FakePolicyTypetoGet, + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, PolicyTypeDetailBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/requests_test.go new file mode 100644 index 00000000..87e42fab --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/testing/requests_test.go @@ -0,0 +1,49 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListPolicyTypes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyTypeList(t) + + count := 0 + err := policytypes.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := policytypes.ExtractPolicyTypes(page) + if err != nil { + t.Errorf("Failed to extract policy types: %v", err) + return false, err + } + th.AssertDeepEquals(t, ExpectedPolicyTypes, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGetPolicyType(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePolicyTypeGet(t) + + actual, err := policytypes.Get(fake.ServiceClient(), FakePolicyTypetoGet).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedPolicyTypeDetail, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/urls.go new file mode 100644 index 00000000..b291a95c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/policytypes/urls.go @@ -0,0 +1,16 @@ +package policytypes + +import "github.com/gophercloud/gophercloud" + +const ( + apiVersion = "v1" + apiName = "policy-types" +) + +func policyTypeListURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func policyTypeGetURL(client *gophercloud.ServiceClient, policyTypeName string) string { + return client.ServiceURL(apiVersion, apiName, policyTypeName) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/doc.go new file mode 100644 index 00000000..13676df8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/doc.go @@ -0,0 +1,85 @@ +/* +Package profiles provides information and interaction with profiles through +the OpenStack Clustering service. + +Example to Create a Profile + + networks := []map[string]interface{} { + {"network": "test-network"}, + } + + props := map[string]interface{}{ + "name": "test_gophercloud_profile", + "flavor": "t2.micro", + "image": "centos7.3-latest", + "networks": networks, + "security_groups": "", + } + + createOpts := profiles.CreateOpts { + Name: "test_profile", + Spec: profiles.Spec{ + Type: "os.nova.server", + Version: "1.0", + Properties: props, + }, + } + + profile, err := profiles.Create(serviceClient, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Println("Profile", profile) + +Example to Get a Profile + + profile, err := profiles.Get(serviceClient, "profile-name").Extract() + if err != nil { + panic(err) + } + + fmt.Print("profile", profile) + + +Example to List Profiles + + listOpts := profiles.ListOpts{ + Limit: 2, + } + + profiles.List(serviceClient, listOpts).EachPage(func(page pagination.Page) (bool, error) { + allProfiles, err := profiles.ExtractProfiles(page) + if err != nil { + panic(err) + } + + for _, profile := range allProfiles { + fmt.Printf("%+v\n", profile) + } + return true, nil + }) + +Example to Update a Profile + + updateOpts := profiles.UpdateOpts{ + Name: "new-name", + } + + profile, err := profiles.Update(serviceClient, profileName, updateOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Print("profile", profile) + +Example to Delete a Profile + + profileID := "6dc6d336e3fc4c0a951b5698cd1236ee" + err := profiles.Delete(serviceClient, profileID).ExtractErr() + if err != nil { + panic(err) + } + +*/ +package profiles diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/requests.go new file mode 100644 index 00000000..5fb10f81 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/requests.go @@ -0,0 +1,139 @@ +package profiles + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToProfileCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options used for creating a profile. +type CreateOpts struct { + Name string `json:"name" required:"true"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Spec Spec `json:"spec" required:"true"` +} + +// ToProfileCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToProfileCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "profile") +} + +// Create requests the creation of a new profile on the server. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToProfileCreateMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201}, + }) + + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Get retrieves detail of a single profile. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + var result *http.Response + result, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + if r.Err == nil { + r.Header = result.Header + } + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToProfileListQuery() (string, error) +} + +// ListOpts represents options used to list profiles. +type ListOpts struct { + GlobalProject *bool `q:"global_project"` + Limit int `q:"limit"` + Marker string `q:"marker"` + Name string `q:"name"` + Sort string `q:"sort"` + Type string `q:"type"` +} + +// ToProfileListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToProfileListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of profiles. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToProfileListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ProfilePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToProfileUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options used to update a profile. +type UpdateOpts struct { + Metadata map[string]interface{} `json:"metadata,omitempty"` + Name string `json:"name,omitempty"` +} + +// ToProfileUpdateMap constructs a request body from UpdateOpts. +func (opts UpdateOpts) ToProfileUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "profile") +} + +// Update updates a profile. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToProfileUpdateMap() + if err != nil { + r.Err = err + return r + } + var result *http.Response + result, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Delete deletes the specified profile via profile id. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + var result *http.Response + result, r.Err = client.Delete(deleteURL(client, id), nil) + if r.Err == nil { + r.Header = result.Header + } + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/results.go new file mode 100644 index 00000000..5b457d56 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/results.go @@ -0,0 +1,148 @@ +package profiles + +import ( + "encoding/json" + "fmt" + "strconv" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Profile represent a detailed profile. +type Profile struct { + CreatedAt time.Time `json:"-"` + Domain string `json:"domain"` + ID string `json:"id"` + Metadata map[string]interface{} `json:"metadata"` + Name string `json:"name"` + Project string `json:"project"` + Spec Spec `json:"spec"` + Type string `json:"type"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Profile) UnmarshalJSON(b []byte) error { + type tmp Profile + var s struct { + tmp + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Profile(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(time.RFC3339, s.CreatedAt) + if err != nil { + return err + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(time.RFC3339, s.UpdatedAt) + if err != nil { + return err + } + } + + return nil +} + +// Spec represents a profile spec. +type Spec struct { + Type string `json:"type"` + Version string `json:"version"` + Properties map[string]interface{} `json:"properties"` +} + +func (r *Spec) UnmarshalJSON(b []byte) error { + type tmp Spec + var s struct { + tmp + Version interface{} `json:"version"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Spec(s.tmp) + + switch t := s.Version.(type) { + case float64: + if t == 1 { + r.Version = fmt.Sprintf("%.1f", t) + } else { + r.Version = strconv.FormatFloat(t, 'f', -1, 64) + } + case string: + r.Version = t + } + + return nil +} + +// commonResult is the base result of a Profile operation. +type commonResult struct { + gophercloud.Result +} + +// Extract provides access to Profile returned by the Get and Create functions. +func (r commonResult) Extract() (*Profile, error) { + var s struct { + Profile *Profile `json:"profile"` + } + err := r.ExtractInto(&s) + return s.Profile, err +} + +// CreateResult is the result of a Create operation. Call its Extract +// method to interpret it as a Profile. +type CreateResult struct { + commonResult +} + +// GetResult is the result of a Get operations. Call its Extract +// method to interpret it as a Profile. +type GetResult struct { + commonResult +} + +// UpdateResult is the result of a Update operations. Call its Extract +// method to interpret it as a Profile. +type UpdateResult struct { + commonResult +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// ProfilePage contains a single page of all profiles from a List operation. +type ProfilePage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines if a ProfilePage contains any results. +func (page ProfilePage) IsEmpty() (bool, error) { + profiles, err := ExtractProfiles(page) + return len(profiles) == 0, err +} + +// ExtractProfiles returns a slice of Profiles from the List operation. +func ExtractProfiles(r pagination.Page) ([]Profile, error) { + var s struct { + Profiles []Profile `json:"profiles"` + } + err := (r.(ProfilePage)).ExtractInto(&s) + return s.Profiles, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/doc.go new file mode 100644 index 00000000..2a99a8a6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_profiles_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/fixtures.go new file mode 100644 index 00000000..f989fc3a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/fixtures.go @@ -0,0 +1,395 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const CreateResponse = ` +{ + "profile": { + "created_at": "2016-01-03T16:22:23Z", + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": {}, + "name": "test-profile", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": "t2.small", + "image": "centos7.3-latest", + "name": "centos_server", + "networks": [ + { + "network": "private-network" + } + ] + }, + "type": "os.nova.server", + "version": "1.0" + }, + "type": "os.nova.server-1.0", + "updated_at": "2016-01-03T17:22:23Z", + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedCreate = profiles.Profile{ + CreatedAt: time.Date(2016, 1, 3, 16, 22, 23, 0, time.UTC), + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{}, + Name: "test-profile", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": "t2.small", + "image": "centos7.3-latest", + "name": "centos_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private-network"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + UpdatedAt: time.Date(2016, 1, 3, 17, 22, 23, 0, time.UTC), + User: "5e5bf8027826429c96af157f68dc9072", +} + +const GetResponse = ` +{ + "profile": { + "created_at": "2016-01-03T16:22:23Z", + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": {}, + "name": "pserver", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": 1, + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": [ + { + "network": "private" + } + ] + }, + "type": "os.nova.server", + "version": "1.0" + }, + "type": "os.nova.server-1.0", + "updated_at": null, + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedGet = profiles.Profile{ + CreatedAt: time.Date(2016, 1, 3, 16, 22, 23, 0, time.UTC), + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{}, + Name: "pserver", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": float64(1), + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + User: "5e5bf8027826429c96af157f68dc9072", +} + +const ListResponse = ` +{ + "profiles": [ + { + "created_at": "2016-01-03T16:22:23Z", + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": {}, + "name": "pserver", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": [ + { + "network": "private" + } + ] + }, + "type": "os.nova.server", + "version": 1.0 + }, + "type": "os.nova.server-1.0", + "updated_at": "2016-01-03T17:22:23Z", + "user": "5e5bf8027826429c96af157f68dc9072" + }, + { + "created_at": null, + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": {}, + "name": "pserver", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": [ + { + "network": "private" + } + ] + }, + "type": "os.nova.server", + "version": 1.0 + }, + "type": "os.nova.server-1.0", + "updated_at": null, + "user": "5e5bf8027826429c96af157f68dc9072" + }, + { + "created_at": "", + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": {}, + "name": "pserver", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": [ + { + "network": "private" + } + ] + }, + "type": "os.nova.server", + "version": "1.0" + }, + "type": "os.nova.server-1.0", + "updated_at": "", + "user": "5e5bf8027826429c96af157f68dc9072" + } + ] +}` + +var ExpectedListProfile1 = profiles.Profile{ + CreatedAt: time.Date(2016, 1, 3, 16, 22, 23, 0, time.UTC), + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{}, + Name: "pserver", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + UpdatedAt: time.Date(2016, 1, 3, 17, 22, 23, 0, time.UTC), + User: "5e5bf8027826429c96af157f68dc9072", +} + +var ExpectedListProfile2 = profiles.Profile{ + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{}, + Name: "pserver", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + User: "5e5bf8027826429c96af157f68dc9072", +} + +var ExpectedListProfile3 = profiles.Profile{ + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{}, + Name: "pserver", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": "t2.small", + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + User: "5e5bf8027826429c96af157f68dc9072", +} + +var ExpectedList = []profiles.Profile{ + ExpectedListProfile1, + ExpectedListProfile2, + ExpectedListProfile3, +} + +const UpdateResponse = ` +{ + "profile": { + "created_at": "2016-01-03T16:22:23Z", + "domain": null, + "id": "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + "metadata": { + "foo": "bar" + }, + "name": "pserver", + "project": "42d9e9663331431f97b75e25136307ff", + "spec": { + "properties": { + "flavor": 1, + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": [ + { + "network": "private" + } + ] + }, + "type": "os.nova.server", + "version": "1.0" + }, + "type": "os.nova.server-1.0", + "updated_at": "2016-01-03T17:22:23Z", + "user": "5e5bf8027826429c96af157f68dc9072" + } +}` + +var ExpectedUpdate = profiles.Profile{ + CreatedAt: time.Date(2016, 1, 3, 16, 22, 23, 0, time.UTC), + Domain: "", + ID: "9e1c6f42-acf5-4688-be2c-8ce954ef0f23", + Metadata: map[string]interface{}{"foo": "bar"}, + Name: "pserver", + Project: "42d9e9663331431f97b75e25136307ff", + Spec: profiles.Spec{ + Properties: map[string]interface{}{ + "flavor": float64(1), + "image": "cirros-0.3.4-x86_64-uec", + "key_name": "oskey", + "name": "cirros_server", + "networks": []interface{}{ + map[string]interface{}{"network": "private"}, + }, + }, + Type: "os.nova.server", + Version: "1.0", + }, + Type: "os.nova.server-1.0", + UpdatedAt: time.Date(2016, 1, 3, 17, 22, 23, 0, time.UTC), + User: "5e5bf8027826429c96af157f68dc9072", +} + +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profiles", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, CreateResponse) + }) +} + +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profiles/9e1c6f42-acf5-4688-be2c-8ce954ef0f23", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, GetResponse) + }) +} + +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profiles", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) +} + +func HandleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profiles/9e1c6f42-acf5-4688-be2c-8ce954ef0f23", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, UpdateResponse) + }) +} + +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profiles/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/requests_test.go new file mode 100644 index 00000000..1793c4bf --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/testing/requests_test.go @@ -0,0 +1,109 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateProfile(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateSuccessfully(t) + + networks := []map[string]interface{}{ + {"network": "private-network"}, + } + + props := map[string]interface{}{ + "name": "test_gopher_cloud_profile", + "flavor": "t2.small", + "image": "centos7.3-latest", + "networks": networks, + "security_groups": "", + } + + createOpts := &profiles.CreateOpts{ + Name: "TestProfile", + Spec: profiles.Spec{ + Type: "os.nova.server", + Version: "1.0", + Properties: props, + }, + } + + profile, err := profiles.Create(fake.ServiceClient(), createOpts).Extract() + if err != nil { + t.Errorf("Failed to extract profile: %v", err) + } + + th.AssertDeepEquals(t, ExpectedCreate, *profile) +} + +func TestGetProfile(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t) + + actual, err := profiles.Get(fake.ServiceClient(), ExpectedGet.ID).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedGet, *actual) +} + +func TestListProfiles(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + var iFalse bool + listOpts := profiles.ListOpts{ + GlobalProject: &iFalse, + } + + count := 0 + err := profiles.List(fake.ServiceClient(), listOpts).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := profiles.ExtractProfiles(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedList, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if count != 1 { + t.Errorf("Expected 1 page of profiles, got %d pages instead", count) + } +} + +func TestUpdateProfile(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateSuccessfully(t) + + updateOpts := profiles.UpdateOpts{ + Name: "pserver", + } + + actual, err := profiles.Update(fake.ServiceClient(), ExpectedUpdate.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedUpdate, *actual) +} + +func TestDeleteProfile(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteSuccessfully(t) + + deleteResult := profiles.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee") + th.AssertNoErr(t, deleteResult.ExtractErr()) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/urls.go new file mode 100644 index 00000000..060d91dd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles/urls.go @@ -0,0 +1,34 @@ +package profiles + +import "github.com/gophercloud/gophercloud" + +var apiVersion = "v1" +var apiName = "profiles" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func createURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func idURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/doc.go new file mode 100644 index 00000000..39877ace --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/doc.go @@ -0,0 +1,47 @@ +/* +Package profiletypes lists all profile types and shows details for a profile type from the OpenStack +Clustering Service. + +Example to List ProfileType + + err = profiletypes.List(serviceClient).EachPage(func(page pagination.Page) (bool, error) { + profileTypes, err := profiletypes.ExtractProfileTypes(page) + if err != nil { + return false, err + } + + for _, profileType := range profileTypes { + fmt.Println("%+v\n", profileType) + } + return true, nil + }) + +Example to Get a ProfileType + + profileTypeName := "os.nova.server" + profileType, err := profiletypes.Get(clusteringClient, profileTypeName).Extract() + if err != nil { + panic(err) + } + fmt.Printf("%+v\n", profileType) + +Example of list operations supported by a profile type + serviceClient.Microversion = "1.5" + + profileTypeName := "os.nova.server-1.0" + allPages, err := profiletypes.ListOps(serviceClient, profileTypeName).AllPages() + if err != nil { + panic(err) + } + + ops, err := profiletypes.ExtractOps(allPages) + if err != nil { + panic(err) + } + + for _, op := range ops { + fmt.Printf("%+v\n", op) + } + +*/ +package profiletypes diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/requests.go new file mode 100644 index 00000000..37fe0313 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/requests.go @@ -0,0 +1,28 @@ +package profiletypes + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, + &gophercloud.RequestOpts{OkCodes: []int{200}}) + + return +} + +// List makes a request against the API to list profile types. +func List(client *gophercloud.ServiceClient) pagination.Pager { + url := listURL(client) + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ProfileTypePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +func ListOps(client *gophercloud.ServiceClient, id string) pagination.Pager { + url := listOpsURL(client, id) + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return OperationPage{pagination.SinglePageBase(r)} + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/results.go new file mode 100644 index 00000000..3259f68a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/results.go @@ -0,0 +1,67 @@ +package profiletypes + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// GetResult is the response of a Get operations. +type GetResult struct { + commonResult +} + +type Schema map[string]interface{} +type SupportStatus map[string]interface{} + +type ProfileType struct { + Name string `json:"name"` + Schema map[string]Schema `json:"schema"` + SupportStatus map[string][]SupportStatus `json:"support_status"` +} + +func (r commonResult) Extract() (*ProfileType, error) { + var s struct { + ProfileType *ProfileType `json:"profile_type"` + } + err := r.ExtractInto(&s) + return s.ProfileType, err +} + +// ExtractProfileTypes provides access to the list of profiles in a page acquired from the List operation. +func ExtractProfileTypes(r pagination.Page) ([]ProfileType, error) { + var s struct { + ProfileTypes []ProfileType `json:"profile_types"` + } + err := (r.(ProfileTypePage)).ExtractInto(&s) + return s.ProfileTypes, err +} + +// ProfileTypePage contains a single page of all profiles from a ListDetails call. +type ProfileTypePage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines if ExtractProfileTypes contains any results. +func (page ProfileTypePage) IsEmpty() (bool, error) { + profileTypes, err := ExtractProfileTypes(page) + return len(profileTypes) == 0, err +} + +// OperationPage contains a single page of all profile type operations from a ListOps call. +type OperationPage struct { + pagination.SinglePageBase +} + +// ExtractOps provides access to the list of operations in a page acquired from the ListOps operation. +func ExtractOps(r pagination.Page) (map[string]interface{}, error) { + var s struct { + Operations map[string]interface{} `json:"operations"` + } + err := (r.(OperationPage)).ExtractInto(&s) + return s.Operations, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/doc.go new file mode 100644 index 00000000..7890e625 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_profiletypes_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/fixtures.go new file mode 100644 index 00000000..64a112ff --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/fixtures.go @@ -0,0 +1,296 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ProfileTypeRequestID = "req-7328d1b0-9945-456f-b2cd-5166b77d14a8" +const ListResponse = ` +{ + "profile_types": [ + { + "name": "os.nova.server-1.0", + "schema": { + "context": { + "description": "Customized security context for operating containers.", + "required": false, + "type": "Map", + "updatable": false + }, + "name": { + "description": "The name of the container.", + "required": false, + "type": "Map", + "updatable": false + } + } + }, + { + "name": "os.heat.stack-1.0", + "schema": { + "context": { + "default": {}, + "description": "A dictionary for specifying the customized context for stack operations", + "required": false, + "type": "Map", + "updatable": false + }, + "disable_rollback": { + "default": true, + "description": "A boolean specifying whether a stack operation can be rolled back.", + "required": false, + "type": "Boolean", + "updatable": true + }, + "environment": { + "default": {}, + "description": "A map that specifies the environment used for stack operations.", + "required": false, + "type": "Map", + "updatable": true + }, + "files": { + "default": {}, + "description": "Contents of files referenced by the template, if any.", + "required": false, + "type": "Map", + "updatable": true + } + }, + "support_status": { + "1.0": [ + { + "status": "SUPPORTED", + "since": "2016.04" + } + ] + } + } + ] +} +` + +const GetResponse1 = ` +{ + "profile_type": { + "name": "os.nova.server-1.0", + "schema": { + "context": { + "description": "Customized security context for operating containers.", + "required": false, + "type": "Map", + "updatable": false + }, + "name": { + "description": "The name of the container.", + "required": false, + "type": "Map", + "updatable": false + } + } + } +} +` + +const GetResponse15 = ` +{ + "profile_type": { + "name": "os.heat.stack-1.0", + "schema": { + "context": { + "default": {}, + "description": "A dictionary for specifying the customized context for stack operations", + "required": false, + "type": "Map", + "updatable": false + }, + "disable_rollback": { + "default": true, + "description": "A boolean specifying whether a stack operation can be rolled back.", + "required": false, + "type": "Boolean", + "updatable": true + }, + "environment": { + "default": {}, + "description": "A map that specifies the environment used for stack operations.", + "required": false, + "type": "Map", + "updatable": true + }, + "files": { + "default": {}, + "description": "Contents of files referenced by the template, if any.", + "required": false, + "type": "Map", + "updatable": true + } + }, + "support_status": { + "1.0": [ + { + "status": "SUPPORTED", + "since": "2016.04" + } + ] + } + } +} +` + +var ExpectedProfileType1 = profiletypes.ProfileType{ + Name: "os.nova.server-1.0", + Schema: map[string]profiletypes.Schema{ + "context": { + "description": "Customized security context for operating containers.", + "required": false, + "type": "Map", + "updatable": false, + }, + "name": { + "description": "The name of the container.", + "required": false, + "type": "Map", + "updatable": false, + }, + }, +} + +var ExpectedProfileType15 = profiletypes.ProfileType{ + Name: "os.heat.stack-1.0", + Schema: map[string]profiletypes.Schema{ + "context": { + "default": map[string]interface{}{}, + "description": "A dictionary for specifying the customized context for stack operations", + "required": false, + "type": "Map", + "updatable": false, + }, + "disable_rollback": { + "default": true, + "description": "A boolean specifying whether a stack operation can be rolled back.", + "required": false, + "type": "Boolean", + "updatable": true, + }, + "environment": { + "default": map[string]interface{}{}, + "description": "A map that specifies the environment used for stack operations.", + "required": false, + "type": "Map", + "updatable": true, + }, + "files": { + "default": map[string]interface{}{}, + "description": "Contents of files referenced by the template, if any.", + "required": false, + "type": "Map", + "updatable": true, + }, + }, + SupportStatus: map[string][]profiletypes.SupportStatus{ + "1.0": { + { + "status": "SUPPORTED", + "since": "2016.04", + }, + }, + }, +} + +var ExpectedProfileTypes = []profiletypes.ProfileType{ExpectedProfileType1, ExpectedProfileType15} + +func HandleList1Successfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profile-types", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResponse) + }) +} + +func HandleGet1Successfully(t *testing.T, id string) { + th.Mux.HandleFunc("/v1/profile-types/"+id, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", ProfileTypeRequestID) + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse1) + }) +} + +func HandleGet15Successfully(t *testing.T, id string) { + th.Mux.HandleFunc("/v1/profile-types/"+id, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", ProfileTypeRequestID) + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse15) + }) +} + +const ProfileTypeName = "os.nova.server-1.0" + +const ListOpsResponse = ` +{ + "operations": { + "pause": { + "description": "Pause the server from running.", + "parameter": null + }, + "change_password": { + "description": "Change the administrator password.", + "parameters": { + "admin_pass": { + "description": "New password for the administrator.", + "required": false, + "type": "String" + } + } + } + } +} +` + +var ExpectedOps = map[string]interface{}{ + "change_password": map[string]interface{}{ + "description": "Change the administrator password.", + "parameters": map[string]interface{}{ + "admin_pass": map[string]interface{}{ + "description": "New password for the administrator.", + "required": false, + "type": "String", + }, + }, + }, + "pause": map[string]interface{}{ + "description": "Pause the server from running.", + "parameter": nil, + }, +} + +func HandleListOpsSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/profile-types/"+ProfileTypeName+"/ops", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("X-OpenStack-Request-ID", ProfileTypeRequestID) + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListOpsResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/requests_test.go new file mode 100644 index 00000000..c4f379b6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/testing/requests_test.go @@ -0,0 +1,74 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/acceptance/tools" + "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListProfileTypes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleList1Successfully(t) + + pageCount := 0 + err := profiletypes.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pageCount++ + actual, err := profiletypes.ExtractProfileTypes(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedProfileTypes, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + + if pageCount != 1 { + t.Errorf("Expected 1 page, got %d", pageCount) + } +} + +func TestGetProfileType10(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGet1Successfully(t, ExpectedProfileType1.Name) + + actual, err := profiletypes.Get(fake.ServiceClient(), ExpectedProfileType1.Name).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedProfileType1, *actual) +} + +func TestGetProfileType15(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGet15Successfully(t, ExpectedProfileType15.Name) + + actual, err := profiletypes.Get(fake.ServiceClient(), ExpectedProfileType15.Name).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedProfileType15, *actual) +} + +func TestListProfileTypesOps(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListOpsSuccessfully(t) + + allPages, err := profiletypes.ListOps(fake.ServiceClient(), ProfileTypeName).AllPages() + th.AssertNoErr(t, err) + + allPolicyTypes, err := profiletypes.ExtractOps(allPages) + th.AssertNoErr(t, err) + + for k, v := range allPolicyTypes { + tools.PrintResource(t, k) + tools.PrintResource(t, v) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/urls.go new file mode 100644 index 00000000..cec8bfe4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/profiletypes/urls.go @@ -0,0 +1,28 @@ +package profiletypes + +import "github.com/gophercloud/gophercloud" + +const ( + apiVersion = "v1" + apiName = "profile-types" +) + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func profileTypeURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return profileTypeURL(client, id) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func listOpsURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id, "ops") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/doc.go new file mode 100644 index 00000000..0217136a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/doc.go @@ -0,0 +1,72 @@ +/* +Package receivers provides information and interaction with the receivers through +the OpenStack Clustering service. + +Example to Create a Receiver + + createOpts := receivers.CreateOpts{ + Action: "CLUSTER_DEL_NODES", + ClusterID: "b7b870ee-d3c5-4a93-b9d7-846c53b2c2dc", + Name: "test_receiver", + Type: receivers.WebhookReceiver, + } + + receiver, err := receivers.Create(serviceClient, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", receiver) + +Example to Get a Receiver + + receiver, err := receivers.Get(serviceClient, "receiver-name").Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", receiver) + +Example to Delete receiver + + receiverID := "6dc6d336e3fc4c0a951b5698cd1236ee" + err := receivers.Delete(serviceClient, receiverID).ExtractErr() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", receiver) + +Example to Update Receiver + + updateOpts := receivers.UpdateOpts{ + Name: "new-name", + } + + receiverID := "6dc6d336e3fc4c0a951b5698cd1236ee" + receiver, err := receivers.Update(serviceClient, receiverID, updateOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", receiver) + +Example to List Receivers + + listOpts := receivers.ListOpts{ + Limit: 2, + } + + receivers.List(serviceClient, listOpts).EachPage(func(page pagination.Page) (bool, error) { + allReceivers, err := receivers.ExtractReceivers(page) + if err != nil { + panic(err) + } + + for _, receiver := range allReceivers { + fmt.Printf("%+v\n", receiver) + } + return true, nil + }) +*/ +package receivers diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/requests.go new file mode 100644 index 00000000..1c528c73 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/requests.go @@ -0,0 +1,145 @@ +package receivers + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ReceiverType represents a valid type of receiver +type ReceiverType string + +const ( + WebhookReceiver ReceiverType = "webhook" + MessageReceiver ReceiverType = "message" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToReceiverCreateMap() (map[string]interface{}, error) +} + +// CreatOpts represents options used to create a receiver. +type CreateOpts struct { + Name string `json:"name" required:"true"` + ClusterID string `json:"cluster_id,omitempty"` + Type ReceiverType `json:"type" required:"true"` + Action string `json:"action,omitempty"` + Actor map[string]interface{} `json:"actor,omitempty"` + Params map[string]interface{} `json:"params,omitempty"` +} + +// ToReceiverCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToReceiverCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "receiver") +} + +// Create requests the creation of a new receiver. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToReceiverCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToReceiverUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options used to update a receiver. +type UpdateOpts struct { + Name string `json:"name,omitempty"` + Action string `json:"action,omitempty"` + Params map[string]interface{} `json:"params,omitempty"` +} + +// ToReceiverUpdateMap constructs a request body from UpdateOpts. +func (opts UpdateOpts) ToReceiverUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "receiver") +} + +// Update requests the update of a receiver. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToReceiverUpdateMap() + if err != nil { + r.Err = err + return + } + + var result *http.Response + result, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201}, + }) + + if r.Err == nil { + r.Header = result.Header + } + return +} + +// Get retrieves details of a single receiver. Use Extract to convert its result into a Receiver. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + var result *http.Response + result, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) + if r.Err == nil { + r.Header = result.Header + } + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToReceiverListQuery() (string, error) +} + +// ListOpts represents options used to list recievers. +type ListOpts struct { + Limit int `q:"limit"` + Marker string `q:"marker"` + Sort string `q:"sort"` + GlobalProject *bool `q:"global_project"` + Name string `q:"name"` + Type string `q:"type"` + ClusterID string `q:"cluster_id"` + Action string `q:"action"` + User string `q:"user"` +} + +// ToReceiverListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToReceiverListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of cluster. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToReceiverListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ReceiverPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Delete deletes the specified receiver ID. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/results.go new file mode 100644 index 00000000..92999215 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/results.go @@ -0,0 +1,114 @@ +package receivers + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Receiver represent a detailed receiver +type Receiver struct { + Action string `json:"action"` + Actor map[string]interface{} `json:"actor"` + Channel map[string]interface{} `json:"channel"` + ClusterID string `json:"cluster_id"` + CreatedAt time.Time `json:"-"` + Domain string `json:"domain"` + ID string `json:"id"` + Name string `json:"name"` + Params map[string]interface{} `json:"params"` + Project string `json:"project"` + Type string `json:"type"` + UpdatedAt time.Time `json:"-"` + User string `json:"user"` +} + +func (r *Receiver) UnmarshalJSON(b []byte) error { + type tmp Receiver + var s struct { + tmp + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Receiver(s.tmp) + + if s.CreatedAt != "" { + r.CreatedAt, err = time.Parse(time.RFC3339, s.CreatedAt) + if err != nil { + return err + } + } + + if s.UpdatedAt != "" { + r.UpdatedAt, err = time.Parse(time.RFC3339, s.UpdatedAt) + if err != nil { + return err + } + } + + return nil +} + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult-based result as a Receiver. +func (r commonResult) Extract() (*Receiver, error) { + var s struct { + Receiver *Receiver `json:"receiver"` + } + err := r.ExtractInto(&s) + return s.Receiver, err +} + +// CreateResult is the result of a Create operation. Call its Extract method +// to interpret it as a Receiver. +type CreateResult struct { + commonResult +} + +// GetResult is the result for of a Get operation. Call its Extract method +// to interpret it as a Receiver. +type GetResult struct { + commonResult +} + +// UpdateResult is the result of a Update operation. Call its Extract method +// to interpret it as a Receiver. +type UpdateResult struct { + commonResult +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// ReceiverPage contains a single page of all nodes from a List operation. +type ReceiverPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines if a ReceiverPage contains any results. +func (page ReceiverPage) IsEmpty() (bool, error) { + receivers, err := ExtractReceivers(page) + return len(receivers) == 0, err +} + +// ExtractReceivers returns a slice of Receivers from the List operation. +func ExtractReceivers(r pagination.Page) ([]Receiver, error) { + var s struct { + Receivers []Receiver `json:"receivers"` + } + err := (r.(ReceiverPage)).ExtractInto(&s) + return s.Receivers, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/doc.go new file mode 100644 index 00000000..c692a35a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_receivers_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/fixtures.go new file mode 100644 index 00000000..498d162d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/fixtures.go @@ -0,0 +1,229 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const CreateResponse = ` +{ + "receiver": { + "action": "CLUSTER_SCALE_OUT", + "actor": { + "trust_id": [ + "6dc6d336e3fc4c0a951b5698cd1236d9" + ] + }, + "channel": { + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" + }, + "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", + "created_at": "2015-11-04T05:21:41Z", + "domain": "Default", + "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + "name": "cluster_inflate", + "params": { + "count": "1" + }, + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "type": "webhook", + "updated_at": "2016-11-04T05:21:41Z", + "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" + } +}` + +var ExpectedReceiver = receivers.Receiver{ + Action: "CLUSTER_SCALE_OUT", + Actor: map[string]interface{}{ + "trust_id": []string{ + "6dc6d336e3fc4c0a951b5698cd1236d9", + }, + }, + Channel: map[string]interface{}{ + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1", + }, + ClusterID: "ae63a10b-4a90-452c-aef1-113a0b255ee3", + CreatedAt: time.Date(2015, 11, 4, 5, 21, 41, 0, time.UTC), + Domain: "Default", + ID: "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + Name: "cluster_inflate", + Params: map[string]interface{}{ + "count": "1", + }, + Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", + Type: "webhook", + UpdatedAt: time.Date(2016, 11, 4, 5, 21, 41, 0, time.UTC), + User: "b4ad2d6e18cc2b9c48049f6dbe8a5b3c", +} + +const GetResponse = ` +{ + "receiver": { + "action": "CLUSTER_SCALE_OUT", + "actor": { + "trust_id": [ + "6dc6d336e3fc4c0a951b5698cd1236d9" + ] + }, + "channel": { + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" + }, + "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", + "created_at": "2015-11-04T05:21:41Z", + "domain": "Default", + "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + "name": "cluster_inflate", + "params": { + "count": "1" + }, + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "type": "webhook", + "updated_at": "2016-11-04T05:21:41Z", + "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" + } +}` + +const UpdateResponse = ` +{ + "receiver": { + "action": "CLUSTER_SCALE_OUT", + "actor": { + "trust_id": [ + "6dc6d336e3fc4c0a951b5698cd1236d9" + ] + }, + "channel": { + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" + }, + "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", + "created_at": "2015-06-27T05:09:43Z", + "domain": "Default", + "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + "name": "cluster_inflate", + "params": { + "count": "1" + }, + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "type": "webhook", + "updated_at": null, + "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" + } +}` + +var ExpectedUpdateReceiver = receivers.Receiver{ + Action: "CLUSTER_SCALE_OUT", + Actor: map[string]interface{}{ + "trust_id": []string{ + "6dc6d336e3fc4c0a951b5698cd1236d9", + }, + }, + Channel: map[string]interface{}{ + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1", + }, + ClusterID: "ae63a10b-4a90-452c-aef1-113a0b255ee3", + CreatedAt: time.Date(2015, 6, 27, 5, 9, 43, 0, time.UTC), + Domain: "Default", + ID: "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + Name: "cluster_inflate", + Params: map[string]interface{}{ + "count": "1", + }, + Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", + Type: "webhook", + User: "b4ad2d6e18cc2b9c48049f6dbe8a5b3c", +} + +const ListResponse = ` +{ + "receivers": [ + { + "action": "CLUSTER_SCALE_OUT", + "actor": { + "trust_id": [ + "6dc6d336e3fc4c0a951b5698cd1236d9" + ] + }, + "channel": { + "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" + }, + "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", + "created_at": "2015-06-27T05:09:43Z", + "domain": "Default", + "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", + "name": "cluster_inflate", + "params": { + "count": "1" + }, + "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", + "type": "webhook", + "updated_at": null, + "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" + } + ] +}` + +var ExpectedReceiversList = []receivers.Receiver{ExpectedUpdateReceiver} + +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/receivers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, CreateResponse) + }) +} + +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/receivers/573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, GetResponse) + }) +} + +func HandleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/receivers/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, UpdateResponse) + }) +} + +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/receivers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestFormValues(t, r, map[string]string{"limit": "2", "sort": "name:asc,status:desc"}) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ListResponse) + }) +} + +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/receivers/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/requests_test.go new file mode 100644 index 00000000..02f8f069 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/testing/requests_test.go @@ -0,0 +1,94 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateReceiver(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateSuccessfully(t) + + opts := receivers.CreateOpts{ + Name: "cluster_inflate", + ClusterID: "ae63a10b-4a90-452c-aef1-113a0b255ee3", + Type: receivers.WebhookReceiver, + Action: "CLUSTER_SCALE_OUT", + Actor: map[string]interface{}{}, + Params: map[string]interface{}{}, + } + + actual, err := receivers.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedReceiver, *actual) +} + +func TestGetReceivers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t) + + actual, err := receivers.Get(fake.ServiceClient(), "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedReceiver, *actual) +} + +func TestUpdateReceiver(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdateSuccessfully(t) + + opts := receivers.UpdateOpts{ + Name: "cluster_inflate", + Action: "CLUSTER_SCALE_OUT", + Params: map[string]interface{}{ + "count": "2", + }, + } + actual, err := receivers.Update(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee", opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedUpdateReceiver, *actual) +} + +func TestListReceivers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + opts := receivers.ListOpts{ + Limit: 2, + Sort: "name:asc,status:desc", + } + + count := 0 + receivers.List(fake.ServiceClient(), opts).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := receivers.ExtractReceivers(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedReceiversList, actual) + + return true, nil + }) + + th.AssertEquals(t, count, 1) +} + +func TestDeleteReceiver(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteSuccessfully(t) + + deleteResult := receivers.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee") + th.AssertNoErr(t, deleteResult.ExtractErr()) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/urls.go new file mode 100644 index 00000000..be97ded5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers/urls.go @@ -0,0 +1,34 @@ +package receivers + +import "github.com/gophercloud/gophercloud" + +var apiVersion = "v1" +var apiName = "receivers" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func createURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func idURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiVersion, apiName, id) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return idURL(client, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/doc.go new file mode 100644 index 00000000..c76dc11f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/doc.go @@ -0,0 +1,15 @@ +/* +Package webhooks provides the ability to trigger an action represented by a webhook from the OpenStack Clustering +Service. + +Example to Trigger webhook action + + result, err := webhooks.Trigger(serviceClient(), "f93f83f6-762b-41b6-b757-80507834d394", webhooks.TriggerOpts{V: "1"}).Extract() + if err != nil { + panic(err) + } + + fmt.Println("result", result) + +*/ +package webhooks diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/requests.go new file mode 100644 index 00000000..1b211b44 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/requests.go @@ -0,0 +1,53 @@ +package webhooks + +import ( + "fmt" + "net/url" + + "github.com/gophercloud/gophercloud" +) + +// TriggerOpts represents options used for triggering an action +type TriggerOpts struct { + V string `q:"V" required:"true"` + Params map[string]string +} + +// TriggerOptsBuilder Query string builder interface for webhooks +type TriggerOptsBuilder interface { + ToWebhookTriggerQuery() (string, error) +} + +// Query string builder for webhooks +func (opts TriggerOpts) ToWebhookTriggerQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + params := q.Query() + + for k, v := range opts.Params { + params.Add(k, v) + } + + q = &url.URL{RawQuery: params.Encode()} + return q.String(), err +} + +// Trigger an action represented by a webhook. +func Trigger(client *gophercloud.ServiceClient, id string, opts TriggerOptsBuilder) (r TriggerResult) { + url := triggerURL(client, id) + if opts != nil { + query, err := opts.ToWebhookTriggerQuery() + if err != nil { + r.Err = err + return + } + url += query + } else { + r.Err = fmt.Errorf("Must contain V for TriggerOpt") + return + } + + _, r.Err = client.Post(url, nil, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/results.go new file mode 100644 index 00000000..ccb06086 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/results.go @@ -0,0 +1,22 @@ +package webhooks + +import ( + "github.com/gophercloud/gophercloud" +) + +type commonResult struct { + gophercloud.Result +} + +type TriggerResult struct { + commonResult +} + +// Extract retrieves the response action +func (r commonResult) Extract() (string, error) { + var s struct { + Action string `json:"action"` + } + err := r.ExtractInto(&s) + return s.Action, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/doc.go new file mode 100644 index 00000000..9a759ee2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/doc.go @@ -0,0 +1,2 @@ +// clustering_webhooks_v1 +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/requests_test.go new file mode 100644 index 00000000..9d0da6f3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/testing/requests_test.go @@ -0,0 +1,136 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "encoding/json" + + "github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestWebhookTrigger(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "action": "290c44fa-c60f-4d75-a0eb-87433ba982a3" + }`) + }) + + triggerOpts := webhooks.TriggerOpts{ + V: "1", + Params: map[string]string{ + "foo": "bar", + "bar": "baz", + }, + } + result, err := webhooks.Trigger(fake.ServiceClient(), "f93f83f6-762b-41b6-b757-80507834d394", triggerOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, result, "290c44fa-c60f-4d75-a0eb-87433ba982a3") +} + +// Test webhook with params that generates query strings +func TestWebhookParams(t *testing.T) { + triggerOpts := webhooks.TriggerOpts{ + V: "1", + Params: map[string]string{ + "foo": "bar", + "bar": "baz", + }, + } + expected := "?V=1&bar=baz&foo=bar" + actual, err := triggerOpts.ToWebhookTriggerQuery() + th.AssertNoErr(t, err) + th.AssertEquals(t, actual, expected) +} + +// Nagative test case for returning invalid type (integer) for action id +func TestWebhooksInvalidAction(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "action": 123 + }`) + }) + + triggerOpts := webhooks.TriggerOpts{ + V: "1", + Params: map[string]string{ + "foo": "bar", + "bar": "baz", + }, + } + _, err := webhooks.Trigger(fake.ServiceClient(), "f93f83f6-762b-41b6-b757-80507834d394", triggerOpts).Extract() + isValid := err.(*json.UnmarshalTypeError) == nil + th.AssertEquals(t, false, isValid) +} + +// Negative test case for passing empty TriggerOpt +func TestWebhookTriggerInvalidEmptyOpt(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "action": "290c44fa-c60f-4d75-a0eb-87433ba982a3" + }`) + }) + + _, err := webhooks.Trigger(fake.ServiceClient(), "f93f83f6-762b-41b6-b757-80507834d394", webhooks.TriggerOpts{}).Extract() + if err == nil { + t.Errorf("Expected error without V param") + } +} + +// Negative test case for passing in nil for TriggerOpt +func TestWebhookTriggerInvalidNilOpt(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "action": "290c44fa-c60f-4d75-a0eb-87433ba982a3" + }`) + }) + + _, err := webhooks.Trigger(fake.ServiceClient(), "f93f83f6-762b-41b6-b757-80507834d394", nil).Extract() + + if err == nil { + t.Errorf("Expected error with nil param") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/urls.go new file mode 100644 index 00000000..563cf811 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/clustering/v1/webhooks/urls.go @@ -0,0 +1,7 @@ +package webhooks + +import "github.com/gophercloud/gophercloud" + +func triggerURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("v1", "webhooks", id, "trigger") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/common/extensions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/common/extensions/testing/requests_test.go new file mode 100644 index 00000000..fbaedfa0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/common/extensions/testing/requests_test.go @@ -0,0 +1,39 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/common/extensions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListExtensionsSuccessfully(t) + + count := 0 + + extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := extensions.ExtractExtensions(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedExtensions, actual) + + return true, nil + }) + + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetExtensionSuccessfully(t) + + actual, err := extensions.Get(client.ServiceClient(), "agent").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SingleExtension, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/doc.go index 8f152899..97f1b033 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/doc.go @@ -66,7 +66,7 @@ Example of Add Host aggregateID := 22 opts := aggregates.AddHostOpts{ - Host: "newhost-cmp1" + Host: "newhost-cmp1", } aggregate, err := aggregates.AddHost(computeClient, aggregateID, opts).Extract() @@ -79,7 +79,7 @@ Example of Remove Host aggregateID := 22 opts := aggregates.RemoveHostOpts{ - Host: "newhost-cmp1" + Host: "newhost-cmp1", } aggregate, err := aggregates.RemoveHost(computeClient, aggregateID, opts).Extract() @@ -88,5 +88,18 @@ Example of Remove Host } fmt.Printf("%+v\n", aggregate) +Example of Create or Update Metadata + + aggregateID := 22 + opts := aggregates.SetMetadata{ + Metadata: map[string]string{"key": "value"}, + } + + aggregate, err := aggregates.SetMetadata(computeClient, aggregateID, opts).Extract() + if err != nil { + panic(err) + } + fmt.Printf("%+v\n", aggregate) + */ package aggregates diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/requests.go index 2f433f64..c37531c5 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/requests.go @@ -137,3 +137,26 @@ func RemoveHost(client *gophercloud.ServiceClient, aggregateID int, opts RemoveH }) return } + +type SetMetadataOpts struct { + Metadata map[string]interface{} `json:"metadata" required:"true"` +} + +func (opts SetMetadataOpts) ToSetMetadataMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "set_metadata") +} + +// SetMetadata makes a request against the API to set metadata to a specific aggregate. +func SetMetadata(client *gophercloud.ServiceClient, aggregateID int, opts SetMetadataOpts) (r ActionResult) { + v := strconv.Itoa(aggregateID) + + b, err := opts.ToSetMetadataMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(aggregatesSetMetadataURL(client, v), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/fixtures.go index 5d1d8025..9ae71d22 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/fixtures.go @@ -137,6 +137,27 @@ const AggregateRemoveHostBody = ` } ` +const AggregateSetMetadataBody = ` +{ + "aggregate": { + "name": "test-aggregate2", + "availability_zone": "test-az", + "deleted": false, + "created_at": "2017-12-22T10:16:07.000000", + "updated_at": "2017-12-23T10:18:00.000000", + "hosts": [ + "cmp0" + ], + "deleted_at": null, + "id": 4, + "metadata": { + "availability_zone": "test-az", + "key": "value" + } + } +} +` + var ( // First aggregate from the AggregateListBody FirstFakeAggregate = aggregates.Aggregate{ @@ -222,6 +243,18 @@ var ( DeletedAt: time.Time{}, Deleted: false, } + + AggregateWithUpdatedMetadata = aggregates.Aggregate{ + AvailabilityZone: "test-az", + Hosts: []string{"cmp0"}, + ID: 4, + Metadata: map[string]string{"availability_zone": "test-az", "key": "value"}, + Name: "test-aggregate2", + CreatedAt: time.Date(2017, 12, 22, 10, 16, 7, 0, time.UTC), + UpdatedAt: time.Date(2017, 12, 23, 10, 18, 0, 0, time.UTC), + DeletedAt: time.Time{}, + Deleted: false, + } ) // HandleListSuccessfully configures the test server to respond to a List request. @@ -298,3 +331,14 @@ func HandleRemoveHostSuccessfully(t *testing.T) { fmt.Fprintf(w, AggregateRemoveHostBody) }) } + +func HandleSetMetadataSuccessfully(t *testing.T) { + v := strconv.Itoa(AggregateWithUpdatedMetadata.ID) + th.Mux.HandleFunc("/os-aggregates/"+v+"/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, AggregateSetMetadataBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/requests_test.go new file mode 100644 index 00000000..bfd18614 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/testing/requests_test.go @@ -0,0 +1,149 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListAggregates(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + pages := 0 + err := aggregates.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := aggregates.ExtractAggregates(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 aggregates, got %d", len(actual)) + } + th.CheckDeepEquals(t, FirstFakeAggregate, actual[0]) + th.CheckDeepEquals(t, SecondFakeAggregate, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestCreateAggregates(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + expected := CreatedAggregate + + opts := aggregates.CreateOpts{ + Name: "name", + AvailabilityZone: "london", + } + + actual, err := aggregates.Create(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestDeleteAggregates(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := aggregates.Delete(client.ServiceClient(), AggregateIDtoDelete).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestGetAggregates(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + expected := SecondFakeAggregate + + actual, err := aggregates.Get(client.ServiceClient(), AggregateIDtoGet).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestUpdateAggregate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + expected := UpdatedAggregate + + opts := aggregates.UpdateOpts{ + Name: "test-aggregates2", + AvailabilityZone: "nova2", + } + + actual, err := aggregates.Update(client.ServiceClient(), expected.ID, opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestAddHostAggregate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAddHostSuccessfully(t) + + expected := AggregateWithAddedHost + + opts := aggregates.AddHostOpts{ + Host: "cmp1", + } + + actual, err := aggregates.AddHost(client.ServiceClient(), expected.ID, opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestRemoveHostAggregate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRemoveHostSuccessfully(t) + + expected := AggregateWithRemovedHost + + opts := aggregates.RemoveHostOpts{ + Host: "cmp1", + } + + actual, err := aggregates.RemoveHost(client.ServiceClient(), expected.ID, opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} + +func TestSetMetadataAggregate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleSetMetadataSuccessfully(t) + + expected := AggregateWithUpdatedMetadata + + opts := aggregates.SetMetadataOpts{ + Metadata: map[string]interface{}{"key": "value"}, + } + + actual, err := aggregates.SetMetadata(client.ServiceClient(), expected.ID, opts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/urls.go index fb109001..bb30c7fc 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates/urls.go @@ -29,3 +29,7 @@ func aggregatesAddHostURL(c *gophercloud.ServiceClient, aggregateID string) stri func aggregatesRemoveHostURL(c *gophercloud.ServiceClient, aggregateID string) string { return c.ServiceURL("os-aggregates", aggregateID, "action") } + +func aggregatesSetMetadataURL(c *gophercloud.ServiceClient, aggregateID string) string { + return c.ServiceURL("os-aggregates", aggregateID, "action") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go index 18dade83..874f7a61 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go @@ -28,7 +28,6 @@ type CreateOptsBuilder interface { // CreateOpts specifies parameters of a new interface attachment. type CreateOpts struct { - // PortID is the ID of the port for which you want to create an interface. // The NetworkID and PortID parameters are mutually exclusive. // If you do not specify the PortID parameter, the OpenStack Networking API @@ -43,6 +42,7 @@ type CreateOpts struct { // Slice of FixedIPs. If you request a specific FixedIP address without a // NetworkID, the request returns a Bad Request (400) response code. + // Note: this uses the FixedIP struct, but only the IPAddress field can be used. FixedIPs []FixedIP `json:"fixed_ips,omitempty"` } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go index a16fa14f..7d15e1ec 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go @@ -37,8 +37,10 @@ type DeleteResult struct { } // FixedIP represents a Fixed IP Address. +// This struct is also used when creating an attachment, +// but it is not possible to specify a SubnetID. type FixedIP struct { - SubnetID string `json:"subnet_id"` + SubnetID string `json:"subnet_id,omitempty"` IPAddress string `json:"ip_address"` } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/testing/requests_test.go new file mode 100644 index 00000000..1ffbd61e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/testing/requests_test.go @@ -0,0 +1,89 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleInterfaceListSuccessfully(t) + + expected := ListInterfacesExpected + pages := 0 + err := attachinterfaces.List(client.ServiceClient(), "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f").EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := attachinterfaces.ExtractInterfaces(page) + th.AssertNoErr(t, err) + + if len(actual) != 1 { + t.Fatalf("Expected 1 interface, got %d", len(actual)) + } + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, pages) +} + +func TestListInterfacesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleInterfaceListSuccessfully(t) + + allPages, err := attachinterfaces.List(client.ServiceClient(), "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f").AllPages() + th.AssertNoErr(t, err) + _, err = attachinterfaces.ExtractInterfaces(allPages) + th.AssertNoErr(t, err) +} + +func TestGetInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleInterfaceGetSuccessfully(t) + + expected := GetInterfaceExpected + + serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" + interfaceID := "0dde1598-b374-474e-986f-5b8dd1df1d4e" + + actual, err := attachinterfaces.Get(client.ServiceClient(), serverID, interfaceID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, actual) +} + +func TestCreateInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleInterfaceCreateSuccessfully(t) + + expected := CreateInterfacesExpected + + serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" + networkID := "8a5fe506-7e9f-4091-899b-96336909d93c" + + actual, err := attachinterfaces.Create(client.ServiceClient(), serverID, attachinterfaces.CreateOpts{ + NetworkID: networkID, + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, actual) +} + +func TestDeleteInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleInterfaceDeleteSuccessfully(t) + + serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" + portID := "0dde1598-b374-474e-986f-5b8dd1df1d4e" + + err := attachinterfaces.Delete(client.ServiceClient(), serverID, portID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/testing/requests_test.go new file mode 100644 index 00000000..8996d366 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/testing/requests_test.go @@ -0,0 +1,41 @@ +package testing + +import ( + "testing" + + az "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// Verifies that availability zones can be listed correctly +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t) + + allPages, err := az.List(client.ServiceClient()).AllPages() + th.AssertNoErr(t, err) + + actual, err := az.ExtractAvailabilityZones(allPages) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, AZResult, actual) +} + +// Verifies that detailed availability zones can be listed correctly +func TestListDetail(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetDetailSuccessfully(t) + + allPages, err := az.ListDetail(client.ServiceClient()).AllPages() + th.AssertNoErr(t, err) + + actual, err := az.ExtractAvailabilityZones(allPages) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, AZDetailResult, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/requests.go index 9dae14c7..30c61701 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/requests.go @@ -67,6 +67,14 @@ type BlockDevice struct { // VolumeSize is the size of the volume to create (in gigabytes). This can be // omitted for existing volumes. VolumeSize int `json:"volume_size,omitempty"` + + // DeviceType specifies the device type of the block devices. + // Examples of this are disk, cdrom, floppy, lun, etc. + DeviceType string `json:"device_type,omitempty"` + + // DiskBus is the bus type of the block devices. + // Examples of this are ide, usb, virtio, scsi, etc. + DiskBus string `json:"disk_bus,omitempty"` } // CreateOptsExt is a structure that extends the server `CreateOpts` structure diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/fixtures.go new file mode 100644 index 00000000..484e40a0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/fixtures.go @@ -0,0 +1,275 @@ +package testing + +import ( + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" +) + +var BaseCreateOpts = servers.CreateOpts{ + Name: "createdserver", + FlavorRef: "performance1-1", +} + +var BaseCreateOptsWithImageRef = servers.CreateOpts{ + Name: "createdserver", + FlavorRef: "performance1-1", + ImageRef: "asdfasdfasdf", +} + +const ExpectedNewVolumeRequest = ` +{ + "server": { + "name":"createdserver", + "flavorRef":"performance1-1", + "imageRef":"", + "block_device_mapping_v2":[ + { + "uuid":"123456", + "source_type":"image", + "destination_type":"volume", + "boot_index": 0, + "delete_on_termination": true, + "volume_size": 10 + } + ] + } +} +` + +var NewVolumeRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOpts, + BlockDevice: []bootfromvolume.BlockDevice{ + { + UUID: "123456", + SourceType: bootfromvolume.SourceImage, + DestinationType: bootfromvolume.DestinationVolume, + VolumeSize: 10, + DeleteOnTermination: true, + }, + }, +} + +const ExpectedExistingVolumeRequest = ` +{ + "server": { + "name":"createdserver", + "flavorRef":"performance1-1", + "imageRef":"", + "block_device_mapping_v2":[ + { + "uuid":"123456", + "source_type":"volume", + "destination_type":"volume", + "boot_index": 0, + "delete_on_termination": true + } + ] + } +} +` + +var ExistingVolumeRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOpts, + BlockDevice: []bootfromvolume.BlockDevice{ + { + UUID: "123456", + SourceType: bootfromvolume.SourceVolume, + DestinationType: bootfromvolume.DestinationVolume, + DeleteOnTermination: true, + }, + }, +} + +const ExpectedImageRequest = ` +{ + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1", + "block_device_mapping_v2":[ + { + "boot_index": 0, + "delete_on_termination": true, + "destination_type":"local", + "source_type":"image", + "uuid":"asdfasdfasdf" + } + ] + } +} +` + +var ImageRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOptsWithImageRef, + BlockDevice: []bootfromvolume.BlockDevice{ + { + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: "asdfasdfasdf", + }, + }, +} + +const ExpectedMultiEphemeralRequest = ` +{ + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1", + "block_device_mapping_v2":[ + { + "boot_index": 0, + "delete_on_termination": true, + "destination_type":"local", + "source_type":"image", + "uuid":"asdfasdfasdf" + }, + { + "boot_index": -1, + "delete_on_termination": true, + "destination_type":"local", + "guest_format":"ext4", + "source_type":"blank", + "volume_size": 1 + }, + { + "boot_index": -1, + "delete_on_termination": true, + "destination_type":"local", + "guest_format":"ext4", + "source_type":"blank", + "volume_size": 1 + } + ] + } +} +` + +var MultiEphemeralRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOptsWithImageRef, + BlockDevice: []bootfromvolume.BlockDevice{ + { + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: "asdfasdfasdf", + }, + { + BootIndex: -1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + GuestFormat: "ext4", + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 1, + }, + { + BootIndex: -1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + GuestFormat: "ext4", + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 1, + }, + }, +} + +const ExpectedImageAndNewVolumeRequest = ` +{ + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1", + "block_device_mapping_v2":[ + { + "boot_index": 0, + "delete_on_termination": true, + "destination_type":"local", + "source_type":"image", + "uuid":"asdfasdfasdf" + }, + { + "boot_index": 1, + "delete_on_termination": true, + "destination_type":"volume", + "source_type":"blank", + "volume_size": 1, + "device_type": "disk", + "disk_bus": "scsi" + } + ] + } +} +` + +var ImageAndNewVolumeRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOptsWithImageRef, + BlockDevice: []bootfromvolume.BlockDevice{ + { + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: "asdfasdfasdf", + }, + { + BootIndex: 1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceBlank, + VolumeSize: 1, + DeviceType: "disk", + DiskBus: "scsi", + }, + }, +} + +const ExpectedImageAndExistingVolumeRequest = ` +{ + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1", + "block_device_mapping_v2":[ + { + "boot_index": 0, + "delete_on_termination": true, + "destination_type":"local", + "source_type":"image", + "uuid":"asdfasdfasdf" + }, + { + "boot_index": 1, + "delete_on_termination": true, + "destination_type":"volume", + "source_type":"volume", + "uuid":"123456", + "volume_size": 1 + } + ] + } +} +` + +var ImageAndExistingVolumeRequest = bootfromvolume.CreateOptsExt{ + CreateOptsBuilder: BaseCreateOptsWithImageRef, + BlockDevice: []bootfromvolume.BlockDevice{ + { + BootIndex: 0, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationLocal, + SourceType: bootfromvolume.SourceImage, + UUID: "asdfasdfasdf", + }, + { + BootIndex: 1, + DeleteOnTermination: true, + DestinationType: bootfromvolume.DestinationVolume, + SourceType: bootfromvolume.SourceVolume, + UUID: "123456", + VolumeSize: 1, + }, + }, +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/requests_test.go new file mode 100644 index 00000000..6b59ff72 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume/testing/requests_test.go @@ -0,0 +1,44 @@ +package testing + +import ( + "testing" + + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestBootFromNewVolume(t *testing.T) { + + actual, err := NewVolumeRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedNewVolumeRequest, actual) +} + +func TestBootFromExistingVolume(t *testing.T) { + actual, err := ExistingVolumeRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedExistingVolumeRequest, actual) +} + +func TestBootFromImage(t *testing.T) { + actual, err := ImageRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedImageRequest, actual) +} + +func TestCreateMultiEphemeralOpts(t *testing.T) { + actual, err := MultiEphemeralRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedMultiEphemeralRequest, actual) +} + +func TestAttachNewVolume(t *testing.T) { + actual, err := ImageAndNewVolumeRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedImageAndNewVolumeRequest, actual) +} + +func TestAttachExistingVolume(t *testing.T) { + actual, err := ImageAndExistingVolumeRequest.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, ExpectedImageAndExistingVolumeRequest, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules/testing/requests_test.go new file mode 100644 index 00000000..1f2fb868 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules/testing/requests_test.go @@ -0,0 +1,127 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ruleID = "{ruleID}" + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockListRulesResponse(t) + + count := 0 + + err := defsecrules.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := defsecrules.ExtractDefaultRules(page) + th.AssertNoErr(t, err) + + expected := []defsecrules.DefaultRule{ + { + FromPort: 80, + ID: ruleID, + IPProtocol: "TCP", + IPRange: secgroups.IPRange{CIDR: "10.10.10.0/24"}, + ToPort: 80, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockCreateRuleResponse(t) + + opts := defsecrules.CreateOpts{ + IPProtocol: "TCP", + FromPort: 80, + ToPort: 80, + CIDR: "10.10.12.0/24", + } + + group, err := defsecrules.Create(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := &defsecrules.DefaultRule{ + ID: ruleID, + FromPort: 80, + ToPort: 80, + IPProtocol: "TCP", + IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"}, + } + th.AssertDeepEquals(t, expected, group) +} + +func TestCreateICMPZero(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockCreateRuleResponseICMPZero(t) + + opts := defsecrules.CreateOpts{ + IPProtocol: "ICMP", + FromPort: 0, + ToPort: 0, + CIDR: "10.10.12.0/24", + } + + group, err := defsecrules.Create(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := &defsecrules.DefaultRule{ + ID: ruleID, + FromPort: 0, + ToPort: 0, + IPProtocol: "ICMP", + IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"}, + } + th.AssertDeepEquals(t, expected, group) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockGetRuleResponse(t, ruleID) + + group, err := defsecrules.Get(client.ServiceClient(), ruleID).Extract() + th.AssertNoErr(t, err) + + expected := &defsecrules.DefaultRule{ + ID: ruleID, + FromPort: 80, + ToPort: 80, + IPProtocol: "TCP", + IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"}, + } + + th.AssertDeepEquals(t, expected, group) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockDeleteRuleResponse(t, ruleID) + + err := defsecrules.Delete(client.ServiceClient(), ruleID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig/testing/requests_test.go new file mode 100644 index 00000000..6ce560aa --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig/testing/requests_test.go @@ -0,0 +1,88 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreateOpts(t *testing.T) { + base := servers.CreateOpts{ + Name: "createdserver", + ImageRef: "asdfasdfasdf", + FlavorRef: "performance1-1", + } + + ext := diskconfig.CreateOptsExt{ + CreateOptsBuilder: base, + DiskConfig: diskconfig.Manual, + } + + expected := ` + { + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1", + "OS-DCF:diskConfig": "MANUAL" + } + } + ` + actual, err := ext.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, expected, actual) +} + +func TestRebuildOpts(t *testing.T) { + base := servers.RebuildOpts{ + Name: "rebuiltserver", + AdminPass: "swordfish", + ImageID: "asdfasdfasdf", + } + + ext := diskconfig.RebuildOptsExt{ + RebuildOptsBuilder: base, + DiskConfig: diskconfig.Auto, + } + + actual, err := ext.ToServerRebuildMap() + th.AssertNoErr(t, err) + + expected := ` + { + "rebuild": { + "name": "rebuiltserver", + "imageRef": "asdfasdfasdf", + "adminPass": "swordfish", + "OS-DCF:diskConfig": "AUTO" + } + } + ` + th.CheckJSONEquals(t, expected, actual) +} + +func TestResizeOpts(t *testing.T) { + base := servers.ResizeOpts{ + FlavorRef: "performance1-8", + } + + ext := diskconfig.ResizeOptsExt{ + ResizeOptsBuilder: base, + DiskConfig: diskconfig.Auto, + } + + actual, err := ext.ToServerResizeMap() + th.AssertNoErr(t, err) + + expected := ` + { + "resize": { + "flavorRef": "performance1-8", + "OS-DCF:diskConfig": "AUTO" + } + } + ` + th.CheckJSONEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/evacuate/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/evacuate/testing/requests_test.go new file mode 100644 index 00000000..aec03114 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/evacuate/testing/requests_test.go @@ -0,0 +1,60 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/evacuate" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestEvacuate(t *testing.T) { + const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + th.SetupHTTP() + defer th.TeardownHTTP() + + mockEvacuateResponse(t, serverID) + + _, err := evacuate.Evacuate(client.ServiceClient(), serverID, evacuate.EvacuateOpts{ + Host: "derp", + AdminPass: "MySecretPass", + OnSharedStorage: false, + }).ExtractAdminPass() + th.AssertNoErr(t, err) +} + +func TestEvacuateWithHost(t *testing.T) { + const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + th.SetupHTTP() + defer th.TeardownHTTP() + + mockEvacuateResponseWithHost(t, serverID) + + _, err := evacuate.Evacuate(client.ServiceClient(), serverID, evacuate.EvacuateOpts{ + Host: "derp", + }).ExtractAdminPass() + th.AssertNoErr(t, err) +} + +func TestEvacuateWithNoOpts(t *testing.T) { + const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + th.SetupHTTP() + defer th.TeardownHTTP() + + mockEvacuateResponseWithNoOpts(t, serverID) + + _, err := evacuate.Evacuate(client.ServiceClient(), serverID, evacuate.EvacuateOpts{}).ExtractAdminPass() + th.AssertNoErr(t, err) +} + +func TestEvacuateAdminpassResponse(t *testing.T) { + const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + th.SetupHTTP() + defer th.TeardownHTTP() + + mockEvacuateAdminpassResponse(t, serverID) + + actual, err := evacuate.Evacuate(client.ServiceClient(), serverID, evacuate.EvacuateOpts{}).ExtractAdminPass() + th.CheckEquals(t, "MySecretPass", actual) + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips/testing/requests_test.go new file mode 100644 index 00000000..2356671e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips/testing/requests_test.go @@ -0,0 +1,111 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := floatingips.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := floatingips.ExtractFloatingIPs(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedFloatingIPsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + actual, err := floatingips.Create(client.ServiceClient(), floatingips.CreateOpts{ + Pool: "nova", + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedFloatingIP, actual) +} + +func TestCreateWithNumericID(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateWithNumericIDSuccessfully(t) + + actual, err := floatingips.Create(client.ServiceClient(), floatingips.CreateOpts{ + Pool: "nova", + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedFloatingIP, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := floatingips.Get(client.ServiceClient(), "2").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &SecondFloatingIP, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := floatingips.Delete(client.ServiceClient(), "1").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestAssociate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAssociateSuccessfully(t) + + associateOpts := floatingips.AssociateOpts{ + FloatingIP: "10.10.10.2", + } + + err := floatingips.AssociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", associateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestAssociateFixed(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAssociateFixedSuccessfully(t) + + associateOpts := floatingips.AssociateOpts{ + FloatingIP: "10.10.10.2", + FixedIP: "166.78.185.201", + } + + err := floatingips.AssociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", associateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestDisassociateInstance(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDisassociateSuccessfully(t) + + disassociateOpts := floatingips.DisassociateOpts{ + FloatingIP: "10.10.10.2", + } + + err := floatingips.DisassociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", disassociateOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors/testing/requests_test.go new file mode 100644 index 00000000..95f9636c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors/testing/requests_test.go @@ -0,0 +1,89 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors" + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListHypervisors(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleHypervisorListSuccessfully(t) + + pages := 0 + err := hypervisors.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := hypervisors.ExtractHypervisors(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 hypervisors, got %d", len(actual)) + } + testhelper.CheckDeepEquals(t, HypervisorFake, actual[0]) + testhelper.CheckDeepEquals(t, HypervisorFake, actual[1]) + + return true, nil + }) + + testhelper.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllHypervisors(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleHypervisorListSuccessfully(t) + + allPages, err := hypervisors.List(client.ServiceClient()).AllPages() + testhelper.AssertNoErr(t, err) + actual, err := hypervisors.ExtractHypervisors(allPages) + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, HypervisorFake, actual[0]) + testhelper.CheckDeepEquals(t, HypervisorFake, actual[1]) +} + +func TestHypervisorsStatistics(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleHypervisorsStatisticsSuccessfully(t) + + expected := HypervisorsStatisticsExpected + + actual, err := hypervisors.GetStatistics(client.ServiceClient()).Extract() + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, &expected, actual) +} + +func TestGetHypervisor(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleHypervisorGetSuccessfully(t) + + expected := HypervisorFake + + actual, err := hypervisors.Get(client.ServiceClient(), expected.ID).Extract() + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, &expected, actual) +} + +func TestHypervisorsUptime(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleHypervisorUptimeSuccessfully(t) + + expected := HypervisorUptimeExpected + + actual, err := hypervisors.GetUptime(client.ServiceClient(), HypervisorFake.ID).Extract() + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, &expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/doc.go index dc7b65fd..24c46077 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/doc.go @@ -58,7 +58,7 @@ Example to Create a Server With a Key Pair FlavorRef: "flavor-uuid", } - createOpts := keypairs.CreateOpts{ + createOpts := keypairs.CreateOptsExt{ CreateOptsBuilder: serverCreateOpts, KeyName: "keypair-name", } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/testing/requests_test.go new file mode 100644 index 00000000..1e05e668 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs/testing/requests_test.go @@ -0,0 +1,72 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := keypairs.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := keypairs.ExtractKeyPairs(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedKeyPairSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + actual, err := keypairs.Create(client.ServiceClient(), keypairs.CreateOpts{ + Name: "createdkey", + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedKeyPair, actual) +} + +func TestImport(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleImportSuccessfully(t) + + actual, err := keypairs.Create(client.ServiceClient(), keypairs.CreateOpts{ + Name: "importedkey", + PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova", + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &ImportedKeyPair, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := keypairs.Get(client.ServiceClient(), "firstkey").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstKeyPair, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := keypairs.Delete(client.ServiceClient(), "deletedkey").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits/testing/requests_test.go new file mode 100644 index 00000000..9c8456c9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits/testing/requests_test.go @@ -0,0 +1,23 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + getOpts := limits.GetOpts{ + TenantID: TenantID, + } + + actual, err := limits.Get(client.ServiceClient(), getOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &LimitsResult, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock/testing/request_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock/testing/request_test.go new file mode 100644 index 00000000..cb2906d2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock/testing/request_test.go @@ -0,0 +1,31 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/lockunlock" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "{serverId}" + +func TestLock(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockStartServerResponse(t, serverID) + + err := lockunlock.Lock(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUnlock(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockStopServerResponse(t, serverID) + + err := lockunlock.Unlock(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate/testing/requests_test.go new file mode 100644 index 00000000..b6906b78 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate/testing/requests_test.go @@ -0,0 +1,41 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/migrate" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + +func TestMigrate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockMigrateResponse(t, serverID) + + err := migrate.Migrate(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestLiveMigrate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockLiveMigrateResponse(t, serverID) + + host := "01c0cadef72d47e28a672a76060d492c" + blockMigration := false + diskOverCommit := true + + migrationOpts := migrate.LiveMigrateOpts{ + Host: &host, + BlockMigration: &blockMigration, + DiskOverCommit: &diskOverCommit, + } + + err := migrate.LiveMigrate(client.ServiceClient(), serverID, migrationOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks/testing/requests_test.go new file mode 100644 index 00000000..36b5463e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks/testing/requests_test.go @@ -0,0 +1,38 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := networks.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := networks.ExtractNetworks(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedNetworkSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := networks.Get(client.ServiceClient(), "20c8acc0-f747-4d71-a389-46d078ebf000").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &SecondNetwork, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause/testing/requests_test.go new file mode 100644 index 00000000..0433e8c4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause/testing/requests_test.go @@ -0,0 +1,31 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/pauseunpause" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "{serverId}" + +func TestPause(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockPauseServerResponse(t, serverID) + + err := pauseunpause.Pause(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUnpause(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockUnpauseServerResponse(t, serverID) + + err := pauseunpause.Unpause(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/requests.go index 34d93589..d5daa7e3 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/requests.go @@ -5,34 +5,32 @@ import ( ) // Get returns public data about a previously created QuotaSet. -func Get(client *gophercloud.ServiceClient, tenantID string) GetResult { - var res GetResult - _, res.Err = client.Get(getURL(client, tenantID), &res.Body, nil) - return res +func Get(client *gophercloud.ServiceClient, tenantID string) (r GetResult) { + _, r.Err = client.Get(getURL(client, tenantID), &r.Body, nil) + return } // GetDetail returns detailed public data about a previously created QuotaSet. -func GetDetail(client *gophercloud.ServiceClient, tenantID string) GetDetailResult { - var res GetDetailResult - _, res.Err = client.Get(getDetailURL(client, tenantID), &res.Body, nil) - return res +func GetDetail(client *gophercloud.ServiceClient, tenantID string) (r GetDetailResult) { + _, r.Err = client.Get(getDetailURL(client, tenantID), &r.Body, nil) + return } // Updates the quotas for the given tenantID and returns the new QuotaSet. -func Update(client *gophercloud.ServiceClient, tenantID string, opts UpdateOptsBuilder) (res UpdateResult) { +func Update(client *gophercloud.ServiceClient, tenantID string, opts UpdateOptsBuilder) (r UpdateResult) { reqBody, err := opts.ToComputeQuotaUpdateMap() if err != nil { - res.Err = err + r.Err = err return } - _, res.Err = client.Put(updateURL(client, tenantID), reqBody, &res.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) - return res + _, r.Err = client.Put(updateURL(client, tenantID), reqBody, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) + return } // Resets the quotas for the given tenant to their default values. -func Delete(client *gophercloud.ServiceClient, tenantID string) (res DeleteResult) { - _, res.Err = client.Delete(deleteURL(client, tenantID), nil) +func Delete(client *gophercloud.ServiceClient, tenantID string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, tenantID), nil) return } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/fixtures.go index 53516413..2915d310 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/fixtures.go @@ -121,7 +121,7 @@ var FirstQuotaSet = quotasets.QuotaSet{ // FirstQuotaDetailsSet is the first result in ListOutput. var FirstQuotaDetailsSet = quotasets.QuotaDetailSet{ - ID: FirstTenantID, + ID: FirstTenantID, InjectedFileContentBytes: quotasets.QuotaDetail{InUse: 0, Reserved: 0, Limit: 10240}, InjectedFilePathBytes: quotasets.QuotaDetail{InUse: 0, Reserved: 0, Limit: 255}, InjectedFiles: quotasets.QuotaDetail{InUse: 0, Reserved: 0, Limit: 5}, diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/requests_test.go new file mode 100644 index 00000000..ccac51b3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets/testing/requests_test.go @@ -0,0 +1,73 @@ +package testing + +import ( + "errors" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + actual, err := quotasets.Get(client.ServiceClient(), FirstTenantID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstQuotaSet, actual) +} + +func TestGetDetail(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetDetailSuccessfully(t) + actual, err := quotasets.GetDetail(client.ServiceClient(), FirstTenantID).Extract() + th.CheckDeepEquals(t, FirstQuotaDetailsSet, actual) + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePutSuccessfully(t) + actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, UpdatedQuotaSet).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstQuotaSet, actual) +} + +func TestPartialUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePartialPutSuccessfully(t) + opts := quotasets.UpdateOpts{Cores: gophercloud.IntToPointer(200), Force: true} + actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstQuotaSet, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + _, err := quotasets.Delete(client.ServiceClient(), FirstTenantID).Extract() + th.AssertNoErr(t, err) +} + +type ErrorUpdateOpts quotasets.UpdateOpts + +func (opts ErrorUpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) { + return nil, errors.New("This is an error") +} + +func TestErrorInToComputeQuotaUpdateMap(t *testing.T) { + opts := &ErrorUpdateOpts{} + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePutSuccessfully(t) + _, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract() + if err == nil { + t.Fatal("Error handling failed") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/resetstate/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/resetstate/testing/requests_test.go new file mode 100644 index 00000000..491a7ee1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/resetstate/testing/requests_test.go @@ -0,0 +1,21 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/resetstate" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "b16ba811-199d-4ffd-8839-ba96c1185a67" + +func TestResetState(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockResetStateResponse(t, serverID, "active") + + err := resetstate.ResetState(client.ServiceClient(), serverID, "active").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints/testing/requests_test.go new file mode 100644 index 00000000..c387eab8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints/testing/requests_test.go @@ -0,0 +1,131 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreateOpts(t *testing.T) { + base := servers.CreateOpts{ + Name: "createdserver", + ImageRef: "asdfasdfasdf", + FlavorRef: "performance1-1", + } + + schedulerHints := schedulerhints.SchedulerHints{ + Group: "101aed42-22d9-4a3e-9ba1-21103b0d1aba", + DifferentHost: []string{ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287", + }, + SameHost: []string{ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287", + }, + Query: []interface{}{">=", "$free_ram_mb", "1024"}, + TargetCell: "foobar", + BuildNearHostIP: "192.168.1.1/24", + AdditionalProperties: map[string]interface{}{"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"}, + } + + ext := schedulerhints.CreateOptsExt{ + CreateOptsBuilder: base, + SchedulerHints: schedulerHints, + } + + expected := ` + { + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1" + }, + "os:scheduler_hints": { + "group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba", + "different_host": [ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287" + ], + "same_host": [ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287" + ], + "query": [ + ">=", "$free_ram_mb", "1024" + ], + "target_cell": "foobar", + "build_near_host_ip": "192.168.1.1", + "cidr": "/24", + "reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1" + } + } + ` + actual, err := ext.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, expected, actual) +} + +func TestCreateOptsWithComplexQuery(t *testing.T) { + base := servers.CreateOpts{ + Name: "createdserver", + ImageRef: "asdfasdfasdf", + FlavorRef: "performance1-1", + } + + schedulerHints := schedulerhints.SchedulerHints{ + Group: "101aed42-22d9-4a3e-9ba1-21103b0d1aba", + DifferentHost: []string{ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287", + }, + SameHost: []string{ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287", + }, + Query: []interface{}{"and", []string{">=", "$free_ram_mb", "1024"}, []string{">=", "$free_disk_mb", "204800"}}, + TargetCell: "foobar", + BuildNearHostIP: "192.168.1.1/24", + AdditionalProperties: map[string]interface{}{"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"}, + } + + ext := schedulerhints.CreateOptsExt{ + CreateOptsBuilder: base, + SchedulerHints: schedulerHints, + } + + expected := ` + { + "server": { + "name": "createdserver", + "imageRef": "asdfasdfasdf", + "flavorRef": "performance1-1" + }, + "os:scheduler_hints": { + "group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba", + "different_host": [ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287" + ], + "same_host": [ + "a0cf03a5-d921-4877-bb5c-86d26cf818e1", + "8c19174f-4220-44f0-824a-cd1eeef10287" + ], + "query": [ + "and", + [">=", "$free_ram_mb", "1024"], + [">=", "$free_disk_mb", "204800"] + ], + "target_cell": "foobar", + "build_near_host_ip": "192.168.1.1", + "cidr": "/24", + "reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1" + } + } + ` + actual, err := ext.ToServerCreateMap() + th.AssertNoErr(t, err) + th.CheckJSONEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go index bcceaeac..8b93f08b 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go @@ -172,12 +172,12 @@ func actionMap(prefix, groupName string) map[string]map[string]string { // AddServer will associate a server and a security group, enforcing the // rules of the group on the server. func AddServer(client *gophercloud.ServiceClient, serverID, groupName string) (r AddServerResult) { - _, r.Err = client.Post(serverActionURL(client, serverID), actionMap("add", groupName), &r.Body, nil) + _, r.Err = client.Post(serverActionURL(client, serverID), actionMap("add", groupName), nil, nil) return } // RemoveServer will disassociate a server from a security group. func RemoveServer(client *gophercloud.ServiceClient, serverID, groupName string) (r RemoveServerResult) { - _, r.Err = client.Post(serverActionURL(client, serverID), actionMap("remove", groupName), &r.Body, nil) + _, r.Err = client.Post(serverActionURL(client, serverID), actionMap("remove", groupName), nil, nil) return } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/fixtures.go index 536e7f8e..27bd56f3 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/fixtures.go @@ -303,7 +303,6 @@ func mockAddServerToGroupResponse(t *testing.T, serverID string) { w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) - fmt.Fprintf(w, `{}`) }) } @@ -323,6 +322,5 @@ func mockRemoveServerFromGroupResponse(t *testing.T, serverID string) { w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) - fmt.Fprintf(w, `{}`) }) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/requests_test.go new file mode 100644 index 00000000..b5207646 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups/testing/requests_test.go @@ -0,0 +1,302 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ( + serverID = "{serverID}" + groupID = "{groupID}" + ruleID = "{ruleID}" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockListGroupsResponse(t) + + count := 0 + + err := secgroups.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := secgroups.ExtractSecurityGroups(page) + if err != nil { + t.Errorf("Failed to extract users: %v", err) + return false, err + } + + expected := []secgroups.SecurityGroup{ + { + ID: groupID, + Description: "default", + Name: "default", + Rules: []secgroups.Rule{}, + TenantID: "openstack", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, count) +} + +func TestListByServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockListGroupsByServerResponse(t, serverID) + + count := 0 + + err := secgroups.ListByServer(client.ServiceClient(), serverID).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := secgroups.ExtractSecurityGroups(page) + if err != nil { + t.Errorf("Failed to extract users: %v", err) + return false, err + } + + expected := []secgroups.SecurityGroup{ + { + ID: groupID, + Description: "default", + Name: "default", + Rules: []secgroups.Rule{}, + TenantID: "openstack", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockCreateGroupResponse(t) + + opts := secgroups.CreateOpts{ + Name: "test", + Description: "something", + } + + group, err := secgroups.Create(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.SecurityGroup{ + ID: groupID, + Name: "test", + Description: "something", + TenantID: "openstack", + Rules: []secgroups.Rule{}, + } + th.AssertDeepEquals(t, expected, group) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockUpdateGroupResponse(t, groupID) + + opts := secgroups.UpdateOpts{ + Name: "new_name", + Description: "new_desc", + } + + group, err := secgroups.Update(client.ServiceClient(), groupID, opts).Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.SecurityGroup{ + ID: groupID, + Name: "new_name", + Description: "something", + TenantID: "openstack", + Rules: []secgroups.Rule{}, + } + th.AssertDeepEquals(t, expected, group) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockGetGroupsResponse(t, groupID) + + group, err := secgroups.Get(client.ServiceClient(), groupID).Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.SecurityGroup{ + ID: groupID, + Description: "default", + Name: "default", + TenantID: "openstack", + Rules: []secgroups.Rule{ + { + FromPort: 80, + ToPort: 85, + IPProtocol: "TCP", + IPRange: secgroups.IPRange{CIDR: "0.0.0.0"}, + Group: secgroups.Group{TenantID: "openstack", Name: "default"}, + ParentGroupID: groupID, + ID: ruleID, + }, + }, + } + + th.AssertDeepEquals(t, expected, group) +} + +func TestGetNumericID(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + numericGroupID := 12345 + + mockGetNumericIDGroupResponse(t, numericGroupID) + + group, err := secgroups.Get(client.ServiceClient(), "12345").Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.SecurityGroup{ID: "12345"} + th.AssertDeepEquals(t, expected, group) +} + +func TestGetNumericRuleID(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + numericGroupID := 12345 + + mockGetNumericIDGroupRuleResponse(t, numericGroupID) + + group, err := secgroups.Get(client.ServiceClient(), "12345").Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.SecurityGroup{ + ID: "12345", + Rules: []secgroups.Rule{ + { + ParentGroupID: "12345", + ID: "12345", + }, + }, + } + th.AssertDeepEquals(t, expected, group) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockDeleteGroupResponse(t, groupID) + + err := secgroups.Delete(client.ServiceClient(), groupID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestAddRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockAddRuleResponse(t) + + opts := secgroups.CreateRuleOpts{ + ParentGroupID: groupID, + FromPort: 22, + ToPort: 22, + IPProtocol: "TCP", + CIDR: "0.0.0.0/0", + } + + rule, err := secgroups.CreateRule(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.Rule{ + FromPort: 22, + ToPort: 22, + Group: secgroups.Group{}, + IPProtocol: "TCP", + ParentGroupID: groupID, + IPRange: secgroups.IPRange{CIDR: "0.0.0.0/0"}, + ID: ruleID, + } + + th.AssertDeepEquals(t, expected, rule) +} + +func TestAddRuleICMPZero(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockAddRuleResponseICMPZero(t) + + opts := secgroups.CreateRuleOpts{ + ParentGroupID: groupID, + FromPort: 0, + ToPort: 0, + IPProtocol: "ICMP", + CIDR: "0.0.0.0/0", + } + + rule, err := secgroups.CreateRule(client.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := &secgroups.Rule{ + FromPort: 0, + ToPort: 0, + Group: secgroups.Group{}, + IPProtocol: "ICMP", + ParentGroupID: groupID, + IPRange: secgroups.IPRange{CIDR: "0.0.0.0/0"}, + ID: ruleID, + } + + th.AssertDeepEquals(t, expected, rule) +} + +func TestDeleteRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockDeleteRuleResponse(t, ruleID) + + err := secgroups.DeleteRule(client.ServiceClient(), ruleID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestAddServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockAddServerToGroupResponse(t, serverID) + + err := secgroups.AddServer(client.ServiceClient(), serverID, "test").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestRemoveServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockRemoveServerFromGroupResponse(t, serverID) + + err := secgroups.RemoveServer(client.ServiceClient(), serverID, "test").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups/testing/requests_test.go new file mode 100644 index 00000000..d86fa568 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups/testing/requests_test.go @@ -0,0 +1,60 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := servergroups.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := servergroups.ExtractServerGroups(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedServerGroupSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + actual, err := servergroups.Create(client.ServiceClient(), servergroups.CreateOpts{ + Name: "test", + Policies: []string{"anti-affinity"}, + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedServerGroup, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := servergroups.Get(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstServerGroup, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := servergroups.Delete(client.ServiceClient(), "616fb98f-46ca-475e-917e-2563e5a8cd19").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services/testing/requests_test.go new file mode 100644 index 00000000..7f998814 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services/testing/requests_test.go @@ -0,0 +1,42 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services" + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListServices(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + HandleListSuccessfully(t) + + pages := 0 + err := services.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := services.ExtractServices(page) + if err != nil { + return false, err + } + + if len(actual) != 4 { + t.Fatalf("Expected 4 services, got %d", len(actual)) + } + testhelper.CheckDeepEquals(t, FirstFakeService, actual[0]) + testhelper.CheckDeepEquals(t, SecondFakeService, actual[1]) + testhelper.CheckDeepEquals(t, ThirdFakeService, actual[2]) + testhelper.CheckDeepEquals(t, FourthFakeService, actual[3]) + + return true, nil + }) + + testhelper.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop/testing/requests_test.go new file mode 100644 index 00000000..be45bf5c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop/testing/requests_test.go @@ -0,0 +1,31 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "{serverId}" + +func TestStart(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockStartServerResponse(t, serverID) + + err := startstop.Start(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestStop(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockStopServerResponse(t, serverID) + + err := startstop.Stop(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume/testing/requests_test.go new file mode 100644 index 00000000..7c8e4ec6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume/testing/requests_test.go @@ -0,0 +1,31 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/suspendresume" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const serverID = "{serverId}" + +func TestSuspend(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockSuspendServerResponse(t, serverID) + + err := suspendresume.Suspend(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestResume(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockResumeServerResponse(t, serverID) + + err := suspendresume.Resume(client.ServiceClient(), serverID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks/testing/requests_test.go new file mode 100644 index 00000000..703c8468 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks/testing/requests_test.go @@ -0,0 +1,38 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := tenantnetworks.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := tenantnetworks.ExtractNetworks(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedNetworkSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := tenantnetworks.Get(client.ServiceClient(), "20c8acc0-f747-4d71-a389-46d078ebf000").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &SecondNetwork, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/testing/delegate_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/testing/delegate_test.go new file mode 100644 index 00000000..822093ff --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/testing/delegate_test.go @@ -0,0 +1,56 @@ +package testing + +import ( + "testing" + + common "github.com/gophercloud/gophercloud/openstack/common/extensions" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListExtensionsSuccessfully(t) + + count := 0 + extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := extensions.ExtractExtensions(page) + th.AssertNoErr(t, err) + + expected := []common.Extension{ + common.Extension{ + Updated: "2013-01-20T00:00:00-00:00", + Name: "Neutron Service Type Management", + Links: []interface{}{}, + Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", + Alias: "service-type", + Description: "API for retrieving service providers for Neutron advanced services", + }, + } + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetExtensionsSuccessfully(t) + + ext, err := extensions.Get(client.ServiceClient(), "agent").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00") + th.AssertEquals(t, ext.Name, "agent") + th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0") + th.AssertEquals(t, ext.Alias, "agent") + th.AssertEquals(t, ext.Description, "The agent management extension.") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/doc.go index 32e8643e..16b3a284 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/doc.go @@ -2,26 +2,58 @@ Package usage provides information and interaction with the SimpleTenantUsage extension for the OpenStack Compute service. +Due to the way the API responses are formatted, it is not recommended to +query by using the AllPages convenience method. Instead, use the EachPage +method to view each result page-by-page. + +This is because the usage calculations are done _per page_ and not as +an aggregated total of the entire usage set. + Example to Retrieve Usage for a Single Tenant: + start := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC) end := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC) - singleTenantOpts := usage.SingleTenantOpts{ - Start: &start, - End: &end, - } + singleTenantOpts := usage.SingleTenantOpts{ + Start: &start, + End: &end, + } + + err := usage.SingleTenant(computeClient, tenantID, singleTenantOpts).EachPage(func(page pagination.Page) (bool, error) { + tenantUsage, err := usage.ExtractSingleTenant(page) + if err != nil { + return false, err + } + + fmt.Printf("%+v\n", tenantUsage) + + return true, nil + }) + + if err != nil { + panic(err) + } + +Example to Retrieve Usage for All Tenants: + + allTenantsOpts := usage.AllTenantsOpts{ + Detailed: true, + } + + err := usage.AllTenants(computeClient, allTenantsOpts).EachPage(func(page pagination.Page) (bool, error) { + allTenantsUsage, err := usage.ExtractAllTenants(page) + if err != nil { + return false, err + } - page, err := usage.SingleTenant(computeClient, tenantID, singleTenantOpts).AllPages() - if err != nil { - panic(err) - } + fmt.Printf("%+v\n", allTenantsUsage) - tenantUsage, err := usage.ExtractSingleTenant(page) - if err != nil { - panic(err) - } + return true, nil + }) - fmt.Printf("%+v\n", tenantUsage) + if err != nil { + panic(err) + } */ package usage diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/requests.go index ee66e2a2..77312227 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/requests.go @@ -8,6 +8,36 @@ import ( "github.com/gophercloud/gophercloud/pagination" ) +// SingleTenantOpts are options for fetching usage of a single tenant. +type SingleTenantOpts struct { + // The ending time to calculate usage statistics on compute and storage resources. + End *time.Time `q:"end"` + + // The beginning time to calculate usage statistics on compute and storage resources. + Start *time.Time `q:"start"` +} + +// SingleTenantOptsBuilder allows extensions to add additional parameters to the +// SingleTenant request. +type SingleTenantOptsBuilder interface { + ToUsageSingleTenantQuery() (string, error) +} + +// ToUsageSingleTenantQuery formats a SingleTenantOpts into a query string. +func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error) { + params := make(url.Values) + if opts.Start != nil { + params.Add("start", opts.Start.Format(gophercloud.RFC3339MilliNoZ)) + } + + if opts.End != nil { + params.Add("end", opts.End.Format(gophercloud.RFC3339MilliNoZ)) + } + + q := &url.URL{RawQuery: params.Encode()} + return q.String(), nil +} + // SingleTenant returns usage data about a single tenant. func SingleTenant(client *gophercloud.ServiceClient, tenantID string, opts SingleTenantOptsBuilder) pagination.Pager { url := getTenantURL(client, tenantID) @@ -19,12 +49,15 @@ func SingleTenant(client *gophercloud.ServiceClient, tenantID string, opts Singl url += query } return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return SingleTenantPage{pagination.SinglePageBase(r)} + return SingleTenantPage{pagination.LinkedPageBase{PageResult: r}} }) } -// SingleTenantOpts are options for fetching usage of a single tenant. -type SingleTenantOpts struct { +// AllTenantsOpts are options for fetching usage of all tenants. +type AllTenantsOpts struct { + // Detailed will return detailed results. + Detailed bool + // The ending time to calculate usage statistics on compute and storage resources. End *time.Time `q:"end"` @@ -32,14 +65,14 @@ type SingleTenantOpts struct { Start *time.Time `q:"start"` } -// SingleTenantOptsBuilder allows extensions to add additional parameters to the -// SingleTenant request. -type SingleTenantOptsBuilder interface { - ToUsageSingleTenantQuery() (string, error) +// AllTenantsOptsBuilder allows extensions to add additional parameters to the +// AllTenants request. +type AllTenantsOptsBuilder interface { + ToUsageAllTenantsQuery() (string, error) } -// ToUsageSingleTenantQuery formats a SingleTenantOpts into a query string. -func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error) { +// ToUsageAllTenantsQuery formats a AllTenantsOpts into a query string. +func (opts AllTenantsOpts) ToUsageAllTenantsQuery() (string, error) { params := make(url.Values) if opts.Start != nil { params.Add("start", opts.Start.Format(gophercloud.RFC3339MilliNoZ)) @@ -49,6 +82,25 @@ func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error) { params.Add("end", opts.End.Format(gophercloud.RFC3339MilliNoZ)) } + if opts.Detailed == true { + params.Add("detailed", "1") + } + q := &url.URL{RawQuery: params.Encode()} return q.String(), nil } + +// AllTenants returns usage data about all tenants. +func AllTenants(client *gophercloud.ServiceClient, opts AllTenantsOptsBuilder) pagination.Pager { + url := allTenantsURL(client) + if opts != nil { + query, err := opts.ToUsageAllTenantsQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return AllTenantsPage{pagination.LinkedPageBase{PageResult: r}} + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/results.go index 39661ba4..f446730e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/results.go @@ -117,21 +117,67 @@ func (u *ServerUsage) UnmarshalJSON(b []byte) error { // SingleTenantPage stores a single, only page of TenantUsage results from a // SingleTenant call. type SingleTenantPage struct { - pagination.SinglePageBase + pagination.LinkedPageBase } // IsEmpty determines whether or not a SingleTenantPage is empty. -func (page SingleTenantPage) IsEmpty() (bool, error) { - ks, err := ExtractSingleTenant(page) +func (r SingleTenantPage) IsEmpty() (bool, error) { + ks, err := ExtractSingleTenant(r) return ks == nil, err } +// NextPageURL uses the response's embedded link reference to navigate to the +// next page of results. +func (r SingleTenantPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"tenant_usage_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + // ExtractSingleTenant interprets a SingleTenantPage as a TenantUsage result. func ExtractSingleTenant(page pagination.Page) (*TenantUsage, error) { var s struct { - TenantUsage *TenantUsage `json:"tenant_usage"` - TenantUsageLinks []gophercloud.Link `json:"tenant_usage_links"` + TenantUsage *TenantUsage `json:"tenant_usage"` } err := (page.(SingleTenantPage)).ExtractInto(&s) return s.TenantUsage, err } + +// AllTenantsPage stores a single, only page of TenantUsage results from a +// AllTenants call. +type AllTenantsPage struct { + pagination.LinkedPageBase +} + +// ExtractAllTenants interprets a AllTenantsPage as a TenantUsage result. +func ExtractAllTenants(page pagination.Page) ([]TenantUsage, error) { + var s struct { + TenantUsages []TenantUsage `json:"tenant_usages"` + } + err := (page.(AllTenantsPage)).ExtractInto(&s) + return s.TenantUsages, err +} + +// IsEmpty determines whether or not an AllTenantsPage is empty. +func (r AllTenantsPage) IsEmpty() (bool, error) { + usages, err := ExtractAllTenants(r) + return len(usages) == 0, err +} + +// NextPageURL uses the response's embedded link reference to navigate to the +// next page of results. +func (r AllTenantsPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"tenant_usages_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/fixtures.go index b7c1ae55..3e37947a 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/fixtures.go @@ -12,6 +12,7 @@ import ( ) const FirstTenantID = "aabbccddeeff112233445566" +const SecondTenantID = "665544332211ffeeddccbbaa" // GetSingleTenant holds the fixtures for the content of the request for a // single tenant. @@ -135,3 +136,179 @@ var SingleTenantUsageResults = usage.TenantUsage{ TotalMemoryMBUsage: 644.27116544, TotalVCPUsUsage: 1.25834212, } + +// GetAllTenants holds the fixtures for the content of the request for +// all tenants. +const GetAllTenants = `{ + "tenant_usages": [ + { + "server_usages": [ + { + "ended_at": null, + "flavor": "m1.tiny", + "hours": 0.021675453333333334, + "instance_id": "a70096fd-8196-406b-86c4-045840f53ad7", + "local_gb": 1, + "memory_mb": 512, + "name": "jttest", + "started_at": "2017-11-30T03:23:43.000000", + "state": "active", + "tenant_id": "aabbccddeeff112233445566", + "uptime": 78, + "vcpus": 1 + }, + { + "ended_at": "2017-11-21T04:10:11.000000", + "flavor": "m1.acctest", + "hours": 0.33444444444444443, + "instance_id": "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd", + "local_gb": 15, + "memory_mb": 512, + "name": "basic", + "started_at": "2017-11-21T03:50:07.000000", + "state": "terminated", + "tenant_id": "aabbccddeeff112233445566", + "uptime": 1204, + "vcpus": 1 + }, + { + "ended_at": "2017-11-30T03:21:21.000000", + "flavor": "m1.acctest", + "hours": 0.004166666666666667, + "instance_id": "ceb654fa-e0e8-44fb-8942-e4d0bfad3941", + "local_gb": 15, + "memory_mb": 512, + "name": "ACPTTESTJSxbPQAC34lTnBE1", + "started_at": "2017-11-30T03:21:06.000000", + "state": "terminated", + "tenant_id": "aabbccddeeff112233445566", + "uptime": 15, + "vcpus": 1 + } + ], + "start": "2017-11-02T03:25:01.000000", + "stop": "2017-11-30T03:25:01.000000", + "tenant_id": "aabbccddeeff112233445566", + "total_hours": 1.25834212, + "total_local_gb_usage": 18.571675453333334, + "total_memory_mb_usage": 644.27116544, + "total_vcpus_usage": 1.25834212 + }, + { + "server_usages": [ + { + "ended_at": null, + "flavor": "m1.tiny", + "hours": 0.021675453333333334, + "instance_id": "a70096fd-8196-406b-86c4-045840f53ad7", + "local_gb": 1, + "memory_mb": 512, + "name": "test", + "started_at": "2017-11-30T03:23:43.000000", + "state": "active", + "tenant_id": "665544332211ffeeddccbbaa", + "uptime": 78, + "vcpus": 1 + } + ], + "start": "2017-11-02T03:25:01.000000", + "stop": "2017-11-30T03:25:01.000000", + "tenant_id": "665544332211ffeeddccbbaa", + "total_hours": 0.021675453333333334, + "total_local_gb_usage": 18.571675453333334, + "total_memory_mb_usage": 644.27116544, + "total_vcpus_usage": 1.25834212 + } + ] +}` + +// HandleGetAllTenantsSuccessfully configures the test server to respond to a +// Get request for all tenants. +func HandleGetAllTenantsSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/os-simple-tenant-usage", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + w.Header().Add("Content-Type", "application/json") + fmt.Fprint(w, GetAllTenants) + }) +} + +// AllTenantsUsageResult is the code fixture for GetAllTenants. +var AllTenantsUsageResult = []usage.TenantUsage{ + { + ServerUsages: []usage.ServerUsage{ + { + Flavor: "m1.tiny", + Hours: 0.021675453333333334, + InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7", + LocalGB: 1, + MemoryMB: 512, + Name: "jttest", + StartedAt: time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC), + State: "active", + TenantID: "aabbccddeeff112233445566", + Uptime: 78, + VCPUs: 1, + }, + { + Flavor: "m1.acctest", + Hours: 0.33444444444444443, + InstanceID: "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd", + LocalGB: 15, + MemoryMB: 512, + Name: "basic", + StartedAt: time.Date(2017, 11, 21, 3, 50, 7, 0, time.UTC), + EndedAt: time.Date(2017, 11, 21, 4, 10, 11, 0, time.UTC), + State: "terminated", + TenantID: "aabbccddeeff112233445566", + Uptime: 1204, + VCPUs: 1, + }, + { + Flavor: "m1.acctest", + Hours: 0.004166666666666667, + InstanceID: "ceb654fa-e0e8-44fb-8942-e4d0bfad3941", + LocalGB: 15, + MemoryMB: 512, + Name: "ACPTTESTJSxbPQAC34lTnBE1", + StartedAt: time.Date(2017, 11, 30, 3, 21, 6, 0, time.UTC), + EndedAt: time.Date(2017, 11, 30, 3, 21, 21, 0, time.UTC), + State: "terminated", + TenantID: "aabbccddeeff112233445566", + Uptime: 15, + VCPUs: 1, + }, + }, + Start: time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC), + Stop: time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC), + TenantID: "aabbccddeeff112233445566", + TotalHours: 1.25834212, + TotalLocalGBUsage: 18.571675453333334, + TotalMemoryMBUsage: 644.27116544, + TotalVCPUsUsage: 1.25834212, + }, + { + ServerUsages: []usage.ServerUsage{ + { + Flavor: "m1.tiny", + Hours: 0.021675453333333334, + InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7", + LocalGB: 1, + MemoryMB: 512, + Name: "test", + StartedAt: time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC), + State: "active", + TenantID: "665544332211ffeeddccbbaa", + Uptime: 78, + VCPUs: 1, + }, + }, + Start: time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC), + Stop: time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC), + TenantID: "665544332211ffeeddccbbaa", + TotalHours: 0.021675453333333334, + TotalLocalGBUsage: 18.571675453333334, + TotalMemoryMBUsage: 644.27116544, + TotalVCPUsUsage: 1.25834212, + }, +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/requests_test.go new file mode 100644 index 00000000..1b4f2769 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/testing/requests_test.go @@ -0,0 +1,52 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetTenant(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSingleTenantSuccessfully(t) + + count := 0 + err := usage.SingleTenant(client.ServiceClient(), FirstTenantID, nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := usage.ExtractSingleTenant(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &SingleTenantUsageResults, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestAllTenants(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetAllTenantsSuccessfully(t) + + getOpts := usage.AllTenantsOpts{ + Detailed: true, + } + + count := 0 + err := usage.AllTenants(client.ServiceClient(), getOpts).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := usage.ExtractAllTenants(page) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, AllTenantsUsageResult, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/urls.go index f172b622..50636107 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/usage/urls.go @@ -4,7 +4,7 @@ import "github.com/gophercloud/gophercloud" const resourcePath = "os-simple-tenant-usage" -func getURL(client *gophercloud.ServiceClient) string { +func allTenantsURL(client *gophercloud.ServiceClient) string { return client.ServiceURL(resourcePath) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach/testing/requests_test.go new file mode 100644 index 00000000..9486f9bb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach/testing/requests_test.go @@ -0,0 +1,102 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// FirstVolumeAttachment is the first result in ListOutput. +var FirstVolumeAttachment = volumeattach.VolumeAttachment{ + Device: "/dev/vdd", + ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803", + ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", + VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803", +} + +// SecondVolumeAttachment is the first result in ListOutput. +var SecondVolumeAttachment = volumeattach.VolumeAttachment{ + Device: "/dev/vdc", + ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", + ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", + VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", +} + +// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed +// from ListOutput, in the expected order. +var ExpectedVolumeAttachmentSlice = []volumeattach.VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment} + +//CreatedVolumeAttachment is the parsed result from CreatedOutput. +var CreatedVolumeAttachment = volumeattach.VolumeAttachment{ + Device: "/dev/vdc", + ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", + ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", + VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" + + count := 0 + err := volumeattach.List(client.ServiceClient(), serverID).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := volumeattach.ExtractVolumeAttachments(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateSuccessfully(t) + + serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" + + actual, err := volumeattach.Create(client.ServiceClient(), serverID, volumeattach.CreateOpts{ + Device: "/dev/vdc", + VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", + }).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetSuccessfully(t) + + aID := "a26887c6-c47b-4654-abb5-dfadf7d3f804" + serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" + + actual, err := volumeattach.Get(client.ServiceClient(), serverID, aID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &SecondVolumeAttachment, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleDeleteSuccessfully(t) + + aID := "a26887c6-c47b-4654-abb5-dfadf7d3f804" + serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" + + err := volumeattach.Delete(client.ServiceClient(), serverID, aID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go index e7041df0..539019e9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/requests.go @@ -52,6 +52,14 @@ type ListOpts struct { MinDisk int `q:"minDisk"` MinRAM int `q:"minRam"` + // SortDir allows to select sort direction. + // It can be "asc" or "desc" (default). + SortDir string `q:"sort_dir"` + + // SortKey allows to sort by one of the flavors attributes. + // Default is flavorid. + SortKey string `q:"sort_key"` + // Marker and Limit control paging. // Marker instructs List where to start listing from. Marker string `q:"marker"` @@ -236,21 +244,22 @@ func GetExtraSpec(client *gophercloud.ServiceClient, flavorID string, key string // CreateExtraSpecsOptsBuilder allows extensions to add additional parameters to the // CreateExtraSpecs requests. type CreateExtraSpecsOptsBuilder interface { - ToExtraSpecsCreateMap() (map[string]interface{}, error) + ToFlavorExtraSpecsCreateMap() (map[string]interface{}, error) } // ExtraSpecsOpts is a map that contains key-value pairs. type ExtraSpecsOpts map[string]string -// ToExtraSpecsCreateMap assembles a body for a Create request based on the -// contents of a ExtraSpecsOpts -func (opts ExtraSpecsOpts) ToExtraSpecsCreateMap() (map[string]interface{}, error) { +// ToFlavorExtraSpecsCreateMap assembles a body for a Create request based on +// the contents of ExtraSpecsOpts. +func (opts ExtraSpecsOpts) ToFlavorExtraSpecsCreateMap() (map[string]interface{}, error) { return map[string]interface{}{"extra_specs": opts}, nil } -// CreateExtraSpecs will create or update the extra-specs key-value pairs for the specified Flavor +// CreateExtraSpecs will create or update the extra-specs key-value pairs for +// the specified Flavor. func CreateExtraSpecs(client *gophercloud.ServiceClient, flavorID string, opts CreateExtraSpecsOptsBuilder) (r CreateExtraSpecsResult) { - b, err := opts.ToExtraSpecsCreateMap() + b, err := opts.ToFlavorExtraSpecsCreateMap() if err != nil { r.Err = err return @@ -261,15 +270,15 @@ func CreateExtraSpecs(client *gophercloud.ServiceClient, flavorID string, opts C return } -// UpdateExtraSpecOptsBuilder allows extensions to add additional parameters to the -// Update request. +// UpdateExtraSpecOptsBuilder allows extensions to add additional parameters to +// the Update request. type UpdateExtraSpecOptsBuilder interface { - ToExtraSpecUpdateMap() (map[string]string, string, error) + ToFlavorExtraSpecUpdateMap() (map[string]string, string, error) } -// ToExtraSpecUpdateMap assembles a body for an Update request based on the -// contents of a ExtraSpecOpts. -func (opts ExtraSpecsOpts) ToExtraSpecUpdateMap() (map[string]string, string, error) { +// ToFlavorExtraSpecUpdateMap assembles a body for an Update request based on +// the contents of a ExtraSpecOpts. +func (opts ExtraSpecsOpts) ToFlavorExtraSpecUpdateMap() (map[string]string, string, error) { if len(opts) != 1 { err := gophercloud.ErrInvalidInput{} err.Argument = "flavors.ExtraSpecOpts" @@ -285,9 +294,10 @@ func (opts ExtraSpecsOpts) ToExtraSpecUpdateMap() (map[string]string, string, er return opts, key, nil } -// UpdateExtraSpec will updates the value of the specified flavor's extra spec for the key in opts. +// UpdateExtraSpec will updates the value of the specified flavor's extra spec +// for the key in opts. func UpdateExtraSpec(client *gophercloud.ServiceClient, flavorID string, opts UpdateExtraSpecOptsBuilder) (r UpdateExtraSpecResult) { - b, key, err := opts.ToExtraSpecUpdateMap() + b, key, err := opts.ToFlavorExtraSpecUpdateMap() if err != nil { r.Err = err return diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/testing/requests_test.go new file mode 100644 index 00000000..fba0d477 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors/testing/requests_test.go @@ -0,0 +1,402 @@ +package testing + +import ( + "fmt" + "net/http" + "reflect" + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const tokenID = "blerb" + +func TestListFlavors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/detail", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, ` + { + "flavors": [ + { + "id": "1", + "name": "m1.tiny", + "vcpus": 1, + "disk": 1, + "ram": 512, + "swap":"", + "os-flavor-access:is_public": true, + "OS-FLV-EXT-DATA:ephemeral": 10 + }, + { + "id": "2", + "name": "m1.small", + "vcpus": 1, + "disk": 20, + "ram": 2048, + "swap": 1000, + "os-flavor-access:is_public": true, + "OS-FLV-EXT-DATA:ephemeral": 0 + }, + { + "id": "3", + "name": "m1.medium", + "vcpus": 2, + "disk": 40, + "ram": 4096, + "swap": 1000, + "os-flavor-access:is_public": false, + "OS-FLV-EXT-DATA:ephemeral": 0 + } + ], + "flavors_links": [ + { + "href": "%s/flavors/detail?marker=2", + "rel": "next" + } + ] + } + `, th.Server.URL) + case "2": + fmt.Fprintf(w, `{ "flavors": [] }`) + default: + t.Fatalf("Unexpected marker: [%s]", marker) + } + }) + + pages := 0 + // Get public and private flavors + err := flavors.ListDetail(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := flavors.ExtractFlavors(page) + if err != nil { + return false, err + } + + expected := []flavors.Flavor{ + {ID: "1", Name: "m1.tiny", VCPUs: 1, Disk: 1, RAM: 512, Swap: 0, IsPublic: true, Ephemeral: 10}, + {ID: "2", Name: "m1.small", VCPUs: 1, Disk: 20, RAM: 2048, Swap: 1000, IsPublic: true, Ephemeral: 0}, + {ID: "3", Name: "m1.medium", VCPUs: 2, Disk: 40, RAM: 4096, Swap: 1000, IsPublic: false, Ephemeral: 0}, + } + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } + + return true, nil + }) + if err != nil { + t.Fatal(err) + } + if pages != 1 { + t.Errorf("Expected one page, got %d", pages) + } +} + +func TestGetFlavor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/12345", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "flavor": { + "id": "1", + "name": "m1.tiny", + "disk": 1, + "ram": 512, + "vcpus": 1, + "rxtx_factor": 1, + "swap": "" + } + } + `) + }) + + actual, err := flavors.Get(fake.ServiceClient(), "12345").Extract() + if err != nil { + t.Fatalf("Unable to get flavor: %v", err) + } + + expected := &flavors.Flavor{ + ID: "1", + Name: "m1.tiny", + Disk: 1, + RAM: 512, + VCPUs: 1, + RxTxFactor: 1, + Swap: 0, + } + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } +} + +func TestCreateFlavor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "flavor": { + "id": "1", + "name": "m1.tiny", + "disk": 1, + "ram": 512, + "vcpus": 1, + "rxtx_factor": 1, + "swap": "" + } + } + `) + }) + + disk := 1 + opts := &flavors.CreateOpts{ + ID: "1", + Name: "m1.tiny", + Disk: &disk, + RAM: 512, + VCPUs: 1, + RxTxFactor: 1.0, + } + actual, err := flavors.Create(fake.ServiceClient(), opts).Extract() + if err != nil { + t.Fatalf("Unable to create flavor: %v", err) + } + + expected := &flavors.Flavor{ + ID: "1", + Name: "m1.tiny", + Disk: 1, + RAM: 512, + VCPUs: 1, + RxTxFactor: 1, + Swap: 0, + } + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } +} + +func TestDeleteFlavor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/12345678", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.WriteHeader(http.StatusAccepted) + }) + + res := flavors.Delete(fake.ServiceClient(), "12345678") + th.AssertNoErr(t, res.Err) +} + +func TestFlavorAccessesList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/12345678/os-flavor-access", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "flavor_access": [ + { + "flavor_id": "12345678", + "tenant_id": "2f954bcf047c4ee9b09a37d49ae6db54" + } + ] + } + `) + }) + + expected := []flavors.FlavorAccess{ + flavors.FlavorAccess{ + FlavorID: "12345678", + TenantID: "2f954bcf047c4ee9b09a37d49ae6db54", + }, + } + + allPages, err := flavors.ListAccesses(fake.ServiceClient(), "12345678").AllPages() + th.AssertNoErr(t, err) + + actual, err := flavors.ExtractAccesses(allPages) + th.AssertNoErr(t, err) + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } +} + +func TestFlavorAccessAdd(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/12345678/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "addTenantAccess": { + "tenant": "2f954bcf047c4ee9b09a37d49ae6db54" + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ` + { + "flavor_access": [ + { + "flavor_id": "12345678", + "tenant_id": "2f954bcf047c4ee9b09a37d49ae6db54" + } + ] + } + `) + }) + + expected := []flavors.FlavorAccess{ + flavors.FlavorAccess{ + FlavorID: "12345678", + TenantID: "2f954bcf047c4ee9b09a37d49ae6db54", + }, + } + + addAccessOpts := flavors.AddAccessOpts{ + Tenant: "2f954bcf047c4ee9b09a37d49ae6db54", + } + + actual, err := flavors.AddAccess(fake.ServiceClient(), "12345678", addAccessOpts).Extract() + th.AssertNoErr(t, err) + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } +} + +func TestFlavorAccessRemove(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/flavors/12345678/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "removeTenantAccess": { + "tenant": "2f954bcf047c4ee9b09a37d49ae6db54" + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ` + { + "flavor_access": [] + } + `) + }) + + expected := []flavors.FlavorAccess{} + removeAccessOpts := flavors.RemoveAccessOpts{ + Tenant: "2f954bcf047c4ee9b09a37d49ae6db54", + } + + actual, err := flavors.RemoveAccess(fake.ServiceClient(), "12345678", removeAccessOpts).Extract() + th.AssertNoErr(t, err) + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but was %#v", expected, actual) + } +} + +func TestFlavorExtraSpecsList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleExtraSpecsListSuccessfully(t) + + expected := ExtraSpecs + actual, err := flavors.ListExtraSpecs(fake.ServiceClient(), "1").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestFlavorExtraSpecGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleExtraSpecGetSuccessfully(t) + + expected := ExtraSpec + actual, err := flavors.GetExtraSpec(fake.ServiceClient(), "1", "hw:cpu_policy").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestFlavorExtraSpecsCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleExtraSpecsCreateSuccessfully(t) + + createOpts := flavors.ExtraSpecsOpts{ + "hw:cpu_policy": "CPU-POLICY", + "hw:cpu_thread_policy": "CPU-THREAD-POLICY", + } + expected := ExtraSpecs + actual, err := flavors.CreateExtraSpecs(fake.ServiceClient(), "1", createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestFlavorExtraSpecUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleExtraSpecUpdateSuccessfully(t) + + updateOpts := flavors.ExtraSpecsOpts{ + "hw:cpu_policy": "CPU-POLICY-2", + } + expected := UpdatedExtraSpec + actual, err := flavors.UpdateExtraSpec(fake.ServiceClient(), "1", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestFlavorExtraSpecDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleExtraSpecDeleteSuccessfully(t) + + res := flavors.DeleteExtraSpec(fake.ServiceClient(), "1", "hw:cpu_policy") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/testing/requests_test.go new file mode 100644 index 00000000..1de03035 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images/testing/requests_test.go @@ -0,0 +1,225 @@ +package testing + +import ( + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/images" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListImages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, ` + { + "images": [ + { + "status": "ACTIVE", + "updated": "2014-09-23T12:54:56Z", + "id": "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7", + "OS-EXT-IMG-SIZE:size": 476704768, + "name": "F17-x86_64-cfntools", + "created": "2014-09-23T12:54:52Z", + "minDisk": 0, + "progress": 100, + "minRam": 0, + "metadata": { + "architecture": "x86_64", + "block_device_mapping": { + "guest_format": null, + "boot_index": 0, + "device_name": "/dev/vda", + "delete_on_termination": false + } + } + }, + { + "status": "ACTIVE", + "updated": "2014-09-23T12:51:43Z", + "id": "f90f6034-2570-4974-8351-6b49732ef2eb", + "OS-EXT-IMG-SIZE:size": 13167616, + "name": "cirros-0.3.2-x86_64-disk", + "created": "2014-09-23T12:51:42Z", + "minDisk": 0, + "progress": 100, + "minRam": 0 + } + ] + } + `) + case "2": + fmt.Fprintf(w, `{ "images": [] }`) + default: + t.Fatalf("Unexpected marker: [%s]", marker) + } + }) + + pages := 0 + options := &images.ListOpts{Limit: 2} + err := images.ListDetail(fake.ServiceClient(), options).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := images.ExtractImages(page) + if err != nil { + return false, err + } + + expected := []images.Image{ + { + ID: "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7", + Name: "F17-x86_64-cfntools", + Created: "2014-09-23T12:54:52Z", + Updated: "2014-09-23T12:54:56Z", + MinDisk: 0, + MinRAM: 0, + Progress: 100, + Status: "ACTIVE", + Metadata: map[string]interface{}{ + "architecture": "x86_64", + "block_device_mapping": map[string]interface{}{ + "guest_format": interface{}(nil), + "boot_index": float64(0), + "device_name": "/dev/vda", + "delete_on_termination": false, + }, + }, + }, + { + ID: "f90f6034-2570-4974-8351-6b49732ef2eb", + Name: "cirros-0.3.2-x86_64-disk", + Created: "2014-09-23T12:51:42Z", + Updated: "2014-09-23T12:51:43Z", + MinDisk: 0, + MinRAM: 0, + Progress: 100, + Status: "ACTIVE", + }, + } + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Unexpected page contents: expected %#v, got %#v", expected, actual) + } + + return false, nil + }) + + if err != nil { + t.Fatalf("EachPage error: %v", err) + } + if pages != 1 { + t.Errorf("Expected one page, got %d", pages) + } +} + +func TestGetImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/images/12345678", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "image": { + "status": "ACTIVE", + "updated": "2014-09-23T12:54:56Z", + "id": "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7", + "OS-EXT-IMG-SIZE:size": 476704768, + "name": "F17-x86_64-cfntools", + "created": "2014-09-23T12:54:52Z", + "minDisk": 0, + "progress": 100, + "minRam": 0, + "metadata": { + "architecture": "x86_64", + "block_device_mapping": { + "guest_format": null, + "boot_index": 0, + "device_name": "/dev/vda", + "delete_on_termination": false + } + } + } + } + `) + }) + + actual, err := images.Get(fake.ServiceClient(), "12345678").Extract() + if err != nil { + t.Fatalf("Unexpected error from Get: %v", err) + } + + expected := &images.Image{ + Status: "ACTIVE", + Updated: "2014-09-23T12:54:56Z", + ID: "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7", + Name: "F17-x86_64-cfntools", + Created: "2014-09-23T12:54:52Z", + MinDisk: 0, + Progress: 100, + MinRAM: 0, + Metadata: map[string]interface{}{ + "architecture": "x86_64", + "block_device_mapping": map[string]interface{}{ + "guest_format": interface{}(nil), + "boot_index": float64(0), + "device_name": "/dev/vda", + "delete_on_termination": false, + }, + }, + } + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Expected %#v, but got %#v", expected, actual) + } +} + +func TestNextPageURL(t *testing.T) { + var page images.ImagePage + var body map[string]interface{} + bodyString := []byte(`{"images":{"links":[{"href":"http://192.154.23.87/12345/images/image3","rel":"bookmark"}]}, "images_links":[{"href":"http://192.154.23.87/12345/images/image4","rel":"next"}]}`) + err := json.Unmarshal(bodyString, &body) + if err != nil { + t.Fatalf("Error unmarshaling data into page body: %v", err) + } + page.Body = body + + expected := "http://192.154.23.87/12345/images/image4" + actual, err := page.NextPageURL() + th.AssertNoErr(t, err) + th.CheckEquals(t, expected, actual) +} + +// Test Image delete +func TestDeleteImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/images/12345678", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) + + res := images.Delete(fake.ServiceClient(), "12345678") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go index 626eb63e..cf7e94d0 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go @@ -383,7 +383,7 @@ type RebootOpts struct { } // ToServerRebootMap builds a body for the reboot request. -func (opts *RebootOpts) ToServerRebootMap() (map[string]interface{}, error) { +func (opts RebootOpts) ToServerRebootMap() (map[string]interface{}, error) { return gophercloud.BuildRequestBody(opts, "reboot") } @@ -756,7 +756,12 @@ func CreateImage(client *gophercloud.ServiceClient, id string, opts CreateImageO func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - allPages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + allPages, err := List(client, listOpts).AllPages() if err != nil { return "", err } @@ -789,3 +794,34 @@ func GetPassword(client *gophercloud.ServiceClient, serverId string) (r GetPassw _, r.Err = client.Get(passwordURL(client, serverId), &r.Body, nil) return } + +// ShowConsoleOutputOptsBuilder is the interface types must satisfy in order to be +// used as ShowConsoleOutput options +type ShowConsoleOutputOptsBuilder interface { + ToServerShowConsoleOutputMap() (map[string]interface{}, error) +} + +// ShowConsoleOutputOpts satisfies the ShowConsoleOutputOptsBuilder +type ShowConsoleOutputOpts struct { + // The number of lines to fetch from the end of console log. + // All lines will be returned if this is not specified. + Length int `json:"length,omitempty"` +} + +// ToServerShowConsoleOutputMap formats a ShowConsoleOutputOpts structure into a request body. +func (opts ShowConsoleOutputOpts) ToServerShowConsoleOutputMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "os-getConsoleOutput") +} + +// ShowConsoleOutput makes a request against the nova API to get console log from the server +func ShowConsoleOutput(client *gophercloud.ServiceClient, id string, opts ShowConsoleOutputOptsBuilder) (r ShowConsoleOutputResult) { + b, err := opts.ToServerShowConsoleOutputMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(actionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go index c6c1ff43..ac685e77 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/results.go @@ -80,6 +80,21 @@ type CreateImageResult struct { gophercloud.Result } +// ShowConsoleOutputResult represents the result of console output from a server +type ShowConsoleOutputResult struct { + gophercloud.Result +} + +// Extract will return the console output from a ShowConsoleOutput request. +func (r ShowConsoleOutputResult) Extract() (string, error) { + var s struct { + Output string `json:"output"` + } + + err := r.ExtractInto(&s) + return s.Output, err +} + // GetPasswordResult represent the result of a get os-server-password operation. // Call its ExtractPassword method to retrieve the password. type GetPasswordResult struct { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/fixtures.go index baec93ef..d6af0193 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/fixtures.go @@ -387,6 +387,10 @@ const ServerPasswordBody = ` } ` +const ConsoleOutputBody = `{ + "output": "abc" +}` + var ( herpTimeCreated, _ = time.Parse(time.RFC3339, "2014-09-25T13:10:02Z") herpTimeUpdated, _ = time.Parse(time.RFC3339, "2014-09-25T13:10:10Z") @@ -504,6 +508,8 @@ var ( }, } + ConsoleOutput = "abc" + merpTimeCreated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:41Z") merpTimeUpdated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:49Z") // ServerMerp is a Server struct that should correspond to the second server in ServerListBody. @@ -847,6 +853,19 @@ func HandleRebootSuccessfully(t *testing.T) { }) } +// HandleShowConsoleOutputSuccessfully sets up the test server to respond to a os-getConsoleOutput request with success. +func HandleShowConsoleOutputSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ "os-getConsoleOutput": { "length": 50 } }`) + + w.WriteHeader(http.StatusOK) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + // HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success. func HandleRebuildSuccessfully(t *testing.T, response string) { th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/requests_test.go new file mode 100644 index 00000000..b11e25c3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/requests_test.go @@ -0,0 +1,566 @@ +package testing + +import ( + "encoding/base64" + "encoding/json" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/diskconfig" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/extendedstatus" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListServers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerListSuccessfully(t) + + pages := 0 + err := servers.List(client.ServiceClient(), servers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := servers.ExtractServers(page) + if err != nil { + return false, err + } + + if len(actual) != 3 { + t.Fatalf("Expected 3 servers, got %d", len(actual)) + } + th.CheckDeepEquals(t, ServerHerp, actual[0]) + th.CheckDeepEquals(t, ServerDerp, actual[1]) + th.CheckDeepEquals(t, ServerMerp, actual[2]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllServers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerListSuccessfully(t) + + allPages, err := servers.List(client.ServiceClient(), servers.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := servers.ExtractServers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ServerHerp, actual[0]) + th.CheckDeepEquals(t, ServerDerp, actual[1]) +} + +func TestListAllServersWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerListSuccessfully(t) + + type ServerWithExt struct { + servers.Server + availabilityzones.ServerAvailabilityZoneExt + extendedstatus.ServerExtendedStatusExt + diskconfig.ServerDiskConfigExt + } + + allPages, err := servers.List(client.ServiceClient(), servers.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + var actual []ServerWithExt + err = servers.ExtractServersInto(allPages, &actual) + th.AssertNoErr(t, err) + th.AssertEquals(t, 3, len(actual)) + th.AssertEquals(t, "nova", actual[0].AvailabilityZone) + th.AssertEquals(t, "RUNNING", actual[0].PowerState.String()) + th.AssertEquals(t, "", actual[0].TaskState) + th.AssertEquals(t, "active", actual[0].VmState) + th.AssertEquals(t, diskconfig.Manual, actual[0].DiskConfig) +} + +func TestCreateServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationSuccessfully(t, SingleServerBody) + + actual, err := servers.Create(client.ServiceClient(), servers.CreateOpts{ + Name: "derp", + ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", + FlavorRef: "1", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestCreateServerWithCustomField(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationWithCustomFieldSuccessfully(t, SingleServerBody) + + actual, err := servers.Create(client.ServiceClient(), CreateOptsWithCustomField{ + CreateOpts: servers.CreateOpts{ + Name: "derp", + ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", + FlavorRef: "1", + }, + Foo: "bar", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestCreateServerWithMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationWithMetadata(t, SingleServerBody) + + actual, err := servers.Create(client.ServiceClient(), servers.CreateOpts{ + Name: "derp", + ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", + FlavorRef: "1", + Metadata: map[string]string{ + "abc": "def", + }, + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestCreateServerWithUserdataString(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationWithUserdata(t, SingleServerBody) + + actual, err := servers.Create(client.ServiceClient(), servers.CreateOpts{ + Name: "derp", + ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", + FlavorRef: "1", + UserData: []byte("userdata string"), + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestCreateServerWithUserdataEncoded(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationWithUserdata(t, SingleServerBody) + + encoded := base64.StdEncoding.EncodeToString([]byte("userdata string")) + + actual, err := servers.Create(client.ServiceClient(), servers.CreateOpts{ + Name: "derp", + ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", + FlavorRef: "1", + UserData: []byte(encoded), + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestCreateServerWithImageNameAndFlavorName(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerCreationSuccessfully(t, SingleServerBody) + + actual, err := servers.Create(client.ServiceClient(), servers.CreateOpts{ + Name: "derp", + ImageName: "cirros-0.3.2-x86_64-disk", + FlavorName: "m1.tiny", + ServiceClient: client.ServiceClient(), + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestDeleteServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerDeletionSuccessfully(t) + + res := servers.Delete(client.ServiceClient(), "asdfasdfasdf") + th.AssertNoErr(t, res.Err) +} + +func TestForceDeleteServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerForceDeletionSuccessfully(t) + + res := servers.ForceDelete(client.ServiceClient(), "asdfasdfasdf") + th.AssertNoErr(t, res.Err) +} + +func TestGetServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerGetSuccessfully(t) + + client := client.ServiceClient() + actual, err := servers.Get(client, "1234asdf").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestGetFaultyServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerGetFaultSuccessfully(t) + + client := client.ServiceClient() + actual, err := servers.Get(client, "1234asdf").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + FaultyServer := ServerDerp + FaultyServer.Fault = DerpFault + th.CheckDeepEquals(t, FaultyServer, *actual) +} + +func TestGetServerWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerGetSuccessfully(t) + + var s struct { + servers.Server + availabilityzones.ServerAvailabilityZoneExt + extendedstatus.ServerExtendedStatusExt + diskconfig.ServerDiskConfigExt + } + + err := servers.Get(client.ServiceClient(), "1234asdf").ExtractInto(&s) + th.AssertNoErr(t, err) + th.AssertEquals(t, "nova", s.AvailabilityZone) + th.AssertEquals(t, "RUNNING", s.PowerState.String()) + th.AssertEquals(t, "", s.TaskState) + th.AssertEquals(t, "active", s.VmState) + th.AssertEquals(t, diskconfig.Manual, s.DiskConfig) + + err = servers.Get(client.ServiceClient(), "1234asdf").ExtractInto(s) + if err == nil { + t.Errorf("Expected error when providing non-pointer struct") + } +} + +func TestUpdateServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleServerUpdateSuccessfully(t) + + client := client.ServiceClient() + actual, err := servers.Update(client, "1234asdf", servers.UpdateOpts{Name: "new-name"}).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestChangeServerAdminPassword(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAdminPasswordChangeSuccessfully(t) + + res := servers.ChangeAdminPassword(client.ServiceClient(), "1234asdf", "new-password") + th.AssertNoErr(t, res.Err) +} + +func TestShowConsoleOutput(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleShowConsoleOutputSuccessfully(t, ConsoleOutputBody) + + outputOpts := &servers.ShowConsoleOutputOpts{ + Length: 50, + } + actual, err := servers.ShowConsoleOutput(client.ServiceClient(), "1234asdf", outputOpts).Extract() + + th.AssertNoErr(t, err) + th.AssertByteArrayEquals(t, []byte(ConsoleOutput), []byte(actual)) +} + +func TestGetPassword(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePasswordGetSuccessfully(t) + + res := servers.GetPassword(client.ServiceClient(), "1234asdf") + th.AssertNoErr(t, res.Err) +} + +func TestRebootServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRebootSuccessfully(t) + + res := servers.Reboot(client.ServiceClient(), "1234asdf", servers.RebootOpts{ + Type: servers.SoftReboot, + }) + th.AssertNoErr(t, res.Err) +} + +func TestRebuildServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRebuildSuccessfully(t, SingleServerBody) + + opts := servers.RebuildOpts{ + Name: "new-name", + AdminPass: "swordfish", + ImageID: "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", + AccessIPv4: "1.2.3.4", + } + + actual, err := servers.Rebuild(client.ServiceClient(), "1234asdf", opts).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ServerDerp, *actual) +} + +func TestResizeServer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ "resize": { "flavorRef": "2" } }`) + + w.WriteHeader(http.StatusAccepted) + }) + + res := servers.Resize(client.ServiceClient(), "1234asdf", servers.ResizeOpts{FlavorRef: "2"}) + th.AssertNoErr(t, res.Err) +} + +func TestConfirmResize(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ "confirmResize": null }`) + + w.WriteHeader(http.StatusNoContent) + }) + + res := servers.ConfirmResize(client.ServiceClient(), "1234asdf") + th.AssertNoErr(t, res.Err) +} + +func TestRevertResize(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ "revertResize": null }`) + + w.WriteHeader(http.StatusAccepted) + }) + + res := servers.RevertResize(client.ServiceClient(), "1234asdf") + th.AssertNoErr(t, res.Err) +} + +func TestRescue(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleServerRescueSuccessfully(t) + + res := servers.Rescue(client.ServiceClient(), "1234asdf", servers.RescueOpts{ + AdminPass: "1234567890", + }) + th.AssertNoErr(t, res.Err) + adminPass, _ := res.Extract() + th.AssertEquals(t, "1234567890", adminPass) +} + +func TestGetMetadatum(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadatumGetSuccessfully(t) + + expected := map[string]string{"foo": "bar"} + actual, err := servers.Metadatum(client.ServiceClient(), "1234asdf", "foo").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestCreateMetadatum(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadatumCreateSuccessfully(t) + + expected := map[string]string{"foo": "bar"} + actual, err := servers.CreateMetadatum(client.ServiceClient(), "1234asdf", servers.MetadatumOpts{"foo": "bar"}).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestDeleteMetadatum(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadatumDeleteSuccessfully(t) + + err := servers.DeleteMetadatum(client.ServiceClient(), "1234asdf", "foo").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestGetMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadataGetSuccessfully(t) + + expected := map[string]string{"foo": "bar", "this": "that"} + actual, err := servers.Metadata(client.ServiceClient(), "1234asdf").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestResetMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadataResetSuccessfully(t) + + expected := map[string]string{"foo": "bar", "this": "that"} + actual, err := servers.ResetMetadata(client.ServiceClient(), "1234asdf", servers.MetadataOpts{ + "foo": "bar", + "this": "that", + }).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestUpdateMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleMetadataUpdateSuccessfully(t) + + expected := map[string]string{"foo": "baz", "this": "those"} + actual, err := servers.UpdateMetadata(client.ServiceClient(), "1234asdf", servers.MetadataOpts{ + "foo": "baz", + "this": "those", + }).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestListAddresses(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAddressListSuccessfully(t) + + expected := ListAddressesExpected + pages := 0 + err := servers.ListAddresses(client.ServiceClient(), "asdfasdfasdf").EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := servers.ExtractAddresses(page) + th.AssertNoErr(t, err) + + if len(actual) != 2 { + t.Fatalf("Expected 2 networks, got %d", len(actual)) + } + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, pages) +} + +func TestListAddressesByNetwork(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleNetworkAddressListSuccessfully(t) + + expected := ListNetworkAddressesExpected + pages := 0 + err := servers.ListAddressesByNetwork(client.ServiceClient(), "asdfasdfasdf", "public").EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := servers.ExtractNetworkAddresses(page) + th.AssertNoErr(t, err) + + if len(actual) != 2 { + t.Fatalf("Expected 2 addresses, got %d", len(actual)) + } + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, pages) +} + +func TestCreateServerImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateServerImageSuccessfully(t) + + _, err := servers.CreateImage(client.ServiceClient(), "serverimage", servers.CreateImageOpts{Name: "test"}).ExtractImageID() + th.AssertNoErr(t, err) +} + +func TestMarshalPersonality(t *testing.T) { + name := "/etc/test" + contents := []byte("asdfasdf") + + personality := servers.Personality{ + &servers.File{ + Path: name, + Contents: contents, + }, + } + + data, err := json.Marshal(personality) + if err != nil { + t.Fatal(err) + } + + var actual []map[string]string + err = json.Unmarshal(data, &actual) + if err != nil { + t.Fatal(err) + } + + if len(actual) != 1 { + t.Fatal("expected personality length 1") + } + + if actual[0]["path"] != name { + t.Fatal("file path incorrect") + } + + if actual[0]["contents"] != base64.StdEncoding.EncodeToString(contents) { + t.Fatal("file contents incorrect") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/results_test.go new file mode 100644 index 00000000..d4773dc9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/testing/results_test.go @@ -0,0 +1,110 @@ +package testing + +import ( + "crypto/rsa" + "encoding/json" + "fmt" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" + "golang.org/x/crypto/ssh" +) + +// Fail - No password in JSON. +func TestExtractPassword_no_pwd_data(t *testing.T) { + + var dejson interface{} + err := json.Unmarshal([]byte(`{ "Crappy data": ".-.-." }`), &dejson) + if err != nil { + t.Fatalf("%s", err) + } + resp := servers.GetPasswordResult{Result: gophercloud.Result{Body: dejson}} + + pwd, err := resp.ExtractPassword(nil) + th.AssertEquals(t, pwd, "") +} + +// Ok - return encrypted password when no private key is given. +func TestExtractPassword_encrypted_pwd(t *testing.T) { + + var dejson interface{} + sejson := []byte(`{"password":"PP8EnwPO9DhEc8+O/6CKAkPF379mKsUsfFY6yyw0734XXvKsSdV9KbiHQ2hrBvzeZxtGMrlFaikVunCRizyLLWLMuOi4hoH+qy9F9sQid61gQIGkxwDAt85d/7Eau2/KzorFnZhgxArl7IiqJ67X6xjKkR3zur+Yp3V/mtVIehpPYIaAvPbcp2t4mQXl1I9J8yrQfEZOctLL1L4heDEVXnxvNihVLK6pivlVggp6SZCtjj9cduZGrYGsxsOCso1dqJQr7GCojfwvuLOoG0OYwEGuWVTZppxWxi/q1QgeHFhGKA5QUXlz7pS71oqpjYsTeViuHnfvlqb5TVYZpQ1haw=="}`) + + err := json.Unmarshal(sejson, &dejson) + fmt.Printf("%v\n", dejson) + if err != nil { + t.Fatalf("%s", err) + } + resp := servers.GetPasswordResult{Result: gophercloud.Result{Body: dejson}} + + pwd, err := resp.ExtractPassword(nil) + th.AssertNoErr(t, err) + th.AssertEquals(t, "PP8EnwPO9DhEc8+O/6CKAkPF379mKsUsfFY6yyw0734XXvKsSdV9KbiHQ2hrBvzeZxtGMrlFaikVunCRizyLLWLMuOi4hoH+qy9F9sQid61gQIGkxwDAt85d/7Eau2/KzorFnZhgxArl7IiqJ67X6xjKkR3zur+Yp3V/mtVIehpPYIaAvPbcp2t4mQXl1I9J8yrQfEZOctLL1L4heDEVXnxvNihVLK6pivlVggp6SZCtjj9cduZGrYGsxsOCso1dqJQr7GCojfwvuLOoG0OYwEGuWVTZppxWxi/q1QgeHFhGKA5QUXlz7pS71oqpjYsTeViuHnfvlqb5TVYZpQ1haw==", pwd) +} + +// Ok - return decrypted password when private key is given. +// Decrytion can be verified by: +// echo "" | base64 -D | openssl rsautl -decrypt -inkey +func TestExtractPassword_decrypted_pwd(t *testing.T) { + + privateKey, err := ssh.ParseRawPrivateKey([]byte(` +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAo1ODZgwMVdTJYim9UYuYhowoPMhGEuV5IRZjcJ315r7RBSC+ +yEiBb1V+jhf+P8fzAyU35lkBzZGDr7E3jxSesbOuYT8cItQS4ErUnI1LGuqvMxwv +X3GMyE/HmOcaiODF1XZN3Ur5pMJdVknnmczgUsW0hT98Udrh3MQn9WSuh/6LRy6+ +x1QsKHOCLFPnkhWa3LKyxmpQq/Gvhz+6NLe+gt8MFullA5mKQxBJ/K6laVHeaMlw +JG3GCX0EZhRlvzoV8koIBKZtbKFolFr8ZtxBm3R5LvnyrtOvp22sa+xeItUT5kG1 +ZnbGNdK87oYW+VigEUfzT/+8R1i6E2QIXoeZiQIDAQABAoIBAQCVZ70IqbbTAW8j +RAlyQh/J3Qal65LmkFJJKUDX8TfT1/Q/G6BKeMEmxm+Zrmsfj1pHI1HKftt+YEG1 +g4jOc09kQXkgbmnfll6aHPn3J+1vdwXD3GGdjrL5PrnYrngAhJWU2r8J0x8hT8ew +OrUJZXhDX6XuSpAAFRmOKUZgXbSmo4X+LZX76ACnarselJt5FL724ECvpWJ7xxC4 +FMzvp4RqMmNFvv/Uq9lE/EmoSk4dviYyIZZ16DbDNyc9k/sGqCAMktCEwZ3EQm// +S5bkNhgP6oUXjluWy53aPRgykEylgDWo5SSdSEyKnw/fciU0xdprA9JrBGIcTyHS +/k2kgD4xAoGBANTkJ88Q0YrxX3fZNZVqcn00XKTxPGmxN5LRs7eV743q30AxK5Db +QU8iwaAA1IKUWV5DLhgUTNsDCOPUPue4aOSBD3/sj+WEmvIhj7afDL5didkYHsqf +fDnhFHq7y/3i57d428C7BwwR79pGWVyi7vH3pfu9A1iwl1aNOae+zvbVAoGBAMRm +AmwQ9fJ3Qc44jysFK/yliLRGdShjkMMah5G3JlrelwfPtwPwEL2EHHhJB/C1acMs +n6Q6RaoF6WNSZUY65ksQg7aPOYf2X0FTFwQJvwDJ4qlWjmq7w+tQ0AoGJG+dVUmQ +zHZ/Y+HokSXzz9c4oevk4v/rMgAQ00WHrTdtIhnlAoGBALIJJ72D7CkNGHCq5qPQ +xHQukPejgolFGhufYXM7YX3GmPMe67cVlTVv9Isxhoa5N0+cUPT0LR3PGOUm/4Bb +eOT3hZXOqLwhvE6XgI8Rzd95bClwgXekDoh80dqeKMdmta961BQGlKskaPiacmsF +G1yhZV70P9Mwwy8vpbLB4GUNAoGAbTwbjsWkNfa0qCF3J8NZoszjCvnBQfSW2J1R +1+8ZKyNwt0yFi3Ajr3TibNiZzPzp1T9lj29FvfpJxA9Y+sXZvthxmcFxizix5GB1 +ha5yCNtA8VSOI7lJkAFDpL+j1lyYyjD6N9JE2KqEyKoh6J+8F7sXsqW7CqRRDfQX +mKNfey0CgYEAxcEoNoADN2hRl7qY9rbQfVvQb3RkoQkdHhl9gpLFCcV32IP8R4xg +09NbQK5OmgcIuZhLVNzTmUHJbabEGeXqIFIV0DsqECAt3WzbDyKQO23VJysFD46c +KSde3I0ybDz7iS2EtceKB7m4C0slYd+oBkm4efuF00rCOKDwpFq45m0= +-----END RSA PRIVATE KEY----- +`)) + if err != nil { + t.Fatalf("Error parsing private key: %s\n", err) + } + + var dejson interface{} + sejson := []byte(`{"password":"PP8EnwPO9DhEc8+O/6CKAkPF379mKsUsfFY6yyw0734XXvKsSdV9KbiHQ2hrBvzeZxtGMrlFaikVunCRizyLLWLMuOi4hoH+qy9F9sQid61gQIGkxwDAt85d/7Eau2/KzorFnZhgxArl7IiqJ67X6xjKkR3zur+Yp3V/mtVIehpPYIaAvPbcp2t4mQXl1I9J8yrQfEZOctLL1L4heDEVXnxvNihVLK6pivlVggp6SZCtjj9cduZGrYGsxsOCso1dqJQr7GCojfwvuLOoG0OYwEGuWVTZppxWxi/q1QgeHFhGKA5QUXlz7pS71oqpjYsTeViuHnfvlqb5TVYZpQ1haw=="}`) + + err = json.Unmarshal(sejson, &dejson) + fmt.Printf("%v\n", dejson) + if err != nil { + t.Fatalf("%s", err) + } + resp := servers.GetPasswordResult{Result: gophercloud.Result{Body: dejson}} + + pwd, err := resp.ExtractPassword(privateKey.(*rsa.PrivateKey)) + th.AssertNoErr(t, err) + th.AssertEquals(t, "ruZKK0tqxRfYm5t7lSJq", pwd) +} + +func TestListAddressesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAddressListSuccessfully(t) + + allPages, err := servers.ListAddresses(client.ServiceClient(), "asdfasdfasdf").AllPages() + th.AssertNoErr(t, err) + _, err = servers.ExtractAddresses(allPages) + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/doc.go new file mode 100644 index 00000000..5237759e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/doc.go @@ -0,0 +1,4 @@ +// Package capsules contains functionality for working with Zun capsule +// resources. A capsule is a container group, as the co-located and +// co-scheduled unit, is the same like pod in Kubernetes. +package capsules diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/errors.go new file mode 100644 index 00000000..6542e66e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/errors.go @@ -0,0 +1,15 @@ +package capsules + +import ( + "fmt" + + "github.com/gophercloud/gophercloud" +) + +type ErrInvalidDataFormat struct { + gophercloud.BaseError +} + +func (e ErrInvalidDataFormat) Error() string { + return fmt.Sprintf("Data in neither json nor yaml format.") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/requests.go new file mode 100644 index 00000000..611c2767 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/requests.go @@ -0,0 +1,102 @@ +package capsules + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder is the interface options structs have to satisfy in order +// to be used in the main Create operation in this package. Since many +// extensions decorate or modify the common logic, it is useful for them to +// satisfy a basic interface in order for them to be used. +type CreateOptsBuilder interface { + ToCapsuleCreateMap() (map[string]interface{}, error) +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToCapsuleListQuery() (string, error) +} + +// Get requests details on a single capsule, by ID. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 203}, + }) + return +} + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + // A structure that contains either the template file or url. Call the + // associated methods to extract the information relevant to send in a create request. + TemplateOpts *Template `json:"-" required:"true"` +} + +// ToCapsuleCreateMap assembles a request body based on the contents of +// a CreateOpts. +func (opts CreateOpts) ToCapsuleCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + if err := opts.TemplateOpts.Parse(); err != nil { + return nil, err + } + b["template"] = string(opts.TemplateOpts.Bin) + + return b, nil +} + +// Create implements create capsule request. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToCapsuleCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{202}}) + return +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the capsule attributes you want to see returned. Marker and Limit are used +// for pagination. +type ListOpts struct { + Marker string `q:"marker"` + Limit int `q:"limit"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` + AllProjects bool `q:"all_projects"` +} + +// ToCapsuleListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToCapsuleListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List makes a request against the API to list capsules accessible to you. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToCapsuleListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return CapsulePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Delete implements Capsule delete request. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/results.go new file mode 100644 index 00000000..05d17aa9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/results.go @@ -0,0 +1,323 @@ +package capsules + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a capsule resource. +func (r commonResult) Extract() (*Capsule, error) { + var s *Capsule + err := r.ExtractInto(&s) + return s, err +} + +// GetResult represents the result of a get operation. +type GetResult struct { + commonResult +} + +// CreateResult is the response from a Create operation. Call its Extract +// method to interpret it as a Capsule. +type CreateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. +type DeleteResult struct { + gophercloud.ErrResult +} + +type CapsulePage struct { + pagination.LinkedPageBase +} + +// Represents a Capsule +type Capsule struct { + // UUID for the capsule + UUID string `json:"uuid"` + + // User ID for the capsule + UserID string `json:"user_id"` + + // Project ID for the capsule + ProjectID string `json:"project_id"` + + // cpu for the capsule + CPU float64 `json:"cpu"` + + // Memory for the capsule + Memory string `json:"memory"` + + // The name of the capsule + MetaName string `json:"meta_name"` + + // Indicates whether capsule is currently operational. + Status string `json:"status"` + + // Indicates whether capsule is currently operational. + StatusReason string `json:"status_reason"` + + // The created time of the capsule. + CreatedAt time.Time `json:"-"` + + // The updated time of the capsule. + UpdatedAt time.Time `json:"-"` + + // Links includes HTTP references to the itself, useful for passing along to + // other APIs that might want a capsule reference. + Links []interface{} `json:"links"` + + // The capsule version + CapsuleVersion string `json:"capsule_version"` + + // The capsule restart policy + RestartPolicy string `json:"restart_policy"` + + // The capsule metadata labels + MetaLabels map[string]string `json:"meta_labels"` + + // The list of containers uuids inside capsule. + ContainersUUIDs []string `json:"containers_uuids"` + + // The capsule IP addresses + Addresses map[string][]Address `json:"addresses"` + + // The capsule volume attached information + VolumesInfo map[string][]string `json:"volumes_info"` + + // The container object inside capsule + Containers []Container `json:"containers"` + + // The capsule host + Host string `json:"host"` +} + +type Container struct { + // The Container IP addresses + Addresses map[string][]Address `json:"addresses"` + + // UUID for the container + UUID string `json:"uuid"` + + // User ID for the container + UserID string `json:"user_id"` + + // Project ID for the container + ProjectID string `json:"project_id"` + + // cpu for the container + CPU float64 `json:"cpu"` + + // Memory for the container + Memory string `json:"memory"` + + // Image for the container + Image string `json:"image"` + + // The container container + Labels map[string]string `json:"labels"` + + // The created time of the container + CreatedAt time.Time `json:"-"` + + // The updated time of the container + UpdatedAt time.Time `json:"-"` + + // The started time of the container + StartedAt time.Time `json:"-"` + + // Name for the container + Name string `json:"name"` + + // Links includes HTTP references to the itself, useful for passing along to + // other APIs that might want a capsule reference. + Links []interface{} `json:"links"` + + // auto remove flag token for the container + AutoRemove bool `json:"auto_remove"` + + // Host for the container + Host string `json:"host"` + + // Work directory for the container + WorkDir string `json:"workdir"` + + // Disk for the container + Disk int `json:"disk"` + + // Image pull policy for the container + ImagePullPolicy string `json:"image_pull_policy"` + + // Task state for the container + TaskState string `json:"task_state"` + + // Host name for the container + HostName string `json:"hostname"` + + // Environment for the container + Environment map[string]string `json:"environment"` + + // Status for the container + Status string `json:"status"` + + // Auto Heal flag for the container + AutoHeal bool `json:"auto_heal"` + + // Status details for the container + StatusDetail string `json:"status_detail"` + + // Status reason for the container + StatusReason string `json:"status_reason"` + + // Image driver for the container + ImageDriver string `json:"image_driver"` + + // Command for the container + Command []string `json:"command"` + + // Image for the container + Runtime string `json:"runtime"` + + // Interactive flag for the container + Interactive bool `json:"interactive"` + + // Restart Policy for the container + RestartPolicy map[string]string `json:"restart_policy"` + + // Ports information for the container + Ports []int `json:"ports"` + + // Security groups for the container + SecurityGroups []string `json:"security_groups"` +} + +type Address struct { + PreserveOnDelete bool `json:"preserve_on_delete"` + Addr string `json:"addr"` + Port string `json:"port"` + Version float64 `json:"version"` + SubnetID string `json:"subnet_id"` +} + +// NextPageURL is invoked when a paginated collection of capsules has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r CapsulePage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Next, nil +} + +// IsEmpty checks whether a CapsulePage struct is empty. +func (r CapsulePage) IsEmpty() (bool, error) { + is, err := ExtractCapsules(r) + return len(is) == 0, err +} + +// ExtractCapsules accepts a Page struct, specifically a CapsulePage struct, +// and extracts the elements into a slice of Capsule structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractCapsules(r pagination.Page) ([]Capsule, error) { + var s struct { + Capsules []Capsule `json:"capsules"` + } + err := (r.(CapsulePage)).ExtractInto(&s) + return s.Capsules, err +} + +func (r *Capsule) UnmarshalJSON(b []byte) error { + type tmp Capsule + + // Support for "older" zun time formats. + var s1 struct { + tmp + CreatedAt gophercloud.JSONRFC3339ZNoT `json:"created_at"` + UpdatedAt gophercloud.JSONRFC3339ZNoT `json:"updated_at"` + } + + err := json.Unmarshal(b, &s1) + if err == nil { + *r = Capsule(s1.tmp) + + r.CreatedAt = time.Time(s1.CreatedAt) + r.UpdatedAt = time.Time(s1.UpdatedAt) + + return nil + } + + // Support for "new" zun time formats. + var s2 struct { + tmp + CreatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"created_at"` + UpdatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"updated_at"` + } + + err = json.Unmarshal(b, &s2) + if err != nil { + return err + } + + *r = Capsule(s2.tmp) + + r.CreatedAt = time.Time(s2.CreatedAt) + r.UpdatedAt = time.Time(s2.UpdatedAt) + + return nil +} + +func (r *Container) UnmarshalJSON(b []byte) error { + type tmp Container + + // Support for "older" zun time formats. + var s1 struct { + tmp + CreatedAt gophercloud.JSONRFC3339ZNoT `json:"created_at"` + UpdatedAt gophercloud.JSONRFC3339ZNoT `json:"updated_at"` + StartedAt gophercloud.JSONRFC3339ZNoT `json:"started_at"` + } + + err := json.Unmarshal(b, &s1) + if err == nil { + *r = Container(s1.tmp) + + r.CreatedAt = time.Time(s1.CreatedAt) + r.UpdatedAt = time.Time(s1.UpdatedAt) + r.StartedAt = time.Time(s1.StartedAt) + + return nil + } + + // Support for "new" zun time formats. + var s2 struct { + tmp + CreatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"created_at"` + UpdatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"updated_at"` + StartedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"started_at"` + } + + err = json.Unmarshal(b, &s2) + if err != nil { + return err + } + + *r = Container(s2.tmp) + + r.CreatedAt = time.Time(s2.CreatedAt) + r.UpdatedAt = time.Time(s2.UpdatedAt) + r.StartedAt = time.Time(s2.StartedAt) + + return nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/template.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/template.go new file mode 100644 index 00000000..ad72ca9f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/template.go @@ -0,0 +1,27 @@ +package capsules + +import ( + "encoding/json" + + "gopkg.in/yaml.v2" +) + +// Template is a structure that represents OpenStack Zun Capsule templates +type Template struct { + // Bin stores the contents of the template or environment. + Bin []byte + // Parsed contains a parsed version of Bin. Since there are 2 different + // fields referring to the same value, you must be careful when accessing + // this filed. + Parsed map[string]interface{} +} + +// Parse will parse the contents and then validate. The contents MUST be either JSON or YAML. +func (t *Template) Parse() error { + if jerr := json.Unmarshal(t.Bin, &t.Parsed); jerr != nil { + if yerr := yaml.Unmarshal(t.Bin, &t.Parsed); yerr != nil { + return ErrInvalidDataFormat{} + } + } + return nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/doc.go new file mode 100644 index 00000000..7603f836 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/doc.go @@ -0,0 +1 @@ +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/fixtures.go new file mode 100644 index 00000000..18430d54 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/fixtures.go @@ -0,0 +1,570 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/container/v1/capsules" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ValidJSONTemplate is a valid OpenStack Capsule template in JSON format +const ValidJSONTemplate = ` +{ + "capsuleVersion": "beta", + "kind": "capsule", + "metadata": { + "labels": { + "app": "web", + "app1": "web1" + }, + "name": "template" + }, + "spec": { + "restartPolicy": "Always", + "containers": [ + { + "command": [ + "/bin/bash" + ], + "env": { + "ENV1": "/usr/local/bin", + "ENV2": "/usr/bin" + }, + "image": "ubuntu", + "imagePullPolicy": "ifnotpresent", + "ports": [ + { + "containerPort": 80, + "hostPort": 80, + "name": "nginx-port", + "protocol": "TCP" + } + ], + "resources": { + "requests": { + "cpu": 1, + "memory": 1024 + } + }, + "workDir": "/root" + } + ] + } +} +` + +// ValidYAMLTemplate is a valid OpenStack Capsule template in YAML format +const ValidYAMLTemplate = ` +capsuleVersion: beta +kind: capsule +metadata: + name: template + labels: + app: web + app1: web1 +spec: + restartPolicy: Always + containers: + - image: ubuntu + command: + - "/bin/bash" + imagePullPolicy: ifnotpresent + workDir: /root + ports: + - name: nginx-port + containerPort: 80 + hostPort: 80 + protocol: TCP + resources: + requests: + cpu: 1 + memory: 1024 + env: + ENV1: /usr/local/bin + ENV2: /usr/bin +` + +// ValidJSONTemplateParsed is the expected parsed version of ValidJSONTemplate +var ValidJSONTemplateParsed = map[string]interface{}{ + "capsuleVersion": "beta", + "kind": "capsule", + "metadata": map[string]interface{}{ + "name": "template", + "labels": map[string]string{ + "app": "web", + "app1": "web1", + }, + }, + "spec": map[string]interface{}{ + "restartPolicy": "Always", + "containers": []map[string]interface{}{ + map[string]interface{}{ + "image": "ubuntu", + "command": []interface{}{ + "/bin/bash", + }, + "imagePullPolicy": "ifnotpresent", + "workDir": "/root", + "ports": []interface{}{ + map[string]interface{}{ + "name": "nginx-port", + "containerPort": float64(80), + "hostPort": float64(80), + "protocol": "TCP", + }, + }, + "resources": map[string]interface{}{ + "requests": map[string]interface{}{ + "cpu": float64(1), + "memory": float64(1024), + }, + }, + "env": map[string]interface{}{ + "ENV1": "/usr/local/bin", + "ENV2": "/usr/bin", + }, + }, + }, + }, +} + +// ValidYAMLTemplateParsed is the expected parsed version of ValidYAMLTemplate +var ValidYAMLTemplateParsed = map[string]interface{}{ + "capsuleVersion": "beta", + "kind": "capsule", + "metadata": map[string]interface{}{ + "name": "template", + "labels": map[string]string{ + "app": "web", + "app1": "web1", + }, + }, + "spec": map[interface{}]interface{}{ + "restartPolicy": "Always", + "containers": []map[interface{}]interface{}{ + map[interface{}]interface{}{ + "image": "ubuntu", + "command": []interface{}{ + "/bin/bash", + }, + "imagePullPolicy": "ifnotpresent", + "workDir": "/root", + "ports": []interface{}{ + map[interface{}]interface{}{ + "name": "nginx-port", + "containerPort": 80, + "hostPort": 80, + "protocol": "TCP", + }, + }, + "resources": map[interface{}]interface{}{ + "requests": map[interface{}]interface{}{ + "cpu": 1, + "memory": 1024, + }, + }, + "env": map[interface{}]interface{}{ + "ENV1": "/usr/local/bin", + "ENV2": "/usr/bin", + }, + }, + }, + }, +} + +const CapsuleGetBody_OldTime = ` +{ + "uuid": "cc654059-1a77-47a3-bfcf-715bde5aad9e", + "status": "Running", + "user_id": "d33b18c384574fd2a3299447aac285f0", + "project_id": "6b8ffef2a0ac42ee87887b9cc98bdf68", + "cpu": 1, + "memory": "1024M", + "meta_name": "test", + "meta_labels": {"web": "app"}, + "created_at": "2018-01-12 09:37:25+00:00", + "updated_at": "2018-01-12 09:37:26+00:00", + "links": [ + { + "href": "http://10.10.10.10/v1/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "self" + }, + { + "href": "http://10.10.10.10/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "bookmark" + } + ], + "capsule_version": "beta", + "restart_policy": "always", + "containers_uuids": ["1739e28a-d391-4fd9-93a5-3ba3f29a4c9b"], + "addresses": { + "b1295212-64e1-471d-aa01-25ff46f9818d": [ + { + "version": 4, + "preserve_on_delete": false, + "addr": "172.24.4.11", + "port": "8439060f-381a-4386-a518-33d5a4058636", + "subnet_id": "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a" + } + ] + }, + "volumes_info": { + "67618d54-dd55-4f7e-91b3-39ffb3ba7f5f": [ + "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b" + ] + }, + "host": "test-host", + "status_reason": "No reason", + "containers": [ + { + "addresses": { + "b1295212-64e1-471d-aa01-25ff46f9818d": [ + { + "version": 4, + "preserve_on_delete": false, + "addr": "172.24.4.11", + "port": "8439060f-381a-4386-a518-33d5a4058636", + "subnet_id": "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a" + } + ] + }, + "image": "test", + "labels": {"foo": "bar"}, + "created_at": "2018-01-12 09:37:25+00:00", + "updated_at": "2018-01-12 09:37:26+00:00", + "started_at": "2018-01-12 09:37:26+00:00", + "workdir": "/root", + "disk": 0, + "security_groups": ["default"], + "image_pull_policy": "ifnotpresent", + "task_state": "Creating", + "user_id": "d33b18c384574fd2a3299447aac285f0", + "project_id": "6b8ffef2a0ac42ee87887b9cc98bdf68", + "uuid": "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", + "hostname": "test-hostname", + "environment": {"USER1": "test"}, + "memory": "1024M", + "status": "Running", + "auto_remove": false, + "auto_heal": false, + "host": "test-host", + "image_driver": "docker", + "status_detail": "Just created", + "status_reason": "No reason", + "name": "test-demo-omicron-13", + "restart_policy": { + "MaximumRetryCount": "0", + "Name": "always" + }, + "ports": [80], + "command": ["testcmd"], + "runtime": "runc", + "cpu": 1, + "interactive": true + } + ] +}` + +const CapsuleGetBody_NewTime = ` +{ + "uuid": "cc654059-1a77-47a3-bfcf-715bde5aad9e", + "status": "Running", + "user_id": "d33b18c384574fd2a3299447aac285f0", + "project_id": "6b8ffef2a0ac42ee87887b9cc98bdf68", + "cpu": 1, + "memory": "1024M", + "meta_name": "test", + "meta_labels": {"web": "app"}, + "created_at": "2018-01-12 09:37:25", + "updated_at": "2018-01-12 09:37:26", + "links": [ + { + "href": "http://10.10.10.10/v1/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "self" + }, + { + "href": "http://10.10.10.10/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "bookmark" + } + ], + "capsule_version": "beta", + "restart_policy": "always", + "containers_uuids": ["1739e28a-d391-4fd9-93a5-3ba3f29a4c9b"], + "addresses": { + "b1295212-64e1-471d-aa01-25ff46f9818d": [ + { + "version": 4, + "preserve_on_delete": false, + "addr": "172.24.4.11", + "port": "8439060f-381a-4386-a518-33d5a4058636", + "subnet_id": "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a" + } + ] + }, + "volumes_info": { + "67618d54-dd55-4f7e-91b3-39ffb3ba7f5f": [ + "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b" + ] + }, + "host": "test-host", + "status_reason": "No reason", + "containers": [ + { + "addresses": { + "b1295212-64e1-471d-aa01-25ff46f9818d": [ + { + "version": 4, + "preserve_on_delete": false, + "addr": "172.24.4.11", + "port": "8439060f-381a-4386-a518-33d5a4058636", + "subnet_id": "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a" + } + ] + }, + "image": "test", + "labels": {"foo": "bar"}, + "created_at": "2018-01-12 09:37:25", + "updated_at": "2018-01-12 09:37:26", + "started_at": "2018-01-12 09:37:26", + "workdir": "/root", + "disk": 0, + "security_groups": ["default"], + "image_pull_policy": "ifnotpresent", + "task_state": "Creating", + "user_id": "d33b18c384574fd2a3299447aac285f0", + "project_id": "6b8ffef2a0ac42ee87887b9cc98bdf68", + "uuid": "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", + "hostname": "test-hostname", + "environment": {"USER1": "test"}, + "memory": "1024M", + "status": "Running", + "auto_remove": false, + "auto_heal": false, + "host": "test-host", + "image_driver": "docker", + "status_detail": "Just created", + "status_reason": "No reason", + "name": "test-demo-omicron-13", + "restart_policy": { + "MaximumRetryCount": "0", + "Name": "always" + }, + "ports": [80], + "command": ["testcmd"], + "runtime": "runc", + "cpu": 1, + "interactive": true + } + ] +}` + +const CapsuleListBody = ` +{ + "capsules": [ + { + "uuid": "cc654059-1a77-47a3-bfcf-715bde5aad9e", + "status": "Running", + "user_id": "d33b18c384574fd2a3299447aac285f0", + "project_id": "6b8ffef2a0ac42ee87887b9cc98bdf68", + "cpu": 1, + "memory": "1024M", + "meta_name": "test", + "meta_labels": {"web": "app"}, + "created_at": "2018-01-12 09:37:25+00:00", + "updated_at": "2018-01-12 09:37:25+01:00", + "links": [ + { + "href": "http://10.10.10.10/v1/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "self" + }, + { + "href": "http://10.10.10.10/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "bookmark" + } + ], + "capsule_version": "beta", + "restart_policy": "always", + "containers_uuids": ["1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", "d1469e8d-bcbc-43fc-b163-8b9b6a740930"], + "addresses": { + "b1295212-64e1-471d-aa01-25ff46f9818d": [ + { + "version": 4, + "preserve_on_delete": false, + "addr": "172.24.4.11", + "port": "8439060f-381a-4386-a518-33d5a4058636", + "subnet_id": "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a" + } + ] + }, + "volumes_info": { + "67618d54-dd55-4f7e-91b3-39ffb3ba7f5f": [ + "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b" + ] + }, + "host": "test-host", + "status_reason": "No reason" + } + ] +}` + +var ExpectedContainer1 = capsules.Container{ + Name: "test-demo-omicron-13", + UUID: "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", + UserID: "d33b18c384574fd2a3299447aac285f0", + ProjectID: "6b8ffef2a0ac42ee87887b9cc98bdf68", + CPU: float64(1), + Memory: "1024M", + Host: "test-host", + Status: "Running", + Image: "test", + Labels: map[string]string{ + "foo": "bar", + }, + WorkDir: "/root", + Disk: 0, + Command: []string{ + "testcmd", + }, + Ports: []int{ + 80, + }, + SecurityGroups: []string{ + "default", + }, + ImagePullPolicy: "ifnotpresent", + Runtime: "runc", + TaskState: "Creating", + HostName: "test-hostname", + Environment: map[string]string{ + "USER1": "test", + }, + StatusReason: "No reason", + StatusDetail: "Just created", + ImageDriver: "docker", + Interactive: true, + AutoRemove: false, + AutoHeal: false, + RestartPolicy: map[string]string{ + "MaximumRetryCount": "0", + "Name": "always", + }, + Addresses: map[string][]capsules.Address{ + "b1295212-64e1-471d-aa01-25ff46f9818d": []capsules.Address{ + { + PreserveOnDelete: false, + Addr: "172.24.4.11", + Port: "8439060f-381a-4386-a518-33d5a4058636", + Version: float64(4), + SubnetID: "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a", + }, + }, + }, +} + +var ExpectedCapsule = capsules.Capsule{ + UUID: "cc654059-1a77-47a3-bfcf-715bde5aad9e", + Status: "Running", + UserID: "d33b18c384574fd2a3299447aac285f0", + ProjectID: "6b8ffef2a0ac42ee87887b9cc98bdf68", + CPU: float64(1), + Memory: "1024M", + MetaName: "test", + Links: []interface{}{ + map[string]interface{}{ + "href": "http://10.10.10.10/v1/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "self", + }, + map[string]interface{}{ + "href": "http://10.10.10.10/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", + "rel": "bookmark", + }, + }, + CapsuleVersion: "beta", + RestartPolicy: "always", + MetaLabels: map[string]string{ + "web": "app", + }, + ContainersUUIDs: []string{ + "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", + }, + Addresses: map[string][]capsules.Address{ + "b1295212-64e1-471d-aa01-25ff46f9818d": []capsules.Address{ + { + PreserveOnDelete: false, + Addr: "172.24.4.11", + Port: "8439060f-381a-4386-a518-33d5a4058636", + Version: float64(4), + SubnetID: "4a2bcd64-93ad-4436-9f48-3a7f9b267e0a", + }, + }, + }, + VolumesInfo: map[string][]string{ + "67618d54-dd55-4f7e-91b3-39ffb3ba7f5f": []string{ + "1739e28a-d391-4fd9-93a5-3ba3f29a4c9b", + }, + }, + Host: "test-host", + StatusReason: "No reason", + Containers: []capsules.Container{ + ExpectedContainer1, + }, +} + +// HandleCapsuleGetOldTimeSuccessfully test setup +func HandleCapsuleGetOldTimeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.WriteHeader(http.StatusOK) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, CapsuleGetBody_OldTime) + }) +} + +// HandleCapsuleGetNewTimeSuccessfully test setup +func HandleCapsuleGetNewTimeSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/capsules/cc654059-1a77-47a3-bfcf-715bde5aad9e", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.WriteHeader(http.StatusOK) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, CapsuleGetBody_NewTime) + }) +} + +// HandleCapsuleCreateSuccessfully creates an HTTP handler at `/capsules` on the test handler mux +// that responds with a `Create` response. +func HandleCapsuleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/capsules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + w.WriteHeader(http.StatusAccepted) + fmt.Fprintf(w, CapsuleGetBody_NewTime) + }) +} + +// HandleCapsuleListSuccessfully test setup +func HandleCapsuleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/capsules/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, CapsuleListBody) + }) +} + +func HandleCapsuleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/capsules/963a239d-3946-452b-be5a-055eab65a421", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/requests_test.go new file mode 100644 index 00000000..03b93cfe --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/requests_test.go @@ -0,0 +1,119 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/container/v1/capsules" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetCapsule_OldTime(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCapsuleGetOldTimeSuccessfully(t) + + createdAt, _ := time.Parse(gophercloud.RFC3339ZNoT, "2018-01-12 09:37:25+00:00") + updatedAt, _ := time.Parse(gophercloud.RFC3339ZNoT, "2018-01-12 09:37:26+00:00") + startedAt, _ := time.Parse(gophercloud.RFC3339ZNoT, "2018-01-12 09:37:26+00:00") + + ExpectedCapsule.CreatedAt = createdAt + ExpectedCapsule.UpdatedAt = updatedAt + ExpectedCapsule.Containers[0].CreatedAt = createdAt + ExpectedCapsule.Containers[0].UpdatedAt = updatedAt + ExpectedCapsule.Containers[0].StartedAt = startedAt + + actualCapsule, err := capsules.Get(fakeclient.ServiceClient(), ExpectedCapsule.UUID).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &ExpectedCapsule, actualCapsule) +} + +func TestGetCapsule_NewTime(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCapsuleGetNewTimeSuccessfully(t) + + createdAt, _ := time.Parse(gophercloud.RFC3339ZNoTNoZ, "2018-01-12 09:37:25") + updatedAt, _ := time.Parse(gophercloud.RFC3339ZNoTNoZ, "2018-01-12 09:37:26") + startedAt, _ := time.Parse(gophercloud.RFC3339ZNoTNoZ, "2018-01-12 09:37:26") + + ExpectedCapsule.CreatedAt = createdAt + ExpectedCapsule.UpdatedAt = updatedAt + ExpectedCapsule.Containers[0].CreatedAt = createdAt + ExpectedCapsule.Containers[0].UpdatedAt = updatedAt + ExpectedCapsule.Containers[0].StartedAt = startedAt + + actualCapsule, err := capsules.Get(fakeclient.ServiceClient(), ExpectedCapsule.UUID).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &ExpectedCapsule, actualCapsule) +} + +func TestCreateCapsule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCapsuleCreateSuccessfully(t) + + template := new(capsules.Template) + template.Bin = []byte(ValidJSONTemplate) + + createOpts := capsules.CreateOpts{ + TemplateOpts: template, + } + actualCapsule, err := capsules.Create(fakeclient.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &ExpectedCapsule, actualCapsule) +} + +func TestListCapsule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCapsuleListSuccessfully(t) + + createdAt, _ := time.Parse(gophercloud.RFC3339ZNoT, "2018-01-12 09:37:25+00:00") + updatedAt, _ := time.Parse(gophercloud.RFC3339ZNoT, "2018-01-12 09:37:25+01:00") + + ExpectedCapsule.CreatedAt = createdAt + ExpectedCapsule.UpdatedAt = updatedAt + ExpectedCapsule.Containers = nil + + expected := []capsules.Capsule{ExpectedCapsule} + + count := 0 + results := capsules.List(fakeclient.ServiceClient(), nil) + err := results.EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := capsules.ExtractCapsules(page) + if err != nil { + t.Errorf("Failed to extract capsules: %v", err) + return false, err + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCapsuleDeleteSuccessfully(t) + + res := capsules.Delete(fakeclient.ServiceClient(), "963a239d-3946-452b-be5a-055eab65a421") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/template_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/template_test.go new file mode 100644 index 00000000..62d0de8f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/testing/template_test.go @@ -0,0 +1,29 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/container/v1/capsules" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTemplateParsing(t *testing.T) { + templateJSON := new(capsules.Template) + templateJSON.Bin = []byte(ValidJSONTemplate) + err := templateJSON.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidJSONTemplateParsed, templateJSON.Parsed) + + templateYAML := new(capsules.Template) + templateYAML.Bin = []byte(ValidYAMLTemplate) + err = templateYAML.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidYAMLTemplateParsed, templateYAML.Parsed) + + templateInvalid := new(capsules.Template) + templateInvalid.Bin = []byte("Keep Austin Weird") + err = templateInvalid.Parse() + if err == nil { + t.Error("Template parsing did not catch invalid template") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/urls.go new file mode 100644 index 00000000..575fb2a7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/container/v1/capsules/urls.go @@ -0,0 +1,21 @@ +package capsules + +import "github.com/gophercloud/gophercloud" + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("capsules", id) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("capsules") +} + +// `listURL` is a pure function. `listURL(c)` is a URL for which a GET +// request will respond with a list of capsules in the service `c`. +func listURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL("capsules") +} + +func deleteURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL("capsules", id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/doc.go new file mode 100644 index 00000000..d949ebfe --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/doc.go @@ -0,0 +1,15 @@ +// Package certificates contains functionality for working with Magnum Certificate +// resources. +/* +Package certificates provides information and interaction with the certificates through +the OpenStack Container Infra service. + +Example to get certificates + + certificate, err := certificates.Get(serviceClient, "d564b18a-2890-4152-be3d-e05d784ff72").Extract() + if err != nil { + panic(err) + } + +*/ +package certificates diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/requests.go new file mode 100644 index 00000000..bda1fcef --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/requests.go @@ -0,0 +1,16 @@ +package certificates + +import ( + "github.com/gophercloud/gophercloud" +) + +// Get makes a request against the API to get details for a certificate. +func Get(client *gophercloud.ServiceClient, clusterID string) (r GetResult) { + url := getURL(client, clusterID) + + _, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/results.go new file mode 100644 index 00000000..9d93f1a8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/results.go @@ -0,0 +1,29 @@ +package certificates + +import ( + "github.com/gophercloud/gophercloud" +) + +type commonResult struct { + gophercloud.Result +} + +// GetResult is the response of a Get operations. +type GetResult struct { + commonResult +} + +// Extract is a function that accepts a result and extracts a certificate resource. +func (r commonResult) Extract() (*Certificate, error) { + var s *Certificate + err := r.ExtractInto(&s) + return s, err +} + +// Represents a template for a Cluster Template +type Certificate struct { + ClusterUUID string `json:"cluster_uuid"` + BayUUID string `json:"bay_uuid"` + Links []gophercloud.Link `json:"links"` + Pem string `json:"pem"` +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/doc.go new file mode 100644 index 00000000..7603f836 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/doc.go @@ -0,0 +1 @@ +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/fixtures.go new file mode 100644 index 00000000..2e15683f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/fixtures.go @@ -0,0 +1,55 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const CertificateResponse = ` +{ + "cluster_uuid": "d564b18a-2890-4152-be3d-e05d784ff727", + "bay_uuid": "d564b18a-2890-4152-be3d-e05d784ff727", + "pem": "FAKE_CERTIFICATE", + "links": [ + { + "href": "http://10.63.176.154:9511/v1/certificates/d564b18a-2890-4152-be3d-e05d784ff727", + "rel": "self" + }, + { + "href": "http://10.63.176.154:9511/certificates/d564b18a-2890-4152-be3d-e05d784ff727", + "rel": "bookmark" + } + ] +}` + +var ExpectedCertificate = certificates.Certificate{ + ClusterUUID: "d564b18a-2890-4152-be3d-e05d784ff727", + BayUUID: "d564b18a-2890-4152-be3d-e05d784ff727", + Pem: "FAKE_CERTIFICATE", + Links: []gophercloud.Link{ + {Href: "http://10.63.176.154:9511/v1/certificates/d564b18a-2890-4152-be3d-e05d784ff727", Rel: "self"}, + {Href: "http://10.63.176.154:9511/certificates/d564b18a-2890-4152-be3d-e05d784ff727", Rel: "bookmark"}, + }, +} + +func HandleGetCertificateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/certificates/d564b18a-2890-4152-be3d-e05d784ff72", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("OpenStack-API-Minimum-Version", "container-infra 1.1") + w.Header().Add("OpenStack-API-Maximum-Version", "container-infra 1.6") + w.Header().Add("OpenStack-API-Version", "container-infra 1.1") + w.Header().Add("X-OpenStack-Request-Id", "req-781e9bdc-4163-46eb-91c9-786c53188bbb") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, CertificateResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/requests_test.go new file mode 100644 index 00000000..cc3421c8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/testing/requests_test.go @@ -0,0 +1,23 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetCertificates(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetCertificateSuccessfully(t) + + sc := fake.ServiceClient() + sc.Endpoint = sc.Endpoint + "v1/" + + actual, err := certificates.Get(sc, "d564b18a-2890-4152-be3d-e05d784ff72").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCertificate, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/urls.go new file mode 100644 index 00000000..e7d40937 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates/urls.go @@ -0,0 +1,15 @@ +package certificates + +import ( + "github.com/gophercloud/gophercloud" +) + +var apiName = "certificates" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiName) +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL(apiName, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/doc.go new file mode 100644 index 00000000..b07b6e64 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/doc.go @@ -0,0 +1,42 @@ +// Package clustertemplates contains functionality for working with Magnum Cluster Templates +// resources. +/* +Package clustertemplates provides information and interaction with the cluster-templates through +the OpenStack Container Infra service. + +Example to Create Cluster Template + + boolFalse := false + boolTrue := true + createOpts := clustertemplates.CreateOpts{ + Name: "test-cluster-template", + Labels: map[string]string{}, + FixedSubnet: "", + MasterFlavorID: "", + NoProxy: "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", + HTTPSProxy: "http://10.164.177.169:8080", + TLSDisabled: &boolFalse, + KeyPairID: "kp", + Public: &boolFalse, + HTTPProxy: "http://10.164.177.169:8080", + ServerType: "vm", + ExternalNetworkID: "public", + ImageID: "fedora-atomic-latest", + VolumeDriver: "cinder", + RegistryEnabled: &boolFalse, + DockerStorageDriver: "devicemapper", + NetworkDriver: "flannel", + FixedNetwork: "", + COE: "kubernetes", + FlavorID: "m1.small", + MasterLBEnabled: &boolTrue, + DNSNameServer: "8.8.8.8", + } + + clustertemplate, err := clustertemplates.Create(serviceClient, createOpts).Extract() + if err != nil { + panic(err) + } + +*/ +package clustertemplates diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/requests.go new file mode 100644 index 00000000..59628f65 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/requests.go @@ -0,0 +1,66 @@ +package clustertemplates + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" +) + +// CreateOptsBuilder Builder. +type CreateOptsBuilder interface { + ToClusterCreateMap() (map[string]interface{}, error) +} + +// CreateOpts params +type CreateOpts struct { + APIServerPort *int `json:"apiserver_port,omitempty"` + COE string `json:"coe" required:"true"` + DNSNameServer string `json:"dns_nameserver,omitempty"` + DockerStorageDriver string `json:"docker_storage_driver,omitempty"` + DockerVolumeSize *int `json:"docker_volume_size,omitempty"` + ExternalNetworkID string `json:"external_network_id,omitempty"` + FixedNetwork string `json:"fixed_network,omitempty"` + FixedSubnet string `json:"fixed_subnet,omitempty"` + FlavorID string `json:"flavor_id,omitempty"` + FloatingIPEnabled *bool `json:"floating_ip_enabled,omitempty"` + HTTPProxy string `json:"http_proxy,omitempty"` + HTTPSProxy string `json:"https_proxy,omitempty"` + ImageID string `json:"image_id" required:"true"` + InsecureRegistry string `json:"insecure_registry,omitempty"` + KeyPairID string `json:"keypair_id,omitempty"` + Labels map[string]string `json:"labels,omitempty"` + MasterFlavorID string `json:"master_flavor_id,omitempty"` + MasterLBEnabled *bool `json:"master_lb_enabled,omitempty"` + Name string `json:"name,omitempty"` + NetworkDriver string `json:"network_driver,omitempty"` + NoProxy string `json:"no_proxy,omitempty"` + Public *bool `json:"public,omitempty"` + RegistryEnabled *bool `json:"registry_enabled,omitempty"` + ServerType string `json:"server_type,omitempty"` + TLSDisabled *bool `json:"tls_disabled,omitempty"` + VolumeDriver string `json:"volume_driver,omitempty"` +} + +// ToClusterCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// Create requests the creation of a new cluster. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToClusterCreateMap() + if err != nil { + r.Err = err + return + } + var result *http.Response + result, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + + if r.Err == nil { + r.Header = result.Header + } + + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/results.go new file mode 100644 index 00000000..e4978ff2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/results.go @@ -0,0 +1,60 @@ +package clustertemplates + +import ( + "time" + + "github.com/gophercloud/gophercloud" +) + +type commonResult struct { + gophercloud.Result +} + +// CreateResult is the response of a Create operations. +type CreateResult struct { + commonResult +} + +// Extract is a function that accepts a result and extracts a cluster-template resource. +func (r commonResult) Extract() (*ClusterTemplate, error) { + var s *ClusterTemplate + err := r.ExtractInto(&s) + return s, err +} + +// Represents a template for a Cluster Template +type ClusterTemplate struct { + APIServerPort string `json:"apiserver_port"` + COE string `json:"coe"` + ClusterDistro string `json:"cluster_distro"` + CreatedAt time.Time `json:"created_at"` + DNSNameServer string `json:"dns_nameserver"` + DockerStorageDriver string `json:"docker_storage_driver"` + DockerVolumeSize int `json:"docker_volume_size"` + ExternalNetworkID string `json:"external_network_id"` + FixedNetwork string `json:"fixed_network"` + FixedSubnet string `json:"fixed_subnet"` + FlavorID string `json:"flavor_id"` + FloatingIPEnabled bool `json:"floating_ip_enabled"` + HTTPProxy string `json:"http_proxy"` + HTTPSProxy string `json:"https_proxy"` + ImageID string `json:"image_id"` + InsecureRegistry string `json:"insecure_registry"` + KeyPairID string `json:"keypair_id"` + Labels map[string]string `json:"labels"` + Links []gophercloud.Link `json:"links"` + MasterFlavorID string `json:"master_flavor_id"` + MasterLBEnabled bool `json:"master_lb_enabled"` + Name string `json:"name"` + NetworkDriver string `json:"network_driver"` + NoProxy string `json:"no_proxy"` + ProjectID string `json:"project_id"` + Public bool `json:"public"` + RegistryEnabled bool `json:"registry_enabled"` + ServerType string `json:"server_type"` + TLSDisabled bool `json:"tls_disabled"` + UUID string `json:"uuid"` + UpdatedAt time.Time `json:"updated_at"` + UserID string `json:"user_id"` + VolumeDriver string `json:"volume_driver"` +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/doc.go new file mode 100644 index 00000000..7603f836 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/doc.go @@ -0,0 +1 @@ +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/fixtures.go new file mode 100644 index 00000000..84893f20 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/fixtures.go @@ -0,0 +1,114 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +const ClusterTemplateResponse = ` +{ + "insecure_registry": null, + "links": [ + { + "href": "http://10.63.176.154:9511/v1/clustertemplates/79c0f9e5-93b8-4719-8fab-063afc67bffe", + "rel": "self" + }, + { + "href": "http://10.63.176.154:9511/clustertemplates/79c0f9e5-93b8-4719-8fab-063afc67bffe", + "rel": "bookmark" + } + ], + "http_proxy": "http://10.164.177.169:8080", + "updated_at": null, + "floating_ip_enabled": true, + "fixed_subnet": null, + "master_flavor_id": null, + "user_id": "c48d66144e9c4a54ae2b164b85cfefe3", + "uuid": "79c0f9e5-93b8-4719-8fab-063afc67bffe", + "no_proxy": "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", + "https_proxy": "http://10.164.177.169:8080", + "tls_disabled": false, + "keypair_id": "kp", + "project_id": "76bd201dbc1641729904ab190d3390c6", + "public": false, + "labels": null, + "docker_volume_size": 3, + "server_type": "vm", + "external_network_id": "public", + "cluster_distro": "fedora-atomic", + "image_id": "Fedora-Atomic-27-20180212.2.x86_64", + "volume_driver": "cinder", + "registry_enabled": false, + "docker_storage_driver": "devicemapper", + "apiserver_port": null, + "name": "kubernetes-dev", + "created_at": "2018-06-27T16:52:21+00:00", + "network_driver": "flannel", + "fixed_network": null, + "coe": "kubernetes", + "flavor_id": "m1.small", + "master_lb_enabled": true, + "dns_nameserver": "8.8.8.8" +}` + +var ExpectedClusterTemplate = clustertemplates.ClusterTemplate{ + InsecureRegistry: "", + Links: []gophercloud.Link{ + {Href: "http://10.63.176.154:9511/v1/clustertemplates/79c0f9e5-93b8-4719-8fab-063afc67bffe", Rel: "self"}, + {Href: "http://10.63.176.154:9511/clustertemplates/79c0f9e5-93b8-4719-8fab-063afc67bffe", Rel: "bookmark"}, + }, + HTTPProxy: "http://10.164.177.169:8080", + UpdatedAt: time.Time{}, + FloatingIPEnabled: true, + FixedSubnet: "", + MasterFlavorID: "", + UserID: "c48d66144e9c4a54ae2b164b85cfefe3", + UUID: "79c0f9e5-93b8-4719-8fab-063afc67bffe", + NoProxy: "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", + HTTPSProxy: "http://10.164.177.169:8080", + TLSDisabled: false, + KeyPairID: "kp", + ProjectID: "76bd201dbc1641729904ab190d3390c6", + Public: false, + Labels: map[string]string(nil), + DockerVolumeSize: 3, + ServerType: "vm", + ExternalNetworkID: "public", + ClusterDistro: "fedora-atomic", + ImageID: "Fedora-Atomic-27-20180212.2.x86_64", + VolumeDriver: "cinder", + RegistryEnabled: false, + DockerStorageDriver: "devicemapper", + APIServerPort: "", + Name: "kubernetes-dev", + CreatedAt: time.Date(2018, 6, 27, 16, 52, 21, 0, time.UTC), + NetworkDriver: "flannel", + FixedNetwork: "", + COE: "kubernetes", + FlavorID: "m1.small", + MasterLBEnabled: true, + DNSNameServer: "8.8.8.8", +} + +func HandleCreateClusterTemplateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v1/clustertemplates", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.Header().Add("OpenStack-API-Minimum-Version", "container-infra 1.1") + w.Header().Add("OpenStack-API-Maximum-Version", "container-infra 1.6") + w.Header().Add("OpenStack-API-Version", "container-infra 1.1") + w.Header().Add("X-OpenStack-Request-Id", "req-781e9bdc-4163-46eb-91c9-786c53188bbb") + w.WriteHeader(http.StatusCreated) + + fmt.Fprint(w, ClusterTemplateResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go new file mode 100644 index 00000000..22572574 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go @@ -0,0 +1,59 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateClusterTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateClusterTemplateSuccessfully(t) + + boolFalse := false + boolTrue := true + dockerVolumeSize := 3 + opts := clustertemplates.CreateOpts{ + Name: "kubernetes-dev", + Labels: map[string]string{}, + FixedSubnet: "", + MasterFlavorID: "", + NoProxy: "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", + HTTPSProxy: "http://10.164.177.169:8080", + TLSDisabled: &boolFalse, + KeyPairID: "kp", + Public: &boolFalse, + HTTPProxy: "http://10.164.177.169:8080", + DockerVolumeSize: &dockerVolumeSize, + ServerType: "vm", + ExternalNetworkID: "public", + ImageID: "Fedora-Atomic-27-20180212.2.x86_64", + VolumeDriver: "cinder", + RegistryEnabled: &boolFalse, + DockerStorageDriver: "devicemapper", + NetworkDriver: "flannel", + FixedNetwork: "", + COE: "kubernetes", + FlavorID: "m1.small", + MasterLBEnabled: &boolTrue, + DNSNameServer: "8.8.8.8", + } + + sc := fake.ServiceClient() + sc.Endpoint = sc.Endpoint + "v1/" + res := clustertemplates.Create(sc, opts) + th.AssertNoErr(t, res.Err) + + requestID := res.Header.Get("X-OpenStack-Request-Id") + th.AssertEquals(t, "req-781e9bdc-4163-46eb-91c9-786c53188bbb", requestID) + + actual, err := res.Extract() + th.AssertNoErr(t, err) + + actual.CreatedAt = actual.CreatedAt.UTC() + th.AssertDeepEquals(t, ExpectedClusterTemplate, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/urls.go new file mode 100644 index 00000000..8aee327b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates/urls.go @@ -0,0 +1,15 @@ +package clustertemplates + +import ( + "github.com/gophercloud/gophercloud" +) + +var apiName = "clustertemplates" + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiName) +} + +func createURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/configurations/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/configurations/testing/requests_test.go new file mode 100644 index 00000000..643f3634 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/configurations/testing/requests_test.go @@ -0,0 +1,237 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" + "github.com/gophercloud/gophercloud/openstack/db/v1/instances" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" + "github.com/gophercloud/gophercloud/testhelper/fixture" +) + +var ( + configID = "{configID}" + _baseURL = "/configurations" + resURL = _baseURL + "/" + configID + + dsID = "{datastoreID}" + versionID = "{versionID}" + paramID = "{paramID}" + dsParamListURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters" + dsParamGetURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters/" + paramID + globalParamListURL = "/datastores/versions/" + versionID + "/parameters" + globalParamGetURL = "/datastores/versions/" + versionID + "/parameters/" + paramID +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, _baseURL, "GET", "", ListConfigsJSON, 200) + + count := 0 + err := configurations.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := configurations.ExtractConfigs(page) + th.AssertNoErr(t, err) + + expected := []configurations.Config{ExampleConfig} + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertEquals(t, 1, count) + th.AssertNoErr(t, err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, resURL, "GET", "", GetConfigJSON, 200) + + config, err := configurations.Get(fake.ServiceClient(), configID).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &ExampleConfig, config) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, _baseURL, "POST", CreateReq, CreateConfigJSON, 200) + + opts := configurations.CreateOpts{ + Datastore: &configurations.DatastoreOpts{ + Type: "a00000a0-00a0-0a00-00a0-000a000000aa", + Version: "b00000b0-00b0-0b00-00b0-000b000000bb", + }, + Description: "example description", + Name: "example-configuration-name", + Values: map[string]interface{}{ + "collation_server": "latin1_swedish_ci", + "connect_timeout": 120, + }, + } + + config, err := configurations.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &ExampleConfigWithValues, config) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, resURL, "PATCH", UpdateReq, "", 200) + + opts := configurations.UpdateOpts{ + Values: map[string]interface{}{ + "connect_timeout": 300, + }, + } + + err := configurations.Update(fake.ServiceClient(), configID, opts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestReplace(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, resURL, "PUT", UpdateReq, "", 202) + + opts := configurations.UpdateOpts{ + Values: map[string]interface{}{ + "connect_timeout": 300, + }, + } + + err := configurations.Replace(fake.ServiceClient(), configID, opts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, resURL, "DELETE", "", "", 202) + + err := configurations.Delete(fake.ServiceClient(), configID).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestListInstances(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, resURL+"/instances", "GET", "", ListInstancesJSON, 200) + + expectedInstance := instances.Instance{ + ID: "d4603f69-ec7e-4e9b-803f-600b9205576f", + Name: "json_rack_instance", + } + + pages := 0 + err := configurations.ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := instances.ExtractInstances(page) + if err != nil { + return false, err + } + + th.AssertDeepEquals(t, actual, []instances.Instance{expectedInstance}) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestListDSParams(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, dsParamListURL, "GET", "", ListParamsJSON, 200) + + pages := 0 + err := configurations.ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := configurations.ExtractParams(page) + if err != nil { + return false, err + } + + expected := []configurations.Param{ + {Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"}, + {Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"}, + {Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"}, + {Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"}, + } + + th.AssertDeepEquals(t, actual, expected) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGetDSParam(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, dsParamGetURL, "GET", "", GetParamJSON, 200) + + param, err := configurations.GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract() + th.AssertNoErr(t, err) + + expected := &configurations.Param{ + Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer", + } + + th.AssertDeepEquals(t, expected, param) +} + +func TestListGlobalParams(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, globalParamListURL, "GET", "", ListParamsJSON, 200) + + pages := 0 + err := configurations.ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := configurations.ExtractParams(page) + if err != nil { + return false, err + } + + expected := []configurations.Param{ + {Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"}, + {Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"}, + {Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"}, + {Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"}, + } + + th.AssertDeepEquals(t, actual, expected) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGetGlobalParam(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, globalParamGetURL, "GET", "", GetParamJSON, 200) + + param, err := configurations.GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract() + th.AssertNoErr(t, err) + + expected := &configurations.Param{ + Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer", + } + + th.AssertDeepEquals(t, expected, param) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/databases/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/databases/testing/requests_test.go new file mode 100644 index 00000000..a470ffa8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/databases/testing/requests_test.go @@ -0,0 +1,67 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/db/v1/databases" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreate(t) + + opts := databases.BatchCreateOpts{ + databases.CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"}, + databases.CreateOpts{Name: "sampledb"}, + } + + res := databases.Create(fake.ServiceClient(), instanceID, opts) + th.AssertNoErr(t, res.Err) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleList(t) + + expectedDBs := []databases.Database{ + {Name: "anotherexampledb"}, + {Name: "exampledb"}, + {Name: "nextround"}, + {Name: "sampledb"}, + {Name: "testingdb"}, + } + + pages := 0 + err := databases.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := databases.ExtractDBs(page) + if err != nil { + return false, err + } + + th.CheckDeepEquals(t, expectedDBs, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDelete(t) + + err := databases.Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/datastores/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/datastores/testing/requests_test.go new file mode 100644 index 00000000..b505726d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/datastores/testing/requests_test.go @@ -0,0 +1,79 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/db/v1/datastores" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" + "github.com/gophercloud/gophercloud/testhelper/fixture" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, "/datastores", "GET", "", ListDSResp, 200) + + pages := 0 + + err := datastores.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := datastores.ExtractDatastores(page) + if err != nil { + return false, err + } + + th.CheckDeepEquals(t, []datastores.Datastore{ExampleDatastore}, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", GetDSResp, 200) + + ds, err := datastores.Get(fake.ServiceClient(), "{dsID}").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &ExampleDatastore, ds) +} + +func TestListVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", ListVersionsResp, 200) + + pages := 0 + + err := datastores.ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := datastores.ExtractVersions(page) + if err != nil { + return false, err + } + + th.CheckDeepEquals(t, ExampleVersions, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGetVersion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", GetVersionResp, 200) + + ds, err := datastores.GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &ExampleVersion1, ds) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/flavors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/flavors/testing/requests_test.go new file mode 100644 index 00000000..e8b580ae --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/flavors/testing/requests_test.go @@ -0,0 +1,107 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/db/v1/flavors" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListFlavors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleList(t) + + pages := 0 + err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := flavors.ExtractFlavors(page) + if err != nil { + return false, err + } + + expected := []flavors.Flavor{ + { + ID: 1, + Name: "m1.tiny", + RAM: 512, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, + {Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"}, + }, + StrID: "1", + }, + { + ID: 2, + Name: "m1.small", + RAM: 1024, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"}, + {Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"}, + }, + StrID: "2", + }, + { + ID: 3, + Name: "m1.medium", + RAM: 2048, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"}, + {Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"}, + }, + StrID: "3", + }, + { + ID: 4, + Name: "m1.large", + RAM: 4096, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"}, + {Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"}, + }, + StrID: "4", + }, + { + ID: 0, + Name: "ds512M", + RAM: 512, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/d1", Rel: "self"}, + {Href: "https://openstack.example.com/flavors/d1", Rel: "bookmark"}, + }, + StrID: "d1", + }, + } + + th.AssertDeepEquals(t, expected, actual) + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGetFlavor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGet(t) + + actual, err := flavors.Get(fake.ServiceClient(), flavorID).Extract() + th.AssertNoErr(t, err) + + expected := &flavors.Flavor{ + ID: 1, + Name: "m1.tiny", + RAM: 512, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, + }, + StrID: "1", + } + + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/results.go index 1a570899..e47a740c 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/results.go @@ -26,6 +26,36 @@ type Flavor struct { Links []gophercloud.Link } +// Fault describes the fault reason in more detail when a database instance has errored +type Fault struct { + // Indicates the time when the fault occured + Created time.Time `json:"-"` + + // A message describing the fault reason + Message string + + // More details about the fault, for example a stack trace. Only filled + // in for admin users. + Details string +} + +func (r *Fault) UnmarshalJSON(b []byte) error { + type tmp Fault + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Fault(s.tmp) + + r.Created = time.Time(s.Created) + + return nil +} + // Instance represents a remote MySQL instance. type Instance struct { // Indicates the datetime that the instance was created @@ -61,6 +91,9 @@ type Instance struct { // The build status of the instance. Status string + // Fault information (only available when the instance has errored) + Fault *Fault + // Information about the attached volume of the instance. Volume Volume diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/fixtures.go index 93643c4f..3555a008 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/fixtures.go @@ -86,6 +86,48 @@ var createReq = ` } ` +var instanceWithFault = ` +{ + "created": "` + timestamp + `", + "datastore": { + "type": "mysql", + "version": "5.6" + }, + "flavor": { + "id": "1", + "links": [ + { + "href": "https://openstack.example.com/v1.0/1234/flavors/1", + "rel": "self" + }, + { + "href": "https://openstack.example.com/v1.0/1234/flavors/1", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "https://openstack.example.com/v1.0/1234/instances/1", + "rel": "self" + } + ], + "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.openstack.example.com", + "id": "{instanceID}", + "name": "json_rack_instance", + "status": "BUILD", + "updated": "` + timestamp + `", + "volume": { + "size": 2 + }, + "fault": { + "message": "some error message", + "created": "` + timestamp + `", + "details": "some details about the error" + } +} +` + var ( instanceID = "{instanceID}" configGroupID = "00000000-0000-0000-0000-000000000000" @@ -104,11 +146,12 @@ var ( ) var ( - createResp = fmt.Sprintf(`{"instance": %s}`, instance) - listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance) - getInstanceResp = createResp - enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}` - isUserEnabledResp = `{"rootEnabled":true}` + createResp = fmt.Sprintf(`{"instance": %s}`, instance) + createWithFaultResp = fmt.Sprintf(`{"instance": %s}`, instanceWithFault) + listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance) + getInstanceResp = createResp + enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}` + isUserEnabledResp = `{"rootEnabled":true}` ) var expectedInstance = instances.Instance{ @@ -135,10 +178,43 @@ var expectedInstance = instances.Instance{ }, } +var expectedInstanceWithFault = instances.Instance{ + Created: timeVal, + Updated: timeVal, + Flavor: instances.Flavor{ + ID: "1", + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, + {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "bookmark"}, + }, + }, + Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.openstack.example.com", + ID: instanceID, + Links: []gophercloud.Link{ + {Href: "https://openstack.example.com/v1.0/1234/instances/1", Rel: "self"}, + }, + Name: "json_rack_instance", + Status: "BUILD", + Volume: instances.Volume{Size: 2}, + Datastore: datastores.DatastorePartial{ + Type: "mysql", + Version: "5.6", + }, + Fault: &instances.Fault{ + Created: timeVal, + Message: "some error message", + Details: "some details about the error", + }, +} + func HandleCreate(t *testing.T) { fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200) } +func HandleCreateWithFault(t *testing.T) { + fixture.SetupHandler(t, rootURL, "POST", createReq, createWithFaultResp, 200) +} + func HandleList(t *testing.T) { fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/requests_test.go new file mode 100644 index 00000000..6e6c4f12 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/instances/testing/requests_test.go @@ -0,0 +1,182 @@ +package testing + +import ( + "testing" + + db "github.com/gophercloud/gophercloud/openstack/db/v1/databases" + "github.com/gophercloud/gophercloud/openstack/db/v1/instances" + "github.com/gophercloud/gophercloud/openstack/db/v1/users" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreate(t) + + opts := instances.CreateOpts{ + Name: "json_rack_instance", + FlavorRef: "1", + Databases: db.BatchCreateOpts{ + {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, + {Name: "nextround"}, + }, + Users: users.BatchCreateOpts{ + { + Name: "demouser", + Password: "demopassword", + Databases: db.BatchCreateOpts{ + {Name: "sampledb"}, + }, + }, + }, + Size: 2, + } + + instance, err := instances.Create(fake.ServiceClient(), opts).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &expectedInstance, instance) +} + +func TestCreateWithFault(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateWithFault(t) + + opts := instances.CreateOpts{ + Name: "json_rack_instance", + FlavorRef: "1", + Databases: db.BatchCreateOpts{ + {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, + {Name: "nextround"}, + }, + Users: users.BatchCreateOpts{ + { + Name: "demouser", + Password: "demopassword", + Databases: db.BatchCreateOpts{ + {Name: "sampledb"}, + }, + }, + }, + Size: 2, + } + + instance, err := instances.Create(fake.ServiceClient(), opts).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &expectedInstanceWithFault, instance) +} + +func TestInstanceList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleList(t) + + pages := 0 + err := instances.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := instances.ExtractInstances(page) + if err != nil { + return false, err + } + + th.CheckDeepEquals(t, []instances.Instance{expectedInstance}, actual) + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestGetInstance(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGet(t) + + instance, err := instances.Get(fake.ServiceClient(), instanceID).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, &expectedInstance, instance) +} + +func TestDeleteInstance(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDelete(t) + + res := instances.Delete(fake.ServiceClient(), instanceID) + th.AssertNoErr(t, res.Err) +} + +func TestEnableRootUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleEnableRoot(t) + + expected := &users.User{Name: "root", Password: "secretsecret"} + user, err := instances.EnableRootUser(fake.ServiceClient(), instanceID).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expected, user) +} + +func TestIsRootEnabled(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleIsRootEnabled(t) + + isEnabled, err := instances.IsRootEnabled(fake.ServiceClient(), instanceID).Extract() + + th.AssertNoErr(t, err) + th.AssertEquals(t, true, isEnabled) +} + +func TestRestart(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRestart(t) + + res := instances.Restart(fake.ServiceClient(), instanceID) + th.AssertNoErr(t, res.Err) +} + +func TestResize(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleResize(t) + + res := instances.Resize(fake.ServiceClient(), instanceID, "2") + th.AssertNoErr(t, res.Err) +} + +func TestResizeVolume(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleResizeVol(t) + + res := instances.ResizeVolume(fake.ServiceClient(), instanceID, 4) + th.AssertNoErr(t, res.Err) +} + +func TestAttachConfigurationGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAttachConfigurationGroup(t) + + res := instances.AttachConfigurationGroup(fake.ServiceClient(), instanceID, configGroupID) + th.AssertNoErr(t, res.Err) +} + +func TestDetachConfigurationGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDetachConfigurationGroup(t) + + res := instances.DetachConfigurationGroup(fake.ServiceClient(), instanceID) + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/users/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/users/testing/requests_test.go new file mode 100644 index 00000000..952f245e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/db/v1/users/testing/requests_test.go @@ -0,0 +1,85 @@ +package testing + +import ( + "testing" + + db "github.com/gophercloud/gophercloud/openstack/db/v1/databases" + "github.com/gophercloud/gophercloud/openstack/db/v1/users" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreate(t) + + opts := users.BatchCreateOpts{ + { + Databases: db.BatchCreateOpts{ + db.CreateOpts{Name: "databaseA"}, + }, + Name: "dbuser3", + Password: "secretsecret", + }, + { + Databases: db.BatchCreateOpts{ + {Name: "databaseB"}, + {Name: "databaseC"}, + }, + Name: "dbuser4", + Password: "secretsecret", + }, + } + + res := users.Create(fake.ServiceClient(), instanceID, opts) + th.AssertNoErr(t, res.Err) +} + +func TestUserList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleList(t) + + expectedUsers := []users.User{ + { + Databases: []db.Database{ + db.Database{Name: "databaseA"}, + }, + Name: "dbuser3", + }, + { + Databases: []db.Database{ + {Name: "databaseB"}, + {Name: "databaseC"}, + }, + Name: "dbuser4", + }, + } + + pages := 0 + err := users.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := users.ExtractUsers(page) + if err != nil { + return false, err + } + + th.CheckDeepEquals(t, expectedUsers, actual) + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDelete(t) + + res := users.Delete(fake.ServiceClient(), instanceID, "{userName}") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets/testing/requests_test.go new file mode 100644 index 00000000..21630152 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets/testing/requests_test.go @@ -0,0 +1,145 @@ +package testing + +import ( + "encoding/json" + "testing" + + "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListByZone(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListByZoneSuccessfully(t) + + count := 0 + err := recordsets.ListByZone(client.ServiceClient(), "2150b1bf-dee2-4221-9d85-11f7886fb15f", nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := recordsets.ExtractRecordSets(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRecordSetSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestListByZoneLimited(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListByZoneSuccessfully(t) + + count := 0 + listOpts := recordsets.ListOpts{ + Limit: 1, + Marker: "f7b10e9b-0cae-4a91-b162-562bc6096648", + } + err := recordsets.ListByZone(client.ServiceClient(), "2150b1bf-dee2-4221-9d85-11f7886fb15f", listOpts).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := recordsets.ExtractRecordSets(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRecordSetSliceLimited, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestListByZoneAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListByZoneSuccessfully(t) + + allPages, err := recordsets.ListByZone(client.ServiceClient(), "2150b1bf-dee2-4221-9d85-11f7886fb15f", nil).AllPages() + th.AssertNoErr(t, err) + allRecordSets, err := recordsets.ExtractRecordSets(allPages) + th.AssertNoErr(t, err) + th.CheckEquals(t, 2, len(allRecordSets)) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := recordsets.Get(client.ServiceClient(), "2150b1bf-dee2-4221-9d85-11f7886fb15f", "f7b10e9b-0cae-4a91-b162-562bc6096648").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstRecordSet, actual) +} + +func TestNextPageURL(t *testing.T) { + var page recordsets.RecordSetPage + var body map[string]interface{} + err := json.Unmarshal([]byte(NextPageRequest), &body) + if err != nil { + t.Fatalf("Error unmarshaling data into page body: %v", err) + } + page.Body = body + expected := "http://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets?limit=1&marker=f7b10e9b-0cae-4a91-b162-562bc6096648" + actual, err := page.NextPageURL() + th.AssertNoErr(t, err) + th.CheckEquals(t, expected, actual) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + createOpts := recordsets.CreateOpts{ + Name: "example.org.", + Type: "A", + TTL: 3600, + Description: "This is an example record set.", + Records: []string{"10.1.0.2"}, + } + + actual, err := recordsets.Create(client.ServiceClient(), "2150b1bf-dee2-4221-9d85-11f7886fb15f", createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedRecordSet, actual) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + updateOpts := recordsets.UpdateOpts{ + TTL: 0, + Description: "Updated description", + Records: []string{"10.1.0.2", "10.1.0.3"}, + } + + UpdatedRecordSet := CreatedRecordSet + UpdatedRecordSet.Status = "PENDING" + UpdatedRecordSet.Action = "UPDATE" + UpdatedRecordSet.Description = "Updated description" + UpdatedRecordSet.Records = []string{"10.1.0.2", "10.1.0.3"} + UpdatedRecordSet.Version = 2 + + actual, err := recordsets.Update(client.ServiceClient(), UpdatedRecordSet.ZoneID, UpdatedRecordSet.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &UpdatedRecordSet, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + DeletedRecordSet := CreatedRecordSet + DeletedRecordSet.Status = "PENDING" + DeletedRecordSet.Action = "UPDATE" + DeletedRecordSet.Description = "Updated description" + DeletedRecordSet.Records = []string{"10.1.0.2", "10.1.0.3"} + DeletedRecordSet.Version = 2 + + err := recordsets.Delete(client.ServiceClient(), DeletedRecordSet.ZoneID, DeletedRecordSet.ID).ExtractErr() + th.AssertNoErr(t, err) + //th.CheckDeepEquals(t, &DeletedZone, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/zones/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/zones/testing/requests_test.go new file mode 100644 index 00000000..412b3493 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/zones/testing/requests_test.go @@ -0,0 +1,105 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + count := 0 + err := zones.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := zones.ExtractZones(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedZonesSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestListAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + allPages, err := zones.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + allZones, err := zones.ExtractZones(allPages) + th.AssertNoErr(t, err) + th.CheckEquals(t, 2, len(allZones)) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := zones.Get(client.ServiceClient(), "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstZone, actual) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + createOpts := zones.CreateOpts{ + Name: "example.org.", + Email: "joe@example.org", + Type: "PRIMARY", + TTL: 7200, + Description: "This is an example zone.", + } + + actual, err := zones.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &CreatedZone, actual) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + updateOpts := zones.UpdateOpts{ + TTL: 600, + Description: "Updated Description", + } + + UpdatedZone := CreatedZone + UpdatedZone.Status = "PENDING" + UpdatedZone.Action = "UPDATE" + UpdatedZone.TTL = 600 + UpdatedZone.Description = "Updated Description" + + actual, err := zones.Update(client.ServiceClient(), UpdatedZone.ID, updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &UpdatedZone, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + DeletedZone := CreatedZone + DeletedZone.Status = "PENDING" + DeletedZone.Action = "DELETE" + DeletedZone.TTL = 600 + DeletedZone.Description = "Updated Description" + + actual, err := zones.Delete(client.ServiceClient(), DeletedZone.ID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &DeletedZone, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/endpoint_location.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/endpoint_location.go index 070ea7cb..12c8aebc 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/endpoint_location.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/endpoint_location.go @@ -84,7 +84,7 @@ func V3EndpointURL(catalog *tokens3.ServiceCatalog, opts gophercloud.EndpointOpt return "", err } if (opts.Availability == gophercloud.Availability(endpoint.Interface)) && - (opts.Region == "" || endpoint.Region == opts.Region) { + (opts.Region == "" || endpoint.Region == opts.Region || endpoint.RegionID == opts.Region) { endpoints = append(endpoints, endpoint) } } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go new file mode 100644 index 00000000..8cf53955 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go @@ -0,0 +1,65 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestRole(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListRoleResponse(t) + + count := 0 + + err := roles.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := roles.ExtractRoles(page) + if err != nil { + t.Errorf("Failed to extract users: %v", err) + return false, err + } + + expected := []roles.Role{ + { + ID: "123", + Name: "compute:admin", + Description: "Nova Administrator", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, count) +} + +func TestAddUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockAddUserRoleResponse(t) + + err := roles.AddUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr() + + th.AssertNoErr(t, err) +} + +func TestDeleteUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteUserRoleResponse(t) + + err := roles.DeleteUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr() + + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/testing/delegate_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/testing/delegate_test.go new file mode 100644 index 00000000..e7869d8d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/testing/delegate_test.go @@ -0,0 +1,39 @@ +package testing + +import ( + "testing" + + common "github.com/gophercloud/gophercloud/openstack/common/extensions/testing" + "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListExtensionsSuccessfully(t) + + count := 0 + err := extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := extensions.ExtractExtensions(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, common.ExpectedExtensions, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + common.HandleGetExtensionSuccessfully(t) + + actual, err := extensions.Get(client.ServiceClient(), "agent").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, common.SingleExtension, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/testing/requests_test.go new file mode 100644 index 00000000..86f2c947 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/testing/requests_test.go @@ -0,0 +1,113 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListTenants(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListTenantsSuccessfully(t) + + count := 0 + err := tenants.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := tenants.ExtractTenants(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedTenantSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestCreateTenant(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockCreateTenantResponse(t) + + opts := tenants.CreateOpts{ + Name: "new_tenant", + Description: "This is new tenant", + Enabled: gophercloud.Enabled, + } + + tenant, err := tenants.Create(client.ServiceClient(), opts).Extract() + + th.AssertNoErr(t, err) + + expected := &tenants.Tenant{ + Name: "new_tenant", + Description: "This is new tenant", + Enabled: true, + ID: "5c62ef576dc7444cbb73b1fe84b97648", + } + + th.AssertDeepEquals(t, expected, tenant) +} + +func TestDeleteTenant(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockDeleteTenantResponse(t) + + err := tenants.Delete(client.ServiceClient(), "2466f69cd4714d89a548a68ed97ffcd4").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUpdateTenant(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockUpdateTenantResponse(t) + + id := "5c62ef576dc7444cbb73b1fe84b97648" + opts := tenants.UpdateOpts{ + Name: "new_name", + Description: "This is new name", + Enabled: gophercloud.Enabled, + } + + tenant, err := tenants.Update(client.ServiceClient(), id, opts).Extract() + + th.AssertNoErr(t, err) + + expected := &tenants.Tenant{ + Name: "new_name", + ID: id, + Description: "This is new name", + Enabled: true, + } + + th.AssertDeepEquals(t, expected, tenant) +} + +func TestGetTenant(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockGetTenantResponse(t) + + tenant, err := tenants.Get(client.ServiceClient(), "5c62ef576dc7444cbb73b1fe84b97648").Extract() + th.AssertNoErr(t, err) + + expected := &tenants.Tenant{ + Name: "new_tenant", + ID: "5c62ef576dc7444cbb73b1fe84b97648", + Description: "This is new tenant", + Enabled: true, + } + + th.AssertDeepEquals(t, expected, tenant) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/testing/requests_test.go new file mode 100644 index 00000000..b687a929 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tokens/testing/requests_test.go @@ -0,0 +1,104 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) tokens.CreateResult { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleTokenPost(t, requestJSON) + + return tokens.Create(client.ServiceClient(), options) +} + +func tokenPostErr(t *testing.T, options gophercloud.AuthOptions, expectedErr error) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleTokenPost(t, "") + + actualErr := tokens.Create(client.ServiceClient(), options).Err + th.CheckDeepEquals(t, expectedErr, actualErr) +} + +func TestCreateWithPassword(t *testing.T) { + options := gophercloud.AuthOptions{ + Username: "me", + Password: "swordfish", + } + + IsSuccessful(t, tokenPost(t, options, ` + { + "auth": { + "passwordCredentials": { + "username": "me", + "password": "swordfish" + } + } + } + `)) +} + +func TestCreateTokenWithTenantID(t *testing.T) { + options := gophercloud.AuthOptions{ + Username: "me", + Password: "opensesame", + TenantID: "fc394f2ab2df4114bde39905f800dc57", + } + + IsSuccessful(t, tokenPost(t, options, ` + { + "auth": { + "tenantId": "fc394f2ab2df4114bde39905f800dc57", + "passwordCredentials": { + "username": "me", + "password": "opensesame" + } + } + } + `)) +} + +func TestCreateTokenWithTenantName(t *testing.T) { + options := gophercloud.AuthOptions{ + Username: "me", + Password: "opensesame", + TenantName: "demo", + } + + IsSuccessful(t, tokenPost(t, options, ` + { + "auth": { + "tenantName": "demo", + "passwordCredentials": { + "username": "me", + "password": "opensesame" + } + } + } + `)) +} + +func TestRequireUsername(t *testing.T) { + options := gophercloud.AuthOptions{ + Password: "thing", + } + + tokenPostErr(t, options, gophercloud.ErrMissingInput{Argument: "Username"}) +} + +func tokenGet(t *testing.T, tokenId string) tokens.GetResult { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleTokenGet(t, tokenId) + return tokens.Get(client.ServiceClient(), tokenId) +} + +func TestGetWithToken(t *testing.T) { + GetIsSuccessful(t, tokenGet(t, "db22caf43c934e6c829087c41ff8d8d6")) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/users/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/users/testing/requests_test.go new file mode 100644 index 00000000..3cb047e2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/users/testing/requests_test.go @@ -0,0 +1,161 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/identity/v2/users" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListUserResponse(t) + + count := 0 + + err := users.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := users.ExtractUsers(page) + th.AssertNoErr(t, err) + + expected := []users.User{ + { + ID: "u1000", + Name: "John Smith", + Username: "jqsmith", + Email: "john.smith@example.org", + Enabled: true, + TenantID: "12345", + }, + { + ID: "u1001", + Name: "Jane Smith", + Username: "jqsmith", + Email: "jane.smith@example.org", + Enabled: true, + TenantID: "12345", + }, + } + th.CheckDeepEquals(t, expected, actual) + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, count) +} + +func TestCreateUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockCreateUserResponse(t) + + opts := users.CreateOpts{ + Name: "new_user", + TenantID: "12345", + Enabled: gophercloud.Disabled, + Email: "new_user@foo.com", + } + + user, err := users.Create(client.ServiceClient(), opts).Extract() + + th.AssertNoErr(t, err) + + expected := &users.User{ + Name: "new_user", + ID: "c39e3de9be2d4c779f1dfd6abacc176d", + Email: "new_user@foo.com", + Enabled: false, + TenantID: "12345", + } + + th.AssertDeepEquals(t, expected, user) +} + +func TestGetUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockGetUserResponse(t) + + user, err := users.Get(client.ServiceClient(), "new_user").Extract() + th.AssertNoErr(t, err) + + expected := &users.User{ + Name: "new_user", + ID: "c39e3de9be2d4c779f1dfd6abacc176d", + Email: "new_user@foo.com", + Enabled: false, + TenantID: "12345", + } + + th.AssertDeepEquals(t, expected, user) +} + +func TestUpdateUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockUpdateUserResponse(t) + + id := "c39e3de9be2d4c779f1dfd6abacc176d" + opts := users.UpdateOpts{ + Name: "new_name", + Enabled: gophercloud.Enabled, + Email: "new_email@foo.com", + } + + user, err := users.Update(client.ServiceClient(), id, opts).Extract() + + th.AssertNoErr(t, err) + + expected := &users.User{ + Name: "new_name", + ID: id, + Email: "new_email@foo.com", + Enabled: true, + TenantID: "12345", + } + + th.AssertDeepEquals(t, expected, user) +} + +func TestDeleteUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockDeleteUserResponse(t) + + res := users.Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d") + th.AssertNoErr(t, res.Err) +} + +func TestListingUserRoles(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + mockListRolesResponse(t) + + tenantID := "1d8b6120dcc640fda4fc9194ffc80273" + userID := "c39e3de9be2d4c779f1dfd6abacc176d" + + err := users.ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) { + actual, err := users.ExtractRoles(page) + th.AssertNoErr(t, err) + + expected := []users.Role{ + {ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"}, + {ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"}, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/domains/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/domains/testing/requests_test.go new file mode 100644 index 00000000..73ac97aa --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/domains/testing/requests_test.go @@ -0,0 +1,89 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/domains" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListDomains(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListDomainsSuccessfully(t) + + count := 0 + err := domains.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := domains.ExtractDomains(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedDomainsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListDomainsAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListDomainsSuccessfully(t) + + allPages, err := domains.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := domains.ExtractDomains(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedDomainsSlice, actual) +} + +func TestGetDomain(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetDomainSuccessfully(t) + + actual, err := domains.Get(client.ServiceClient(), "9fe1d3").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondDomain, *actual) +} + +func TestCreateDomain(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateDomainSuccessfully(t) + + createOpts := domains.CreateOpts{ + Name: "domain two", + } + + actual, err := domains.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondDomain, *actual) +} + +func TestDeleteDomain(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteDomainSuccessfully(t) + + res := domains.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateDomain(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateDomainSuccessfully(t) + + updateOpts := domains.UpdateOpts{ + Description: "Staging Domain", + } + + actual, err := domains.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondDomainUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/requests.go index 645632dd..0764a118 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/requests.go @@ -61,11 +61,8 @@ type ListOpts struct { // ServiceID is the ID of the service the Endpoint refers to. ServiceID string `q:"service_id"` - // Page is a result page to reference in the results. - Page int `q:"page"` - - // PerPage determines how many results per page are returned. - PerPage int `q:"per_page"` + // RegionID is the ID of the region the Endpoint refers to. + RegionID int `q:"region_id"` } // ToEndpointListParams builds a list request from the List options. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/testing/requests_test.go new file mode 100644 index 00000000..53d84888 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints/testing/requests_test.go @@ -0,0 +1,214 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateSuccessful(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/endpoints", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, ` + { + "endpoint": { + "interface": "public", + "name": "the-endiest-of-points", + "region": "underground", + "url": "https://1.2.3.4:9000/", + "service_id": "asdfasdfasdfasdf" + } + } + `) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, ` + { + "endpoint": { + "id": "12", + "interface": "public", + "links": { + "self": "https://localhost:5000/v3/endpoints/12" + }, + "name": "the-endiest-of-points", + "region": "underground", + "service_id": "asdfasdfasdfasdf", + "url": "https://1.2.3.4:9000/" + } + } + `) + }) + + actual, err := endpoints.Create(client.ServiceClient(), endpoints.CreateOpts{ + Availability: gophercloud.AvailabilityPublic, + Name: "the-endiest-of-points", + Region: "underground", + URL: "https://1.2.3.4:9000/", + ServiceID: "asdfasdfasdfasdf", + }).Extract() + th.AssertNoErr(t, err) + + expected := &endpoints.Endpoint{ + ID: "12", + Availability: gophercloud.AvailabilityPublic, + Name: "the-endiest-of-points", + Region: "underground", + ServiceID: "asdfasdfasdfasdf", + URL: "https://1.2.3.4:9000/", + } + + th.AssertDeepEquals(t, expected, actual) +} + +func TestListEndpoints(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/endpoints", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "endpoints": [ + { + "id": "12", + "interface": "public", + "links": { + "self": "https://localhost:5000/v3/endpoints/12" + }, + "name": "the-endiest-of-points", + "region": "underground", + "service_id": "asdfasdfasdfasdf", + "url": "https://1.2.3.4:9000/" + }, + { + "id": "13", + "interface": "internal", + "links": { + "self": "https://localhost:5000/v3/endpoints/13" + }, + "name": "shhhh", + "region": "underground", + "service_id": "asdfasdfasdfasdf", + "url": "https://1.2.3.4:9001/" + } + ], + "links": { + "next": null, + "previous": null + } + } + `) + }) + + count := 0 + endpoints.List(client.ServiceClient(), endpoints.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := endpoints.ExtractEndpoints(page) + if err != nil { + t.Errorf("Failed to extract endpoints: %v", err) + return false, err + } + + expected := []endpoints.Endpoint{ + { + ID: "12", + Availability: gophercloud.AvailabilityPublic, + Name: "the-endiest-of-points", + Region: "underground", + ServiceID: "asdfasdfasdfasdf", + URL: "https://1.2.3.4:9000/", + }, + { + ID: "13", + Availability: gophercloud.AvailabilityInternal, + Name: "shhhh", + Region: "underground", + ServiceID: "asdfasdfasdfasdf", + URL: "https://1.2.3.4:9001/", + }, + } + th.AssertDeepEquals(t, expected, actual) + return true, nil + }) + th.AssertEquals(t, 1, count) +} + +func TestUpdateEndpoint(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/endpoints/12", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, ` + { + "endpoint": { + "name": "renamed", + "region": "somewhere-else" + } + } + `) + + fmt.Fprintf(w, ` + { + "endpoint": { + "id": "12", + "interface": "public", + "links": { + "self": "https://localhost:5000/v3/endpoints/12" + }, + "name": "renamed", + "region": "somewhere-else", + "service_id": "asdfasdfasdfasdf", + "url": "https://1.2.3.4:9000/" + } + } + `) + }) + + actual, err := endpoints.Update(client.ServiceClient(), "12", endpoints.UpdateOpts{ + Name: "renamed", + Region: "somewhere-else", + }).Extract() + if err != nil { + t.Fatalf("Unexpected error from Update: %v", err) + } + + expected := &endpoints.Endpoint{ + ID: "12", + Availability: gophercloud.AvailabilityPublic, + Name: "renamed", + Region: "somewhere-else", + ServiceID: "asdfasdfasdfasdf", + URL: "https://1.2.3.4:9000/", + } + th.AssertDeepEquals(t, expected, actual) +} + +func TestDeleteEndpoint(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/endpoints/34", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) + + res := endpoints.Delete(client.ServiceClient(), "34") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts/testing/requests_test.go new file mode 100644 index 00000000..f8a65adb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts/testing/requests_test.go @@ -0,0 +1,74 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts" + "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateUserIDPasswordTrustID(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + ao := trusts.AuthOptsExt{ + TrustID: "de0945a", + AuthOptionsBuilder: &tokens.AuthOptions{ + UserID: "me", + Password: "squirrel!", + }, + } + HandleCreateTokenWithTrustID(t, ao, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { "id": "me", "password": "squirrel!" } + } + }, + "scope": { + "OS-TRUST:trust": { + "id": "de0945a" + } + } + } + } + `) + + var actual struct { + tokens.Token + trusts.TokenExt + } + err := tokens.Create(client.ServiceClient(), ao).ExtractInto(&actual) + if err != nil { + t.Errorf("Create returned an error: %v", err) + } + expected := struct { + tokens.Token + trusts.TokenExt + }{ + tokens.Token{ + ExpiresAt: time.Date(2013, 02, 27, 18, 30, 59, 999999000, time.UTC), + }, + trusts.TokenExt{ + Trust: trusts.Trust{ + ID: "fe0aef", + Impersonation: false, + TrusteeUser: trusts.TrusteeUser{ + ID: "0ca8f6", + }, + TrustorUser: trusts.TrustorUser{ + ID: "bd263c", + }, + RedelegatedTrustID: "3ba234", + RedelegationCount: 2, + }, + }, + } + + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/errors.go new file mode 100644 index 00000000..98e6fe4b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/errors.go @@ -0,0 +1,17 @@ +package groups + +import "fmt" + +// InvalidListFilter is returned by the ToUserListQuery method when validation of +// a filter does not pass +type InvalidListFilter struct { + FilterName string +} + +func (e InvalidListFilter) Error() string { + s := fmt.Sprintf( + "Invalid filter name [%s]: it must be in format of NAME__COMPARATOR", + e.FilterName, + ) + return s +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/requests.go index b6e74dcf..cc991204 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/requests.go @@ -1,6 +1,9 @@ package groups import ( + "net/url" + "strings" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" ) @@ -18,11 +21,30 @@ type ListOpts struct { // Name filters the response by group name. Name string `q:"name"` + + // Filters filters the response by custom filters such as + // 'name__contains=foo' + Filters map[string]string `q:"-"` } // ToGroupListQuery formats a ListOpts into a query string. func (opts ListOpts) ToGroupListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + + params := q.Query() + for k, v := range opts.Filters { + i := strings.Index(k, "__") + if i > 0 && i < len(k)-2 { + params.Add(k, v) + } else { + return "", InvalidListFilter{FilterName: k} + } + } + + q = &url.URL{RawQuery: params.Encode()} return q.String(), err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/testing/requests_test.go new file mode 100644 index 00000000..b62779a9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/groups/testing/requests_test.go @@ -0,0 +1,133 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListGroupsSuccessfully(t) + + count := 0 + err := groups.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := groups.ExtractGroups(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedGroupsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListGroupsAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListGroupsSuccessfully(t) + + allPages, err := groups.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := groups.ExtractGroups(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedGroupsSlice, actual) + th.AssertEquals(t, ExpectedGroupsSlice[0].Extra["email"], "support@localhost") + th.AssertEquals(t, ExpectedGroupsSlice[1].Extra["email"], "support@example.com") +} + +func TestListGroupsFiltersCheck(t *testing.T) { + type test struct { + filterName string + wantErr bool + } + tests := []test{ + {"foo__contains", false}, + {"foo", true}, + {"foo_contains", true}, + {"foo__", true}, + {"__foo", true}, + } + + var listOpts groups.ListOpts + for _, _test := range tests { + listOpts.Filters = map[string]string{_test.filterName: "bar"} + _, err := listOpts.ToGroupListQuery() + + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case groups.InvalidListFilter: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestGetGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetGroupSuccessfully(t) + + actual, err := groups.Get(client.ServiceClient(), "9fe1d3").Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondGroup, *actual) + th.AssertEquals(t, SecondGroup.Extra["email"], "support@example.com") +} + +func TestCreateGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateGroupSuccessfully(t) + + createOpts := groups.CreateOpts{ + Name: "support", + DomainID: "1789d1", + Description: "group for support users", + Extra: map[string]interface{}{ + "email": "support@example.com", + }, + } + + actual, err := groups.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondGroup, *actual) +} + +func TestUpdateGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateGroupSuccessfully(t) + + updateOpts := groups.UpdateOpts{ + Description: "L2 Support Team", + Extra: map[string]interface{}{ + "email": "supportteam@example.com", + }, + } + + actual, err := groups.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondGroupUpdated, *actual) +} + +func TestDeleteGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteGroupSuccessfully(t) + + res := groups.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/doc.go new file mode 100644 index 00000000..0bdc7a68 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/doc.go @@ -0,0 +1,77 @@ +/* +Package policies provides information and interaction with the policies API +resource for the OpenStack Identity service. + +Example to List Policies + + listOpts := policies.ListOpts{ + Type: "application/json", + } + + allPages, err := policies.List(identityClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allPolicies, err := policies.ExtractPolicies(allPages) + if err != nil { + panic(err) + } + + for _, policy := range allPolicies { + fmt.Printf("%+v\n", policy) + } + +Example to Create a Policy + + createOpts := policies.CreateOpts{ + Type: "application/json", + Blob: []byte("{'foobar_user': 'role:compute-user'}"), + Extra: map[string]interface{}{ + "description": "policy for foobar_user", + }, + } + + policy, err := policies.Create(identityClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Get a Policy + + policyID := "0fe36e73809d46aeae6705c39077b1b3" + policy, err := policies.Get(identityClient, policyID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", policy) + +Example to Update a Policy + + policyID := "0fe36e73809d46aeae6705c39077b1b3" + + updateOpts := policies.UpdateOpts{ + Type: "application/json", + Blob: []byte("{'foobar_user': 'role:compute-user'}"), + Extra: map[string]interface{}{ + "description": "policy for foobar_user", + }, + } + + policy, err := policies.Update(identityClient, policyID, updateOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", policy) + +Example to Delete a Policy + + policyID := "0fe36e73809d46aeae6705c39077b1b3" + err := policies.Delete(identityClient, policyID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package policies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/errors.go new file mode 100644 index 00000000..27fb4b1c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/errors.go @@ -0,0 +1,31 @@ +package policies + +import "fmt" + +// InvalidListFilter is returned by the ToPolicyListQuery method when +// validation of a filter does not pass +type InvalidListFilter struct { + FilterName string +} + +func (e InvalidListFilter) Error() string { + s := fmt.Sprintf( + "Invalid filter name [%s]: it must be in format of TYPE__COMPARATOR", + e.FilterName, + ) + return s +} + +// StringFieldLengthExceedsLimit is returned by the +// ToPolicyCreateMap/ToPolicyUpdateMap methods when validation of +// a type does not pass +type StringFieldLengthExceedsLimit struct { + Field string + Limit int +} + +func (e StringFieldLengthExceedsLimit) Error() string { + return fmt.Sprintf("String length of field [%s] exceeds limit (%d)", + e.Field, e.Limit, + ) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/requests.go new file mode 100644 index 00000000..c9640b22 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/requests.go @@ -0,0 +1,195 @@ +package policies + +import ( + "net/url" + "strings" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +const policyTypeMaxLength = 255 + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request +type ListOptsBuilder interface { + ToPolicyListQuery() (string, error) +} + +// ListOpts provides options to filter the List results. +type ListOpts struct { + // Type filters the response by MIME media type + // of the serialized policy blob. + Type string `q:"type"` + + // Filters filters the response by custom filters such as + // 'type__contains=foo' + Filters map[string]string `q:"-"` +} + +// ToPolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + + params := q.Query() + for k, v := range opts.Filters { + i := strings.Index(k, "__") + if i > 0 && i < len(k)-2 { + params.Add(k, v) + } else { + return "", InvalidListFilter{FilterName: k} + } + } + + q = &url.URL{RawQuery: params.Encode()} + return q.String(), err +} + +// List enumerates the policies to which the current token has access. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return PolicyPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// CreateOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateOptsBuilder interface { + ToPolicyCreateMap() (map[string]interface{}, error) +} + +// CreateOpts provides options used to create a policy. +type CreateOpts struct { + // Type is the MIME media type of the serialized policy blob. + Type string `json:"type" required:"true"` + + // Blob is the policy rule as a serialized blob. + Blob []byte `json:"-" required:"true"` + + // Extra is free-form extra key/value pairs to describe the policy. + Extra map[string]interface{} `json:"-"` +} + +// ToPolicyCreateMap formats a CreateOpts into a create request. +func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { + if len(opts.Type) > policyTypeMaxLength { + return nil, StringFieldLengthExceedsLimit{ + Field: "type", + Limit: policyTypeMaxLength, + } + } + + b, err := gophercloud.BuildRequestBody(opts, "policy") + if err != nil { + return nil, err + } + + if v, ok := b["policy"].(map[string]interface{}); ok { + v["blob"] = string(opts.Blob) + + if opts.Extra != nil { + for key, value := range opts.Extra { + v[key] = value + } + } + } + + return b, nil +} + +// Create creates a new Policy. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// Get retrieves details on a single policy, by ID. +func Get(client *gophercloud.ServiceClient, policyID string) (r GetResult) { + _, r.Err = client.Get(getURL(client, policyID), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to +// the Update request. +type UpdateOptsBuilder interface { + ToPolicyUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts provides options for updating a policy. +type UpdateOpts struct { + // Type is the MIME media type of the serialized policy blob. + Type string `json:"type,omitempty"` + + // Blob is the policy rule as a serialized blob. + Blob []byte `json:"-"` + + // Extra is free-form extra key/value pairs to describe the policy. + Extra map[string]interface{} `json:"-"` +} + +// ToPolicyUpdateMap formats a UpdateOpts into an update request. +func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { + if len(opts.Type) > policyTypeMaxLength { + return nil, StringFieldLengthExceedsLimit{ + Field: "type", + Limit: policyTypeMaxLength, + } + } + + b, err := gophercloud.BuildRequestBody(opts, "policy") + if err != nil { + return nil, err + } + + if v, ok := b["policy"].(map[string]interface{}); ok { + if len(opts.Blob) != 0 { + v["blob"] = string(opts.Blob) + } + + if opts.Extra != nil { + for key, value := range opts.Extra { + v[key] = value + } + } + } + + return b, nil +} + +// Update updates an existing Role. +func Update(client *gophercloud.ServiceClient, policyID string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Patch(updateURL(client, policyID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Delete deletes a policy. +func Delete(client *gophercloud.ServiceClient, policyID string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, policyID), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/results.go new file mode 100644 index 00000000..131a9f81 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/results.go @@ -0,0 +1,131 @@ +package policies + +import ( + "encoding/json" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/internal" + "github.com/gophercloud/gophercloud/pagination" +) + +// Policy is an arbitrarily serialized policy engine rule +// set to be consumed by a remote service. +type Policy struct { + // ID is the unique ID of the policy. + ID string `json:"id"` + + // Blob is the policy rule as a serialized blob. + Blob string `json:"blob"` + + // Type is the MIME media type of the serialized policy blob. + Type string `json:"type"` + + // Links contains referencing links to the policy. + Links map[string]interface{} `json:"links"` + + // Extra is a collection of miscellaneous key/values. + Extra map[string]interface{} `json:"-"` +} + +func (r *Policy) UnmarshalJSON(b []byte) error { + type tmp Policy + var s struct { + tmp + Extra map[string]interface{} `json:"extra"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Policy(s.tmp) + + // Collect other fields and bundle them into Extra + // but only if a field titled "extra" wasn't sent. + if s.Extra != nil { + r.Extra = s.Extra + } else { + var result interface{} + err := json.Unmarshal(b, &result) + if err != nil { + return err + } + if resultMap, ok := result.(map[string]interface{}); ok { + r.Extra = internal.RemainingKeys(Policy{}, resultMap) + } + } + + return err +} + +type policyResult struct { + gophercloud.Result +} + +// CreateResult is the response from a Create operation. Call its Extract method +// to interpret it as a Policy +type CreateResult struct { + policyResult +} + +// GetResult is the response from a Get operation. Call its Extract method +// to interpret it as a Policy. +type GetResult struct { + policyResult +} + +// UpdateResult is the response from an Update operation. Call its Extract +// method to interpret it as a Policy. +type UpdateResult struct { + policyResult +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// PolicyPage is a single page of Policy results. +type PolicyPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of Policies contains any results. +func (r PolicyPage) IsEmpty() (bool, error) { + policies, err := ExtractPolicies(r) + return len(policies) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r PolicyPage) NextPageURL() (string, error) { + var s struct { + Links struct { + Next string `json:"next"` + Previous string `json:"previous"` + } `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Links.Next, err +} + +// ExtractPolicies returns a slice of Policies +// contained in a single page of results. +func ExtractPolicies(r pagination.Page) ([]Policy, error) { + var s struct { + Policies []Policy `json:"policies"` + } + err := (r.(PolicyPage)).ExtractInto(&s) + return s.Policies, err +} + +// Extract interprets any policyResults as a Policy. +func (r policyResult) Extract() (*Policy, error) { + var s struct { + Policy *Policy `json:"policy"` + } + err := r.ExtractInto(&s) + return s.Policy, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/doc.go new file mode 100644 index 00000000..80554d44 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/doc.go @@ -0,0 +1,2 @@ +// Package testing contains policies unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/fixtures.go new file mode 100644 index 00000000..24bca7e1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/fixtures.go @@ -0,0 +1,229 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/policies" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListOutput provides a single page of Policy results. +const ListOutput = ` +{ + "links": { + "next": null, + "previous": null, + "self": "http://example.com/identity/v3/policies" + }, + "policies": [ + { + "type": "text/plain", + "id": "2844b2a08be147a08ef58317d6471f1f", + "links": { + "self": "http://example.com/identity/v3/policies/2844b2a08be147a08ef58317d6471f1f" + }, + "blob": "'foo_user': 'role:compute-user'" + }, + { + "type": "application/json", + "id": "b49884da9d31494ea02aff38d4b4e701", + "links": { + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701" + }, + "blob": "{'bar_user': 'role:network-user'}", + "description": "policy for bar_user" + } + ] +} +` + +// ListWithFilterOutput provides a single page of filtered Policy results. +const ListWithFilterOutput = ` +{ + "links": { + "next": null, + "previous": null, + "self": "http://example.com/identity/v3/policies" + }, + "policies": [ + { + "type": "application/json", + "id": "b49884da9d31494ea02aff38d4b4e701", + "links": { + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701" + }, + "blob": "{'bar_user': 'role:network-user'}", + "description": "policy for bar_user" + } + ] +} +` + +// GetOutput provides a Get result. +const GetOutput = ` +{ + "policy": { + "type": "application/json", + "id": "b49884da9d31494ea02aff38d4b4e701", + "links": { + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701" + }, + "blob": "{'bar_user': 'role:network-user'}", + "description": "policy for bar_user" + } +} +` + +// CreateRequest provides the input to a Create request. +const CreateRequest = ` +{ + "policy": { + "blob": "{'bar_user': 'role:network-user'}", + "description": "policy for bar_user", + "type": "application/json" + } +} +` + +// UpdateRequest provides the input to as Update request. +const UpdateRequest = ` +{ + "policy": { + "description": "updated policy for bar_user" + } +} +` + +// UpdateOutput provides an update result. +const UpdateOutput = ` +{ + "policy": { + "type": "application/json", + "id": "b49884da9d31494ea02aff38d4b4e701", + "links": { + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701" + }, + "blob": "{'bar_user': 'role:network-user'}", + "description": "updated policy for bar_user" + } +} +` + +// FirstPolicy is the first policy in the List request. +var FirstPolicy = policies.Policy{ + ID: "2844b2a08be147a08ef58317d6471f1f", + Blob: "'foo_user': 'role:compute-user'", + Type: "text/plain", + Links: map[string]interface{}{ + "self": "http://example.com/identity/v3/policies/2844b2a08be147a08ef58317d6471f1f", + }, + Extra: map[string]interface{}{}, +} + +// SecondPolicy is the second policy in the List request. +var SecondPolicy = policies.Policy{ + ID: "b49884da9d31494ea02aff38d4b4e701", + Blob: "{'bar_user': 'role:network-user'}", + Type: "application/json", + Links: map[string]interface{}{ + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701", + }, + Extra: map[string]interface{}{ + "description": "policy for bar_user", + }, +} + +// SecondPolicyUpdated is the policy in the Update request. +var SecondPolicyUpdated = policies.Policy{ + ID: "b49884da9d31494ea02aff38d4b4e701", + Blob: "{'bar_user': 'role:network-user'}", + Type: "application/json", + Links: map[string]interface{}{ + "self": "http://example.com/identity/v3/policies/b49884da9d31494ea02aff38d4b4e701", + }, + Extra: map[string]interface{}{ + "description": "updated policy for bar_user", + }, +} + +// ExpectedPoliciesSlice is the slice of policies expected to be returned from ListOutput. +var ExpectedPoliciesSlice = []policies.Policy{FirstPolicy, SecondPolicy} + +// HandleListPoliciesSuccessfully creates an HTTP handler at `/policies` on the +// test handler mux that responds with a list of two policies. +func HandleListPoliciesSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + switch r.URL.Query().Get("type") { + case "": + fmt.Fprintf(w, ListOutput) + case "application/json": + fmt.Fprintf(w, ListWithFilterOutput) + default: + w.WriteHeader(http.StatusBadRequest) + } + }) +} + +// HandleCreatePolicySuccessfully creates an HTTP handler at `/policies` on the +// test handler mux that tests policy creation. +func HandleCreatePolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreateRequest) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, GetOutput) + }) +} + +// HandleGetPolicySuccessfully creates an HTTP handler at `/policies` on the +// test handler mux that responds with a single policy. +func HandleGetPolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/policies/b49884da9d31494ea02aff38d4b4e701", + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetOutput) + }, + ) +} + +// HandleUpdatePolicySuccessfully creates an HTTP handler at `/policies` on the +// test handler mux that tests role update. +func HandleUpdatePolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/policies/b49884da9d31494ea02aff38d4b4e701", + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, UpdateRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, UpdateOutput) + }, + ) +} + +// HandleDeletePolicySuccessfully creates an HTTP handler at `/policies` on the +// test handler mux that tests policy deletion. +func HandleDeletePolicySuccessfully(t *testing.T) { + th.Mux.HandleFunc("/policies/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/requests_test.go new file mode 100644 index 00000000..6348fd57 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/testing/requests_test.go @@ -0,0 +1,229 @@ +package testing + +import ( + "fmt" + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/policies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListPolicies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListPoliciesSuccessfully(t) + + count := 0 + err := policies.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := policies.ExtractPolicies(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedPoliciesSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListPoliciesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListPoliciesSuccessfully(t) + + allPages, err := policies.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedPoliciesSlice, actual) +} + +func TestListPoliciesWithFilter(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListPoliciesSuccessfully(t) + + listOpts := policies.ListOpts{ + Type: "application/json", + } + allPages, err := policies.List(client.ServiceClient(), listOpts).AllPages() + th.AssertNoErr(t, err) + actual, err := policies.ExtractPolicies(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, []policies.Policy{SecondPolicy}, actual) +} + +func TestListPoliciesFiltersCheck(t *testing.T) { + type test struct { + filterName string + wantErr bool + } + tests := []test{ + {"foo__contains", false}, + {"foo", true}, + {"foo_contains", true}, + {"foo__", true}, + {"__foo", true}, + } + + var listOpts policies.ListOpts + for _, _test := range tests { + listOpts.Filters = map[string]string{_test.filterName: "bar"} + _, err := listOpts.ToPolicyListQuery() + + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case policies.InvalidListFilter: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestCreatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreatePolicySuccessfully(t) + + createOpts := policies.CreateOpts{ + Type: "application/json", + Blob: []byte("{'bar_user': 'role:network-user'}"), + Extra: map[string]interface{}{ + "description": "policy for bar_user", + }, + } + + actual, err := policies.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondPolicy, *actual) +} + +func TestCreatePolicyTypeLengthCheck(t *testing.T) { + // strGenerator generates a string of fixed length filled with '0' + strGenerator := func(length int) string { + return fmt.Sprintf(fmt.Sprintf("%%0%dd", length), 0) + } + + type test struct { + length int + wantErr bool + } + + tests := []test{ + {100, false}, + {255, false}, + {256, true}, + {300, true}, + } + + createOpts := policies.CreateOpts{ + Blob: []byte("{'bar_user': 'role:network-user'}"), + } + + for _, _test := range tests { + createOpts.Type = strGenerator(_test.length) + if len(createOpts.Type) != _test.length { + t.Fatal("function strGenerator does not work properly") + } + + _, err := createOpts.ToPolicyCreateMap() + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case policies.StringFieldLengthExceedsLimit: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestGetPolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetPolicySuccessfully(t) + + id := "b49884da9d31494ea02aff38d4b4e701" + actual, err := policies.Get(client.ServiceClient(), id).Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondPolicy, *actual) +} + +func TestUpdatePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdatePolicySuccessfully(t) + + updateOpts := policies.UpdateOpts{ + Extra: map[string]interface{}{ + "description": "updated policy for bar_user", + }, + } + + id := "b49884da9d31494ea02aff38d4b4e701" + actual, err := policies.Update(client.ServiceClient(), id, updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondPolicyUpdated, *actual) +} + +func TestUpdatePolicyTypeLengthCheck(t *testing.T) { + // strGenerator generates a string of fixed length filled with '0' + strGenerator := func(length int) string { + return fmt.Sprintf(fmt.Sprintf("%%0%dd", length), 0) + } + + type test struct { + length int + wantErr bool + } + + tests := []test{ + {100, false}, + {255, false}, + {256, true}, + {300, true}, + } + + var updateOpts policies.UpdateOpts + for _, _test := range tests { + updateOpts.Type = strGenerator(_test.length) + if len(updateOpts.Type) != _test.length { + t.Fatal("function strGenerator does not work properly") + } + + _, err := updateOpts.ToPolicyUpdateMap() + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case policies.StringFieldLengthExceedsLimit: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestDeletePolicy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeletePolicySuccessfully(t) + + res := policies.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/urls.go new file mode 100644 index 00000000..df0d183b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/policies/urls.go @@ -0,0 +1,25 @@ +package policies + +import "github.com/gophercloud/gophercloud" + +const policyPath = "policies" + +func listURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(policyPath) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(policyPath) +} + +func getURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(policyPath, policyID) +} + +func updateURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(policyPath, policyID) +} + +func deleteURL(client *gophercloud.ServiceClient, policyID string) string { + return client.ServiceURL(policyPath, policyID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/errors.go new file mode 100644 index 00000000..7be97d85 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/errors.go @@ -0,0 +1,17 @@ +package projects + +import "fmt" + +// InvalidListFilter is returned by the ToUserListQuery method when validation of +// a filter does not pass +type InvalidListFilter struct { + FilterName string +} + +func (e InvalidListFilter) Error() string { + s := fmt.Sprintf( + "Invalid filter name [%s]: it must be in format of NAME__COMPARATOR", + e.FilterName, + ) + return s +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/requests.go index 368b7321..30f3d1f9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/requests.go @@ -1,6 +1,9 @@ package projects import ( + "net/url" + "strings" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" ) @@ -28,11 +31,30 @@ type ListOpts struct { // ParentID filters the response by projects of a given parent project. ParentID string `q:"parent_id"` + + // Filters filters the response by custom filters such as + // 'name__contains=foo' + Filters map[string]string `q:"-"` } // ToProjectListQuery formats a ListOpts into a query string. func (opts ListOpts) ToProjectListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + + params := q.Query() + for k, v := range opts.Filters { + i := strings.Index(k, "__") + if i > 0 && i < len(k)-2 { + params.Add(k, v) + } else { + return "", InvalidListFilter{FilterName: k} + } + } + + q = &url.URL{RawQuery: params.Encode()} return q.String(), err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/testing/requests_test.go new file mode 100644 index 00000000..9a666488 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/projects/testing/requests_test.go @@ -0,0 +1,111 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListProjects(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListProjectsSuccessfully(t) + + count := 0 + err := projects.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := projects.ExtractProjects(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedProjectSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListGroupsFiltersCheck(t *testing.T) { + type test struct { + filterName string + wantErr bool + } + tests := []test{ + {"foo__contains", false}, + {"foo", true}, + {"foo_contains", true}, + {"foo__", true}, + {"__foo", true}, + } + + var listOpts projects.ListOpts + for _, _test := range tests { + listOpts.Filters = map[string]string{_test.filterName: "bar"} + _, err := listOpts.ToProjectListQuery() + + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case projects.InvalidListFilter: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestGetProject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetProjectSuccessfully(t) + + actual, err := projects.Get(client.ServiceClient(), "1234").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, RedTeam, *actual) +} + +func TestCreateProject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateProjectSuccessfully(t) + + createOpts := projects.CreateOpts{ + Name: "Red Team", + Description: "The team that is red", + } + + actual, err := projects.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, RedTeam, *actual) +} + +func TestDeleteProject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteProjectSuccessfully(t) + + res := projects.Delete(client.ServiceClient(), "1234") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateProject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateProjectSuccessfully(t) + + updateOpts := projects.UpdateOpts{ + Name: "Bright Red Team", + Description: "The team that is bright red", + } + + actual, err := projects.Update(client.ServiceClient(), "1234", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, UpdatedRedTeam, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/regions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/regions/testing/requests_test.go new file mode 100644 index 00000000..7f575570 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/regions/testing/requests_test.go @@ -0,0 +1,105 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/regions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListRegions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListRegionsSuccessfully(t) + + count := 0 + err := regions.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := regions.ExtractRegions(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedRegionsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListRegionsAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListRegionsSuccessfully(t) + + allPages, err := regions.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := regions.ExtractRegions(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRegionsSlice, actual) + th.AssertEquals(t, ExpectedRegionsSlice[1].Extra["email"], "westsupport@example.com") +} + +func TestGetRegion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetRegionSuccessfully(t) + + actual, err := regions.Get(client.ServiceClient(), "RegionOne-West").Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRegion, *actual) +} + +func TestCreateRegion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateRegionSuccessfully(t) + + createOpts := regions.CreateOpts{ + ID: "RegionOne-West", + Description: "West sub-region of RegionOne", + Extra: map[string]interface{}{ + "email": "westsupport@example.com", + }, + ParentRegionID: "RegionOne", + } + + actual, err := regions.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRegion, *actual) +} + +func TestUpdateRegion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateRegionSuccessfully(t) + + updateOpts := regions.UpdateOpts{ + Description: "First West sub-region of RegionOne", + /* + // Due to a bug in Keystone, the Extra column of the Region table + // is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933 + // The following lines should be uncommented once the fix is merged. + + Extra: map[string]interface{}{ + "email": "1stwestsupport@example.com", + }, + */ + } + + actual, err := regions.Update(client.ServiceClient(), "RegionOne-West", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRegionUpdated, *actual) +} + +func TestDeleteRegion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteRegionSuccessfully(t) + + res := regions.Delete(client.ServiceClient(), "RegionOne-West") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/doc.go index 2886a872..f0e4d045 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/doc.go @@ -79,6 +79,29 @@ Example to List Role Assignments fmt.Printf("%+v\n", role) } +Example to List Role Assignments for a User on a Project + + projectID := "a99e9b4e620e4db09a2dfb6e42a01e66" + userID := "9df1a02f5eb2416a9781e8b0c022d3ae" + listAssignmentsOnResourceOpts := roles.ListAssignmentsOnResourceOpts{ + UserID: userID, + ProjectID: projectID, + } + + allPages, err := roles.ListAssignmentsOnResource(identityClient, listAssignmentsOnResourceOpts).AllPages() + if err != nil { + panic(err) + } + + allRoles, err := roles.ExtractRoles(allPages) + if err != nil { + panic(err) + } + + for _, role := range allRoles { + fmt.Printf("%+v\n", role) + } + Example to Assign a Role to a User in a Project projectID := "a99e9b4e620e4db09a2dfb6e42a01e66" diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/errors.go new file mode 100644 index 00000000..b60d7d18 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/errors.go @@ -0,0 +1,17 @@ +package roles + +import "fmt" + +// InvalidListFilter is returned by the ToUserListQuery method when validation of +// a filter does not pass +type InvalidListFilter struct { + FilterName string +} + +func (e InvalidListFilter) Error() string { + s := fmt.Sprintf( + "Invalid filter name [%s]: it must be in format of NAME__COMPARATOR", + e.FilterName, + ) + return s +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/requests.go index 7908baa0..573db9ea 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/requests.go @@ -1,6 +1,9 @@ package roles import ( + "net/url" + "strings" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" ) @@ -18,11 +21,30 @@ type ListOpts struct { // Name filters the response by role name. Name string `q:"name"` + + // Filters filters the response by custom filters such as + // 'name__contains=foo' + Filters map[string]string `q:"-"` } // ToRoleListQuery formats a ListOpts into a query string. func (opts ListOpts) ToRoleListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + + params := q.Query() + for k, v := range opts.Filters { + i := strings.Index(k, "__") + if i > 0 && i < len(k)-2 { + params.Add(k, v) + } else { + return "", InvalidListFilter{FilterName: k} + } + } + + q = &url.URL{RawQuery: params.Encode()} return q.String(), err } @@ -201,6 +223,26 @@ func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOpts }) } +// ListAssignmentsOnResourceOpts provides options to list role assignments +// for a user/group on a project/domain +type ListAssignmentsOnResourceOpts struct { + // UserID is the ID of a user to assign a role + // Note: exactly one of UserID or GroupID must be provided + UserID string `xor:"GroupID"` + + // GroupID is the ID of a group to assign a role + // Note: exactly one of UserID or GroupID must be provided + GroupID string `xor:"UserID"` + + // ProjectID is the ID of a project to assign a role on + // Note: exactly one of ProjectID or DomainID must be provided + ProjectID string `xor:"DomainID"` + + // DomainID is the ID of a domain to assign a role on + // Note: exactly one of ProjectID or DomainID must be provided + DomainID string `xor:"ProjectID"` +} + // AssignOpts provides options to assign a role type AssignOpts struct { // UserID is the ID of a user to assign a role @@ -239,6 +281,42 @@ type UnassignOpts struct { DomainID string `xor:"ProjectID"` } +// ListAssignmentsOnResource is the operation responsible for listing role +// assignments for a user/group on a project/domain. +func ListAssignmentsOnResource(client *gophercloud.ServiceClient, opts ListAssignmentsOnResourceOpts) pagination.Pager { + // Check xor conditions + _, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return pagination.Pager{Err: err} + } + + // Get corresponding URL + var targetID string + var targetType string + if opts.ProjectID != "" { + targetID = opts.ProjectID + targetType = "projects" + } else { + targetID = opts.DomainID + targetType = "domains" + } + + var actorID string + var actorType string + if opts.UserID != "" { + actorID = opts.UserID + actorType = "users" + } else { + actorID = opts.GroupID + actorType = "groups" + } + + url := listAssignmentsOnResourceURL(client, targetType, targetID, actorType, actorID) + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return RolePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + // Assign is the operation responsible for assigning a role // to a user/group on a project/domain. func Assign(client *gophercloud.ServiceClient, roleID string, opts AssignOpts) (r AssignmentResult) { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/fixtures.go index fa73b11e..9bcc2c7d 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/fixtures.go @@ -141,6 +141,29 @@ const ListAssignmentOutput = ` } ` +// ListAssignmentsOnResourceOutput provides a result of ListAssignmentsOnResource request. +const ListAssignmentsOnResourceOutput = ` +{ + "links": { + "next": null, + "previous": null, + "self": "http://example.com/identity/v3/projects/9e5a15/users/b964a9/roles" + }, + "roles": [ + { + "id": "9fe1d3", + "links": { + "self": "https://example.com/identity/v3/roles/9fe1d3" + }, + "name": "support", + "extra": { + "description": "read-only support role" + } + } + ] +} +` + // FirstRole is the first role in the List request. var FirstRole = roles.Role{ DomainID: "default", @@ -331,3 +354,75 @@ func HandleListRoleAssignmentsSuccessfully(t *testing.T) { fmt.Fprintf(w, ListAssignmentOutput) }) } + +// RoleOnResource is the role in the ListAssignmentsOnResource request. +var RoleOnResource = roles.Role{ + ID: "9fe1d3", + Links: map[string]interface{}{ + "self": "https://example.com/identity/v3/roles/9fe1d3", + }, + Name: "support", + Extra: map[string]interface{}{ + "description": "read-only support role", + }, +} + +// ExpectedRolesOnResourceSlice is the slice of roles expected to be returned +// from ListAssignmentsOnResourceOutput. +var ExpectedRolesOnResourceSlice = []roles.Role{RoleOnResource} + +func HandleListAssignmentsOnResourceSuccessfully_ProjectsUsers(t *testing.T) { + fn := func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListAssignmentsOnResourceOutput) + } + + th.Mux.HandleFunc("/projects/{project_id}/users/{user_id}/roles", fn) +} + +func HandleListAssignmentsOnResourceSuccessfully_ProjectsGroups(t *testing.T) { + fn := func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListAssignmentsOnResourceOutput) + } + + th.Mux.HandleFunc("/projects/{project_id}/groups/{group_id}/roles", fn) +} + +func HandleListAssignmentsOnResourceSuccessfully_DomainsUsers(t *testing.T) { + fn := func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListAssignmentsOnResourceOutput) + } + + th.Mux.HandleFunc("/domains/{domain_id}/users/{user_id}/roles", fn) +} + +func HandleListAssignmentsOnResourceSuccessfully_DomainsGroups(t *testing.T) { + fn := func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListAssignmentsOnResourceOutput) + } + + th.Mux.HandleFunc("/domains/{domain_id}/groups/{group_id}/roles", fn) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/requests_test.go new file mode 100644 index 00000000..c8ac5a9b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/testing/requests_test.go @@ -0,0 +1,296 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListRoles(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListRolesSuccessfully(t) + + count := 0 + err := roles.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := roles.ExtractRoles(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedRolesSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListRolesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListRolesSuccessfully(t) + + allPages, err := roles.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := roles.ExtractRoles(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRolesSlice, actual) + th.AssertEquals(t, ExpectedRolesSlice[1].Extra["description"], "read-only support role") +} + +func TestListUsersFiltersCheck(t *testing.T) { + type test struct { + filterName string + wantErr bool + } + tests := []test{ + {"foo__contains", false}, + {"foo", true}, + {"foo_contains", true}, + {"foo__", true}, + {"__foo", true}, + } + + var listOpts roles.ListOpts + for _, _test := range tests { + listOpts.Filters = map[string]string{_test.filterName: "bar"} + _, err := listOpts.ToRoleListQuery() + + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case roles.InvalidListFilter: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestGetRole(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetRoleSuccessfully(t) + + actual, err := roles.Get(client.ServiceClient(), "9fe1d3").Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRole, *actual) +} + +func TestCreateRole(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateRoleSuccessfully(t) + + createOpts := roles.CreateOpts{ + Name: "support", + DomainID: "1789d1", + Extra: map[string]interface{}{ + "description": "read-only support role", + }, + } + + actual, err := roles.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRole, *actual) +} + +func TestUpdateRole(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateRoleSuccessfully(t) + + updateOpts := roles.UpdateOpts{ + Extra: map[string]interface{}{ + "description": "admin read-only support role", + }, + } + + actual, err := roles.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondRoleUpdated, *actual) +} + +func TestDeleteRole(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteRoleSuccessfully(t) + + res := roles.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestListAssignmentsSinglePage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListRoleAssignmentsSuccessfully(t) + + count := 0 + err := roles.ListAssignments(client.ServiceClient(), roles.ListAssignmentsOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := roles.ExtractRoleAssignments(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedRoleAssignmentsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAssignmentsOnResource_ProjectsUsers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListAssignmentsOnResourceSuccessfully_ProjectsUsers(t) + + count := 0 + err := roles.ListAssignmentsOnResource(client.ServiceClient(), roles.ListAssignmentsOnResourceOpts{ + UserID: "{user_id}", + ProjectID: "{project_id}", + }).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := roles.ExtractRoles(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRolesOnResourceSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAssignmentsOnResource_DomainsUsers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListAssignmentsOnResourceSuccessfully_DomainsUsers(t) + + count := 0 + err := roles.ListAssignmentsOnResource(client.ServiceClient(), roles.ListAssignmentsOnResourceOpts{ + UserID: "{user_id}", + DomainID: "{domain_id}", + }).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := roles.ExtractRoles(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRolesOnResourceSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAssignmentsOnResource_ProjectsGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListAssignmentsOnResourceSuccessfully_ProjectsGroups(t) + + count := 0 + err := roles.ListAssignmentsOnResource(client.ServiceClient(), roles.ListAssignmentsOnResourceOpts{ + GroupID: "{group_id}", + ProjectID: "{project_id}", + }).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := roles.ExtractRoles(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRolesOnResourceSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAssignmentsOnResource_DomainsGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListAssignmentsOnResourceSuccessfully_DomainsGroups(t) + + count := 0 + err := roles.ListAssignmentsOnResource(client.ServiceClient(), roles.ListAssignmentsOnResourceOpts{ + GroupID: "{group_id}", + DomainID: "{domain_id}", + }).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := roles.ExtractRoles(page) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedRolesOnResourceSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestAssign(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAssignSuccessfully(t) + + err := roles.Assign(client.ServiceClient(), "{role_id}", roles.AssignOpts{ + UserID: "{user_id}", + ProjectID: "{project_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Assign(client.ServiceClient(), "{role_id}", roles.AssignOpts{ + UserID: "{user_id}", + DomainID: "{domain_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Assign(client.ServiceClient(), "{role_id}", roles.AssignOpts{ + GroupID: "{group_id}", + ProjectID: "{project_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Assign(client.ServiceClient(), "{role_id}", roles.AssignOpts{ + GroupID: "{group_id}", + DomainID: "{domain_id}", + }).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUnassign(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUnassignSuccessfully(t) + + err := roles.Unassign(client.ServiceClient(), "{role_id}", roles.UnassignOpts{ + UserID: "{user_id}", + ProjectID: "{project_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Unassign(client.ServiceClient(), "{role_id}", roles.UnassignOpts{ + UserID: "{user_id}", + DomainID: "{domain_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Unassign(client.ServiceClient(), "{role_id}", roles.UnassignOpts{ + GroupID: "{group_id}", + ProjectID: "{project_id}", + }).ExtractErr() + th.AssertNoErr(t, err) + + err = roles.Unassign(client.ServiceClient(), "{role_id}", roles.UnassignOpts{ + GroupID: "{group_id}", + DomainID: "{domain_id}", + }).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/urls.go index 38d592dc..2b820114 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/roles/urls.go @@ -30,6 +30,10 @@ func listAssignmentsURL(client *gophercloud.ServiceClient) string { return client.ServiceURL("role_assignments") } +func listAssignmentsOnResourceURL(client *gophercloud.ServiceClient, targetType, targetID, actorType, actorID string) string { + return client.ServiceURL(targetType, targetID, actorType, actorID, rolePath) +} + func assignURL(client *gophercloud.ServiceClient, targetType, targetID, actorType, actorID, roleID string) string { return client.ServiceURL(targetType, targetID, actorType, actorID, rolePath, roleID) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/services/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/services/testing/requests_test.go new file mode 100644 index 00000000..2a8a89dd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/services/testing/requests_test.go @@ -0,0 +1,107 @@ +package testing + +import ( + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/services" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateSuccessful(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateServiceSuccessfully(t) + + createOpts := services.CreateOpts{ + Type: "compute", + Extra: map[string]interface{}{ + "name": "service-two", + "description": "Service Two", + "email": "service@example.com", + }, + } + + actual, err := services.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondService, *actual) +} + +func TestListServices(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListServicesSuccessfully(t) + + count := 0 + err := services.List(client.ServiceClient(), services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := services.ExtractServices(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedServicesSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListServicesAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListServicesSuccessfully(t) + + allPages, err := services.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := services.ExtractServices(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedServicesSlice, actual) + th.AssertEquals(t, ExpectedServicesSlice[0].Extra["name"], "service-one") + th.AssertEquals(t, ExpectedServicesSlice[1].Extra["email"], "service@example.com") +} + +func TestGetSuccessful(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetServiceSuccessfully(t) + + actual, err := services.Get(client.ServiceClient(), "9876").Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondService, *actual) + th.AssertEquals(t, SecondService.Extra["email"], "service@example.com") +} + +func TestUpdateSuccessful(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateServiceSuccessfully(t) + + updateOpts := services.UpdateOpts{ + Type: "compute2", + Extra: map[string]interface{}{ + "description": "Service Two Updated", + }, + } + actual, err := services.Update(client.ServiceClient(), "9876", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondServiceUpdated, *actual) + th.AssertEquals(t, SecondServiceUpdated.Extra["description"], "Service Two Updated") +} + +func TestDeleteSuccessful(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/services/12345", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := services.Delete(client.ServiceClient(), "12345") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go index ca35851e..6e99a793 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go @@ -72,72 +72,15 @@ func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]interface{}) (map[s // ToTokenV3CreateMap builds a scope request body from AuthOptions. func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) { - if opts.Scope.ProjectName != "" { - // ProjectName provided: either DomainID or DomainName must also be supplied. - // ProjectID may not be supplied. - if opts.Scope.DomainID == "" && opts.Scope.DomainName == "" { - return nil, gophercloud.ErrScopeDomainIDOrDomainName{} - } - if opts.Scope.ProjectID != "" { - return nil, gophercloud.ErrScopeProjectIDOrProjectName{} - } - - if opts.Scope.DomainID != "" { - // ProjectName + DomainID - return map[string]interface{}{ - "project": map[string]interface{}{ - "name": &opts.Scope.ProjectName, - "domain": map[string]interface{}{"id": &opts.Scope.DomainID}, - }, - }, nil - } - - if opts.Scope.DomainName != "" { - // ProjectName + DomainName - return map[string]interface{}{ - "project": map[string]interface{}{ - "name": &opts.Scope.ProjectName, - "domain": map[string]interface{}{"name": &opts.Scope.DomainName}, - }, - }, nil - } - } else if opts.Scope.ProjectID != "" { - // ProjectID provided. ProjectName, DomainID, and DomainName may not be provided. - if opts.Scope.DomainID != "" { - return nil, gophercloud.ErrScopeProjectIDAlone{} - } - if opts.Scope.DomainName != "" { - return nil, gophercloud.ErrScopeProjectIDAlone{} - } - - // ProjectID - return map[string]interface{}{ - "project": map[string]interface{}{ - "id": &opts.Scope.ProjectID, - }, - }, nil - } else if opts.Scope.DomainID != "" { - // DomainID provided. ProjectID, ProjectName, and DomainName may not be provided. - if opts.Scope.DomainName != "" { - return nil, gophercloud.ErrScopeDomainIDOrDomainName{} - } - - // DomainID - return map[string]interface{}{ - "domain": map[string]interface{}{ - "id": &opts.Scope.DomainID, - }, - }, nil - } else if opts.Scope.DomainName != "" { - // DomainName - return map[string]interface{}{ - "domain": map[string]interface{}{ - "name": &opts.Scope.DomainName, - }, - }, nil + scope := gophercloud.AuthScope(opts.Scope) + + gophercloudAuthOpts := gophercloud.AuthOptions{ + Scope: &scope, + DomainID: opts.DomainID, + DomainName: opts.DomainName, } - return nil, nil + return gophercloudAuthOpts.ToTokenV3ScopeMap() } func (opts *AuthOptions) CanReauth() bool { @@ -190,7 +133,7 @@ func Get(c *gophercloud.ServiceClient, token string) (r GetResult) { // Validate determines if a specified token is valid or not. func Validate(c *gophercloud.ServiceClient, token string) (bool, error) { - resp, err := c.Request("HEAD", tokenURL(c), &gophercloud.RequestOpts{ + resp, err := c.Head(tokenURL(c), &gophercloud.RequestOpts{ MoreHeaders: subjectTokenHeaders(c, token), OkCodes: []int{200, 204, 404}, }) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go index 6e78d1cb..ebdca58f 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go @@ -13,6 +13,7 @@ import ( type Endpoint struct { ID string `json:"id"` Region string `json:"region"` + RegionID string `json:"region_id"` Interface string `json:"interface"` URL string `json:"url"` } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/fixtures.go index a475acb1..e6f44178 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/fixtures.go @@ -125,18 +125,21 @@ var catalogEntry1 = tokens.CatalogEntry{ tokens.Endpoint{ ID: "3eac9e7588eb4eb2a4650cf5e079505f", Region: "RegionOne", + RegionID: "RegionOne", Interface: "admin", URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", }, tokens.Endpoint{ ID: "6b33fabc69c34ea782a3f6282582b59f", Region: "RegionOne", + RegionID: "RegionOne", Interface: "internal", URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", }, tokens.Endpoint{ ID: "dae63c71bee24070a71f5425e7a916b5", Region: "RegionOne", + RegionID: "RegionOne", Interface: "public", URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", }, @@ -150,18 +153,21 @@ var catalogEntry2 = tokens.CatalogEntry{ tokens.Endpoint{ ID: "0539aeff80954a0bb756cec496768d3d", Region: "RegionOne", + RegionID: "RegionOne", Interface: "admin", URL: "http://127.0.0.1:35357/v3", }, tokens.Endpoint{ ID: "15bdf2d0853e4c939993d29548b1b56f", Region: "RegionOne", + RegionID: "RegionOne", Interface: "public", URL: "http://127.0.0.1:5000/v3", }, tokens.Endpoint{ ID: "3b4423c54ba343c58226bc424cb11c4b", Region: "RegionOne", + RegionID: "RegionOne", Interface: "internal", URL: "http://127.0.0.1:5000/v3", }, diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/requests_test.go new file mode 100644 index 00000000..3891ae4a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/requests_test.go @@ -0,0 +1,551 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" + "github.com/gophercloud/gophercloud/testhelper" +) + +// authTokenPost verifies that providing certain AuthOptions and Scope results in an expected JSON structure. +func authTokenPost(t *testing.T, options tokens.AuthOptions, scope *tokens.Scope, requestJSON string) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{}, + Endpoint: testhelper.Endpoint(), + } + + testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + testhelper.TestMethod(t, r, "POST") + testhelper.TestHeader(t, r, "Content-Type", "application/json") + testhelper.TestHeader(t, r, "Accept", "application/json") + testhelper.TestJSONRequest(t, r, requestJSON) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{ + "token": { + "expires_at": "2014-10-02T13:45:00.000000Z" + } + }`) + }) + + if scope != nil { + options.Scope = *scope + } + + expected := &tokens.Token{ + ExpiresAt: time.Date(2014, 10, 2, 13, 45, 0, 0, time.UTC), + } + actual, err := tokens.Create(&client, &options).Extract() + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, expected, actual) +} + +func authTokenPostErr(t *testing.T, options tokens.AuthOptions, scope *tokens.Scope, includeToken bool, expectedErr error) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{}, + Endpoint: testhelper.Endpoint(), + } + if includeToken { + client.TokenID = "abcdef123456" + } + + if scope != nil { + options.Scope = *scope + } + + _, err := tokens.Create(&client, &options).Extract() + if err == nil { + t.Errorf("Create did NOT return an error") + } + if err != expectedErr { + t.Errorf("Create returned an unexpected error: wanted %v, got %v", expectedErr, err) + } +} + +func TestCreateUserIDAndPassword(t *testing.T) { + authTokenPost(t, tokens.AuthOptions{UserID: "me", Password: "squirrel!"}, nil, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { "id": "me", "password": "squirrel!" } + } + } + } + } + `) +} + +func TestCreateUsernameDomainIDPassword(t *testing.T) { + authTokenPost(t, tokens.AuthOptions{Username: "fakey", Password: "notpassword", DomainID: "abc123"}, nil, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "domain": { + "id": "abc123" + }, + "name": "fakey", + "password": "notpassword" + } + } + } + } + } + `) +} + +func TestCreateUsernameDomainNamePassword(t *testing.T) { + authTokenPost(t, tokens.AuthOptions{Username: "frank", Password: "swordfish", DomainName: "spork.net"}, nil, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "domain": { + "name": "spork.net" + }, + "name": "frank", + "password": "swordfish" + } + } + } + } + } + `) +} + +func TestCreateTokenID(t *testing.T) { + authTokenPost(t, tokens.AuthOptions{TokenID: "12345abcdef"}, nil, ` + { + "auth": { + "identity": { + "methods": ["token"], + "token": { + "id": "12345abcdef" + } + } + } + } + `) +} + +func TestCreateProjectIDScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"} + scope := &tokens.Scope{ProjectID: "123456"} + authTokenPost(t, options, scope, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "id": "fenris", + "password": "g0t0h311" + } + } + }, + "scope": { + "project": { + "id": "123456" + } + } + } + } + `) +} + +func TestCreateDomainIDScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"} + scope := &tokens.Scope{DomainID: "1000"} + authTokenPost(t, options, scope, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "id": "fenris", + "password": "g0t0h311" + } + } + }, + "scope": { + "domain": { + "id": "1000" + } + } + } + } + `) +} + +func TestCreateDomainNameScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"} + scope := &tokens.Scope{DomainName: "evil-plans"} + authTokenPost(t, options, scope, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "id": "fenris", + "password": "g0t0h311" + } + } + }, + "scope": { + "domain": { + "name": "evil-plans" + } + } + } + } + `) +} + +func TestCreateProjectNameAndDomainIDScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"} + scope := &tokens.Scope{ProjectName: "world-domination", DomainID: "1000"} + authTokenPost(t, options, scope, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "id": "fenris", + "password": "g0t0h311" + } + } + }, + "scope": { + "project": { + "domain": { + "id": "1000" + }, + "name": "world-domination" + } + } + } + } + `) +} + +func TestCreateProjectNameAndDomainNameScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"} + scope := &tokens.Scope{ProjectName: "world-domination", DomainName: "evil-plans"} + authTokenPost(t, options, scope, ` + { + "auth": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "id": "fenris", + "password": "g0t0h311" + } + } + }, + "scope": { + "project": { + "domain": { + "name": "evil-plans" + }, + "name": "world-domination" + } + } + } + } + `) +} + +func TestCreateExtractsTokenFromResponse(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{}, + Endpoint: testhelper.Endpoint(), + } + + testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("X-Subject-Token", "aaa111") + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{ + "token": { + "expires_at": "2014-10-02T13:45:00.000000Z" + } + }`) + }) + + options := tokens.AuthOptions{UserID: "me", Password: "shhh"} + token, err := tokens.Create(&client, &options).Extract() + if err != nil { + t.Fatalf("Create returned an error: %v", err) + } + + if token.ID != "aaa111" { + t.Errorf("Expected token to be aaa111, but was %s", token.ID) + } +} + +func TestCreateFailureEmptyAuth(t *testing.T) { + authTokenPostErr(t, tokens.AuthOptions{}, nil, false, gophercloud.ErrMissingPassword{}) +} + +func TestCreateFailureTokenIDUsername(t *testing.T) { + authTokenPostErr(t, tokens.AuthOptions{Username: "something", TokenID: "12345"}, nil, true, gophercloud.ErrUsernameWithToken{}) +} + +func TestCreateFailureTokenIDUserID(t *testing.T) { + authTokenPostErr(t, tokens.AuthOptions{UserID: "something", TokenID: "12345"}, nil, true, gophercloud.ErrUserIDWithToken{}) +} + +func TestCreateFailureTokenIDDomainID(t *testing.T) { + authTokenPostErr(t, tokens.AuthOptions{DomainID: "something", TokenID: "12345"}, nil, true, gophercloud.ErrDomainIDWithToken{}) +} + +func TestCreateFailureTokenIDDomainName(t *testing.T) { + authTokenPostErr(t, tokens.AuthOptions{DomainName: "something", TokenID: "12345"}, nil, true, gophercloud.ErrDomainNameWithToken{}) +} + +func TestCreateFailureMissingUser(t *testing.T) { + options := tokens.AuthOptions{Password: "supersecure"} + authTokenPostErr(t, options, nil, false, gophercloud.ErrUsernameOrUserID{}) +} + +func TestCreateFailureBothUser(t *testing.T) { + options := tokens.AuthOptions{ + Password: "supersecure", + Username: "oops", + UserID: "redundancy", + } + authTokenPostErr(t, options, nil, false, gophercloud.ErrUsernameOrUserID{}) +} + +func TestCreateFailureMissingDomain(t *testing.T) { + options := tokens.AuthOptions{ + Password: "supersecure", + Username: "notuniqueenough", + } + authTokenPostErr(t, options, nil, false, gophercloud.ErrDomainIDOrDomainName{}) +} + +func TestCreateFailureBothDomain(t *testing.T) { + options := tokens.AuthOptions{ + Password: "supersecure", + Username: "someone", + DomainID: "hurf", + DomainName: "durf", + } + authTokenPostErr(t, options, nil, false, gophercloud.ErrDomainIDOrDomainName{}) +} + +func TestCreateFailureUserIDDomainID(t *testing.T) { + options := tokens.AuthOptions{ + UserID: "100", + Password: "stuff", + DomainID: "oops", + } + authTokenPostErr(t, options, nil, false, gophercloud.ErrDomainIDWithUserID{}) +} + +func TestCreateFailureUserIDDomainName(t *testing.T) { + options := tokens.AuthOptions{ + UserID: "100", + Password: "sssh", + DomainName: "oops", + } + authTokenPostErr(t, options, nil, false, gophercloud.ErrDomainNameWithUserID{}) +} + +func TestCreateFailureScopeProjectNameAlone(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{ProjectName: "notenough"} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeDomainIDOrDomainName{}) +} + +func TestCreateFailureScopeProjectNameAndID(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{ProjectName: "whoops", ProjectID: "toomuch", DomainID: "1234"} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeProjectIDOrProjectName{}) +} + +func TestCreateFailureScopeProjectIDAndDomainID(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{ProjectID: "toomuch", DomainID: "notneeded"} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeProjectIDAlone{}) +} + +func TestCreateFailureScopeProjectIDAndDomainNAme(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{ProjectID: "toomuch", DomainName: "notneeded"} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeProjectIDAlone{}) +} + +func TestCreateFailureScopeDomainIDAndDomainName(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{DomainID: "toomuch", DomainName: "notneeded"} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeDomainIDOrDomainName{}) +} + +/* +func TestCreateFailureEmptyScope(t *testing.T) { + options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"} + scope := &tokens.Scope{} + authTokenPostErr(t, options, scope, false, gophercloud.ErrScopeEmpty{}) +} +*/ + +func TestGetRequest(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{ + TokenID: "12345abcdef", + }, + Endpoint: testhelper.Endpoint(), + } + + testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + testhelper.TestMethod(t, r, "GET") + testhelper.TestHeader(t, r, "Content-Type", "") + testhelper.TestHeader(t, r, "Accept", "application/json") + testhelper.TestHeader(t, r, "X-Auth-Token", "12345abcdef") + testhelper.TestHeader(t, r, "X-Subject-Token", "abcdef12345") + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ` + { "token": { "expires_at": "2014-08-29T13:10:01.000000Z" } } + `) + }) + + token, err := tokens.Get(&client, "abcdef12345").Extract() + if err != nil { + t.Errorf("Info returned an error: %v", err) + } + + expected, _ := time.Parse(time.UnixDate, "Fri Aug 29 13:10:01 UTC 2014") + if token.ExpiresAt != expected { + t.Errorf("Expected expiration time %s, but was %s", expected.Format(time.UnixDate), time.Time(token.ExpiresAt).Format(time.UnixDate)) + } +} + +func prepareAuthTokenHandler(t *testing.T, expectedMethod string, status int) gophercloud.ServiceClient { + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{ + TokenID: "12345abcdef", + }, + Endpoint: testhelper.Endpoint(), + } + + testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + testhelper.TestMethod(t, r, expectedMethod) + testhelper.TestHeader(t, r, "Content-Type", "") + testhelper.TestHeader(t, r, "Accept", "application/json") + testhelper.TestHeader(t, r, "X-Auth-Token", "12345abcdef") + testhelper.TestHeader(t, r, "X-Subject-Token", "abcdef12345") + + w.WriteHeader(status) + }) + + return client +} + +func TestValidateRequestSuccessful(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + client := prepareAuthTokenHandler(t, "HEAD", http.StatusNoContent) + + ok, err := tokens.Validate(&client, "abcdef12345") + if err != nil { + t.Errorf("Unexpected error from Validate: %v", err) + } + + if !ok { + t.Errorf("Validate returned false for a valid token") + } +} + +func TestValidateRequestFailure(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + client := prepareAuthTokenHandler(t, "HEAD", http.StatusNotFound) + + ok, err := tokens.Validate(&client, "abcdef12345") + if err != nil { + t.Errorf("Unexpected error from Validate: %v", err) + } + + if ok { + t.Errorf("Validate returned true for an invalid token") + } +} + +func TestValidateRequestError(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + client := prepareAuthTokenHandler(t, "HEAD", http.StatusMethodNotAllowed) + + _, err := tokens.Validate(&client, "abcdef12345") + if err == nil { + t.Errorf("Missing expected error from Validate") + } +} + +func TestRevokeRequestSuccessful(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + client := prepareAuthTokenHandler(t, "DELETE", http.StatusNoContent) + + res := tokens.Revoke(&client, "abcdef12345") + testhelper.AssertNoErr(t, res.Err) +} + +func TestRevokeRequestError(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + client := prepareAuthTokenHandler(t, "DELETE", http.StatusNotFound) + + res := tokens.Revoke(&client, "abcdef12345") + if res.Err == nil { + t.Errorf("Missing expected error from Revoke") + } +} + +func TestNoTokenInResponse(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + client := gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{}, + Endpoint: testhelper.Endpoint(), + } + + testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{}`) + }) + + options := tokens.AuthOptions{UserID: "me", Password: "squirrel!"} + _, err := tokens.Create(&client, &options).Extract() + testhelper.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/results_test.go new file mode 100644 index 00000000..d55a538b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/testing/results_test.go @@ -0,0 +1,52 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/testhelper" +) + +func TestExtractToken(t *testing.T) { + result := getGetResult(t) + + token, err := result.ExtractToken() + testhelper.AssertNoErr(t, err) + + testhelper.CheckDeepEquals(t, &ExpectedToken, token) +} + +func TestExtractCatalog(t *testing.T) { + result := getGetResult(t) + + catalog, err := result.ExtractServiceCatalog() + testhelper.AssertNoErr(t, err) + + testhelper.CheckDeepEquals(t, &ExpectedServiceCatalog, catalog) +} + +func TestExtractUser(t *testing.T) { + result := getGetResult(t) + + user, err := result.ExtractUser() + testhelper.AssertNoErr(t, err) + + testhelper.CheckDeepEquals(t, &ExpectedUser, user) +} + +func TestExtractRoles(t *testing.T) { + result := getGetResult(t) + + roles, err := result.ExtractRoles() + testhelper.AssertNoErr(t, err) + + testhelper.CheckDeepEquals(t, ExpectedRoles, roles) +} + +func TestExtractProject(t *testing.T) { + result := getGetResult(t) + + project, err := result.ExtractProject() + testhelper.AssertNoErr(t, err) + + testhelper.CheckDeepEquals(t, &ExpectedProject, project) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/doc.go index aa7ec196..994ce71b 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/doc.go @@ -54,6 +54,22 @@ Example to Update a User panic(err) } +Example to Change Password of a User + + userID := "0fe36e73809d46aeae6705c39077b1b3" + originalPassword := "secretsecret" + password := "new_secretsecret" + + changePasswordOpts := users.ChangePasswordOpts{ + OriginalPassword: originalPassword, + Password: password, + } + + err := users.ChangePassword(identityClient, userID, changePasswordOpts).ExtractErr() + if err != nil { + panic(err) + } + Example to Delete a User userID := "0fe36e73809d46aeae6705c39077b1b3" @@ -80,6 +96,39 @@ Example to List Groups a User Belongs To fmt.Printf("%+v\n", group) } +Example to Add a User to a Group + + groupID := "bede500ee1124ae9b0006ff859758b3a" + userID := "0fe36e73809d46aeae6705c39077b1b3" + err := users.AddToGroup(identityClient, groupID, userID).ExtractErr() + + if err != nil { + panic(err) + } + +Example to Check Whether a User Belongs to a Group + + groupID := "bede500ee1124ae9b0006ff859758b3a" + userID := "0fe36e73809d46aeae6705c39077b1b3" + ok, err := users.IsMemberOfGroup(identityClient, groupID, userID).Extract() + if err != nil { + panic(err) + } + + if ok { + fmt.Printf("user %s is a member of group %s\n", userID, groupID) + } + +Example to Remove a User from a Group + + groupID := "bede500ee1124ae9b0006ff859758b3a" + userID := "0fe36e73809d46aeae6705c39077b1b3" + err := users.RemoveFromGroup(identityClient, groupID, userID).ExtractErr() + + if err != nil { + panic(err) + } + Example to List Projects a User Belongs To userID := "0fe36e73809d46aeae6705c39077b1b3" diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/errors.go new file mode 100644 index 00000000..0f0b7987 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/errors.go @@ -0,0 +1,17 @@ +package users + +import "fmt" + +// InvalidListFilter is returned by the ToUserListQuery method when validation of +// a filter does not pass +type InvalidListFilter struct { + FilterName string +} + +func (e InvalidListFilter) Error() string { + s := fmt.Sprintf( + "Invalid filter name [%s]: it must be in format of NAME__COMPARATOR", + e.FilterName, + ) + return s +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/requests.go index 779d116f..ed3d1a02 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/requests.go @@ -1,6 +1,10 @@ package users import ( + "net/http" + "net/url" + "strings" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" @@ -47,11 +51,30 @@ type ListOpts struct { // UniqueID filters the response by unique ID. UniqueID string `q:"unique_id"` + + // Filters filters the response by custom filters such as + // 'name__contains=foo' + Filters map[string]string `q:"-"` } // ToUserListQuery formats a ListOpts into a query string. func (opts ListOpts) ToUserListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + + params := q.Query() + for k, v := range opts.Filters { + i := strings.Index(k, "__") + if i > 0 && i < len(k)-2 { + params.Add(k, v) + } else { + return "", InvalidListFilter{FilterName: k} + } + } + + q = &url.URL{RawQuery: params.Encode()} return q.String(), err } @@ -204,6 +227,45 @@ func Update(client *gophercloud.ServiceClient, userID string, opts UpdateOptsBui return } +// ChangePasswordOptsBuilder allows extensions to add additional parameters to +// the ChangePassword request. +type ChangePasswordOptsBuilder interface { + ToUserChangePasswordMap() (map[string]interface{}, error) +} + +// ChangePasswordOpts provides options for changing password for a user. +type ChangePasswordOpts struct { + // OriginalPassword is the original password of the user. + OriginalPassword string `json:"original_password"` + + // Password is the new password of the user. + Password string `json:"password"` +} + +// ToUserChangePasswordMap formats a ChangePasswordOpts into a ChangePassword request. +func (opts ChangePasswordOpts) ToUserChangePasswordMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "user") + if err != nil { + return nil, err + } + + return b, nil +} + +// ChangePassword changes password for a user. +func ChangePassword(client *gophercloud.ServiceClient, userID string, opts ChangePasswordOptsBuilder) (r ChangePasswordResult) { + b, err := opts.ToUserChangePasswordMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(changePasswordURL(client, userID), &b, nil, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + // Delete deletes a user. func Delete(client *gophercloud.ServiceClient, userID string) (r DeleteResult) { _, r.Err = client.Delete(deleteURL(client, userID), nil) @@ -218,6 +280,40 @@ func ListGroups(client *gophercloud.ServiceClient, userID string) pagination.Pag }) } +// AddToGroup adds a user to a group. +func AddToGroup(client *gophercloud.ServiceClient, groupID, userID string) (r AddToGroupResult) { + url := addToGroupURL(client, groupID, userID) + _, r.Err = client.Put(url, nil, nil, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + +// IsMemberOfGroup checks whether a user belongs to a group. +func IsMemberOfGroup(client *gophercloud.ServiceClient, groupID, userID string) (r IsMemberOfGroupResult) { + url := isMemberOfGroupURL(client, groupID, userID) + var response *http.Response + response, r.Err = client.Head(url, &gophercloud.RequestOpts{ + OkCodes: []int{204, 404}, + }) + if r.Err == nil && response != nil { + if (*response).StatusCode == 204 { + r.isMember = true + } + } + + return +} + +// RemoveFromGroup removes a user from a group. +func RemoveFromGroup(client *gophercloud.ServiceClient, groupID, userID string) (r RemoveFromGroupResult) { + url := removeFromGroupURL(client, groupID, userID) + _, r.Err = client.Delete(url, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + // ListProjects enumerates groups user belongs to. func ListProjects(client *gophercloud.ServiceClient, userID string) pagination.Pager { url := listProjectsURL(client, userID) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/results.go index c474e882..e158ac72 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/results.go @@ -98,12 +98,37 @@ type UpdateResult struct { userResult } +// ChangePasswordResult is the response from a ChangePassword operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type ChangePasswordResult struct { + gophercloud.ErrResult +} + // DeleteResult is the response from a Delete operation. Call its ExtractErr to // determine if the request succeeded or failed. type DeleteResult struct { gophercloud.ErrResult } +// AddToGroupResult is the response from a AddToGroup operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type AddToGroupResult struct { + gophercloud.ErrResult +} + +// IsMemberOfGroupResult is the response from a IsMemberOfGroup operation. Call its +// Extract method to determine if the request succeeded or failed. +type IsMemberOfGroupResult struct { + isMember bool + gophercloud.Result +} + +// RemoveFromGroupResult is the response from a RemoveFromGroup operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type RemoveFromGroupResult struct { + gophercloud.ErrResult +} + // UserPage is a single page of User results. type UserPage struct { pagination.LinkedPageBase @@ -147,3 +172,8 @@ func (r userResult) Extract() (*User, error) { err := r.ExtractInto(&s) return s.User, err } + +// Extract extracts IsMemberOfGroupResult as bool and error values +func (r IsMemberOfGroupResult) Extract() (bool, error) { + return r.isMember, r.Err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/fixtures.go index 8d8e6df6..d68e1ac2 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/fixtures.go @@ -129,7 +129,7 @@ const CreateNoOptionsRequest = ` } ` -// UpdateRequest provides the input to as Update request. +// UpdateRequest provides the input to an Update request. const UpdateRequest = ` { "user": { @@ -164,6 +164,16 @@ const UpdateOutput = ` } ` +// ChangePasswordRequest provides the input to a ChangePassword request. +const ChangePasswordRequest = ` +{ + "user": { + "password": "new_secretsecret", + "original_password": "secretsecret" + } +} +` + // ListGroupsOutput provides a ListGroups result. const ListGroupsOutput = ` { @@ -423,6 +433,18 @@ func HandleUpdateUserSuccessfully(t *testing.T) { }) } +// HandleChangeUserPasswordSuccessfully creates an HTTP handler at `/users` on the +// test handler mux that tests change user password. +func HandleChangeUserPasswordSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/users/9fe1d3/password", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, ChangePasswordRequest) + + w.WriteHeader(http.StatusNoContent) + }) +} + // HandleDeleteUserSuccessfully creates an HTTP handler at `/users` on the // test handler mux that tests user deletion. func HandleDeleteUserSuccessfully(t *testing.T) { @@ -448,6 +470,39 @@ func HandleListUserGroupsSuccessfully(t *testing.T) { }) } +// HandleAddToGroupSuccessfully creates an HTTP handler at /groups/{groupID}/users/{userID} +// on the test handler mux that tests adding user to group. +func HandleAddToGroupSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/groups/ea167b/users/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleIsMemberOfGroupSuccessfully creates an HTTP handler at /groups/{groupID}/users/{userID} +// on the test handler mux that tests checking whether user belongs to group. +func HandleIsMemberOfGroupSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/groups/ea167b/users/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "HEAD") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleRemoveFromGroupSuccessfully creates an HTTP handler at /groups/{groupID}/users/{userID} +// on the test handler mux that tests removing user from group. +func HandleRemoveFromGroupSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/groups/ea167b/users/9fe1d3", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + // HandleListUserProjectsSuccessfully creates an HTTP handler at /users/{userID}/projects // on the test handler mux that respons wit a list of two projects func HandleListUserProjectsSuccessfully(t *testing.T) { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/requests_test.go new file mode 100644 index 00000000..3eb1b46f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/testing/requests_test.go @@ -0,0 +1,248 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" + "github.com/gophercloud/gophercloud/openstack/identity/v3/users" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListUsers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListUsersSuccessfully(t) + + count := 0 + err := users.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := users.ExtractUsers(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedUsersSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListUsersAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListUsersSuccessfully(t) + + allPages, err := users.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedUsersSlice, actual) + th.AssertEquals(t, ExpectedUsersSlice[0].Extra["email"], "glance@localhost") + th.AssertEquals(t, ExpectedUsersSlice[1].Extra["email"], "jsmith@example.com") +} + +func TestListUsersFiltersCheck(t *testing.T) { + type test struct { + filterName string + wantErr bool + } + tests := []test{ + {"foo__contains", false}, + {"foo", true}, + {"foo_contains", true}, + {"foo__", true}, + {"__foo", true}, + } + + var listOpts users.ListOpts + for _, _test := range tests { + listOpts.Filters = map[string]string{_test.filterName: "bar"} + _, err := listOpts.ToUserListQuery() + + if !_test.wantErr { + th.AssertNoErr(t, err) + } else { + switch _t := err.(type) { + case nil: + t.Fatal("error expected but got a nil") + case users.InvalidListFilter: + default: + t.Fatalf("unexpected error type: [%T]", _t) + } + } + } +} + +func TestGetUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetUserSuccessfully(t) + + actual, err := users.Get(client.ServiceClient(), "9fe1d3").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondUser, *actual) + th.AssertEquals(t, SecondUser.Extra["email"], "jsmith@example.com") +} + +func TestCreateUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateUserSuccessfully(t) + + iTrue := true + createOpts := users.CreateOpts{ + Name: "jsmith", + DomainID: "1789d1", + Enabled: &iTrue, + Password: "secretsecret", + DefaultProjectID: "263fd9", + Options: map[users.Option]interface{}{ + users.IgnorePasswordExpiry: true, + users.MultiFactorAuthRules: []interface{}{ + []string{"password", "totp"}, + []string{"password", "custom-auth-method"}, + }, + }, + Extra: map[string]interface{}{ + "email": "jsmith@example.com", + }, + } + + actual, err := users.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondUser, *actual) +} + +func TestCreateNoOptionsUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateNoOptionsUserSuccessfully(t) + + iTrue := true + createOpts := users.CreateOpts{ + Name: "jsmith", + DomainID: "1789d1", + Enabled: &iTrue, + Password: "secretsecret", + DefaultProjectID: "263fd9", + Extra: map[string]interface{}{ + "email": "jsmith@example.com", + }, + } + + actual, err := users.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondUserNoOptions, *actual) +} + +func TestUpdateUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateUserSuccessfully(t) + + iFalse := false + updateOpts := users.UpdateOpts{ + Enabled: &iFalse, + Options: map[users.Option]interface{}{ + users.MultiFactorAuthRules: nil, + }, + Extra: map[string]interface{}{ + "disabled_reason": "DDOS", + }, + } + + actual, err := users.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, SecondUserUpdated, *actual) +} + +func TestChangeUserPassword(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleChangeUserPasswordSuccessfully(t) + + changePasswordOpts := users.ChangePasswordOpts{ + OriginalPassword: "secretsecret", + Password: "new_secretsecret", + } + + res := users.ChangePassword(client.ServiceClient(), "9fe1d3", changePasswordOpts) + th.AssertNoErr(t, res.Err) +} + +func TestDeleteUser(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteUserSuccessfully(t) + + res := users.Delete(client.ServiceClient(), "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestListUserGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListUserGroupsSuccessfully(t) + allPages, err := users.ListGroups(client.ServiceClient(), "9fe1d3").AllPages() + th.AssertNoErr(t, err) + actual, err := groups.ExtractGroups(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedGroupsSlice, actual) +} + +func TestAddToGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAddToGroupSuccessfully(t) + res := users.AddToGroup(client.ServiceClient(), "ea167b", "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestIsMemberOfGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleIsMemberOfGroupSuccessfully(t) + ok, err := users.IsMemberOfGroup(client.ServiceClient(), "ea167b", "9fe1d3").Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, true, ok) +} + +func TestRemoveFromGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRemoveFromGroupSuccessfully(t) + res := users.RemoveFromGroup(client.ServiceClient(), "ea167b", "9fe1d3") + th.AssertNoErr(t, res.Err) +} + +func TestListUserProjects(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListUserProjectsSuccessfully(t) + allPages, err := users.ListProjects(client.ServiceClient(), "9fe1d3").AllPages() + th.AssertNoErr(t, err) + actual, err := projects.ExtractProjects(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedProjectsSlice, actual) +} + +func TestListInGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListInGroupSuccessfully(t) + + iTrue := true + listOpts := users.ListOpts{ + Enabled: &iTrue, + } + + allPages, err := users.ListInGroup(client.ServiceClient(), "ea167b", listOpts).AllPages() + th.AssertNoErr(t, err) + actual, err := users.ExtractUsers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedUsersSlice, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/urls.go index 1db2831b..3caa8bbb 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/users/urls.go @@ -18,6 +18,10 @@ func updateURL(client *gophercloud.ServiceClient, userID string) string { return client.ServiceURL("users", userID) } +func changePasswordURL(client *gophercloud.ServiceClient, userID string) string { + return client.ServiceURL("users", userID, "password") +} + func deleteURL(client *gophercloud.ServiceClient, userID string) string { return client.ServiceURL("users", userID) } @@ -26,6 +30,18 @@ func listGroupsURL(client *gophercloud.ServiceClient, userID string) string { return client.ServiceURL("users", userID, "groups") } +func addToGroupURL(client *gophercloud.ServiceClient, groupID, userID string) string { + return client.ServiceURL("groups", groupID, "users", userID) +} + +func isMemberOfGroupURL(client *gophercloud.ServiceClient, groupID, userID string) string { + return client.ServiceURL("groups", groupID, "users", userID) +} + +func removeFromGroupURL(client *gophercloud.ServiceClient, groupID, userID string) string { + return client.ServiceURL("groups", groupID, "users", userID) +} + func listProjectsURL(client *gophercloud.ServiceClient, userID string) string { return client.ServiceURL("users", userID, "projects") } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata/testing/requests_test.go new file mode 100644 index 00000000..4ac42d0e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata/testing/requests_test.go @@ -0,0 +1,87 @@ +package testing + +import ( + "fmt" + "io" + "io/ioutil" + "testing" + + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestUpload(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandlePutImageDataSuccessfully(t) + + err := imagedata.Upload( + fakeclient.ServiceClient(), + "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + readSeekerOfBytes([]byte{5, 3, 7, 24})).ExtractErr() + + th.AssertNoErr(t, err) +} + +func readSeekerOfBytes(bs []byte) io.ReadSeeker { + return &RS{bs: bs} +} + +// implements io.ReadSeeker +type RS struct { + bs []byte + offset int +} + +func (rs *RS) Read(p []byte) (int, error) { + leftToRead := len(rs.bs) - rs.offset + + if 0 < leftToRead { + bytesToWrite := min(leftToRead, len(p)) + for i := 0; i < bytesToWrite; i++ { + p[i] = rs.bs[rs.offset] + rs.offset++ + } + return bytesToWrite, nil + } + return 0, io.EOF +} + +func min(a int, b int) int { + if a < b { + return a + } + return b +} + +func (rs *RS) Seek(offset int64, whence int) (int64, error) { + var offsetInt = int(offset) + if whence == 0 { + rs.offset = offsetInt + } else if whence == 1 { + rs.offset = rs.offset + offsetInt + } else if whence == 2 { + rs.offset = len(rs.bs) - offsetInt + } else { + return 0, fmt.Errorf("For parameter `whence`, expected value in {0,1,2} but got: %#v", whence) + } + + return int64(rs.offset), nil +} + +func TestDownload(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGetImageDataSuccessfully(t) + + rdr, err := imagedata.Download(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea").Extract() + th.AssertNoErr(t, err) + + bs, err := ioutil.ReadAll(rdr) + th.AssertNoErr(t, err) + + th.AssertByteArrayEquals(t, []byte{34, 87, 0, 23, 23, 23, 56, 255, 254, 0}, bs) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/requests.go index 081262f1..c2cbfb32 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/requests.go @@ -1,6 +1,10 @@ package images import ( + "fmt" + "net/url" + "time" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" ) @@ -18,6 +22,11 @@ type ListOptsBuilder interface { // // http://developer.openstack.org/api-ref-image-v2.html type ListOpts struct { + // ID is the ID of the image. + // Multiple IDs can be specified by constructing a string + // such as "in:uuid1,uuid2,uuid3". + ID string `q:"id"` + // Integer value for the limit of values to return. Limit int `q:"limit"` @@ -25,6 +34,8 @@ type ListOpts struct { Marker string `q:"marker"` // Name filters on the name of the image. + // Multiple names can be specified by constructing a string + // such as "in:name1,name2,name3". Name string `q:"name"` // Visibility filters on the visibility of the image. @@ -37,6 +48,8 @@ type ListOpts struct { Owner string `q:"owner"` // Status filters on the status of the image. + // Multiple statuses can be specified by constructing a string + // such as "in:saving,queued". Status ImageStatus `q:"status"` // SizeMin filters on the size_min image property. @@ -56,12 +69,52 @@ type ListOpts struct { // SortDir will sort the list results either ascending or decending. SortDir string `q:"sort_dir"` - Tag string `q:"tag"` + + // Tags filters on specific image tags. + Tags []string `q:"tag"` + + // CreatedAtQuery filters images based on their creation date. + CreatedAtQuery *ImageDateQuery + + // UpdatedAtQuery filters images based on their updated date. + UpdatedAtQuery *ImageDateQuery + + // ContainerFormat filters images based on the container_format. + // Multiple container formats can be specified by constructing a + // string such as "in:bare,ami". + ContainerFormat string `q:"container_format"` + + // DiskFormat filters images based on the disk_format. + // Multiple disk formats can be specified by constructing a string + // such as "in:qcow2,iso". + DiskFormat string `q:"disk_format"` } // ToImageListQuery formats a ListOpts into a query string. func (opts ListOpts) ToImageListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) + params := q.Query() + + if opts.CreatedAtQuery != nil { + createdAt := opts.CreatedAtQuery.Date.Format(time.RFC3339) + if v := opts.CreatedAtQuery.Filter; v != "" { + createdAt = fmt.Sprintf("%s:%s", v, createdAt) + } + + params.Add("created_at", createdAt) + } + + if opts.UpdatedAtQuery != nil { + updatedAt := opts.UpdatedAtQuery.Date.Format(time.RFC3339) + if v := opts.UpdatedAtQuery.Filter; v != "" { + updatedAt = fmt.Sprintf("%s:%s", v, updatedAt) + } + + params.Add("updated_at", updatedAt) + } + + q = &url.URL{RawQuery: params.Encode()} + return q.String(), err } @@ -76,7 +129,12 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { url += query } return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { - return ImagePage{pagination.LinkedPageBase{PageResult: r}} + imagePage := ImagePage{ + serviceURL: c.ServiceURL(), + LinkedPageBase: pagination.LinkedPageBase{PageResult: r}, + } + + return imagePage }) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/results.go index cd819ec9..dbc3c452 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/results.go @@ -102,7 +102,7 @@ func (r *Image) UnmarshalJSON(b []byte) error { switch t := s.SizeBytes.(type) { case nil: - return nil + r.SizeBytes = 0 case float32: r.SizeBytes = int64(t) case float64: @@ -162,6 +162,7 @@ type DeleteResult struct { // ImagePage represents the results of a List request. type ImagePage struct { + serviceURL string pagination.LinkedPageBase } @@ -186,7 +187,7 @@ func (r ImagePage) NextPageURL() (string, error) { return "", nil } - return nextPageURL(r.URL.String(), s.Next) + return nextPageURL(r.serviceURL, s.Next) } // ExtractImages interprets the results of a single page from a List() call, diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/fixtures.go index 33177c23..ddfe0438 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/fixtures.go @@ -212,6 +212,7 @@ func HandleImageCreationSuccessfullyNulls(t *testing.T) { th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) th.TestJSONRequest(t, r, `{ "id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd", + "architecture": "x86_64", "name": "Ubuntu 12.10", "tags": [ "ubuntu", @@ -222,6 +223,7 @@ func HandleImageCreationSuccessfullyNulls(t *testing.T) { w.WriteHeader(http.StatusCreated) w.Header().Add("Content-Type", "application/json") fmt.Fprintf(w, `{ + "architecture": "x86_64", "status": "queued", "name": "Ubuntu 12.10", "protected": false, @@ -345,3 +347,44 @@ func HandleImageUpdateSuccessfully(t *testing.T) { }`) }) } + +// HandleImageListByTagsSuccessfully tests a list operation with tags. +func HandleImageListByTagsSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/images", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.Header().Add("Content-Type", "application/json") + + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, `{ + "images": [ + { + "status": "active", + "name": "cirros-0.3.2-x86_64-disk", + "tags": ["foo", "bar"], + "container_format": "bare", + "created_at": "2014-05-05T17:15:10Z", + "disk_format": "qcow2", + "updated_at": "2014-05-05T17:15:11Z", + "visibility": "public", + "self": "/v2/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27", + "min_disk": 0, + "protected": false, + "id": "1bea47ed-f6a9-463b-b423-14b9cca9ad27", + "file": "/v2/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27/file", + "checksum": "64d7c1cd2b6f60c92c14662941cb7913", + "owner": "5ef70662f8b34079a6eddb8da9d75fe8", + "size": 13167616, + "min_ram": 0, + "schema": "/v2/schemas/image", + "virtual_size": null, + "hw_disk_bus": "scsi", + "hw_disk_bus_model": "virtio-scsi", + "hw_scsi_model": "virtio-scsi" + } + ] + }`) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/requests_test.go new file mode 100644 index 00000000..ac71db86 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/testing/requests_test.go @@ -0,0 +1,390 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageListSuccessfully(t) + + t.Logf("Test setup %+v\n", th.Server) + + t.Logf("Id\tName\tOwner\tChecksum\tSizeBytes") + + pager := images.List(fakeclient.ServiceClient(), images.ListOpts{Limit: 1}) + t.Logf("Pager state %v", pager) + count, pages := 0, 0 + err := pager.EachPage(func(page pagination.Page) (bool, error) { + pages++ + t.Logf("Page %v", page) + images, err := images.ExtractImages(page) + if err != nil { + return false, err + } + + for _, i := range images { + t.Logf("%s\t%s\t%s\t%s\t%v\t\n", i.ID, i.Name, i.Owner, i.Checksum, i.SizeBytes) + count++ + } + + return true, nil + }) + th.AssertNoErr(t, err) + + t.Logf("--------\n%d images listed on %d pages.\n", count, pages) + th.AssertEquals(t, 3, pages) + th.AssertEquals(t, 3, count) +} + +func TestAllPagesImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageListSuccessfully(t) + + pages, err := images.List(fakeclient.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + images, err := images.ExtractImages(pages) + th.AssertNoErr(t, err) + th.AssertEquals(t, 3, len(images)) +} + +func TestCreateImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageCreationSuccessfully(t) + + id := "e7db3b45-8db7-47ad-8109-3fb55c2c24fd" + name := "Ubuntu 12.10" + + actualImage, err := images.Create(fakeclient.ServiceClient(), images.CreateOpts{ + ID: id, + Name: name, + Properties: map[string]string{ + "architecture": "x86_64", + }, + Tags: []string{"ubuntu", "quantal"}, + }).Extract() + + th.AssertNoErr(t, err) + + containerFormat := "bare" + diskFormat := "qcow2" + owner := "b4eedccc6fb74fa8a7ad6b08382b852b" + minDiskGigabytes := 0 + minRAMMegabytes := 0 + file := actualImage.File + createdDate := actualImage.CreatedAt + lastUpdate := actualImage.UpdatedAt + schema := "/v2/schemas/image" + + expectedImage := images.Image{ + ID: "e7db3b45-8db7-47ad-8109-3fb55c2c24fd", + Name: "Ubuntu 12.10", + Tags: []string{"ubuntu", "quantal"}, + + Status: images.ImageStatusQueued, + + ContainerFormat: containerFormat, + DiskFormat: diskFormat, + + MinDiskGigabytes: minDiskGigabytes, + MinRAMMegabytes: minRAMMegabytes, + + Owner: owner, + + Visibility: images.ImageVisibilityPrivate, + File: file, + CreatedAt: createdDate, + UpdatedAt: lastUpdate, + Schema: schema, + VirtualSize: 0, + Properties: map[string]interface{}{ + "hw_disk_bus": "scsi", + "hw_disk_bus_model": "virtio-scsi", + "hw_scsi_model": "virtio-scsi", + }, + } + + th.AssertDeepEquals(t, &expectedImage, actualImage) +} + +func TestCreateImageNulls(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageCreationSuccessfullyNulls(t) + + id := "e7db3b45-8db7-47ad-8109-3fb55c2c24fd" + name := "Ubuntu 12.10" + + actualImage, err := images.Create(fakeclient.ServiceClient(), images.CreateOpts{ + ID: id, + Name: name, + Tags: []string{"ubuntu", "quantal"}, + Properties: map[string]string{ + "architecture": "x86_64", + }, + }).Extract() + + th.AssertNoErr(t, err) + + containerFormat := "bare" + diskFormat := "qcow2" + owner := "b4eedccc6fb74fa8a7ad6b08382b852b" + minDiskGigabytes := 0 + minRAMMegabytes := 0 + file := actualImage.File + createdDate := actualImage.CreatedAt + lastUpdate := actualImage.UpdatedAt + schema := "/v2/schemas/image" + properties := map[string]interface{}{ + "architecture": "x86_64", + } + sizeBytes := int64(0) + + expectedImage := images.Image{ + ID: "e7db3b45-8db7-47ad-8109-3fb55c2c24fd", + Name: "Ubuntu 12.10", + Tags: []string{"ubuntu", "quantal"}, + + Status: images.ImageStatusQueued, + + ContainerFormat: containerFormat, + DiskFormat: diskFormat, + + MinDiskGigabytes: minDiskGigabytes, + MinRAMMegabytes: minRAMMegabytes, + + Owner: owner, + + Visibility: images.ImageVisibilityPrivate, + File: file, + CreatedAt: createdDate, + UpdatedAt: lastUpdate, + Schema: schema, + Properties: properties, + SizeBytes: sizeBytes, + } + + th.AssertDeepEquals(t, &expectedImage, actualImage) +} + +func TestGetImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageGetSuccessfully(t) + + actualImage, err := images.Get(fakeclient.ServiceClient(), "1bea47ed-f6a9-463b-b423-14b9cca9ad27").Extract() + + th.AssertNoErr(t, err) + + checksum := "64d7c1cd2b6f60c92c14662941cb7913" + sizeBytes := int64(13167616) + containerFormat := "bare" + diskFormat := "qcow2" + minDiskGigabytes := 0 + minRAMMegabytes := 0 + owner := "5ef70662f8b34079a6eddb8da9d75fe8" + file := actualImage.File + createdDate := actualImage.CreatedAt + lastUpdate := actualImage.UpdatedAt + schema := "/v2/schemas/image" + + expectedImage := images.Image{ + ID: "1bea47ed-f6a9-463b-b423-14b9cca9ad27", + Name: "cirros-0.3.2-x86_64-disk", + Tags: []string{}, + + Status: images.ImageStatusActive, + + ContainerFormat: containerFormat, + DiskFormat: diskFormat, + + MinDiskGigabytes: minDiskGigabytes, + MinRAMMegabytes: minRAMMegabytes, + + Owner: owner, + + Protected: false, + Visibility: images.ImageVisibilityPublic, + + Checksum: checksum, + SizeBytes: sizeBytes, + File: file, + CreatedAt: createdDate, + UpdatedAt: lastUpdate, + Schema: schema, + VirtualSize: 0, + Properties: map[string]interface{}{ + "hw_disk_bus": "scsi", + "hw_disk_bus_model": "virtio-scsi", + "hw_scsi_model": "virtio-scsi", + }, + } + + th.AssertDeepEquals(t, &expectedImage, actualImage) +} + +func TestDeleteImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageDeleteSuccessfully(t) + + result := images.Delete(fakeclient.ServiceClient(), "1bea47ed-f6a9-463b-b423-14b9cca9ad27") + th.AssertNoErr(t, result.Err) +} + +func TestUpdateImage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageUpdateSuccessfully(t) + + actualImage, err := images.Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", images.UpdateOpts{ + images.ReplaceImageName{NewName: "Fedora 17"}, + images.ReplaceImageTags{NewTags: []string{"fedora", "beefy"}}, + }).Extract() + + th.AssertNoErr(t, err) + + sizebytes := int64(2254249) + checksum := "2cec138d7dae2aa59038ef8c9aec2390" + file := actualImage.File + createdDate := actualImage.CreatedAt + lastUpdate := actualImage.UpdatedAt + schema := "/v2/schemas/image" + + expectedImage := images.Image{ + ID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + Name: "Fedora 17", + Status: images.ImageStatusActive, + Visibility: images.ImageVisibilityPublic, + + SizeBytes: sizebytes, + Checksum: checksum, + + Tags: []string{ + "fedora", + "beefy", + }, + + Owner: "", + MinRAMMegabytes: 0, + MinDiskGigabytes: 0, + + DiskFormat: "", + ContainerFormat: "", + File: file, + CreatedAt: createdDate, + UpdatedAt: lastUpdate, + Schema: schema, + VirtualSize: 0, + Properties: map[string]interface{}{ + "hw_disk_bus": "scsi", + "hw_disk_bus_model": "virtio-scsi", + "hw_scsi_model": "virtio-scsi", + }, + } + + th.AssertDeepEquals(t, &expectedImage, actualImage) +} + +func TestImageDateQuery(t *testing.T) { + date := time.Date(2014, 1, 1, 1, 1, 1, 0, time.UTC) + + listOpts := images.ListOpts{ + CreatedAtQuery: &images.ImageDateQuery{ + Date: date, + Filter: images.FilterGTE, + }, + UpdatedAtQuery: &images.ImageDateQuery{ + Date: date, + }, + } + + expectedQueryString := "?created_at=gte%3A2014-01-01T01%3A01%3A01Z&updated_at=2014-01-01T01%3A01%3A01Z" + actualQueryString, err := listOpts.ToImageListQuery() + th.AssertNoErr(t, err) + th.AssertEquals(t, expectedQueryString, actualQueryString) +} + +func TestImageListByTags(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageListByTagsSuccessfully(t) + + listOpts := images.ListOpts{ + Tags: []string{"foo", "bar"}, + } + + expectedQueryString := "?tag=foo&tag=bar" + actualQueryString, err := listOpts.ToImageListQuery() + th.AssertNoErr(t, err) + th.AssertEquals(t, expectedQueryString, actualQueryString) + + pages, err := images.List(fakeclient.ServiceClient(), listOpts).AllPages() + th.AssertNoErr(t, err) + allImages, err := images.ExtractImages(pages) + th.AssertNoErr(t, err) + + checksum := "64d7c1cd2b6f60c92c14662941cb7913" + sizeBytes := int64(13167616) + containerFormat := "bare" + diskFormat := "qcow2" + minDiskGigabytes := 0 + minRAMMegabytes := 0 + owner := "5ef70662f8b34079a6eddb8da9d75fe8" + file := allImages[0].File + createdDate := allImages[0].CreatedAt + lastUpdate := allImages[0].UpdatedAt + schema := "/v2/schemas/image" + tags := []string{"foo", "bar"} + + expectedImage := images.Image{ + ID: "1bea47ed-f6a9-463b-b423-14b9cca9ad27", + Name: "cirros-0.3.2-x86_64-disk", + Tags: tags, + + Status: images.ImageStatusActive, + + ContainerFormat: containerFormat, + DiskFormat: diskFormat, + + MinDiskGigabytes: minDiskGigabytes, + MinRAMMegabytes: minRAMMegabytes, + + Owner: owner, + + Protected: false, + Visibility: images.ImageVisibilityPublic, + + Checksum: checksum, + SizeBytes: sizeBytes, + File: file, + CreatedAt: createdDate, + UpdatedAt: lastUpdate, + Schema: schema, + VirtualSize: 0, + Properties: map[string]interface{}{ + "hw_disk_bus": "scsi", + "hw_disk_bus_model": "virtio-scsi", + "hw_scsi_model": "virtio-scsi", + }, + } + + th.AssertDeepEquals(t, expectedImage, allImages[0]) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/types.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/types.go index 2e01b38f..d2f9cbd3 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/types.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/types.go @@ -1,5 +1,9 @@ package images +import ( + "time" +) + // ImageStatus image statuses // http://docs.openstack.org/developer/glance/statuses.html type ImageStatus string @@ -77,3 +81,24 @@ const ( // ImageMemberStatusAll ImageMemberStatusAll ImageMemberStatus = "all" ) + +// ImageDateFilter represents a valid filter to use for filtering +// images by their date during a List. +type ImageDateFilter string + +const ( + FilterGT ImageDateFilter = "gt" + FilterGTE ImageDateFilter = "gte" + FilterLT ImageDateFilter = "lt" + FilterLTE ImageDateFilter = "lte" + FilterNEQ ImageDateFilter = "neq" + FilterEQ ImageDateFilter = "eq" +) + +// ImageDateQuery represents a date field to be used for listing images. +// If no filter is specified, the query will act as though FilterEQ was +// set. +type ImageDateQuery struct { + Date time.Time + Filter ImageDateFilter +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/urls.go index bf7cea1e..1780c3c6 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images/urls.go @@ -2,8 +2,10 @@ package images import ( "net/url" + "strings" "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/utils" ) // `listURL` is a pure function. `listURL(c)` is a URL for which a GET @@ -38,14 +40,26 @@ func deleteURL(c *gophercloud.ServiceClient, imageID string) string { } // builds next page full url based on current url -func nextPageURL(currentURL string, next string) (string, error) { - base, err := url.Parse(currentURL) +func nextPageURL(serviceURL, requestedNext string) (string, error) { + base, err := utils.BaseEndpoint(serviceURL) if err != nil { return "", err } - rel, err := url.Parse(next) + + requestedNextURL, err := url.Parse(requestedNext) + if err != nil { + return "", err + } + + base = gophercloud.NormalizeURL(base) + nextPath := base + strings.TrimPrefix(requestedNextURL.Path, "/") + + nextURL, err := url.Parse(nextPath) if err != nil { return "", err } - return base.ResolveReference(rel).String(), nil + + nextURL.RawQuery = requestedNextURL.RawQuery + + return nextURL.String(), nil } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/members/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/members/testing/requests_test.go new file mode 100644 index 00000000..04624c99 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/members/testing/requests_test.go @@ -0,0 +1,172 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +const createdAtString = "2013-09-20T19:22:19Z" +const updatedAtString = "2013-09-20T19:25:31Z" + +func TestCreateMemberSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreateImageMemberSuccessfully(t) + im, err := members.Create(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + "8989447062e04a818baf9e073fd04fa7").Extract() + th.AssertNoErr(t, err) + + createdAt, err := time.Parse(time.RFC3339, createdAtString) + th.AssertNoErr(t, err) + + updatedAt, err := time.Parse(time.RFC3339, updatedAtString) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, members.Member{ + CreatedAt: createdAt, + ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + MemberID: "8989447062e04a818baf9e073fd04fa7", + Schema: "/v2/schemas/member", + Status: "pending", + UpdatedAt: updatedAt, + }, *im) + +} + +func TestMemberListSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageMemberList(t) + + pager := members.List(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea") + t.Logf("Pager state %v", pager) + count, pages := 0, 0 + err := pager.EachPage(func(page pagination.Page) (bool, error) { + pages++ + t.Logf("Page %v", page) + members, err := members.ExtractMembers(page) + if err != nil { + return false, err + } + + for _, i := range members { + t.Logf("%s\t%s\t%s\t%s\t\n", i.ImageID, i.MemberID, i.Status, i.Schema) + count++ + } + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, pages) + th.AssertEquals(t, 2, count) +} + +func TestMemberListEmpty(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageMemberEmptyList(t) + + pager := members.List(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea") + t.Logf("Pager state %v", pager) + count, pages := 0, 0 + err := pager.EachPage(func(page pagination.Page) (bool, error) { + pages++ + t.Logf("Page %v", page) + members, err := members.ExtractMembers(page) + if err != nil { + return false, err + } + + for _, i := range members { + t.Logf("%s\t%s\t%s\t%s\t\n", i.ImageID, i.MemberID, i.Status, i.Schema) + count++ + } + + return true, nil + }) + + th.AssertNoErr(t, err) + th.AssertEquals(t, 0, pages) + th.AssertEquals(t, 0, count) +} + +func TestShowMemberDetails(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleImageMemberDetails(t) + md, err := members.Get(fakeclient.ServiceClient(), + "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + "8989447062e04a818baf9e073fd04fa7").Extract() + + th.AssertNoErr(t, err) + if md == nil { + t.Errorf("Expected non-nil value for md") + } + + createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") + th.AssertNoErr(t, err) + + updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, members.Member{ + CreatedAt: createdAt, + ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + MemberID: "8989447062e04a818baf9e073fd04fa7", + Schema: "/v2/schemas/member", + Status: "pending", + UpdatedAt: updatedAt, + }, *md) +} + +func TestDeleteMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + counter := HandleImageMemberDeleteSuccessfully(t) + + result := members.Delete(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + "8989447062e04a818baf9e073fd04fa7") + th.AssertEquals(t, 1, counter.Counter) + th.AssertNoErr(t, result.Err) +} + +func TestMemberUpdateSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + counter := HandleImageMemberUpdate(t) + im, err := members.Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + "8989447062e04a818baf9e073fd04fa7", + members.UpdateOpts{ + Status: "accepted", + }).Extract() + th.AssertEquals(t, 1, counter.Counter) + th.AssertNoErr(t, err) + + createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") + th.AssertNoErr(t, err) + + updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, members.Member{ + CreatedAt: createdAt, + ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", + MemberID: "8989447062e04a818baf9e073fd04fa7", + Schema: "/v2/schemas/member", + Status: "accepted", + UpdatedAt: updatedAt, + }, *im) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/doc.go new file mode 100644 index 00000000..28ed82e5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/doc.go @@ -0,0 +1,55 @@ +/* +Package tasks enables management and retrieval of tasks from the OpenStack +Imageservice. + +Example to List Tasks + + listOpts := tasks.ListOpts{ + Owner: "424e7cf0243c468ca61732ba45973b3e", + } + + allPages, err := tasks.List(imagesClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allTasks, err := tasks.ExtractTasks(allPages) + if err != nil { + panic(err) + } + + for _, task := range allTasks { + fmt.Printf("%+v\n", task) + } + +Example to Get a Task + + task, err := tasks.Get(imagesClient, "1252f636-1246-4319-bfba-c47cde0efbe0").Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", task) + +Example to Create a Task + + createOpts := tasks.CreateOpts{ + Type: "import", + Input: map[string]interface{}{ + "image_properties": map[string]interface{}{ + "container_format": "bare", + "disk_format": "raw", + }, + "import_from_format": "raw", + "import_from": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img", + }, + } + + task, err := tasks.Create(imagesClient, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", task) +*/ +package tasks diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/requests.go new file mode 100644 index 00000000..94fe45d9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/requests.go @@ -0,0 +1,128 @@ +package tasks + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// TaskStatus represents valid task status. +// You can use this type to compare the actual status of a task to a one of the +// pre-defined statuses. +type TaskStatus string + +const ( + // TaskStatusPending represents status of the pending task. + TaskStatusPending TaskStatus = "pending" + + // TaskStatusProcessing represents status of the processing task. + TaskStatusProcessing TaskStatus = "processing" + + // TaskStatusSuccess represents status of the success task. + TaskStatusSuccess TaskStatus = "success" + + // TaskStatusFailure represents status of the failure task. + TaskStatusFailure TaskStatus = "failure" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToTaskListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the OpenStack Imageservice tasks API. +type ListOpts struct { + // Integer value for the limit of values to return. + Limit int `q:"limit"` + + // ID of the task at which you want to set a marker. + Marker string `q:"marker"` + + // SortDir allows to select sort direction. + // It can be "asc" or "desc" (default). + SortDir string `q:"sort_dir"` + + // SortKey allows to sort by one of the following tTask attributes: + // - created_at + // - expires_at + // - status + // - type + // - updated_at + // Default is created_at. + SortKey string `q:"sort_key"` + + // ID filters on the identifier of the task. + ID string `json:"id"` + + // Type filters on the type of the task. + Type string `json:"type"` + + // Status filters on the status of the task. + Status TaskStatus `q:"status"` +} + +// ToTaskListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToTaskListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of the tasks. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(c) + if opts != nil { + query, err := opts.ToTaskListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + taskPage := TaskPage{ + serviceURL: c.ServiceURL(), + LinkedPageBase: pagination.LinkedPageBase{PageResult: r}, + } + + return taskPage + }) +} + +// Get retrieves a specific Imageservice task based on its ID. +func Get(c *gophercloud.ServiceClient, taskID string) (r GetResult) { + _, r.Err = c.Get(getURL(c, taskID), &r.Body, nil) + return +} + +// CreateOptsBuilder allows to add additional parameters to the Create request. +type CreateOptsBuilder interface { + ToTaskCreateMap() (map[string]interface{}, error) +} + +// CreateOpts specifies parameters of a new Imageservice task. +type CreateOpts struct { + Type string `json:"type" required:"true"` + Input map[string]interface{} `json:"input"` +} + +// ToTaskCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToTaskCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +// Create requests the creation of a new Imageservice task on the server. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToTaskCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/results.go new file mode 100644 index 00000000..3a7f5ca1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/results.go @@ -0,0 +1,114 @@ +package tasks + +import ( + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type commonResult struct { + gophercloud.Result +} + +// GetResult represents the result of a Get operation. Call its Extract +// method to interpret it as a Task. +type GetResult struct { + commonResult +} + +// CreateResult represents the result of a Create operation. Call its Extract +// method to interpret it as a Task. +type CreateResult struct { + commonResult +} + +// Task represents a single task of the OpenStack Image service. +type Task struct { + // ID is a unique identifier of the task. + ID string `json:"id"` + + // Type represents the type of the task. + Type string `json:"type"` + + // Status represents current status of the task. + // You can use the TaskStatus custom type to unmarshal raw JSON response into + // the pre-defined valid task status. + Status string `json:"status"` + + // Input represents different parameters for the task. + Input map[string]interface{} `json:"input"` + + // Result represents task result details. + Result map[string]interface{} `json:"result"` + + // Owner is a unique identifier of the task owner. + Owner string `json:"owner"` + + // Message represents human-readable message that is usually populated + // on task failure. + Message string `json:"message"` + + // ExpiresAt contains the timestamp of when the task will become a subject of + // removal. + ExpiresAt time.Time `json:"expires_at"` + + // CreatedAt contains the task creation timestamp. + CreatedAt time.Time `json:"created_at"` + + // UpdatedAt contains the latest timestamp of when the task was updated. + UpdatedAt time.Time `json:"updated_at"` + + // Self contains URI for the task. + Self string `json:"self"` + + // Schema the path to the JSON-schema that represent the task. + Schema string `json:"schema"` +} + +// Extract interprets any commonResult as a Task. +func (r commonResult) Extract() (*Task, error) { + var s *Task + err := r.ExtractInto(&s) + return s, err +} + +// TaskPage represents the results of a List request. +type TaskPage struct { + serviceURL string + pagination.LinkedPageBase +} + +// IsEmpty returns true if a TaskPage contains no Tasks results. +func (r TaskPage) IsEmpty() (bool, error) { + tasks, err := ExtractTasks(r) + return len(tasks) == 0, err +} + +// NextPageURL uses the response's embedded link reference to navigate to +// the next page of results. +func (r TaskPage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + + if s.Next == "" { + return "", nil + } + + return nextPageURL(r.serviceURL, s.Next) +} + +// ExtractTasks interprets the results of a single page from a List() call, +// producing a slice of Task entities. +func ExtractTasks(r pagination.Page) ([]Task, error) { + var s struct { + Tasks []Task `json:"tasks"` + } + err := (r.(TaskPage)).ExtractInto(&s) + return s.Tasks, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/doc.go new file mode 100644 index 00000000..8d4a7684 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/doc.go @@ -0,0 +1,2 @@ +// tasks unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/fixtures.go new file mode 100644 index 00000000..6a1a9d3e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/fixtures.go @@ -0,0 +1,124 @@ +package testing + +import ( + "time" + + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks" +) + +// TasksListResult represents raw server response from a server to a list call. +const TasksListResult = ` +{ + "schema": "/v2/schemas/tasks", + "tasks": [ + { + "status": "pending", + "self": "/v2/tasks/1252f636-1246-4319-bfba-c47cde0efbe0", + "updated_at": "2018-07-25T08:59:14Z", + "id": "1252f636-1246-4319-bfba-c47cde0efbe0", + "owner": "424e7cf0243c468ca61732ba45973b3e", + "type": "import", + "created_at": "2018-07-25T08:59:13Z", + "schema": "/v2/schemas/task" + }, + { + "status": "processing", + "self": "/v2/tasks/349a51f4-d51d-47b6-82da-4fa516f0ca32", + "updated_at": "2018-07-25T08:56:19Z", + "id": "349a51f4-d51d-47b6-82da-4fa516f0ca32", + "owner": "fb57277ef2f84a0e85b9018ec2dedbf7", + "type": "import", + "created_at": "2018-07-25T08:56:17Z", + "schema": "/v2/schemas/task" + } + ], + "first": "/v2/tasks?sort_key=status&sort_dir=desc&limit=20" +} +` + +// Task1 is an expected representation of a first task from the TasksListResult. +var Task1 = tasks.Task{ + ID: "1252f636-1246-4319-bfba-c47cde0efbe0", + Status: string(tasks.TaskStatusPending), + Type: "import", + Owner: "424e7cf0243c468ca61732ba45973b3e", + CreatedAt: time.Date(2018, 7, 25, 8, 59, 13, 0, time.UTC), + UpdatedAt: time.Date(2018, 7, 25, 8, 59, 14, 0, time.UTC), + Self: "/v2/tasks/1252f636-1246-4319-bfba-c47cde0efbe0", + Schema: "/v2/schemas/task", +} + +// Task2 is an expected representation of a first task from the TasksListResult. +var Task2 = tasks.Task{ + ID: "349a51f4-d51d-47b6-82da-4fa516f0ca32", + Status: string(tasks.TaskStatusProcessing), + Type: "import", + Owner: "fb57277ef2f84a0e85b9018ec2dedbf7", + CreatedAt: time.Date(2018, 7, 25, 8, 56, 17, 0, time.UTC), + UpdatedAt: time.Date(2018, 7, 25, 8, 56, 19, 0, time.UTC), + Self: "/v2/tasks/349a51f4-d51d-47b6-82da-4fa516f0ca32", + Schema: "/v2/schemas/task", +} + +// TasksGetResult represents raw server response from a server to a get call. +const TasksGetResult = ` +{ + "status": "pending", + "created_at": "2018-07-25T08:59:13Z", + "updated_at": "2018-07-25T08:59:14Z", + "self": "/v2/tasks/1252f636-1246-4319-bfba-c47cde0efbe0", + "result": null, + "owner": "424e7cf0243c468ca61732ba45973b3e", + "input": { + "image_properties": { + "container_format": "bare", + "disk_format": "raw" + }, + "import_from_format": "raw", + "import_from": "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img" + }, + "message": "", + "type": "import", + "id": "1252f636-1246-4319-bfba-c47cde0efbe0", + "schema": "/v2/schemas/task" +} +` + +// TaskCreateRequest represents a request to create a task. +const TaskCreateRequest = ` +{ + "input": { + "image_properties": { + "container_format": "bare", + "disk_format": "raw" + }, + "import_from_format": "raw", + "import_from": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img" + }, + "type": "import" +} +` + +// TaskCreateResult represents a raw server response to the TaskCreateRequest. +const TaskCreateResult = ` +{ + "status": "pending", + "created_at": "2018-07-25T11:07:54Z", + "updated_at": "2018-07-25T11:07:54Z", + "self": "/v2/tasks/d550c87d-86ed-430a-9895-c7a1f5ce87e9", + "result": null, + "owner": "fb57277ef2f84a0e85b9018ec2dedbf7", + "input": { + "image_properties": { + "container_format": "bare", + "disk_format": "raw" + }, + "import_from_format": "raw", + "import_from": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img" + }, + "message": "", + "type": "import", + "id": "d550c87d-86ed-430a-9895-c7a1f5ce87e9", + "schema": "/v2/schemas/task" +} +` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/requests_test.go new file mode 100644 index 00000000..bc9af17a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/testing/requests_test.go @@ -0,0 +1,138 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fakeclient "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/tasks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, TasksListResult) + }) + + count := 0 + + tasks.List(fakeclient.ServiceClient(), tasks.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := tasks.ExtractTasks(page) + if err != nil { + t.Errorf("Failed to extract tasks: %v", err) + return false, nil + } + + expected := []tasks.Task{ + Task1, + Task2, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/tasks/1252f636-1246-4319-bfba-c47cde0efbe0", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, TasksGetResult) + }) + + s, err := tasks.Get(fakeclient.ServiceClient(), "1252f636-1246-4319-bfba-c47cde0efbe0").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, string(tasks.TaskStatusPending)) + th.AssertEquals(t, s.CreatedAt, time.Date(2018, 7, 25, 8, 59, 13, 0, time.UTC)) + th.AssertEquals(t, s.UpdatedAt, time.Date(2018, 7, 25, 8, 59, 14, 0, time.UTC)) + th.AssertEquals(t, s.Self, "/v2/tasks/1252f636-1246-4319-bfba-c47cde0efbe0") + th.AssertEquals(t, s.Owner, "424e7cf0243c468ca61732ba45973b3e") + th.AssertEquals(t, s.Message, "") + th.AssertEquals(t, s.Type, "import") + th.AssertEquals(t, s.ID, "1252f636-1246-4319-bfba-c47cde0efbe0") + th.AssertEquals(t, s.Schema, "/v2/schemas/task") + th.AssertDeepEquals(t, s.Result, map[string]interface{}(nil)) + th.AssertDeepEquals(t, s.Input, map[string]interface{}{ + "import_from": "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img", + "import_from_format": "raw", + "image_properties": map[string]interface{}{ + "container_format": "bare", + "disk_format": "raw", + }, + }) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/tasks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) + th.TestJSONRequest(t, r, TaskCreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, TaskCreateResult) + }) + + opts := tasks.CreateOpts{ + Type: "import", + Input: map[string]interface{}{ + "image_properties": map[string]interface{}{ + "container_format": "bare", + "disk_format": "raw", + }, + "import_from_format": "raw", + "import_from": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img", + }, + } + s, err := tasks.Create(fakeclient.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, string(tasks.TaskStatusPending)) + th.AssertEquals(t, s.CreatedAt, time.Date(2018, 7, 25, 11, 7, 54, 0, time.UTC)) + th.AssertEquals(t, s.UpdatedAt, time.Date(2018, 7, 25, 11, 7, 54, 0, time.UTC)) + th.AssertEquals(t, s.Self, "/v2/tasks/d550c87d-86ed-430a-9895-c7a1f5ce87e9") + th.AssertEquals(t, s.Owner, "fb57277ef2f84a0e85b9018ec2dedbf7") + th.AssertEquals(t, s.Message, "") + th.AssertEquals(t, s.Type, "import") + th.AssertEquals(t, s.ID, "d550c87d-86ed-430a-9895-c7a1f5ce87e9") + th.AssertEquals(t, s.Schema, "/v2/schemas/task") + th.AssertDeepEquals(t, s.Result, map[string]interface{}(nil)) + th.AssertDeepEquals(t, s.Input, map[string]interface{}{ + "import_from": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img", + "import_from_format": "raw", + "image_properties": map[string]interface{}{ + "container_format": "bare", + "disk_format": "raw", + }, + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/urls.go new file mode 100644 index 00000000..8133f383 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/tasks/urls.go @@ -0,0 +1,55 @@ +package tasks + +import ( + "net/url" + "strings" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/utils" +) + +const resourcePath = "tasks" + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, taskID string) string { + return c.ServiceURL(resourcePath, taskID) +} + +func listURL(c *gophercloud.ServiceClient) string { + return rootURL(c) +} + +func getURL(c *gophercloud.ServiceClient, taskID string) string { + return resourceURL(c, taskID) +} + +func createURL(c *gophercloud.ServiceClient) string { + return rootURL(c) +} + +func nextPageURL(serviceURL, requestedNext string) (string, error) { + base, err := utils.BaseEndpoint(serviceURL) + if err != nil { + return "", err + } + + requestedNextURL, err := url.Parse(requestedNext) + if err != nil { + return "", err + } + + base = gophercloud.NormalizeURL(base) + nextPath := base + strings.TrimPrefix(requestedNextURL.Path, "/") + + nextURL, err := url.Parse(nextPath) + if err != nil { + return "", err + } + + nextURL.RawQuery = requestedNextURL.RawQuery + + return nextURL.String(), nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/doc.go new file mode 100644 index 00000000..d61940cb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/doc.go @@ -0,0 +1,54 @@ +/* +Package acls manages acls in the OpenStack Key Manager Service. + +All functions have a Secret and Container equivalent. + +Example to Get a Secret's ACL + + acl, err := acls.GetSecretACL(client, secretID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", acl) + +Example to Set a Secret's ACL + + users := []string{"uuid", "uuid"} + iFalse := false + setOpts := acls.SetOpts{ + Type: "read", + users: &users, + ProjectAccess: &iFalse, + } + + aclRef, err := acls.SetSecretACL(client, secretID, setOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", aclRef) + +Example to Update a Secret's ACL + + users := []string{} + setOpts := acls.SetOpts{ + Type: "read", + users: &users, + } + + aclRef, err := acls.UpdateSecretACL(client, secretID, setOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", aclRef) + +Example to Delete a Secret's ACL + + err := acls.DeleteSecretACL(client, secretID).ExtractErr() + if err != nil { + panci(err) + } +*/ +package acls diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/requests.go new file mode 100644 index 00000000..b83c5607 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/requests.go @@ -0,0 +1,112 @@ +package acls + +import ( + "github.com/gophercloud/gophercloud" +) + +// GetContainerACL retrieves the ACL of a container. +func GetContainerACL(client *gophercloud.ServiceClient, containerID string) (r ACLResult) { + _, r.Err = client.Get(containerURL(client, containerID), &r.Body, nil) + return +} + +// GetSecretACL retrieves the ACL of a secret. +func GetSecretACL(client *gophercloud.ServiceClient, secretID string) (r ACLResult) { + _, r.Err = client.Get(secretURL(client, secretID), &r.Body, nil) + return +} + +// SetOptsBuilder allows extensions to add additional parameters to the +// Set request. +type SetOptsBuilder interface { + ToACLSetMap() (map[string]interface{}, error) +} + +// SetOpts represents options to set an ACL on a resource. +type SetOpts struct { + // Type is the type of ACL to set. ie: read. + Type string `json:"-" required:"true"` + + // Users are the list of Keystone user UUIDs. + Users *[]string `json:"users,omitempty"` + + // ProjectAccess toggles if all users in a project can access the resource. + ProjectAccess *bool `json:"project-access,omitempty"` +} + +// ToACLSetMap formats a SetOpts into a set request. +func (opts SetOpts) ToACLSetMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, opts.Type) +} + +// SetContainerACL will set an ACL on a container. +func SetContainerACL(client *gophercloud.ServiceClient, containerID string, opts SetOptsBuilder) (r ACLRefResult) { + b, err := opts.ToACLSetMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(containerURL(client, containerID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// SetSecretACL will set an ACL on a secret. +func SetSecretACL(client *gophercloud.ServiceClient, secretID string, opts SetOptsBuilder) (r ACLRefResult) { + b, err := opts.ToACLSetMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(secretURL(client, secretID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// UpdateContainerACL will update an ACL on a container. +func UpdateContainerACL(client *gophercloud.ServiceClient, containerID string, opts SetOptsBuilder) (r ACLRefResult) { + b, err := opts.ToACLSetMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Patch(containerURL(client, containerID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// UpdateSecretACL will update an ACL on a secret. +func UpdateSecretACL(client *gophercloud.ServiceClient, secretID string, opts SetOptsBuilder) (r ACLRefResult) { + b, err := opts.ToACLSetMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Patch(secretURL(client, secretID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// DeleteContainerACL will delete an ACL from a conatiner. +func DeleteContainerACL(client *gophercloud.ServiceClient, containerID string) (r DeleteResult) { + _, r.Err = client.Delete(containerURL(client, containerID), &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// DeleteSecretACL will delete an ACL from a secret. +func DeleteSecretACL(client *gophercloud.ServiceClient, secretID string) (r DeleteResult) { + _, r.Err = client.Delete(secretURL(client, secretID), &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/results.go new file mode 100644 index 00000000..959742da --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/results.go @@ -0,0 +1,85 @@ +package acls + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" +) + +// ACL represents an ACL on a resource. +type ACL map[string]ACLDetails + +// ACLDetails represents the details of an ACL. +type ACLDetails struct { + // Created is when the ACL was created. + Created time.Time `json:"-"` + + // ProjectAccess denotes project-level access of the resource. + ProjectAccess bool `json:"project-access"` + + // Updated is when the ACL was updated + Updated time.Time `json:"-"` + + // Users are the UserIDs who have access to the resource. + Users []string `json:"users"` +} + +func (r *ACLDetails) UnmarshalJSON(b []byte) error { + type tmp ACLDetails + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + Updated gophercloud.JSONRFC3339NoZ `json:"updated"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = ACLDetails(s.tmp) + + r.Created = time.Time(s.Created) + r.Updated = time.Time(s.Updated) + + return nil +} + +// ACLRef represents an ACL reference. +type ACLRef string + +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult as an ACL. +func (r commonResult) Extract() (*ACL, error) { + var s *ACL + err := r.ExtractInto(&s) + return s, err +} + +// ACLResult is the response from a Get operation. Call its Extract method +// to interpret it as an ACL. +type ACLResult struct { + commonResult +} + +// ACLRefResult is the response from a Set or Update operation. Call its +// Extract method to interpret it as an ACLRef. +type ACLRefResult struct { + gophercloud.Result +} + +func (r ACLRefResult) Extract() (*ACLRef, error) { + var s struct { + ACLRef ACLRef `json:"acl_ref"` + } + err := r.ExtractInto(&s) + return &s.ACLRef, err +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/fixtures.go new file mode 100644 index 00000000..7ae5b597 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/fixtures.go @@ -0,0 +1,168 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const GetResponse = ` +{ + "read": { + "created": "2018-06-22T17:54:24", + "project-access": false, + "updated": "2018-06-22T17:54:24", + "users": [ + "GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW" + ] + } +}` + +const SetRequest = ` +{ + "read": { + "project-access": false, + "users": [ + "GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW" + ] + } +}` + +const SecretSetResponse = ` +{ + "acl_ref": "http://barbican:9311/v1/secrets/4befede0-fbde-4480-982c-b160c1014a47/acl" +}` + +const ContainerSetResponse = ` +{ + "acl_ref": "http://barbican:9311/v1/containers/4befede0-fbde-4480-982c-b160c1014a47/acl" +}` + +var ExpectedACL = acls.ACL{ + "read": acls.ACLDetails{ + Created: time.Date(2018, 6, 22, 17, 54, 24, 0, time.UTC), + ProjectAccess: false, + Updated: time.Date(2018, 6, 22, 17, 54, 24, 0, time.UTC), + Users: []string{ + "GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW", + }, + }, +} + +var ExpectedSecretACLRef = acls.ACLRef("http://barbican:9311/v1/secrets/4befede0-fbde-4480-982c-b160c1014a47/acl") + +var ExpectedContainerACLRef = acls.ACLRef("http://barbican:9311/v1/containers/4befede0-fbde-4480-982c-b160c1014a47/acl") + +const UpdateRequest = ` +{ + "read": { + "users": [] + } +}` + +// HandleGetSecretACLSuccessfully creates an HTTP handler at `/secrets/uuid/acl` +// on the test handler mux that responds with an acl. +func HandleGetSecretACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleGetContainerACLSuccessfully creates an HTTP handler at `/secrets/uuid/acl` +// on the test handler mux that responds with an acl. +func HandleGetContainerACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleSetSecretACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret creation. +func HandleSetSecretACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, SetRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, SecretSetResponse) + }) +} + +// HandleSetContainerACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret creation. +func HandleSetContainerACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, SetRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ContainerSetResponse) + }) +} + +// HandleUpdateSecretACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret creation. +func HandleUpdateSecretACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, UpdateRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, SecretSetResponse) + }) +} + +// HandleUpdateContainerACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret creation. +func HandleUpdateContainerACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, UpdateRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ContainerSetResponse) + }) +} + +// HandleDeleteSecretACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret deletion. +func HandleDeleteSecretACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusOK) + }) +} + +// HandleDeleteContainerACLSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret deletion. +func HandleDeleteContainerACLSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusOK) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/requests_test.go new file mode 100644 index 00000000..b978f405 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/testing/requests_test.go @@ -0,0 +1,115 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetSecretACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSecretACLSuccessfully(t) + + actual, err := acls.GetSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedACL, *actual) +} + +func TestGetContainerACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetContainerACLSuccessfully(t) + + actual, err := acls.GetContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedACL, *actual) +} + +func TestSetSecretACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleSetSecretACLSuccessfully(t) + + users := []string{"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"} + iFalse := false + setOpts := acls.SetOpts{ + Type: "read", + Users: &users, + ProjectAccess: &iFalse, + } + + actual, err := acls.SetSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", setOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedSecretACLRef, *actual) +} + +func TestSetContainerACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleSetContainerACLSuccessfully(t) + + users := []string{"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"} + iFalse := false + setOpts := acls.SetOpts{ + Type: "read", + Users: &users, + ProjectAccess: &iFalse, + } + + actual, err := acls.SetContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", setOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedContainerACLRef, *actual) +} + +func TestDeleteSecretACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSecretACLSuccessfully(t) + + res := acls.DeleteSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c") + th.AssertNoErr(t, res.Err) +} + +func TestDeleteContainerACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteContainerACLSuccessfully(t) + + res := acls.DeleteContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateSecretACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSecretACLSuccessfully(t) + + newUsers := []string{} + updateOpts := acls.SetOpts{ + Type: "read", + Users: &newUsers, + } + + actual, err := acls.UpdateSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedSecretACLRef, *actual) +} + +func TestUpdateContainerACL(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateContainerACLSuccessfully(t) + + newUsers := []string{} + updateOpts := acls.SetOpts{ + Type: "read", + Users: &newUsers, + } + + actual, err := acls.UpdateContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedContainerACLRef, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/urls.go new file mode 100644 index 00000000..5cb4439a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls/urls.go @@ -0,0 +1,11 @@ +package acls + +import "github.com/gophercloud/gophercloud" + +func containerURL(client *gophercloud.ServiceClient, containerID string) string { + return client.ServiceURL("containers", containerID, "acl") +} + +func secretURL(client *gophercloud.ServiceClient, secretID string) string { + return client.ServiceURL("secrets", secretID, "acl") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/doc.go new file mode 100644 index 00000000..cb11920f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/doc.go @@ -0,0 +1,86 @@ +/* +Package containers manages and retrieves containers in the OpenStack Key Manager +Service. + +Example to List Containers + + allPages, err := containers.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allContainers, err := containers.ExtractContainers(allPages) + if err != nil { + panic(err) + } + + for _, v := range allContainers { + fmt.Printf("%v\n", v) + } + +Example to Create a Container + + createOpts := containers.CreateOpts{ + Type: containers.GenericContainer, + Name: "mycontainer", + SecretRefs: []containers.SecretRef{ + { + Name: secret.Name, + SecretRef: secret.SecretRef, + }, + }, + } + + container, err := containers.Create(client, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", container) + +Example to Delete a Container + + err := containers.Delete(client, containerID).ExtractErr() + if err != nil { + panic(err) + } + +Example to List Consumers of a Container + + allPages, err := containers.ListConsumers(client, containerID, nil).AllPages() + if err != nil { + panic(err) + } + + allConsumers, err := containers.ExtractConsumers(allPages) + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", allConsumers) + +Example to Create a Consumer of a Container + + createOpts := containers.CreateConsumerOpts{ + Name: "jdoe", + URL: "http://example.com", + } + + container, err := containers.CreateConsumer(client, containerID, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Consumer of a Container + + deleteOpts := containers.DeleteConsumerOpts{ + Name: "jdoe", + URL: "http://example.com", + } + + container, err := containers.DeleteConsumer(client, containerID, deleteOpts).Extract() + if err != nil { + panic(err) + } +*/ +package containers diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/requests.go new file mode 100644 index 00000000..190438ed --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/requests.go @@ -0,0 +1,212 @@ +package containers + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ContainerType represents the valid types of containers. +type ContainerType string + +const ( + GenericContainer ContainerType = "generic" + RSAContainer ContainerType = "rsa" + CertificateContainer ContainerType = "certificate" +) + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request +type ListOptsBuilder interface { + ToContainerListQuery() (string, error) +} + +// ListOpts provides options to filter the List results. +type ListOpts struct { + // Limit is the amount of containers to retrieve. + Limit int `q:"limit"` + + // Name is the name of the container + Name string `q:"name"` + + // Offset is the index within the list to retrieve. + Offset int `q:"offset"` +} + +// ToContainerListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToContainerListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List retrieves a list of containers. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToContainerListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ContainerPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves details of a container. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} + +// CreateOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateOptsBuilder interface { + ToContainerCreateMap() (map[string]interface{}, error) +} + +// CreateOpts provides options used to create a container. +type CreateOpts struct { + // Type represents the type of container. + Type ContainerType `json:"type" required:"true"` + + // Name is the name of the container. + Name string `json:"name"` + + // SecretRefs is a list of secret refs for the container. + SecretRefs []SecretRef `json:"secret_refs"` +} + +// ToContainerCreateMap formats a CreateOpts into a create request. +func (opts CreateOpts) ToContainerCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// Create creates a new container. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToContainerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// Delete deletes a container. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +// ListConsumersOptsBuilder allows extensions to add additional parameters to +// the ListConsumers request +type ListConsumersOptsBuilder interface { + ToContainerListConsumersQuery() (string, error) +} + +// ListConsumersOpts provides options to filter the List results. +type ListConsumersOpts struct { + // Limit is the amount of consumers to retrieve. + Limit int `q:"limit"` + + // Offset is the index within the list to retrieve. + Offset int `q:"offset"` +} + +// ToContainerListConsumersQuery formats a ListConsumersOpts into a query +// string. +func (opts ListOpts) ToContainerListConsumersQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListConsumers retrieves a list of consumers from a container. +func ListConsumers(client *gophercloud.ServiceClient, containerID string, opts ListConsumersOptsBuilder) pagination.Pager { + url := listConsumersURL(client, containerID) + if opts != nil { + query, err := opts.ToContainerListConsumersQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ConsumerPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// CreateConsumerOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateConsumerOptsBuilder interface { + ToContainerConsumerCreateMap() (map[string]interface{}, error) +} + +// CreateConsumerOpts provides options used to create a container. +type CreateConsumerOpts struct { + // Name is the name of the consumer. + Name string `json:"name"` + + // URL is the URL to the consumer resource. + URL string `json:"URL"` +} + +// ToContainerConsumerCreateMap formats a CreateConsumerOpts into a create +// request. +func (opts CreateConsumerOpts) ToContainerConsumerCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// CreateConsumer creates a new consumer. +func CreateConsumer(client *gophercloud.ServiceClient, containerID string, opts CreateConsumerOptsBuilder) (r CreateConsumerResult) { + b, err := opts.ToContainerConsumerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createConsumerURL(client, containerID), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// DeleteConsumerOptsBuilder allows extensions to add additional parameters to +// the Delete request. +type DeleteConsumerOptsBuilder interface { + ToContainerConsumerDeleteMap() (map[string]interface{}, error) +} + +// DeleteConsumerOpts represents options used for deleting a consumer. +type DeleteConsumerOpts struct { + // Name is the name of the consumer. + Name string `json:"name"` + + // URL is the URL to the consumer resource. + URL string `json:"URL"` +} + +// ToContainerConsumerDeleteMap formats a DeleteConsumerOpts into a create +// request. +func (opts DeleteConsumerOpts) ToContainerConsumerDeleteMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// DeleteConsumer deletes a consumer. +func DeleteConsumer(client *gophercloud.ServiceClient, containerID string, opts DeleteConsumerOptsBuilder) (r DeleteConsumerResult) { + url := deleteConsumerURL(client, containerID) + + b, err := opts.ToContainerConsumerDeleteMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Request("DELETE", url, &gophercloud.RequestOpts{ + JSONBody: b, + JSONResponse: &r.Body, + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/results.go new file mode 100644 index 00000000..c94c9ac6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/results.go @@ -0,0 +1,232 @@ +package containers + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Container represents a container in the key manager service. +type Container struct { + // Consumers are the consumers of the container. + Consumers []ConsumerRef `json:"consumers"` + + // ContainerRef is the URL to the container + ContainerRef string `json:"container_ref"` + + // Created is the date the container was created. + Created time.Time `json:"-"` + + // CreatorID is the creator of the container. + CreatorID string `json:"creator_id"` + + // Name is the name of the container. + Name string `json:"name"` + + // SecretRefs are the secret references of the container. + SecretRefs []SecretRef `json:"secret_refs"` + + // Status is the status of the container. + Status string `json:"status"` + + // Type is the type of container. + Type string `json:"type"` + + // Updated is the date the container was updated. + Updated time.Time `json:"-"` +} + +func (r *Container) UnmarshalJSON(b []byte) error { + type tmp Container + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + Updated gophercloud.JSONRFC3339NoZ `json:"updated"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Container(s.tmp) + + r.Created = time.Time(s.Created) + r.Updated = time.Time(s.Updated) + + return nil +} + +// ConsumerRef represents a consumer reference in a container. +type ConsumerRef struct { + // Name is the name of the consumer. + Name string `json:"name"` + + // URL is the URL to the consumer resource. + URL string `json:"url"` +} + +// SecretRef is a reference to a secret. +type SecretRef struct { + SecretRef string `json:"secret_ref"` + Name string `json:"name"` +} + +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult as a Container. +func (r commonResult) Extract() (*Container, error) { + var s *Container + err := r.ExtractInto(&s) + return s, err +} + +// GetResult is the response from a Get operation. Call its Extract method +// to interpret it as a container. +type GetResult struct { + commonResult +} + +// CreateResult is the response from a Create operation. Call its Extract method +// to interpret it as a container. +type CreateResult struct { + commonResult +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// ContainerPage is a single page of container results. +type ContainerPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of Container contains any results. +func (r ContainerPage) IsEmpty() (bool, error) { + containers, err := ExtractContainers(r) + return len(containers) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r ContainerPage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + Previous string `json:"previous"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Next, err +} + +// ExtractContainers returns a slice of Containers contained in a single page of +// results. +func ExtractContainers(r pagination.Page) ([]Container, error) { + var s struct { + Containers []Container `json:"containers"` + } + err := (r.(ContainerPage)).ExtractInto(&s) + return s.Containers, err +} + +// Consumer represents a consumer in a container. +type Consumer struct { + // Created is the date the container was created. + Created time.Time `json:"-"` + + // Name is the name of the container. + Name string `json:"name"` + + // Status is the status of the container. + Status string `json:"status"` + + // Updated is the date the container was updated. + Updated time.Time `json:"-"` + + // URL is the url to the consumer. + URL string `json:"url"` +} + +func (r *Consumer) UnmarshalJSON(b []byte) error { + type tmp Consumer + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + Updated gophercloud.JSONRFC3339NoZ `json:"updated"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Consumer(s.tmp) + + r.Created = time.Time(s.Created) + r.Updated = time.Time(s.Updated) + + return nil +} + +type consumerResult struct { + gophercloud.Result +} + +// Extract interprets any consumerResult as a Consumer. +func (r consumerResult) Extract() (*Consumer, error) { + var s *Consumer + err := r.ExtractInto(&s) + return s, err +} + +// CreateConsumerResult is the response from a CreateConsumer operation. +// Call its Extract method to interpret it as a container. +type CreateConsumerResult struct { + // This is not a typo. + commonResult +} + +// DeleteConsumerResult is the response from a DeleteConsumer operation. +// Call its Extract to interpret it as a container. +type DeleteConsumerResult struct { + // This is not a typo. + commonResult +} + +// ConsumerPage is a single page of consumer results. +type ConsumerPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of consumers contains any results. +func (r ConsumerPage) IsEmpty() (bool, error) { + consumers, err := ExtractConsumers(r) + return len(consumers) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r ConsumerPage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + Previous string `json:"previous"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Next, err +} + +// ExtractConsumers returns a slice of Consumers contained in a single page of +// results. +func ExtractConsumers(r pagination.Page) ([]Consumer, error) { + var s struct { + Consumers []Consumer `json:"consumers"` + } + err := (r.(ConsumerPage)).ExtractInto(&s) + return s.Consumers, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/fixtures.go new file mode 100644 index 00000000..3c73e38b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/fixtures.go @@ -0,0 +1,321 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListResponse provides a single page of container results. +const ListResponse = ` +{ + "containers": [ + { + "consumers": [], + "container_ref": "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + "created": "2018-06-21T21:28:37", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "name": "mycontainer", + "secret_refs": [ + { + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" + } + ], + "status": "ACTIVE", + "type": "generic", + "updated": "2018-06-21T21:28:37" + }, + { + "consumers": [], + "container_ref": "http://barbican:9311/v1/containers/47b20e73-335b-4867-82dc-3796524d5e20", + "created": "2018-06-21T21:30:09", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "name": "anothercontainer", + "secret_refs": [ + { + "name": "another", + "secret_ref": "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac" + } + ], + "status": "ACTIVE", + "type": "generic", + "updated": "2018-06-21T21:30:09" + } + ], + "total": 2 +}` + +// GetResponse provides a Get result. +const GetResponse = ` +{ + "consumers": [], + "container_ref": "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + "created": "2018-06-21T21:28:37", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "name": "mycontainer", + "secret_refs": [ + { + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" + } + ], + "status": "ACTIVE", + "type": "generic", + "updated": "2018-06-21T21:28:37" +}` + +// CreateRequest provides the input to a Create request. +const CreateRequest = ` +{ + "name": "mycontainer", + "secret_refs": [ + { + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" + } + ], + "type": "generic" +}` + +// CreateResponse is the response of a Create request. +const CreateResponse = ` +{ + "consumers": [], + "container_ref": "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + "created": "2018-06-21T21:28:37", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "name": "mycontainer", + "secret_refs": [ + { + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" + } + ], + "status": "ACTIVE", + "type": "generic", + "updated": "2018-06-21T21:28:37" +}` + +// FirstContainer is the first resource in the List request. +var FirstContainer = containers.Container{ + Consumers: []containers.ConsumerRef{}, + ContainerRef: "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + Created: time.Date(2018, 6, 21, 21, 28, 37, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Name: "mycontainer", + SecretRefs: []containers.SecretRef{ + { + Name: "mysecret", + SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + }, + }, + Status: "ACTIVE", + Type: "generic", + Updated: time.Date(2018, 6, 21, 21, 28, 37, 0, time.UTC), +} + +// SecondContainer is the second resource in the List request. +var SecondContainer = containers.Container{ + Consumers: []containers.ConsumerRef{}, + ContainerRef: "http://barbican:9311/v1/containers/47b20e73-335b-4867-82dc-3796524d5e20", + Created: time.Date(2018, 6, 21, 21, 30, 9, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Name: "anothercontainer", + SecretRefs: []containers.SecretRef{ + { + Name: "another", + SecretRef: "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac", + }, + }, + Status: "ACTIVE", + Type: "generic", + Updated: time.Date(2018, 6, 21, 21, 30, 9, 0, time.UTC), +} + +// ExpectedContainersSlice is the slice of containers expected to be returned from ListResponse. +var ExpectedContainersSlice = []containers.Container{FirstContainer, SecondContainer} + +const ListConsumersResponse = ` +{ + "consumers": [ + { + "URL": "http://example.com", + "created": "2018-06-22T16:26:25", + "name": "CONSUMER-LZILN1zq", + "status": "ACTIVE", + "updated": "2018-06-22T16:26:25" + } + ], + "total": 1 +}` + +// ExpectedConsumer is the expected result of a consumer retrieval. +var ExpectedConsumer = containers.Consumer{ + URL: "http://example.com", + Created: time.Date(2018, 6, 22, 16, 26, 25, 0, time.UTC), + Name: "CONSUMER-LZILN1zq", + Status: "ACTIVE", + Updated: time.Date(2018, 6, 22, 16, 26, 25, 0, time.UTC), +} + +// ExpectedConsumersSlice is an expected slice of consumers. +var ExpectedConsumersSlice = []containers.Consumer{ExpectedConsumer} + +const CreateConsumerRequest = ` +{ + "URL": "http://example.com", + "name": "CONSUMER-LZILN1zq" +}` + +const CreateConsumerResponse = ` +{ + "consumers": [ + { + "URL": "http://example.com", + "name": "CONSUMER-LZILN1zq" + } + ], + "container_ref": "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + "created": "2018-06-21T21:28:37", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "name": "mycontainer", + "secret_refs": [ + { + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" + } + ], + "status": "ACTIVE", + "type": "generic", + "updated": "2018-06-21T21:28:37" +}` + +// ExpectedCreatedConsumer is the expected result of adding a consumer. +var ExpectedCreatedConsumer = containers.Container{ + Consumers: []containers.ConsumerRef{ + { + Name: "CONSUMER-LZILN1zq", + URL: "http://example.com", + }, + }, + ContainerRef: "http://barbican:9311/v1/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", + Created: time.Date(2018, 6, 21, 21, 28, 37, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Name: "mycontainer", + SecretRefs: []containers.SecretRef{ + { + Name: "mysecret", + SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + }, + }, + Status: "ACTIVE", + Type: "generic", + Updated: time.Date(2018, 6, 21, 21, 28, 37, 0, time.UTC), +} + +const DeleteConsumerRequest = ` +{ + "URL": "http://example.com", + "name": "CONSUMER-LZILN1zq" +}` + +// HandleListContainersSuccessfully creates an HTTP handler at `/containers` on the +// test handler mux that responds with a list of two containers. +func HandleListContainersSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResponse) + }) +} + +// HandleGetContainerSuccessfully creates an HTTP handler at `/containers` on the +// test handler mux that responds with a single resource. +func HandleGetContainerSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleCreateContainerSuccessfully creates an HTTP handler at `/containers` on the +// test handler mux that tests resource creation. +func HandleCreateContainerSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateRequest) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleDeleteContainerSuccessfully creates an HTTP handler at `/containers` on the +// test handler mux that tests resource deletion. +func HandleDeleteContainerSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleListConsumersSuccessfully creates an HTTP handler at +// `/containers/uuid/consumers` on the test handler mux that responds with +// a list of consumers. +func HandleListConsumersSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0/consumers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListConsumersResponse) + }) +} + +// HandleCreateConsumerSuccessfully creates an HTTP handler at +// `/containers/uuid/consumers` on the test handler mux that tests resource +// creation. +func HandleCreateConsumerSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0/consumers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateConsumerRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, CreateConsumerResponse) + }) +} + +// HandleDeleteConsumerSuccessfully creates an HTTP handler at +// `/containers/uuid/consumers` on the test handler mux that tests resource +// deletion. +func HandleDeleteConsumerSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/containers/dfdb88f3-4ddb-4525-9da6-066453caa9b0/consumers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateConsumerRequest) + + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/requests_test.go new file mode 100644 index 00000000..2f405e3c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/testing/requests_test.go @@ -0,0 +1,144 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListContainers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainersSuccessfully(t) + + count := 0 + err := containers.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := containers.ExtractContainers(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedContainersSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestListContainersAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainersSuccessfully(t) + + allPages, err := containers.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := containers.ExtractContainers(allPages) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedContainersSlice, actual) +} + +func TestGetContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetContainerSuccessfully(t) + + actual, err := containers.Get(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, FirstContainer, *actual) +} + +func TestCreateContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateContainerSuccessfully(t) + + createOpts := containers.CreateOpts{ + Type: containers.GenericContainer, + Name: "mycontainer", + SecretRefs: []containers.SecretRef{ + { + Name: "mysecret", + SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + }, + }, + } + + actual, err := containers.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, FirstContainer, *actual) +} + +func TestDeleteContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteContainerSuccessfully(t) + + res := containers.Delete(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0") + th.AssertNoErr(t, res.Err) +} + +func TestListConsumers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListConsumersSuccessfully(t) + + count := 0 + err := containers.ListConsumers(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := containers.ExtractConsumers(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedConsumersSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestListConsumersAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListConsumersSuccessfully(t) + + allPages, err := containers.ListConsumers(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", nil).AllPages() + th.AssertNoErr(t, err) + actual, err := containers.ExtractConsumers(allPages) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedConsumersSlice, actual) +} + +func TestCreateConsumer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateConsumerSuccessfully(t) + + createOpts := containers.CreateConsumerOpts{ + Name: "CONSUMER-LZILN1zq", + URL: "http://example.com", + } + + actual, err := containers.CreateConsumer(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCreatedConsumer, *actual) +} + +func TestDeleteConsumer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteConsumerSuccessfully(t) + + deleteOpts := containers.DeleteConsumerOpts{ + Name: "CONSUMER-LZILN1zq", + URL: "http://example.com", + } + + actual, err := containers.DeleteConsumer(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", deleteOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, FirstContainer, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/urls.go new file mode 100644 index 00000000..236ebc81 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers/urls.go @@ -0,0 +1,31 @@ +package containers + +import "github.com/gophercloud/gophercloud" + +func listURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("containers") +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("containers", id) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("containers") +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("containers", id) +} + +func listConsumersURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("containers", id, "consumers") +} + +func createConsumerURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("containers", id, "consumers") +} + +func deleteConsumerURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("containers", id, "consumers") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/doc.go new file mode 100644 index 00000000..fcbeccf4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/doc.go @@ -0,0 +1,45 @@ +/* +Package orders manages and retrieves orders in the OpenStack Key Manager +Service. + +Example to List Orders + + allPages, err := orders.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allOrders, err := orders.ExtractOrders(allPages) + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", allOrders) + +Example to Create a Order + + createOpts := orders.CreateOpts{ + Type: orders.KeyOrder, + Meta: orders.MetaOpts{ + Name: "order-name", + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + }, + } + + order, err := orders.Create(client, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", order) + +Example to Delete a Order + + err := orders.Delete(client, orderID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package orders diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/requests.go new file mode 100644 index 00000000..7a55f9dd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/requests.go @@ -0,0 +1,129 @@ +package orders + +import ( + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// OrderType represents the valid types of orders. +type OrderType string + +const ( + KeyOrder OrderType = "key" + AsymmetricOrder OrderType = "asymmetric" +) + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request +type ListOptsBuilder interface { + ToOrderListQuery() (string, error) +} + +// ListOpts provides options to filter the List results. +type ListOpts struct { + // Limit is the amount of containers to retrieve. + Limit int `q:"limit"` + + // Offset is the index within the list to retrieve. + Offset int `q:"offset"` +} + +// ToOrderListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToOrderListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List retrieves a list of orders. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToOrderListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return OrderPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves details of a orders. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} + +// CreateOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateOptsBuilder interface { + ToOrderCreateMap() (map[string]interface{}, error) +} + +// MetaOpts represents options used for creating an order. +type MetaOpts struct { + // Algorithm is the algorithm of the secret. + Algorithm string `json:"algorithm"` + + // BitLength is the bit length of the secret. + BitLength int `json:"bit_length"` + + // Expiration is the expiration date of the order. + Expiration *time.Time `json:"-"` + + // Mode is the mode of the secret. + Mode string `json:"mode"` + + // Name is the name of the secret. + Name string `json:"name,omitempty"` + + // PayloadContentType is the content type of the secret payload. + PayloadContentType string `json:"payload_content_type,omitempty"` +} + +// CreateOpts provides options used to create a orders. +type CreateOpts struct { + // Type is the type of order to create. + Type OrderType `json:"type"` + + // Meta contains secrets data to create a secret. + Meta MetaOpts `json:"meta"` +} + +// ToOrderCreateMap formats a CreateOpts into a create request. +func (opts CreateOpts) ToOrderCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + if opts.Meta.Expiration != nil { + meta := b["meta"].(map[string]interface{}) + meta["expiration"] = opts.Meta.Expiration.Format(gophercloud.RFC3339NoZ) + b["meta"] = meta + } + + return b, nil +} + +// Create creates a new orders. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToOrderCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{202}, + }) + return +} + +// Delete deletes a orders. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/results.go new file mode 100644 index 00000000..35e89b50 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/results.go @@ -0,0 +1,170 @@ +package orders + +import ( + "encoding/json" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Order represents an order in the key manager service. +type Order struct { + // ContainerRef is the container URL. + ContainerRef string `json:"container_ref"` + + // Created is when the order was created. + Created time.Time `json:"-"` + + // CreatorID is the creator of the order. + CreatorID string `json:"creator_id"` + + // ErrorReason is the reason of the error. + ErrorReason string `json:"error_reason"` + + // ErrorStatusCode is the error status code. + ErrorStatusCode string `json:"error_status_code"` + + // OrderRef is the order URL. + OrderRef string `json:"order_ref"` + + // Meta is secret data about the order. + Meta Meta `json:"meta"` + + // SecretRef is the secret URL. + SecretRef string `json:"secret_ref"` + + // Status is the status of the order. + Status string `json:"status"` + + // SubStatus is the status of the order. + SubStatus string `json:"sub_status"` + + // SubStatusMessage is the message of the sub status. + SubStatusMessage string `json:"sub_status_message"` + + // Type is the order type. + Type string `json:"type"` + + // Updated is when the order was updated. + Updated time.Time `json:"-"` +} + +func (r *Order) UnmarshalJSON(b []byte) error { + type tmp Order + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + Updated gophercloud.JSONRFC3339NoZ `json:"updated"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Order(s.tmp) + + r.Created = time.Time(s.Created) + r.Updated = time.Time(s.Updated) + + return nil +} + +type Meta struct { + // Algorithm is the algorithm of the secret. + Algorithm string `json:"algorithm"` + + // BitLength is the bit length of the secret. + BitLength int `json:"bit_length"` + + // Expiration is the expiration date of the order. + Expiration time.Time `json:"-"` + + // Mode is the mode of the secret. + Mode string `json:"mode"` + + // Name is the name of the secret. + Name string `json:"name"` + + // PayloadContentType is the content type of the secret payload. + PayloadContentType string `json:"payload_content_type"` +} + +func (r *Meta) UnmarshalJSON(b []byte) error { + type tmp Meta + var s struct { + tmp + Expiration gophercloud.JSONRFC3339NoZ `json:"expiration"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Meta(s.tmp) + + r.Expiration = time.Time(s.Expiration) + + return nil +} + +type commonResult struct { + gophercloud.Result +} + +// GetResult is the response from a Get operation. Call its Extract method +// to interpret it as a orders. +type GetResult struct { + commonResult +} + +// CreateResult is the response from a Create operation. Call its Extract method +// to interpret it as a orders. +type CreateResult struct { + commonResult +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// OrderPage is a single page of orders results. +type OrderPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of ordersS contains any results. +func (r OrderPage) IsEmpty() (bool, error) { + orders, err := ExtractOrders(r) + return len(orders) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r OrderPage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + Previous string `json:"previous"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Next, err +} + +// ExtractOrders returns a slice of Orders contained in a single page of +// results. +func ExtractOrders(r pagination.Page) ([]Order, error) { + var s struct { + Orders []Order `json:"orders"` + } + err := (r.(OrderPage)).ExtractInto(&s) + return s.Orders, err +} + +// Extract interprets any commonResult as a Order. +func (r commonResult) Extract() (*Order, error) { + var s *Order + err := r.ExtractInto(&s) + return s, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/fixtures.go new file mode 100644 index 00000000..bdab5427 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/fixtures.go @@ -0,0 +1,186 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListResponse provides a single page of RESOURCE results. +const ListResponse = ` +{ + "orders": [ + { + "created": "2018-06-22T05:05:43", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "meta": { + "algorithm": "aes", + "bit_length": 256, + "expiration": null, + "mode": "cbc", + "name": null, + "payload_content_type": "application/octet-stream" + }, + "order_ref": "http://barbican:9311/v1/orders/46f73695-82bb-447a-bf96-6635f0fb0ce7", + "secret_ref": "http://barbican:9311/v1/secrets/22dfef44-1046-4549-a86d-95af462e8fa0", + "status": "ACTIVE", + "sub_status": "Unknown", + "sub_status_message": "Unknown", + "type": "key", + "updated": "2018-06-22T05:05:43" + }, + { + "created": "2018-06-22T05:08:15", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "meta": { + "algorithm": "aes", + "bit_length": 256, + "expiration": null, + "mode": "cbc", + "name": null, + "payload_content_type": "application/octet-stream" + }, + "order_ref": "http://barbican:9311/v1/orders/07fba88b-3dcf-44e3-a4a3-0bad7f56f01c", + "secret_ref": "http://barbican:9311/v1/secrets/a31ad551-1aa5-4ba0-810e-0865163e0fa9", + "status": "ACTIVE", + "sub_status": "Unknown", + "sub_status_message": "Unknown", + "type": "key", + "updated": "2018-06-22T05:08:15" + } + ], + "total": 2 +}` + +// GetResponse provides a Get result. +const GetResponse = ` +{ + "created": "2018-06-22T05:08:15", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "meta": { + "algorithm": "aes", + "bit_length": 256, + "expiration": null, + "mode": "cbc", + "name": null, + "payload_content_type": "application/octet-stream" + }, + "order_ref": "http://barbican:9311/v1/orders/07fba88b-3dcf-44e3-a4a3-0bad7f56f01c", + "secret_ref": "http://barbican:9311/v1/secrets/a31ad551-1aa5-4ba0-810e-0865163e0fa9", + "status": "ACTIVE", + "sub_status": "Unknown", + "sub_status_message": "Unknown", + "type": "key", + "updated": "2018-06-22T05:08:15" +} +` + +// CreateRequest provides the input to a Create request. +const CreateRequest = ` +{ + "meta": { + "algorithm": "aes", + "bit_length": 256, + "mode": "cbc", + "payload_content_type": "application/octet-stream" + }, + "type": "key" +}` + +// FirstOrder is the first resource in the List request. +var FirstOrder = orders.Order{ + Created: time.Date(2018, 6, 22, 5, 5, 43, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Meta: orders.Meta{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + PayloadContentType: "application/octet-stream", + }, + OrderRef: "http://barbican:9311/v1/orders/46f73695-82bb-447a-bf96-6635f0fb0ce7", + SecretRef: "http://barbican:9311/v1/secrets/22dfef44-1046-4549-a86d-95af462e8fa0", + Status: "ACTIVE", + SubStatus: "Unknown", + SubStatusMessage: "Unknown", + Type: "key", + Updated: time.Date(2018, 6, 22, 5, 5, 43, 0, time.UTC), +} + +// SecondOrder is the second resource in the List request. +var SecondOrder = orders.Order{ + Created: time.Date(2018, 6, 22, 5, 8, 15, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Meta: orders.Meta{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + PayloadContentType: "application/octet-stream", + }, + OrderRef: "http://barbican:9311/v1/orders/07fba88b-3dcf-44e3-a4a3-0bad7f56f01c", + SecretRef: "http://barbican:9311/v1/secrets/a31ad551-1aa5-4ba0-810e-0865163e0fa9", + Status: "ACTIVE", + SubStatus: "Unknown", + SubStatusMessage: "Unknown", + Type: "key", + Updated: time.Date(2018, 6, 22, 5, 8, 15, 0, time.UTC), +} + +// ExpectedOrdersSlice is the slice of orders expected to be returned from ListResponse. +var ExpectedOrdersSlice = []orders.Order{FirstOrder, SecondOrder} + +// HandleListOrdersSuccessfully creates an HTTP handler at `/orders` on the +// test handler mux that responds with a list of two orders. +func HandleListOrdersSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/orders", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResponse) + }) +} + +// HandleGetOrderSuccessfully creates an HTTP handler at `/orders` on the +// test handler mux that responds with a single resource. +func HandleGetOrderSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/orders/46f73695-82bb-447a-bf96-6635f0fb0ce7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleCreateOrderSuccessfully creates an HTTP handler at `/orders` on the +// test handler mux that tests resource creation. +func HandleCreateOrderSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/orders", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateRequest) + + w.WriteHeader(http.StatusAccepted) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleDeleteOrderSuccessfully creates an HTTP handler at `/orders` on the +// test handler mux that tests resource deletion. +func HandleDeleteOrderSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/orders/46f73695-82bb-447a-bf96-6635f0fb0ce7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/requests_test.go new file mode 100644 index 00000000..5c9fcb31 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/testing/requests_test.go @@ -0,0 +1,81 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListOrders(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListOrdersSuccessfully(t) + + count := 0 + err := orders.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := orders.ExtractOrders(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedOrdersSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestListOrdersAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListOrdersSuccessfully(t) + + allPages, err := orders.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := orders.ExtractOrders(allPages) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedOrdersSlice, actual) +} + +func TestGetOrder(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetOrderSuccessfully(t) + + actual, err := orders.Get(client.ServiceClient(), "46f73695-82bb-447a-bf96-6635f0fb0ce7").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, SecondOrder, *actual) +} + +func TestCreateOrder(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateOrderSuccessfully(t) + + createOpts := orders.CreateOpts{ + Type: orders.KeyOrder, + Meta: orders.MetaOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + PayloadContentType: "application/octet-stream", + }, + } + + actual, err := orders.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, SecondOrder, *actual) +} + +func TestDeleteOrder(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteOrderSuccessfully(t) + + res := orders.Delete(client.ServiceClient(), "46f73695-82bb-447a-bf96-6635f0fb0ce7") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/urls.go new file mode 100644 index 00000000..36890e53 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders/urls.go @@ -0,0 +1,19 @@ +package orders + +import "github.com/gophercloud/gophercloud" + +func listURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("orders") +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("orders", id) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("orders") +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("orders", id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/doc.go new file mode 100644 index 00000000..4167e425 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/doc.go @@ -0,0 +1,142 @@ +/* +Package secrets manages and retrieves secrets in the OpenStack Key Manager +Service. + +Example to List Secrets + + createdQuery := &secrets.DateQuery{ + Date: time.Date(2049, 6, 7, 1, 2, 3, 0, time.UTC), + Filter: secrets.DateFilterLT, + } + + listOpts := secrets.ListOpts{ + CreatedQuery: createdQuery, + } + + allPages, err := secrets.List(client, listOpts).AllPages() + if err != nil { + panic(err) + } + + allSecrets, err := secrets.ExtractSecrets(allPages) + if err != nil { + panic(err) + } + + for _, v := range allSecrets { + fmt.Printf("%v\n", v) + } + +Example to Get a Secret + + secret, err := secrets.Get(client, secretID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", secret) + +Example to Get a Payload + + payload, err := secrets.GetPayload(client, secretID).Extract() + if err != nil { + panic(err) + } + + fmt.Println(string(payload)) + +Example to Create a Secrets + + createOpts := secrets.CreateOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Name: "mysecret", + Payload: "super-secret", + PayloadContentType: "text/plain", + SecretType: secrets.OpaqueSecret, + } + + secret, err := secrets.Create(client, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Println(secret.SecretRef) + +Example to Add a Payload + + updateOpts := secrets.UpdateOpts{ + ContentType: "text/plain", + Payload: "super-secret", + } + + err := secrets.Update(client, secretID, updateOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to Delete a Secrets + + err := secrets.Delete(client, secretID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Create Metadata for a Secret + + createOpts := secrets.MetadataOpts{ + "foo": "bar", + "something": "something else", + } + + ref, err := secrets.CreateMetadata(client, secretID, createOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", ref) + +Example to Get Metadata for a Secret + + metadata, err := secrets.GetMetadata(client, secretID).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", metadata) + +Example to Add Metadata to a Secret + + metadatumOpts := secrets.MetadatumOpts{ + Key: "foo", + Value: "bar", + } + + err := secrets.CreateMetadatum(client, secretID, metadatumOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to Update Metadata of a Secret + + metadatumOpts := secrets.MetadatumOpts{ + Key: "foo", + Value: "bar", + } + + metadatum, err := secrets.UpdateMetadatum(client, secretID, metadatumOpts).Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%v\n", metadatum) + +Example to Delete Metadata of a Secret + + err := secrets.DeleteMetadatum(client, secretID, "foo").ExtractErr() + if err != nil { + panic(err) + } +*/ +package secrets diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/requests.go new file mode 100644 index 00000000..900cbcaa --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/requests.go @@ -0,0 +1,412 @@ +package secrets + +import ( + "fmt" + "net/url" + "strings" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// DateFilter represents a valid filter to use for filtering +// secrets by their date during a list. +type DateFilter string + +const ( + DateFilterGT DateFilter = "gt" + DateFilterGTE DateFilter = "gte" + DateFilterLT DateFilter = "lt" + DateFilterLTE DateFilter = "lte" +) + +// DateQuery represents a date field to be used for listing secrets. +// If no filter is specified, the query will act as if "equal" is used. +type DateQuery struct { + Date time.Time + Filter DateFilter +} + +// SecretType represents a valid secret type. +type SecretType string + +const ( + SymmetricSecret SecretType = "symmetric" + PublicSecret SecretType = "public" + PrivateSecret SecretType = "private" + PassphraseSecret SecretType = "passphrase" + CertificateSecret SecretType = "certificate" + OpaqueSecret SecretType = "opaque" +) + +// ListOptsBuilder allows extensions to add additional parameters to +// the List request +type ListOptsBuilder interface { + ToSecretListQuery() (string, error) +} + +// ListOpts provides options to filter the List results. +type ListOpts struct { + // Offset is the starting index within the total list of the secrets that + // you would like to retrieve. + Offset int `q:"offset"` + + // Limit is the maximum number of records to return. + Limit int `q:"limit"` + + // Name will select all secrets with a matching name. + Name string `q:"name"` + + // Alg will select all secrets with a matching algorithm. + Alg string `q:"alg"` + + // Mode will select all secrets with a matching mode. + Mode string `q:"mode"` + + // Bits will select all secrets with a matching bit length. + Bits int `q:"bits"` + + // SecretType will select all secrets with a matching secret type. + SecretType SecretType `q:"secret_type"` + + // ACLOnly will select all secrets with an ACL that contains the user. + ACLOnly *bool `q:"acl_only"` + + // CreatedQuery will select all secrets with a created date matching + // the query. + CreatedQuery *DateQuery + + // UpdatedQuery will select all secrets with an updated date matching + // the query. + UpdatedQuery *DateQuery + + // ExpirationQuery will select all secrets with an expiration date + // matching the query. + ExpirationQuery *DateQuery + + // Sort will sort the results in the requested order. + Sort string `q:"sort"` +} + +// ToSecretListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToSecretListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + params := q.Query() + + if opts.CreatedQuery != nil { + created := opts.CreatedQuery.Date.Format(time.RFC3339) + if v := opts.CreatedQuery.Filter; v != "" { + created = fmt.Sprintf("%s:%s", v, created) + } + + params.Add("created", created) + } + + if opts.UpdatedQuery != nil { + updated := opts.UpdatedQuery.Date.Format(time.RFC3339) + if v := opts.UpdatedQuery.Filter; v != "" { + updated = fmt.Sprintf("%s:%s", v, updated) + } + + params.Add("updated", updated) + } + + if opts.ExpirationQuery != nil { + expiration := opts.ExpirationQuery.Date.Format(time.RFC3339) + if v := opts.ExpirationQuery.Filter; v != "" { + expiration = fmt.Sprintf("%s:%s", v, expiration) + } + + params.Add("expiration", expiration) + } + + q = &url.URL{RawQuery: params.Encode()} + + return q.String(), err +} + +// List retrieves a list of Secrets. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToSecretListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return SecretPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves details of a secrets. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} + +// GetPayloadOpts represents options used for obtaining a payload. +type GetPayloadOpts struct { + PayloadContentType string `h:"Accept"` +} + +// GetPayloadOptsBuilder allows extensions to add additional parameters to +// the GetPayload request. +type GetPayloadOptsBuilder interface { + ToSecretPayloadGetParams() (map[string]string, error) +} + +// ToSecretPayloadGetParams formats a GetPayloadOpts into a query string. +func (opts GetPayloadOpts) ToSecretPayloadGetParams() (map[string]string, error) { + return gophercloud.BuildHeaders(opts) +} + +// GetPayload retrieves the payload of a secret. +func GetPayload(client *gophercloud.ServiceClient, id string, opts GetPayloadOptsBuilder) (r PayloadResult) { + h := map[string]string{"Accept": "text/plain"} + + if opts != nil { + headers, err := opts.ToSecretPayloadGetParams() + if err != nil { + r.Err = err + return + } + for k, v := range headers { + h[k] = v + } + } + + url := payloadURL(client, id) + resp, err := client.Get(url, nil, &gophercloud.RequestOpts{ + MoreHeaders: h, + OkCodes: []int{200}, + }) + + if resp != nil { + r.Header = resp.Header + r.Body = resp.Body + } + r.Err = err + return +} + +// CreateOptsBuilder allows extensions to add additional parameters to +// the Create request. +type CreateOptsBuilder interface { + ToSecretCreateMap() (map[string]interface{}, error) +} + +// CreateOpts provides options used to create a secrets. +type CreateOpts struct { + // Algorithm is the algorithm of the secret. + Algorithm string `json:"algorithm,omitempty"` + + // BitLength is the bit length of the secret. + BitLength int `json:"bit_length,omitempty"` + + // Mode is the mode of encryption for the secret. + Mode string `json:"mode,omitempty"` + + // Name is the name of the secret + Name string `json:"name,omitempty"` + + // Payload is the secret. + Payload string `json:"payload,omitempty"` + + // PayloadContentType is the content type of the payload. + PayloadContentType string `json:"payload_content_type,omitempty"` + + // PayloadContentEncoding is the content encoding of the payload. + PayloadContentEncoding string `json:"payload_content_encoding,omitempty"` + + // SecretType is the type of secret. + SecretType SecretType `json:"secret_type,omitempty"` +} + +// ToSecretCreateMap formats a CreateOpts into a create request. +func (opts CreateOpts) ToSecretCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// Create creates a new secrets. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToSecretCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// Delete deletes a secrets. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to +// the Update request. +type UpdateOptsBuilder interface { + ToSecretUpdateRequest() (string, map[string]string, error) +} + +// UpdateOpts represents parameters to add a payload to an existing +// secret which does not already contain a payload. +type UpdateOpts struct { + // ContentType represents the content type of the payload. + ContentType string `h:"Content-Type"` + + // ContentEncoding represents the content encoding of the payload. + ContentEncoding string `h:"Content-Encoding"` + + // Payload is the payload of the secret. + Payload string +} + +// ToUpdateCreateRequest formats a UpdateOpts into an update request. +func (opts UpdateOpts) ToSecretUpdateRequest() (string, map[string]string, error) { + h, err := gophercloud.BuildHeaders(opts) + if err != nil { + return "", nil, err + } + + return opts.Payload, h, nil +} + +// Update modifies the attributes of a secrets. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + url := updateURL(client, id) + h := make(map[string]string) + var b string + + if opts != nil { + payload, headers, err := opts.ToSecretUpdateRequest() + if err != nil { + r.Err = err + return + } + + for k, v := range headers { + h[k] = v + } + + b = payload + } + + resp, err := client.Put(url, nil, nil, &gophercloud.RequestOpts{ + RawBody: strings.NewReader(b), + MoreHeaders: h, + OkCodes: []int{204}, + }) + r.Err = err + if resp != nil { + r.Header = resp.Header + } + + return +} + +// GetMetadata will list metadata for a given secret. +func GetMetadata(client *gophercloud.ServiceClient, secretID string) (r MetadataResult) { + _, r.Err = client.Get(metadataURL(client, secretID), &r.Body, nil) + return +} + +// MetadataOpts is a map that contains key-value pairs for secret metadata. +type MetadataOpts map[string]string + +// CreateMetadataOptsBuilder allows extensions to add additional parameters to +// the CreateMetadata request. +type CreateMetadataOptsBuilder interface { + ToMetadataCreateMap() (map[string]interface{}, error) +} + +// ToMetadataCreateMap converts a MetadataOpts into a request body. +func (opts MetadataOpts) ToMetadataCreateMap() (map[string]interface{}, error) { + return map[string]interface{}{"metadata": opts}, nil +} + +// CreateMetadata will set metadata for a given secret. +func CreateMetadata(client *gophercloud.ServiceClient, secretID string, opts CreateMetadataOptsBuilder) (r MetadataCreateResult) { + b, err := opts.ToMetadataCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(metadataURL(client, secretID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// GetMetadatum will get a single key/value metadata from a secret. +func GetMetadatum(client *gophercloud.ServiceClient, secretID string, key string) (r MetadatumResult) { + _, r.Err = client.Get(metadatumURL(client, secretID, key), &r.Body, nil) + return +} + +// MetadatumOpts represents a single metadata. +type MetadatumOpts struct { + Key string `json:"key" required:"true"` + Value string `json:"value" required:"true"` +} + +// CreateMetadatumOptsBuilder allows extensions to add additional parameters to +// the CreateMetadatum request. +type CreateMetadatumOptsBuilder interface { + ToMetadatumCreateMap() (map[string]interface{}, error) +} + +// ToMetadatumCreateMap converts a MetadatumOpts into a request body. +func (opts MetadatumOpts) ToMetadatumCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// CreateMetadatum will add a single key/value metadata to a secret. +func CreateMetadatum(client *gophercloud.ServiceClient, secretID string, opts CreateMetadatumOptsBuilder) (r MetadatumCreateResult) { + b, err := opts.ToMetadatumCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(metadataURL(client, secretID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// UpdateMetadatumOptsBuilder allows extensions to add additional parameters to +// the UpdateMetadatum request. +type UpdateMetadatumOptsBuilder interface { + ToMetadatumUpdateMap() (map[string]interface{}, string, error) +} + +// ToMetadatumUpdateMap converts a MetadataOpts into a request body. +func (opts MetadatumOpts) ToMetadatumUpdateMap() (map[string]interface{}, string, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + return b, opts.Key, err +} + +// UpdateMetadatum will update a single key/value metadata to a secret. +func UpdateMetadatum(client *gophercloud.ServiceClient, secretID string, opts UpdateMetadatumOptsBuilder) (r MetadatumResult) { + b, key, err := opts.ToMetadatumUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(metadatumURL(client, secretID, key), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// DeleteMetadatum will delete an individual metadatum from a secret. +func DeleteMetadatum(client *gophercloud.ServiceClient, secretID string, key string) (r MetadatumDeleteResult) { + _, r.Err = client.Delete(metadatumURL(client, secretID, key), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/results.go new file mode 100644 index 00000000..a3230a8b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/results.go @@ -0,0 +1,227 @@ +package secrets + +import ( + "encoding/json" + "io" + "io/ioutil" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Secret represents a secret stored in the key manager service. +type Secret struct { + // BitLength is the bit length of the secret. + BitLength int `json:"bit_length"` + + // Algorithm is the algorithm type of the secret. + Algorithm string `json:"algorithm"` + + // Expiration is the expiration date of the secret. + Expiration time.Time `json:"-"` + + // ContentTypes are the content types of the secret. + ContentTypes map[string]string `json:"content_types"` + + // Created is the created date of the secret. + Created time.Time `json:"-"` + + // CreatorID is the creator of the secret. + CreatorID string `json:"creator_id"` + + // Mode is the mode of the secret. + Mode string `json:"mode"` + + // Name is the name of the secret. + Name string `json:"name"` + + // SecretRef is the URL to the secret. + SecretRef string `json:"secret_ref"` + + // SecretType represents the type of secret. + SecretType string `json:"secret_type"` + + // Status represents the status of the secret. + Status string `json:"status"` + + // Updated is the updated date of the secret. + Updated time.Time `json:"-"` +} + +func (r *Secret) UnmarshalJSON(b []byte) error { + type tmp Secret + var s struct { + tmp + Created gophercloud.JSONRFC3339NoZ `json:"created"` + Updated gophercloud.JSONRFC3339NoZ `json:"updated"` + Expiration gophercloud.JSONRFC3339NoZ `json:"expiration"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = Secret(s.tmp) + + r.Created = time.Time(s.Created) + r.Updated = time.Time(s.Updated) + r.Expiration = time.Time(s.Expiration) + + return nil +} + +type commonResult struct { + gophercloud.Result +} + +// Extract interprets any commonResult as a Secret. +func (r commonResult) Extract() (*Secret, error) { + var s *Secret + err := r.ExtractInto(&s) + return s, err +} + +// GetResult is the response from a Get operation. Call its Extract method +// to interpret it as a secrets. +type GetResult struct { + commonResult +} + +// CreateResult is the response from a Create operation. Call its Extract method +// to interpret it as a secrets. +type CreateResult struct { + commonResult +} + +// UpdateResult is the response from an Update operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type UpdateResult struct { + gophercloud.ErrResult +} + +// DeleteResult is the response from a Delete operation. Call its ExtractErr to +// determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// PayloadResult is the response from a GetPayload operation. Call its Extract +// method to extract the payload as a string. +type PayloadResult struct { + gophercloud.Result + Body io.ReadCloser +} + +// Extract is a function that takes a PayloadResult's io.Reader body +// and reads all available data into a slice of bytes. Please be aware that due +// to the nature of io.Reader is forward-only - meaning that it can only be read +// once and not rewound. You can recreate a reader from the output of this +// function by using bytes.NewReader(downloadBytes) +func (r PayloadResult) Extract() ([]byte, error) { + if r.Err != nil { + return nil, r.Err + } + defer r.Body.Close() + body, err := ioutil.ReadAll(r.Body) + if err != nil { + return nil, err + } + r.Body.Close() + return body, nil +} + +// SecretPage is a single page of secrets results. +type SecretPage struct { + pagination.LinkedPageBase +} + +// IsEmpty determines whether or not a page of secrets contains any results. +func (r SecretPage) IsEmpty() (bool, error) { + secrets, err := ExtractSecrets(r) + return len(secrets) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r SecretPage) NextPageURL() (string, error) { + var s struct { + Next string `json:"next"` + Previous string `json:"previous"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Next, err +} + +// ExtractSecrets returns a slice of Secrets contained in a single page of +// results. +func ExtractSecrets(r pagination.Page) ([]Secret, error) { + var s struct { + Secrets []Secret `json:"secrets"` + } + err := (r.(SecretPage)).ExtractInto(&s) + return s.Secrets, err +} + +// MetadataResult is the result of a metadata request. Call its Extract method +// to interpret it as a map[string]string. +type MetadataResult struct { + gophercloud.Result +} + +// Extract interprets any MetadataResult as map[string]string. +func (r MetadataResult) Extract() (map[string]string, error) { + var s struct { + Metadata map[string]string `json:"metadata"` + } + err := r.ExtractInto(&s) + return s.Metadata, err +} + +// MetadataCreateResult is the result of a metadata create request. Call its +// Extract method to interpret it as a map[string]string. +type MetadataCreateResult struct { + gophercloud.Result +} + +// Extract interprets any MetadataCreateResult as a map[string]string. +func (r MetadataCreateResult) Extract() (map[string]string, error) { + var s map[string]string + err := r.ExtractInto(&s) + return s, err +} + +// Metadatum represents an individual metadata. +type Metadatum struct { + Key string `json:"key"` + Value string `json:"value"` +} + +// MetadatumResult is the result of a metadatum request. Call its +// Extract method to interpret it as a map[string]string. +type MetadatumResult struct { + gophercloud.Result +} + +// Extract interprets any MetadatumResult as a map[string]string. +func (r MetadatumResult) Extract() (*Metadatum, error) { + var s *Metadatum + err := r.ExtractInto(&s) + return s, err +} + +// MetadatumCreateResult is the response from a metadata Create operation. Call +// it's ExtractErr to determine if the request succeeded or failed. +// +// NOTE: This could be a MetadatumResponse but, at the time of testing, it looks +// like Barbican was returning errneous JSON in the response. +type MetadatumCreateResult struct { + gophercloud.ErrResult +} + +// MetadatumDeleteResult is the response from a metadatum Delete operation. Call +// its ExtractErr to determine if the request succeeded or failed. +type MetadatumDeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/fixtures.go new file mode 100644 index 00000000..2b50658b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/fixtures.go @@ -0,0 +1,355 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListResponse provides a single page of RESOURCE results. +const ListResponse = ` +{ + "secrets": [ + { + "algorithm": "aes", + "bit_length": 256, + "content_types": { + "default": "text/plain" + }, + "created": "2018-06-21T02:49:48", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "expiration": null, + "mode": "cbc", + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + "secret_type": "opaque", + "status": "ACTIVE", + "updated": "2018-06-21T02:49:48" + }, + { + "algorithm": "aes", + "bit_length": 256, + "content_types": { + "default": "text/plain" + }, + "created": "2018-06-21T05:18:45", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "expiration": null, + "mode": "cbc", + "name": "anothersecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac", + "secret_type": "opaque", + "status": "ACTIVE", + "updated": "2018-06-21T05:18:45" + } + ], + "total": 2 +}` + +// GetResponse provides a Get result. +const GetResponse = ` +{ + "algorithm": "aes", + "bit_length": 256, + "content_types": { + "default": "text/plain" + }, + "created": "2018-06-21T02:49:48", + "creator_id": "5c70d99f4a8641c38f8084b32b5e5c0e", + "expiration": null, + "mode": "cbc", + "name": "mysecret", + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + "secret_type": "opaque", + "status": "ACTIVE", + "updated": "2018-06-21T02:49:48" +}` + +// GetPayloadResponse provides a payload result. +const GetPayloadResponse = `foobar` + +// CreateRequest provides the input to a Create request. +const CreateRequest = ` +{ + "algorithm": "aes", + "bit_length": 256, + "mode": "cbc", + "name": "mysecret", + "payload": "foobar", + "payload_content_type": "text/plain", + "secret_type": "opaque" +}` + +// CreateResponse provides a Create result. +const CreateResponse = ` +{ + "secret_ref": "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c" +}` + +// UpdateRequest provides the input to as Update request. +const UpdateRequest = `foobar` + +// FirstSecret is the first secret in the List request. +var FirstSecret = secrets.Secret{ + Algorithm: "aes", + BitLength: 256, + ContentTypes: map[string]string{ + "default": "text/plain", + }, + Created: time.Date(2018, 6, 21, 2, 49, 48, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Mode: "cbc", + Name: "mysecret", + SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", + SecretType: "opaque", + Status: "ACTIVE", + Updated: time.Date(2018, 6, 21, 2, 49, 48, 0, time.UTC), +} + +// SecondSecret is the second secret in the List request. +var SecondSecret = secrets.Secret{ + Algorithm: "aes", + BitLength: 256, + ContentTypes: map[string]string{ + "default": "text/plain", + }, + Created: time.Date(2018, 6, 21, 5, 18, 45, 0, time.UTC), + CreatorID: "5c70d99f4a8641c38f8084b32b5e5c0e", + Mode: "cbc", + Name: "anothersecret", + SecretRef: "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac", + SecretType: "opaque", + Status: "ACTIVE", + Updated: time.Date(2018, 6, 21, 5, 18, 45, 0, time.UTC), +} + +// ExpectedSecretsSlice is the slice of secrets expected to be returned from ListResponse. +var ExpectedSecretsSlice = []secrets.Secret{FirstSecret, SecondSecret} + +// ExpectedCreateResult is the result of a create request +var ExpectedCreateResult = secrets.Secret{ + SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", +} + +const GetMetadataResponse = ` +{ + "metadata": { + "foo": "bar", + "something": "something else" + } +}` + +// ExpectedMetadata is the result of a Get or Create request. +var ExpectedMetadata = map[string]string{ + "foo": "bar", + "something": "something else", +} + +const CreateMetadataRequest = ` +{ + "metadata": { + "foo": "bar", + "something": "something else" + } +}` + +const CreateMetadataResponse = ` +{ + "metadata_ref": "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac/metadata" +}` + +// ExpectedCreateMetadataResult is the result of a Metadata create request. +var ExpectedCreateMetadataResult = map[string]string{ + "metadata_ref": "http://barbican:9311/v1/secrets/1b12b69a-8822-442e-a303-da24ade648ac/metadata", +} + +const MetadatumRequest = ` +{ + "key": "foo", + "value": "bar" +}` + +const MetadatumResponse = ` +{ + "key": "foo", + "value": "bar" +}` + +// ExpectedMetadatum is the result of a Metadatum Get, Create, or Update +// request +var ExpectedMetadatum = secrets.Metadatum{ + Key: "foo", + Value: "bar", +} + +// HandleListSecretsSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that responds with a list of two secrets. +func HandleListSecretsSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, ListResponse) + }) +} + +// HandleGetSecretSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that responds with a single secret. +func HandleGetSecretSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetResponse) + }) +} + +// HandleGetPayloadSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that responds with a single secret. +func HandleGetPayloadSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/payload", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetPayloadResponse) + }) +} + +// HandleCreateSecretSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret creation. +func HandleCreateSecretSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateRequest) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, CreateResponse) + }) +} + +// HandleDeleteSecretSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret deletion. +func HandleDeleteSecretSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleUpdateSecretSuccessfully creates an HTTP handler at `/secrets` on the +// test handler mux that tests secret updates. +func HandleUpdateSecretSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleGetMetadataSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata` on the test handler mux that responds with +// retrieved metadata. +func HandleGetMetadataSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, GetMetadataResponse) + }) +} + +// HandleCreateMetadataSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata` on the test handler mux that responds with +// a metadata reference URL. +func HandleCreateMetadataSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, CreateMetadataRequest) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, CreateMetadataResponse) + }) +} + +// HandleGetMetadatumSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata/foo` on the test handler mux that responds with a +// single metadatum. +func HandleGetMetadatumSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata/foo", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, MetadatumResponse) + }) +} + +// HandleCreateMetadatumSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata` on the test handler mux that responds with +// a single created metadata. +func HandleCreateMetadatumSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, MetadatumRequest) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, MetadatumResponse) + }) +} + +// HandleUpdateMetadatumSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata/foo` on the test handler mux that responds with a +// single updated metadatum. +func HandleUpdateMetadatumSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata/foo", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, MetadatumRequest) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, MetadatumResponse) + }) +} + +// HandleDeleteMetadatumSuccessfully creates an HTTP handler at +// `/secrets/uuid/metadata/key` on the test handler mux that tests metadata +// deletion. +func HandleDeleteMetadatumSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/metadata/foo", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/requests_test.go new file mode 100644 index 00000000..d63879c9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/testing/requests_test.go @@ -0,0 +1,179 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListSecrets(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSecretsSuccessfully(t) + + count := 0 + err := secrets.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + + actual, err := secrets.ExtractSecrets(page) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ExpectedSecretsSlice, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.AssertEquals(t, count, 1) +} + +func TestListSecretsAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSecretsSuccessfully(t) + + allPages, err := secrets.List(client.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + actual, err := secrets.ExtractSecrets(allPages) + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedSecretsSlice, actual) +} + +func TestGetSecret(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSecretSuccessfully(t) + + actual, err := secrets.Get(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, FirstSecret, *actual) +} + +func TestCreateSecret(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSecretSuccessfully(t) + + createOpts := secrets.CreateOpts{ + Algorithm: "aes", + BitLength: 256, + Mode: "cbc", + Name: "mysecret", + Payload: "foobar", + PayloadContentType: "text/plain", + SecretType: secrets.OpaqueSecret, + } + + actual, err := secrets.Create(client.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCreateResult, *actual) +} + +func TestDeleteSecret(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSecretSuccessfully(t) + + res := secrets.Delete(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateSecret(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSecretSuccessfully(t) + + updateOpts := secrets.UpdateOpts{ + Payload: "foobar", + } + + err := secrets.Update(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestGetPayloadSecret(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetPayloadSuccessfully(t) + + res := secrets.GetPayload(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", nil) + th.AssertNoErr(t, res.Err) + payload, err := res.Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, GetPayloadResponse, string(payload)) +} + +func TestGetMetadataSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetMetadataSuccessfully(t) + + actual, err := secrets.GetMetadata(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedMetadata, actual) +} + +func TestCreateMetadataSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateMetadataSuccessfully(t) + + createOpts := secrets.MetadataOpts{ + "foo": "bar", + "something": "something else", + } + + actual, err := secrets.CreateMetadata(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", createOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedCreateMetadataResult, actual) +} + +func TestGetMetadatumSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetMetadatumSuccessfully(t) + + actual, err := secrets.GetMetadatum(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", "foo").Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedMetadatum, *actual) +} + +func TestCreateMetadatumSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateMetadatumSuccessfully(t) + + createOpts := secrets.MetadatumOpts{ + Key: "foo", + Value: "bar", + } + + err := secrets.CreateMetadatum(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", createOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUpdateMetadatumSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateMetadatumSuccessfully(t) + + updateOpts := secrets.MetadatumOpts{ + Key: "foo", + Value: "bar", + } + + actual, err := secrets.UpdateMetadatum(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ExpectedMetadatum, *actual) +} + +func TestDeleteMetadatumSuccessfully(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteMetadatumSuccessfully(t) + + err := secrets.DeleteMetadatum(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", "foo").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/urls.go new file mode 100644 index 00000000..ebd636a6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets/urls.go @@ -0,0 +1,35 @@ +package secrets + +import "github.com/gophercloud/gophercloud" + +func listURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("secrets") +} + +func getURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("secrets", id) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("secrets") +} + +func deleteURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("secrets", id) +} + +func updateURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("secrets", id) +} + +func payloadURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("secrets", id, "payload") +} + +func metadataURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("secrets", id, "metadata") +} + +func metadatumURL(client *gophercloud.ServiceClient, id, key string) string { + return client.ServiceURL("secrets", id, "metadata", key) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/doc.go new file mode 100644 index 00000000..ec7f9d6f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/doc.go @@ -0,0 +1,3 @@ +// Package lbaas_v2 provides information and interaction with the Load Balancer +// as a Service v2 extension for the OpenStack Networking service. +package lbaas_v2 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/doc.go new file mode 100644 index 00000000..81357990 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/doc.go @@ -0,0 +1,123 @@ +/* +Package l7policies provides information and interaction with L7Policies and +Rules of the LBaaS v2 extension for the OpenStack Networking service. + +Example to Create a L7Policy + + createOpts := l7policies.CreateOpts{ + Name: "redirect-example.com", + ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", + Action: l7policies.ActionRedirectToURL, + RedirectURL: "http://www.example.com", + } + l7policy, err := l7policies.Create(lbClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to List L7Policies + + listOpts := l7policies.ListOpts{ + ListenerID: "c79a4468-d788-410c-bf79-9a8ef6354852", + } + allPages, err := l7policies.List(lbClient, listOpts).AllPages() + if err != nil { + panic(err) + } + allL7Policies, err := l7policies.ExtractL7Policies(allPages) + if err != nil { + panic(err) + } + for _, l7policy := range allL7Policies { + fmt.Printf("%+v\n", l7policy) + } + +Example to Get a L7Policy + + l7policy, err := l7policies.Get(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d").Extract() + if err != nil { + panic(err) + } + +Example to Delete a L7Policy + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + err := l7policies.Delete(lbClient, l7policyID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Update a L7Policy + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + name := "new-name" + updateOpts := l7policies.UpdateOpts{ + Name: &name, + } + l7policy, err := l7policies.Update(lbClient, l7policyID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Create a Rule + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + createOpts := l7policies.CreateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeRegex, + Value: "/images*", + } + rule, err := l7policies.CreateRule(lbClient, l7policyID, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to List L7 Rules + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + listOpts := l7policies.ListRulesOpts{ + RuleType: l7policies.TypePath, + } + allPages, err := l7policies.ListRules(lbClient, l7policyID, listOpts).AllPages() + if err != nil { + panic(err) + } + allRules, err := l7policies.ExtractRules(allPages) + if err != nil { + panic(err) + } + for _, rule := allRules { + fmt.Printf("%+v\n", rule) + } + +Example to Get a l7 rule + + l7rule, err := l7policies.GetRule(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d", "53ad8ab8-40fa-11e8-a508-00224d6b7bc1").Extract() + if err != nil { + panic(err) + } + +Example to Delete a l7 rule + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e" + err := l7policies.DeleteRule(lbClient, l7policyID, ruleID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Update a Rule + + l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" + ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e" + updateOpts := l7policies.UpdateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeRegex, + Value: "/images/special*", + } + rule, err := l7policies.UpdateRule(lbClient, l7policyID, ruleID, updateOpts).Extract() + if err != nil { + panic(err) + } +*/ +package l7policies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/requests.go new file mode 100644 index 00000000..c8887ae3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/requests.go @@ -0,0 +1,328 @@ +package l7policies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToL7PolicyCreateMap() (map[string]interface{}, error) +} + +type Action string +type RuleType string +type CompareType string + +const ( + ActionRedirectToPool Action = "REDIRECT_TO_POOL" + ActionRedirectToURL Action = "REDIRECT_TO_URL" + ActionReject Action = "REJECT" + + TypeCookie RuleType = "COOKIE" + TypeFileType RuleType = "FILE_TYPE" + TypeHeader RuleType = "HEADER" + TypeHostName RuleType = "HOST_NAME" + TypePath RuleType = "PATH" + + CompareTypeContains CompareType = "CONTAINS" + CompareTypeEndWith CompareType = "ENDS_WITH" + CompareTypeEqual CompareType = "EQUAL_TO" + CompareTypeRegex CompareType = "REGEX" + CompareTypeStartWith CompareType = "STARTS_WITH" +) + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + // Name of the L7 policy. + Name string `json:"name,omitempty"` + + // The ID of the listener. + ListenerID string `json:"listener_id" required:"true"` + + // The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT. + Action Action `json:"action" required:"true"` + + // The position of this policy on the listener. + Position int32 `json:"position,omitempty"` + + // A human-readable description for the resource. + Description string `json:"description,omitempty"` + + // ProjectID is the UUID of the project who owns the L7 policy in octavia. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // Requests matching this policy will be redirected to the pool with this ID. + // Only valid if action is REDIRECT_TO_POOL. + RedirectPoolID string `json:"redirect_pool_id,omitempty"` + + // Requests matching this policy will be redirected to this URL. + // Only valid if action is REDIRECT_TO_URL. + RedirectURL string `json:"redirect_url,omitempty"` +} + +// ToL7PolicyCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToL7PolicyCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "l7policy") +} + +// Create accepts a CreateOpts struct and uses the values to create a new l7policy. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToL7PolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToL7PolicyListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. +type ListOpts struct { + Name string `q:"name"` + ListenerID string `q:"listener_id"` + Action string `q:"action"` + ProjectID string `q:"project_id"` + RedirectPoolID string `q:"redirect_pool_id"` + RedirectURL string `q:"redirect_url"` + ID string `q:"id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToL7PolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToL7PolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// l7policies. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those l7policies that are owned by the +// project who submits the request, unless an admin user submits the request. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToL7PolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return L7PolicyPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves a particular l7policy based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// Delete will permanently delete a particular l7policy based on its unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToL7PolicyUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options struct used in this package's Update +// operation. +type UpdateOpts struct { + // Name of the L7 policy, empty string is allowed. + Name *string `json:"name,omitempty"` + + // The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT. + Action Action `json:"action,omitempty"` + + // The position of this policy on the listener. + Position int32 `json:"position,omitempty"` + + // A human-readable description for the resource, empty string is allowed. + Description *string `json:"description,omitempty"` + + // Requests matching this policy will be redirected to the pool with this ID. + // Only valid if action is REDIRECT_TO_POOL. + RedirectPoolID string `json:"redirect_pool_id,omitempty"` + + // Requests matching this policy will be redirected to this URL. + // Only valid if action is REDIRECT_TO_URL. + RedirectURL string `json:"redirect_url,omitempty"` +} + +// ToL7PolicyUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToL7PolicyUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "l7policy") +} + +// Update allows l7policy to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToL7PolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// CreateRuleOpts is the common options struct used in this package's CreateRule +// operation. +type CreateRuleOpts struct { + // The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH. + RuleType RuleType `json:"type" required:"true"` + + // The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH. + CompareType CompareType `json:"compare_type" required:"true"` + + // The value to use for the comparison. For example, the file type to compare. + Value string `json:"value" required:"true"` + + // ProjectID is the UUID of the project who owns the rule in octavia. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // The key to use for the comparison. For example, the name of the cookie to evaluate. + Key string `json:"key,omitempty"` + + // When true the logic of the rule is inverted. For example, with invert true, + // equal to would become not equal to. Default is false. + Invert bool `json:"invert,omitempty"` +} + +// ToRuleCreateMap builds a request body from CreateRuleOpts. +func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "rule") +} + +// CreateRule will create and associate a Rule with a particular L7Policy. +func CreateRule(c *gophercloud.ServiceClient, policyID string, opts CreateRuleOpts) (r CreateRuleResult) { + b, err := opts.ToRuleCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(ruleRootURL(c, policyID), b, &r.Body, nil) + return +} + +// ListRulesOptsBuilder allows extensions to add additional parameters to the +// ListRules request. +type ListRulesOptsBuilder interface { + ToRulesListQuery() (string, error) +} + +// ListRulesOpts allows the filtering and sorting of paginated collections +// through the API. +type ListRulesOpts struct { + RuleType RuleType `q:"type"` + ProjectID string `q:"project_id"` + ID string `q:"id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToRulesListQuery formats a ListOpts into a query string. +func (opts ListRulesOpts) ToRulesListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListRules returns a Pager which allows you to iterate over a collection of +// rules. It accepts a ListRulesOptsBuilder, which allows you to filter and +// sort the returned collection for greater efficiency. +// +// Default policy settings return only those rules that are owned by the +// project who submits the request, unless an admin user submits the request. +func ListRules(c *gophercloud.ServiceClient, policyID string, opts ListRulesOptsBuilder) pagination.Pager { + url := ruleRootURL(c, policyID) + if opts != nil { + query, err := opts.ToRulesListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return RulePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// GetRule retrieves a particular L7Policy Rule based on its unique ID. +func GetRule(c *gophercloud.ServiceClient, policyID string, ruleID string) (r GetRuleResult) { + _, r.Err = c.Get(ruleResourceURL(c, policyID, ruleID), &r.Body, nil) + return +} + +// DeleteRule will remove a Rule from a particular L7Policy. +func DeleteRule(c *gophercloud.ServiceClient, policyID string, ruleID string) (r DeleteRuleResult) { + _, r.Err = c.Delete(ruleResourceURL(c, policyID, ruleID), nil) + return +} + +// UpdateRuleOptsBuilder allows to add additional parameters to the PUT request. +type UpdateRuleOptsBuilder interface { + ToRuleUpdateMap() (map[string]interface{}, error) +} + +// UpdateRuleOpts is the common options struct used in this package's Update +// operation. +type UpdateRuleOpts struct { + // The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH. + RuleType RuleType `json:"type,omitempty"` + + // The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH. + CompareType CompareType `json:"compare_type,omitempty"` + + // The value to use for the comparison. For example, the file type to compare. + Value string `json:"value,omitempty"` + + // The key to use for the comparison. For example, the name of the cookie to evaluate. + Key string `json:"key,omitempty"` + + // When true the logic of the rule is inverted. For example, with invert true, + // equal to would become not equal to. Default is false. + Invert bool `json:"invert,omitempty"` +} + +// ToRuleUpdateMap builds a request body from UpdateRuleOpts. +func (opts UpdateRuleOpts) ToRuleUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "rule") +} + +// UpdateRule allows Rule to be updated. +func UpdateRule(c *gophercloud.ServiceClient, policyID string, ruleID string, opts UpdateRuleOptsBuilder) (r UpdateRuleResult) { + b, err := opts.ToRuleUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(ruleResourceURL(c, policyID, ruleID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/results.go new file mode 100644 index 00000000..43c8b74d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/results.go @@ -0,0 +1,223 @@ +package l7policies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// L7Policy is a collection of L7 rules associated with a Listener, and which +// may also have an association to a back-end pool. +type L7Policy struct { + // The unique ID for the L7 policy. + ID string `json:"id"` + + // Name of the L7 policy. + Name string `json:"name"` + + // The ID of the listener. + ListenerID string `json:"listener_id"` + + // The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT. + Action string `json:"action"` + + // The position of this policy on the listener. + Position int32 `json:"position"` + + // A human-readable description for the resource. + Description string `json:"description"` + + // ProjectID is the UUID of the project who owns the L7 policy in octavia. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id"` + + // Requests matching this policy will be redirected to the pool with this ID. + // Only valid if action is REDIRECT_TO_POOL. + RedirectPoolID string `json:"redirect_pool_id"` + + // Requests matching this policy will be redirected to this URL. + // Only valid if action is REDIRECT_TO_URL. + RedirectURL string `json:"redirect_url"` + + // The administrative state of the L7 policy, which is up (true) or down (false). + AdminStateUp bool `json:"admin_state_up"` + + // Rules are List of associated L7 rule IDs. + Rules []Rule `json:"rules"` +} + +// Rule represents layer 7 load balancing rule. +type Rule struct { + // The unique ID for the L7 rule. + ID string `json:"id"` + + // The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH. + RuleType string `json:"type"` + + // The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH. + CompareType string `json:"compare_type"` + + // The value to use for the comparison. For example, the file type to compare. + Value string `json:"value"` + + // ProjectID is the UUID of the project who owns the rule in octavia. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id"` + + // The key to use for the comparison. For example, the name of the cookie to evaluate. + Key string `json:"key"` + + // When true the logic of the rule is inverted. For example, with invert true, + // equal to would become not equal to. Default is false. + Invert bool `json:"invert"` + + // The administrative state of the L7 rule, which is up (true) or down (false). + AdminStateUp bool `json:"admin_state_up"` +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a l7policy. +func (r commonResult) Extract() (*L7Policy, error) { + var s struct { + L7Policy *L7Policy `json:"l7policy"` + } + err := r.ExtractInto(&s) + return s.L7Policy, err +} + +// CreateResult represents the result of a Create operation. Call its Extract +// method to interpret the result as a L7Policy. +type CreateResult struct { + commonResult +} + +// L7PolicyPage is the page returned by a pager when traversing over a +// collection of l7policies. +type L7PolicyPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of l7policies has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r L7PolicyPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"l7policies_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a L7PolicyPage struct is empty. +func (r L7PolicyPage) IsEmpty() (bool, error) { + is, err := ExtractL7Policies(r) + return len(is) == 0, err +} + +// ExtractL7Policies accepts a Page struct, specifically a L7PolicyPage struct, +// and extracts the elements into a slice of L7Policy structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractL7Policies(r pagination.Page) ([]L7Policy, error) { + var s struct { + L7Policies []L7Policy `json:"l7policies"` + } + err := (r.(L7PolicyPage)).ExtractInto(&s) + return s.L7Policies, err +} + +// GetResult represents the result of a Get operation. Call its Extract +// method to interpret the result as a L7Policy. +type GetResult struct { + commonResult +} + +// DeleteResult represents the result of a Delete operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult represents the result of an Update operation. Call its Extract +// method to interpret the result as a L7Policy. +type UpdateResult struct { + commonResult +} + +type commonRuleResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a rule. +func (r commonRuleResult) Extract() (*Rule, error) { + var s struct { + Rule *Rule `json:"rule"` + } + err := r.ExtractInto(&s) + return s.Rule, err +} + +// CreateRuleResult represents the result of a CreateRule operation. +// Call its Extract method to interpret it as a Rule. +type CreateRuleResult struct { + commonRuleResult +} + +// RulePage is the page returned by a pager when traversing over a +// collection of Rules in a L7Policy. +type RulePage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of rules has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r RulePage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"rules_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a RulePage struct is empty. +func (r RulePage) IsEmpty() (bool, error) { + is, err := ExtractRules(r) + return len(is) == 0, err +} + +// ExtractRules accepts a Page struct, specifically a RulePage struct, +// and extracts the elements into a slice of Rules structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractRules(r pagination.Page) ([]Rule, error) { + var s struct { + Rules []Rule `json:"rules"` + } + err := (r.(RulePage)).ExtractInto(&s) + return s.Rules, err +} + +// GetRuleResult represents the result of a GetRule operation. +// Call its Extract method to interpret it as a Rule. +type GetRuleResult struct { + commonRuleResult +} + +// DeleteRuleResult represents the result of a DeleteRule operation. +// Call its ExtractErr method to determine if the request succeeded or failed. +type DeleteRuleResult struct { + gophercloud.ErrResult +} + +// UpdateRuleResult represents the result of an UpdateRule operation. +// Call its Extract method to interpret it as a Rule. +type UpdateRuleResult struct { + commonRuleResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/doc.go new file mode 100644 index 00000000..f8068dfb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/doc.go @@ -0,0 +1,2 @@ +// l7policies unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/fixtures.go new file mode 100644 index 00000000..e14cf898 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/fixtures.go @@ -0,0 +1,375 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// SingleL7PolicyBody is the canned body of a Get request on an existing l7policy. +const SingleL7PolicyBody = ` +{ + "l7policy": { + "listener_id": "023f2e34-7806-443b-bfae-16c324569a3d", + "description": "", + "admin_state_up": true, + "redirect_pool_id": null, + "redirect_url": "http://www.example.com", + "action": "REDIRECT_TO_URL", + "position": 1, + "project_id": "e3cd678b11784734bc366148aa37580e", + "id": "8a1412f0-4c32-4257-8b07-af4770b604fd", + "name": "redirect-example.com", + "rules": [] + } +} +` + +var ( + L7PolicyToURL = l7policies.L7Policy{ + ID: "8a1412f0-4c32-4257-8b07-af4770b604fd", + Name: "redirect-example.com", + ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", + Action: "REDIRECT_TO_URL", + Position: 1, + Description: "", + ProjectID: "e3cd678b11784734bc366148aa37580e", + RedirectPoolID: "", + RedirectURL: "http://www.example.com", + AdminStateUp: true, + Rules: []l7policies.Rule{}, + } + L7PolicyToPool = l7policies.L7Policy{ + ID: "964f4ba4-f6cd-405c-bebd-639460af7231", + Name: "redirect-pool", + ListenerID: "be3138a3-5cf7-4513-a4c2-bb137e668bab", + Action: "REDIRECT_TO_POOL", + Position: 1, + Description: "", + ProjectID: "c1f7910086964990847dc6c8b128f63c", + RedirectPoolID: "bac433c6-5bea-4311-80da-bd1cd90fbd25", + RedirectURL: "", + AdminStateUp: true, + Rules: []l7policies.Rule{}, + } + L7PolicyUpdated = l7policies.L7Policy{ + ID: "8a1412f0-4c32-4257-8b07-af4770b604fd", + Name: "NewL7PolicyName", + ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", + Action: "REDIRECT_TO_URL", + Position: 1, + Description: "Redirect requests to example.com", + ProjectID: "e3cd678b11784734bc366148aa37580e", + RedirectPoolID: "", + RedirectURL: "http://www.new-example.com", + AdminStateUp: true, + Rules: []l7policies.Rule{}, + } + RulePath = l7policies.Rule{ + ID: "16621dbb-a736-4888-a57a-3ecd53df784c", + RuleType: "PATH", + CompareType: "REGEX", + Value: "/images*", + ProjectID: "e3cd678b11784734bc366148aa37580e", + Key: "", + Invert: false, + AdminStateUp: true, + } + RuleHostName = l7policies.Rule{ + ID: "d24521a0-df84-4468-861a-a531af116d1e", + RuleType: "HOST_NAME", + CompareType: "EQUAL_TO", + Value: "www.example.com", + ProjectID: "e3cd678b11784734bc366148aa37580e", + Key: "", + Invert: false, + AdminStateUp: true, + } + RuleUpdated = l7policies.Rule{ + ID: "16621dbb-a736-4888-a57a-3ecd53df784c", + RuleType: "PATH", + CompareType: "REGEX", + Value: "/images/special*", + ProjectID: "e3cd678b11784734bc366148aa37580e", + Key: "", + Invert: false, + AdminStateUp: true, + } +) + +// HandleL7PolicyCreationSuccessfully sets up the test server to respond to a l7policy creation request +// with a given response. +func HandleL7PolicyCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "l7policy": { + "listener_id": "023f2e34-7806-443b-bfae-16c324569a3d", + "redirect_url": "http://www.example.com", + "name": "redirect-example.com", + "action": "REDIRECT_TO_URL" + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// L7PoliciesListBody contains the canned body of a l7policy list response. +const L7PoliciesListBody = ` +{ + "l7policies": [ + { + "redirect_pool_id": null, + "description": "", + "admin_state_up": true, + "rules": [], + "project_id": "e3cd678b11784734bc366148aa37580e", + "listener_id": "023f2e34-7806-443b-bfae-16c324569a3d", + "redirect_url": "http://www.example.com", + "action": "REDIRECT_TO_URL", + "position": 1, + "id": "8a1412f0-4c32-4257-8b07-af4770b604fd", + "name": "redirect-example.com" + }, + { + "redirect_pool_id": "bac433c6-5bea-4311-80da-bd1cd90fbd25", + "description": "", + "admin_state_up": true, + "rules": [], + "project_id": "c1f7910086964990847dc6c8b128f63c", + "listener_id": "be3138a3-5cf7-4513-a4c2-bb137e668bab", + "action": "REDIRECT_TO_POOL", + "position": 1, + "id": "964f4ba4-f6cd-405c-bebd-639460af7231", + "name": "redirect-pool" + } + ] +} +` + +// PostUpdateL7PolicyBody is the canned response body of a Update request on an existing l7policy. +const PostUpdateL7PolicyBody = ` +{ + "l7policy": { + "listener_id": "023f2e34-7806-443b-bfae-16c324569a3d", + "description": "Redirect requests to example.com", + "admin_state_up": true, + "redirect_pool_id": null, + "redirect_url": "http://www.new-example.com", + "action": "REDIRECT_TO_URL", + "position": 1, + "project_id": "e3cd678b11784734bc366148aa37580e", + "id": "8a1412f0-4c32-4257-8b07-af4770b604fd", + "name": "NewL7PolicyName", + "rules": [] + } +} +` + +// HandleL7PolicyListSuccessfully sets up the test server to respond to a l7policy List request. +func HandleL7PolicyListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, L7PoliciesListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "l7policies": [] }`) + default: + t.Fatalf("/v2.0/lbaas/l7policies invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleL7PolicyGetSuccessfully sets up the test server to respond to a l7policy Get request. +func HandleL7PolicyGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleL7PolicyBody) + }) +} + +// HandleL7PolicyDeletionSuccessfully sets up the test server to respond to a l7policy deletion request. +func HandleL7PolicyDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleL7PolicyUpdateSuccessfully sets up the test server to respond to a l7policy Update request. +func HandleL7PolicyUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "l7policy": { + "name": "NewL7PolicyName", + "action": "REDIRECT_TO_URL", + "redirect_url": "http://www.new-example.com" + } + }`) + + fmt.Fprintf(w, PostUpdateL7PolicyBody) + }) +} + +// SingleRuleBody is the canned body of a Get request on an existing rule. +const SingleRuleBody = ` +{ + "rule": { + "compare_type": "REGEX", + "invert": false, + "admin_state_up": true, + "value": "/images*", + "key": null, + "project_id": "e3cd678b11784734bc366148aa37580e", + "type": "PATH", + "id": "16621dbb-a736-4888-a57a-3ecd53df784c" + } +} +` + +// HandleRuleCreationSuccessfully sets up the test server to respond to a rule creation request +// with a given response. +func HandleRuleCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "rule": { + "compare_type": "REGEX", + "type": "PATH", + "value": "/images*" + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// RulesListBody contains the canned body of a rule list response. +const RulesListBody = ` +{ + "rules":[ + { + "compare_type": "REGEX", + "invert": false, + "admin_state_up": true, + "value": "/images*", + "key": null, + "project_id": "e3cd678b11784734bc366148aa37580e", + "type": "PATH", + "id": "16621dbb-a736-4888-a57a-3ecd53df784c" + }, + { + "compare_type": "EQUAL_TO", + "invert": false, + "admin_state_up": true, + "value": "www.example.com", + "key": null, + "project_id": "e3cd678b11784734bc366148aa37580e", + "type": "HOST_NAME", + "id": "d24521a0-df84-4468-861a-a531af116d1e" + } + ] +} +` + +// HandleRuleListSuccessfully sets up the test server to respond to a rule List request. +func HandleRuleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, RulesListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "rules": [] }`) + default: + t.Fatalf("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleRuleGetSuccessfully sets up the test server to respond to a rule Get request. +func HandleRuleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleRuleBody) + }) +} + +// HandleRuleDeletionSuccessfully sets up the test server to respond to a rule deletion request. +func HandleRuleDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// PostUpdateRuleBody is the canned response body of a Update request on an existing rule. +const PostUpdateRuleBody = ` +{ + "rule": { + "compare_type": "REGEX", + "invert": false, + "admin_state_up": true, + "value": "/images/special*", + "key": null, + "project_id": "e3cd678b11784734bc366148aa37580e", + "type": "PATH", + "id": "16621dbb-a736-4888-a57a-3ecd53df784c" + } +} +` + +// HandleRuleUpdateSuccessfully sets up the test server to respond to a rule Update request. +func HandleRuleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "rule": { + "compare_type": "REGEX", + "type": "PATH", + "value": "/images/special*" + } + }`) + + fmt.Fprintf(w, PostUpdateRuleBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/requests_test.go new file mode 100644 index 00000000..dc847545 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/testing/requests_test.go @@ -0,0 +1,292 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreateL7Policy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyCreationSuccessfully(t, SingleL7PolicyBody) + + actual, err := l7policies.Create(fake.ServiceClient(), l7policies.CreateOpts{ + Name: "redirect-example.com", + ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", + Action: l7policies.ActionRedirectToURL, + RedirectURL: "http://www.example.com", + }).Extract() + + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, L7PolicyToURL, *actual) +} + +func TestRequiredL7PolicyCreateOpts(t *testing.T) { + // no param specified. + res := l7policies.Create(fake.ServiceClient(), l7policies.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + + // Action is invalid. + res = l7policies.Create(fake.ServiceClient(), l7policies.CreateOpts{ + ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", + Action: l7policies.Action("invalid"), + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestListL7Policies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyListSuccessfully(t) + + pages := 0 + err := l7policies.List(fake.ServiceClient(), l7policies.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := l7policies.ExtractL7Policies(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 l7policies, got %d", len(actual)) + } + th.CheckDeepEquals(t, L7PolicyToURL, actual[0]) + th.CheckDeepEquals(t, L7PolicyToPool, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllL7Policies(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyListSuccessfully(t) + + allPages, err := l7policies.List(fake.ServiceClient(), l7policies.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := l7policies.ExtractL7Policies(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, L7PolicyToURL, actual[0]) + th.CheckDeepEquals(t, L7PolicyToPool, actual[1]) +} + +func TestGetL7Policy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := l7policies.Get(client, "8a1412f0-4c32-4257-8b07-af4770b604fd").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, L7PolicyToURL, *actual) +} + +func TestDeleteL7Policy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyDeletionSuccessfully(t) + + res := l7policies.Delete(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateL7Policy(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleL7PolicyUpdateSuccessfully(t) + + client := fake.ServiceClient() + newName := "NewL7PolicyName" + actual, err := l7policies.Update(client, "8a1412f0-4c32-4257-8b07-af4770b604fd", + l7policies.UpdateOpts{ + Name: &newName, + Action: l7policies.ActionRedirectToURL, + RedirectURL: "http://www.new-example.com", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, L7PolicyUpdated, *actual) +} + +func TestUpdateL7PolicyWithInvalidOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + res := l7policies.Update(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.UpdateOpts{ + Action: l7policies.Action("invalid"), + }) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestCreateRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleCreationSuccessfully(t, SingleRuleBody) + + actual, err := l7policies.CreateRule(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.CreateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeRegex, + Value: "/images*", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, RulePath, *actual) +} + +func TestRequiredRuleCreateOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + res := l7policies.CreateRule(fake.ServiceClient(), "", l7policies.CreateRuleOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = l7policies.CreateRule(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.CreateRuleOpts{ + RuleType: l7policies.TypePath, + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = l7policies.CreateRule(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.CreateRuleOpts{ + RuleType: l7policies.RuleType("invalid"), + CompareType: l7policies.CompareTypeRegex, + Value: "/images*", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = l7policies.CreateRule(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.CreateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareType("invalid"), + Value: "/images*", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestListRules(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleListSuccessfully(t) + + pages := 0 + err := l7policies.ListRules(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.ListRulesOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := l7policies.ExtractRules(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 rules, got %d", len(actual)) + } + th.CheckDeepEquals(t, RulePath, actual[0]) + th.CheckDeepEquals(t, RuleHostName, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllRules(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleListSuccessfully(t) + + allPages, err := l7policies.ListRules(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", l7policies.ListRulesOpts{}).AllPages() + th.AssertNoErr(t, err) + + actual, err := l7policies.ExtractRules(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, RulePath, actual[0]) + th.CheckDeepEquals(t, RuleHostName, actual[1]) +} + +func TestGetRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := l7policies.GetRule(client, "8a1412f0-4c32-4257-8b07-af4770b604fd", "16621dbb-a736-4888-a57a-3ecd53df784c").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, RulePath, *actual) +} + +func TestDeleteRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleDeletionSuccessfully(t) + + res := l7policies.DeleteRule(fake.ServiceClient(), "8a1412f0-4c32-4257-8b07-af4770b604fd", "16621dbb-a736-4888-a57a-3ecd53df784c") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateRule(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleRuleUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := l7policies.UpdateRule(client, "8a1412f0-4c32-4257-8b07-af4770b604fd", "16621dbb-a736-4888-a57a-3ecd53df784c", l7policies.UpdateRuleOpts{ + RuleType: l7policies.TypePath, + CompareType: l7policies.CompareTypeRegex, + Value: "/images/special*", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, RuleUpdated, *actual) +} + +func TestUpdateRuleWithInvalidOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + res := l7policies.UpdateRule(fake.ServiceClient(), "", "", l7policies.UpdateRuleOpts{ + RuleType: l7policies.RuleType("invalid"), + }) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + + res = l7policies.UpdateRule(fake.ServiceClient(), "", "", l7policies.UpdateRuleOpts{ + CompareType: l7policies.CompareType("invalid"), + }) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/urls.go new file mode 100644 index 00000000..ecb607a8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies/urls.go @@ -0,0 +1,25 @@ +package l7policies + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "lbaas" + resourcePath = "l7policies" + rulePath = "rules" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} + +func ruleRootURL(c *gophercloud.ServiceClient, policyID string) string { + return c.ServiceURL(rootPath, resourcePath, policyID, rulePath) +} + +func ruleResourceURL(c *gophercloud.ServiceClient, policyID string, ruleID string) string { + return c.ServiceURL(rootPath, resourcePath, policyID, rulePath, ruleID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/doc.go new file mode 100644 index 00000000..108cdb03 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/doc.go @@ -0,0 +1,63 @@ +/* +Package listeners provides information and interaction with Listeners of the +LBaaS v2 extension for the OpenStack Networking service. + +Example to List Listeners + + listOpts := listeners.ListOpts{ + LoadbalancerID : "ca430f80-1737-4712-8dc6-3f640d55594b", + } + + allPages, err := listeners.List(networkClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allListeners, err := listeners.ExtractListeners(allPages) + if err != nil { + panic(err) + } + + for _, listener := range allListeners { + fmt.Printf("%+v\n", listener) + } + +Example to Create a Listener + + createOpts := listeners.CreateOpts{ + Protocol: "TCP", + Name: "db", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + AdminStateUp: gophercloud.Enabled, + DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + ProtocolPort: 3306, + } + + listener, err := listeners.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Listener + + listenerID := "d67d56a6-4a86-4688-a282-f46444705c64" + + i1001 := 1001 + updateOpts := listeners.UpdateOpts{ + ConnLimit: &i1001, + } + + listener, err := listeners.Update(networkClient, listenerID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Listener + + listenerID := "d67d56a6-4a86-4688-a282-f46444705c64" + err := listeners.Delete(networkClient, listenerID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package listeners diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/requests.go new file mode 100644 index 00000000..5662ef8a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/requests.go @@ -0,0 +1,194 @@ +package listeners + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Type Protocol represents a listener protocol. +type Protocol string + +// Supported attributes for create/update operations. +const ( + ProtocolTCP Protocol = "TCP" + ProtocolHTTP Protocol = "HTTP" + ProtocolHTTPS Protocol = "HTTPS" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToListenerListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the floating IP attributes you want to see returned. SortKey allows you to +// sort by a particular listener attribute. SortDir sets the direction, and is +// either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + ID string `q:"id"` + Name string `q:"name"` + AdminStateUp *bool `q:"admin_state_up"` + ProjectID string `q:"project_id"` + LoadbalancerID string `q:"loadbalancer_id"` + DefaultPoolID string `q:"default_pool_id"` + Protocol string `q:"protocol"` + ProtocolPort int `q:"protocol_port"` + ConnectionLimit int `q:"connection_limit"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToListenerListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToListenerListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// listeners. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those listeners that are owned by the +// project who submits the request, unless an admin user submits the request. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToListenerListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return ListenerPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToListenerCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options for creating a listener. +type CreateOpts struct { + // The load balancer on which to provision this listener. + LoadbalancerID string `json:"loadbalancer_id" required:"true"` + + // The protocol - can either be TCP, HTTP or HTTPS. + Protocol Protocol `json:"protocol" required:"true"` + + // The port on which to listen for client traffic. + ProtocolPort int `json:"protocol_port" required:"true"` + + // ProjectID is only required if the caller has an admin role and wants + // to create a pool for another project. + ProjectID string `json:"project_id,omitempty"` + + // Human-readable name for the Listener. Does not have to be unique. + Name string `json:"name,omitempty"` + + // The ID of the default pool with which the Listener is associated. + DefaultPoolID string `json:"default_pool_id,omitempty"` + + // Human-readable description for the Listener. + Description string `json:"description,omitempty"` + + // The maximum number of connections allowed for the Listener. + ConnLimit *int `json:"connection_limit,omitempty"` + + // A reference to a Barbican container of TLS secrets. + DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` + + // A list of references to TLS secrets. + SniContainerRefs []string `json:"sni_container_refs,omitempty"` + + // The administrative state of the Listener. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToListenerCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "listener") +} + +// Create is an operation which provisions a new Listeners based on the +// configuration defined in the CreateOpts struct. Once the request is +// validated and progress has started on the provisioning process, a +// CreateResult will be returned. +// +// Users with an admin role can create Listeners on behalf of other projects by +// specifying a ProjectID attribute different than their own. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToListenerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular Listeners based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToListenerUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options for updating a Listener. +type UpdateOpts struct { + // Human-readable name for the Listener. Does not have to be unique. + Name string `json:"name,omitempty"` + + // Human-readable description for the Listener. + Description string `json:"description,omitempty"` + + // The maximum number of connections allowed for the Listener. + ConnLimit *int `json:"connection_limit,omitempty"` + + // A reference to a Barbican container of TLS secrets. + DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` + + // A list of references to TLS secrets. + SniContainerRefs []string `json:"sni_container_refs,omitempty"` + + // The administrative state of the Listener. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToListenerUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "listener") +} + +// Update is an operation which modifies the attributes of the specified +// Listener. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { + b, err := opts.ToListenerUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} + +// Delete will permanently delete a particular Listeners based on its unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/results.go new file mode 100644 index 00000000..3e984232 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/results.go @@ -0,0 +1,135 @@ +package listeners + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/pagination" +) + +type LoadBalancerID struct { + ID string `json:"id"` +} + +// Listener is the primary load balancing configuration object that specifies +// the loadbalancer and port on which client traffic is received, as well +// as other details such as the load balancing method to be use, protocol, etc. +type Listener struct { + // The unique ID for the Listener. + ID string `json:"id"` + + // Owner of the Listener. + ProjectID string `json:"project_id"` + + // Human-readable name for the Listener. Does not have to be unique. + Name string `json:"name"` + + // Human-readable description for the Listener. + Description string `json:"description"` + + // The protocol to loadbalance. A valid value is TCP, HTTP, or HTTPS. + Protocol string `json:"protocol"` + + // The port on which to listen to client traffic that is associated with the + // Loadbalancer. A valid value is from 0 to 65535. + ProtocolPort int `json:"protocol_port"` + + // The UUID of default pool. Must have compatible protocol with listener. + DefaultPoolID string `json:"default_pool_id"` + + // A list of load balancer IDs. + Loadbalancers []LoadBalancerID `json:"loadbalancers"` + + // The maximum number of connections allowed for the Loadbalancer. + // Default is -1, meaning no limit. + ConnLimit int `json:"connection_limit"` + + // The list of references to TLS secrets. + SniContainerRefs []string `json:"sni_container_refs"` + + // A reference to a Barbican container of TLS secrets. + DefaultTlsContainerRef string `json:"default_tls_container_ref"` + + // The administrative state of the Listener. A valid value is true (UP) or false (DOWN). + AdminStateUp bool `json:"admin_state_up"` + + // Pools are the pools which are part of this listener. + Pools []pools.Pool `json:"pools"` + + // The provisioning status of the Listener. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` +} + +// ListenerPage is the page returned by a pager when traversing over a +// collection of listeners. +type ListenerPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of listeners has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r ListenerPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"listeners_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a ListenerPage struct is empty. +func (r ListenerPage) IsEmpty() (bool, error) { + is, err := ExtractListeners(r) + return len(is) == 0, err +} + +// ExtractListeners accepts a Page struct, specifically a ListenerPage struct, +// and extracts the elements into a slice of Listener structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractListeners(r pagination.Page) ([]Listener, error) { + var s struct { + Listeners []Listener `json:"listeners"` + } + err := (r.(ListenerPage)).ExtractInto(&s) + return s.Listeners, err +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a listener. +func (r commonResult) Extract() (*Listener, error) { + var s struct { + Listener *Listener `json:"listener"` + } + err := r.ExtractInto(&s) + return s.Listener, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a Listener. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a Listener. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a Listener. +type UpdateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/doc.go new file mode 100644 index 00000000..f41387e8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/doc.go @@ -0,0 +1,2 @@ +// listeners unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/fixtures.go new file mode 100644 index 00000000..07faa8d4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/fixtures.go @@ -0,0 +1,213 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// ListenersListBody contains the canned body of a listeners list response. +const ListenersListBody = ` +{ + "listeners":[ + { + "id": "db902c0c-d5ff-4753-b465-668ad9656918", + "project_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "web", + "description": "listener config for the web tier", + "loadbalancers": [{"id": "53306cda-815d-4354-9444-59e09da9c3c5"}], + "protocol": "HTTP", + "protocol_port": 80, + "default_pool_id": "fad389a3-9a4a-4762-a365-8c7038508b5d", + "admin_state_up": true, + "default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76", + "sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"] + }, + { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "db", + "description": "listener config for the db tier", + "loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "protocol": "TCP", + "protocol_port": 3306, + "default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e", + "connection_limit": 2000, + "admin_state_up": true, + "default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76", + "sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"] + } + ] +} +` + +// SingleServerBody is the canned body of a Get request on an existing listener. +const SingleListenerBody = ` +{ + "listener": { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "db", + "description": "listener config for the db tier", + "loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "protocol": "TCP", + "protocol_port": 3306, + "default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e", + "connection_limit": 2000, + "admin_state_up": true, + "default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76", + "sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"] + } +} +` + +// PostUpdateListenerBody is the canned response body of a Update request on an existing listener. +const PostUpdateListenerBody = ` +{ + "listener": { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "NewListenerName", + "description": "listener config for the db tier", + "loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "protocol": "TCP", + "protocol_port": 3306, + "default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e", + "connection_limit": 1000, + "admin_state_up": true, + "default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76", + "sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"] + } +} +` + +var ( + ListenerWeb = listeners.Listener{ + ID: "db902c0c-d5ff-4753-b465-668ad9656918", + ProjectID: "310df60f-2a10-4ee5-9554-98393092194c", + Name: "web", + Description: "listener config for the web tier", + Loadbalancers: []listeners.LoadBalancerID{{ID: "53306cda-815d-4354-9444-59e09da9c3c5"}}, + Protocol: "HTTP", + ProtocolPort: 80, + DefaultPoolID: "fad389a3-9a4a-4762-a365-8c7038508b5d", + AdminStateUp: true, + DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76", + SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"}, + } + ListenerDb = listeners.Listener{ + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + ProjectID: "310df60f-2a10-4ee5-9554-98393092194c", + Name: "db", + Description: "listener config for the db tier", + Loadbalancers: []listeners.LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}}, + Protocol: "TCP", + ProtocolPort: 3306, + DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + ConnLimit: 2000, + AdminStateUp: true, + DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76", + SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"}, + } + ListenerUpdated = listeners.Listener{ + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + ProjectID: "310df60f-2a10-4ee5-9554-98393092194c", + Name: "NewListenerName", + Description: "listener config for the db tier", + Loadbalancers: []listeners.LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}}, + Protocol: "TCP", + ProtocolPort: 3306, + DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + ConnLimit: 1000, + AdminStateUp: true, + DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76", + SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"}, + } +) + +// HandleListenerListSuccessfully sets up the test server to respond to a listener List request. +func HandleListenerListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/listeners", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, ListenersListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "listeners": [] }`) + default: + t.Fatalf("/v2.0/lbaas/listeners invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleListenerCreationSuccessfully sets up the test server to respond to a listener creation request +// with a given response. +func HandleListenerCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/listeners", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "listener": { + "loadbalancer_id": "79e05663-7f03-45d2-a092-8b94062f22ab", + "protocol": "TCP", + "name": "db", + "admin_state_up": true, + "default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76", + "default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e", + "protocol_port": 3306 + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// HandleListenerGetSuccessfully sets up the test server to respond to a listener Get request. +func HandleListenerGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleListenerBody) + }) +} + +// HandleListenerDeletionSuccessfully sets up the test server to respond to a listener deletion request. +func HandleListenerDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleListenerUpdateSuccessfully sets up the test server to respond to a listener Update request. +func HandleListenerUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "listener": { + "name": "NewListenerName", + "connection_limit": 1001 + } + }`) + + fmt.Fprintf(w, PostUpdateListenerBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/requests_test.go new file mode 100644 index 00000000..4123b305 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/testing/requests_test.go @@ -0,0 +1,137 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + fake "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListListeners(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerListSuccessfully(t) + + pages := 0 + err := listeners.List(fake.ServiceClient(), listeners.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := listeners.ExtractListeners(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 listeners, got %d", len(actual)) + } + th.CheckDeepEquals(t, ListenerWeb, actual[0]) + th.CheckDeepEquals(t, ListenerDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllListeners(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerListSuccessfully(t) + + allPages, err := listeners.List(fake.ServiceClient(), listeners.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := listeners.ExtractListeners(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ListenerWeb, actual[0]) + th.CheckDeepEquals(t, ListenerDb, actual[1]) +} + +func TestCreateListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerCreationSuccessfully(t, SingleListenerBody) + + actual, err := listeners.Create(fake.ServiceClient(), listeners.CreateOpts{ + Protocol: "TCP", + Name: "db", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + AdminStateUp: gophercloud.Enabled, + DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76", + DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + ProtocolPort: 3306, + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListenerDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := listeners.Create(fake.ServiceClient(), listeners.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", ProjectID: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", ProjectID: "bar", Protocol: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", ProjectID: "bar", Protocol: "bar", ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := listeners.Get(client, "4ec89087-d057-4e2c-911f-60a3b47ee304").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, ListenerDb, *actual) +} + +func TestDeleteListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerDeletionSuccessfully(t) + + res := listeners.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerUpdateSuccessfully(t) + + client := fake.ServiceClient() + i1001 := 1001 + actual, err := listeners.Update(client, "4ec89087-d057-4e2c-911f-60a3b47ee304", listeners.UpdateOpts{ + Name: "NewListenerName", + ConnLimit: &i1001, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, ListenerUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/urls.go new file mode 100644 index 00000000..02fb1eb3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners/urls.go @@ -0,0 +1,16 @@ +package listeners + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "lbaas" + resourcePath = "listeners" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/doc.go new file mode 100644 index 00000000..b0a20b8f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/doc.go @@ -0,0 +1,76 @@ +/* +Package loadbalancers provides information and interaction with Load Balancers +of the LBaaS v2 extension for the OpenStack Networking service. + +Example to List Load Balancers + + listOpts := loadbalancers.ListOpts{ + Provider: "haproxy", + } + + allPages, err := loadbalancers.List(networkClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allLoadbalancers, err := loadbalancers.ExtractLoadBalancers(allPages) + if err != nil { + panic(err) + } + + for _, lb := range allLoadbalancers { + fmt.Printf("%+v\n", lb) + } + +Example to Create a Load Balancer + + createOpts := loadbalancers.CreateOpts{ + Name: "db_lb", + AdminStateUp: gophercloud.Enabled, + VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + VipAddress: "10.30.176.48", + Flavor: "medium", + Provider: "haproxy", + } + + lb, err := loadbalancers.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Load Balancer + + lbID := "d67d56a6-4a86-4688-a282-f46444705c64" + + i1001 := 1001 + updateOpts := loadbalancers.UpdateOpts{ + Name: "new-name", + } + + lb, err := loadbalancers.Update(networkClient, lbID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Load Balancers + + deleteOpts := loadbalancers.DeleteOpts{ + Cascade: true, + } + + lbID := "d67d56a6-4a86-4688-a282-f46444705c64" + + err := loadbalancers.Delete(networkClient, lbID, deleteOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to Get the Status of a Load Balancer + + lbID := "d67d56a6-4a86-4688-a282-f46444705c64" + status, err := loadbalancers.GetStatuses(networkClient, LBID).Extract() + if err != nil { + panic(err) + } +*/ +package loadbalancers diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/requests.go new file mode 100644 index 00000000..0a62f59b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/requests.go @@ -0,0 +1,205 @@ +package loadbalancers + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToLoadBalancerListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the Loadbalancer attributes you want to see returned. SortKey allows you to +// sort by a particular attribute. SortDir sets the direction, and is +// either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + Description string `q:"description"` + AdminStateUp *bool `q:"admin_state_up"` + ProjectID string `q:"project_id"` + ProvisioningStatus string `q:"provisioning_status"` + VipAddress string `q:"vip_address"` + VipPortID string `q:"vip_port_id"` + VipSubnetID string `q:"vip_subnet_id"` + ID string `q:"id"` + OperatingStatus string `q:"operating_status"` + Name string `q:"name"` + Flavor string `q:"flavor"` + Provider string `q:"provider"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToLoadBalancerListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToLoadBalancerListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// load balancers. It accepts a ListOpts struct, which allows you to filter +// and sort the returned collection for greater efficiency. +// +// Default policy settings return only those load balancers that are owned by +// the project who submits the request, unless an admin user submits the request. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToLoadBalancerListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return LoadBalancerPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToLoadBalancerCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + // Human-readable name for the Loadbalancer. Does not have to be unique. + Name string `json:"name,omitempty"` + + // Human-readable description for the Loadbalancer. + Description string `json:"description,omitempty"` + + // The network on which to allocate the Loadbalancer's address. A project can + // only create Loadbalancers on networks authorized by policy (e.g. networks + // that belong to them or networks that are shared). + VipSubnetID string `json:"vip_subnet_id" required:"true"` + + // ProjectID is the UUID of the project who owns the Loadbalancer. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // The IP address of the Loadbalancer. + VipAddress string `json:"vip_address,omitempty"` + + // The administrative state of the Loadbalancer. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // The UUID of a flavor. + Flavor string `json:"flavor,omitempty"` + + // The name of the provider. + Provider string `json:"provider,omitempty"` +} + +// ToLoadBalancerCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "loadbalancer") +} + +// Create is an operation which provisions a new loadbalancer based on the +// configuration defined in the CreateOpts struct. Once the request is +// validated and progress has started on the provisioning process, a +// CreateResult will be returned. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToLoadBalancerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular Loadbalancer based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToLoadBalancerUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options struct used in this package's Update +// operation. +type UpdateOpts struct { + // Human-readable name for the Loadbalancer. Does not have to be unique. + Name string `json:"name,omitempty"` + + // Human-readable description for the Loadbalancer. + Description string `json:"description,omitempty"` + + // The administrative state of the Loadbalancer. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToLoadBalancerUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "loadbalancer") +} + +// Update is an operation which modifies the attributes of the specified +// LoadBalancer. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { + b, err := opts.ToLoadBalancerUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} + +// DeleteOptsBuilder allows extensions to add additional parameters to the +// Delete request. +type DeleteOptsBuilder interface { + ToLoadBalancerDeleteQuery() (string, error) +} + +// DeleteOpts is the common options struct used in this package's Delete +// operation. +type DeleteOpts struct { + // Cascade will delete all children of the load balancer (listners, monitors, etc). + Cascade bool `q:"cascade"` +} + +// ToLoadBalancerDeleteQuery formats a DeleteOpts into a query string. +func (opts DeleteOpts) ToLoadBalancerDeleteQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// Delete will permanently delete a particular LoadBalancer based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string, opts DeleteOptsBuilder) (r DeleteResult) { + url := resourceURL(c, id) + if opts != nil { + query, err := opts.ToLoadBalancerDeleteQuery() + if err != nil { + r.Err = err + return + } + url += query + } + _, r.Err = c.Delete(url, nil) + return +} + +// GetStatuses will return the status of a particular LoadBalancer. +func GetStatuses(c *gophercloud.ServiceClient, id string) (r GetStatusesResult) { + _, r.Err = c.Get(statusRootURL(c, id), &r.Body, nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/results.go new file mode 100644 index 00000000..62d1b668 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/results.go @@ -0,0 +1,149 @@ +package loadbalancers + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/pagination" +) + +// LoadBalancer is the primary load balancing configuration object that +// specifies the virtual IP address on which client traffic is received, as well +// as other details such as the load balancing method to be use, protocol, etc. +type LoadBalancer struct { + // Human-readable description for the Loadbalancer. + Description string `json:"description"` + + // The administrative state of the Loadbalancer. + // A valid value is true (UP) or false (DOWN). + AdminStateUp bool `json:"admin_state_up"` + + // Owner of the LoadBalancer. + ProjectID string `json:"project_id"` + + // The provisioning status of the LoadBalancer. + // This value is ACTIVE, PENDING_CREATE or ERROR. + ProvisioningStatus string `json:"provisioning_status"` + + // The IP address of the Loadbalancer. + VipAddress string `json:"vip_address"` + + // The UUID of the port associated with the IP address. + VipPortID string `json:"vip_port_id"` + + // The UUID of the subnet on which to allocate the virtual IP for the + // Loadbalancer address. + VipSubnetID string `json:"vip_subnet_id"` + + // The unique ID for the LoadBalancer. + ID string `json:"id"` + + // The operating status of the LoadBalancer. This value is ONLINE or OFFLINE. + OperatingStatus string `json:"operating_status"` + + // Human-readable name for the LoadBalancer. Does not have to be unique. + Name string `json:"name"` + + // The UUID of a flavor if set. + Flavor string `json:"flavor"` + + // The name of the provider. + Provider string `json:"provider"` + + // Listeners are the listeners related to this Loadbalancer. + Listeners []listeners.Listener `json:"listeners"` +} + +// StatusTree represents the status of a loadbalancer. +type StatusTree struct { + Loadbalancer *LoadBalancer `json:"loadbalancer"` +} + +// LoadBalancerPage is the page returned by a pager when traversing over a +// collection of load balancers. +type LoadBalancerPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of load balancers has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r LoadBalancerPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"loadbalancers_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a LoadBalancerPage struct is empty. +func (r LoadBalancerPage) IsEmpty() (bool, error) { + is, err := ExtractLoadBalancers(r) + return len(is) == 0, err +} + +// ExtractLoadBalancers accepts a Page struct, specifically a LoadbalancerPage +// struct, and extracts the elements into a slice of LoadBalancer structs. In +// other words, a generic collection is mapped into a relevant slice. +func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) { + var s struct { + LoadBalancers []LoadBalancer `json:"loadbalancers"` + } + err := (r.(LoadBalancerPage)).ExtractInto(&s) + return s.LoadBalancers, err +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a loadbalancer. +func (r commonResult) Extract() (*LoadBalancer, error) { + var s struct { + LoadBalancer *LoadBalancer `json:"loadbalancer"` + } + err := r.ExtractInto(&s) + return s.LoadBalancer, err +} + +// GetStatusesResult represents the result of a GetStatuses operation. +// Call its Extract method to interpret it as a StatusTree. +type GetStatusesResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts the status of +// a Loadbalancer. +func (r GetStatusesResult) Extract() (*StatusTree, error) { + var s struct { + Statuses *StatusTree `json:"statuses"` + } + err := r.ExtractInto(&s) + return s.Statuses, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a LoadBalancer. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a LoadBalancer. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a LoadBalancer. +type UpdateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/doc.go new file mode 100644 index 00000000..b54468c8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/doc.go @@ -0,0 +1,2 @@ +// loadbalancers unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go new file mode 100644 index 00000000..d042f073 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go @@ -0,0 +1,292 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" +) + +// LoadbalancersListBody contains the canned body of a loadbalancer list response. +const LoadbalancersListBody = ` +{ + "loadbalancers":[ + { + "id": "c331058c-6a40-4144-948e-b9fb1df9db4b", + "project_id": "54030507-44f7-473c-9342-b4d14a95f692", + "name": "web_lb", + "description": "lb config for the web tier", + "vip_subnet_id": "8a49c438-848f-467b-9655-ea1548708154", + "vip_address": "10.30.176.47", + "vip_port_id": "2a22e552-a347-44fd-b530-1f2b1b2a6735", + "flavor": "small", + "provider": "haproxy", + "admin_state_up": true, + "provisioning_status": "ACTIVE", + "operating_status": "ONLINE" + }, + { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "54030507-44f7-473c-9342-b4d14a95f692", + "name": "db_lb", + "description": "lb config for the db tier", + "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + "vip_address": "10.30.176.48", + "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", + "flavor": "medium", + "provider": "haproxy", + "admin_state_up": true, + "provisioning_status": "PENDING_CREATE", + "operating_status": "OFFLINE" + } + ] +} +` + +// SingleLoadbalancerBody is the canned body of a Get request on an existing loadbalancer. +const SingleLoadbalancerBody = ` +{ + "loadbalancer": { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "54030507-44f7-473c-9342-b4d14a95f692", + "name": "db_lb", + "description": "lb config for the db tier", + "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + "vip_address": "10.30.176.48", + "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", + "flavor": "medium", + "provider": "haproxy", + "admin_state_up": true, + "provisioning_status": "PENDING_CREATE", + "operating_status": "OFFLINE" + } +} +` + +// PostUpdateLoadbalancerBody is the canned response body of a Update request on an existing loadbalancer. +const PostUpdateLoadbalancerBody = ` +{ + "loadbalancer": { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "project_id": "54030507-44f7-473c-9342-b4d14a95f692", + "name": "NewLoadbalancerName", + "description": "lb config for the db tier", + "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + "vip_address": "10.30.176.48", + "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", + "flavor": "medium", + "provider": "haproxy", + "admin_state_up": true, + "provisioning_status": "PENDING_CREATE", + "operating_status": "OFFLINE" + } +} +` + +// SingleLoadbalancerBody is the canned body of a Get request on an existing loadbalancer. +const LoadbalancerStatuesesTree = ` +{ + "statuses" : { + "loadbalancer": { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "name": "db_lb", + "provisioning_status": "PENDING_UPDATE", + "operating_status": "ACTIVE", + "listeners": [{ + "id": "db902c0c-d5ff-4753-b465-668ad9656918", + "name": "db", + "provisioning_status": "ACTIVE", + "pools": [{ + "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", + "name": "db", + "provisioning_status": "ACTIVE", + "healthmonitor": { + "id": "67306cda-815d-4354-9fe4-59e09da9c3c5", + "type":"PING", + "provisioning_status": "ACTIVE" + }, + "members":[{ + "id": "2a280670-c202-4b0b-a562-34077415aabf", + "name": "db", + "address": "10.0.2.11", + "protocol_port": 80, + "provisioning_status": "ACTIVE" + }] + }] + }] + } + } +} +` + +var ( + LoadbalancerWeb = loadbalancers.LoadBalancer{ + ID: "c331058c-6a40-4144-948e-b9fb1df9db4b", + ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", + Name: "web_lb", + Description: "lb config for the web tier", + VipSubnetID: "8a49c438-848f-467b-9655-ea1548708154", + VipAddress: "10.30.176.47", + VipPortID: "2a22e552-a347-44fd-b530-1f2b1b2a6735", + Flavor: "small", + Provider: "haproxy", + AdminStateUp: true, + ProvisioningStatus: "ACTIVE", + OperatingStatus: "ONLINE", + } + LoadbalancerDb = loadbalancers.LoadBalancer{ + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", + Name: "db_lb", + Description: "lb config for the db tier", + VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + VipAddress: "10.30.176.48", + VipPortID: "2bf413c8-41a9-4477-b505-333d5cbe8b55", + Flavor: "medium", + Provider: "haproxy", + AdminStateUp: true, + ProvisioningStatus: "PENDING_CREATE", + OperatingStatus: "OFFLINE", + } + LoadbalancerUpdated = loadbalancers.LoadBalancer{ + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", + Name: "NewLoadbalancerName", + Description: "lb config for the db tier", + VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + VipAddress: "10.30.176.48", + VipPortID: "2bf413c8-41a9-4477-b505-333d5cbe8b55", + Flavor: "medium", + Provider: "haproxy", + AdminStateUp: true, + ProvisioningStatus: "PENDING_CREATE", + OperatingStatus: "OFFLINE", + } + LoadbalancerStatusesTree = loadbalancers.LoadBalancer{ + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + Name: "db_lb", + ProvisioningStatus: "PENDING_UPDATE", + OperatingStatus: "ACTIVE", + Listeners: []listeners.Listener{{ + ID: "db902c0c-d5ff-4753-b465-668ad9656918", + Name: "db", + ProvisioningStatus: "ACTIVE", + Pools: []pools.Pool{{ + ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", + Name: "db", + ProvisioningStatus: "ACTIVE", + Monitor: monitors.Monitor{ + ID: "67306cda-815d-4354-9fe4-59e09da9c3c5", + Type: "PING", + ProvisioningStatus: "ACTIVE", + }, + Members: []pools.Member{{ + ID: "2a280670-c202-4b0b-a562-34077415aabf", + Name: "db", + Address: "10.0.2.11", + ProtocolPort: 80, + ProvisioningStatus: "ACTIVE", + }}, + }}, + }}, + } +) + +// HandleLoadbalancerListSuccessfully sets up the test server to respond to a loadbalancer List request. +func HandleLoadbalancerListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, LoadbalancersListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "loadbalancers": [] }`) + default: + t.Fatalf("/v2.0/lbaas/loadbalancers invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleLoadbalancerCreationSuccessfully sets up the test server to respond to a loadbalancer creation request +// with a given response. +func HandleLoadbalancerCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "loadbalancer": { + "name": "db_lb", + "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + "vip_address": "10.30.176.48", + "flavor": "medium", + "provider": "haproxy", + "admin_state_up": true + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// HandleLoadbalancerGetSuccessfully sets up the test server to respond to a loadbalancer Get request. +func HandleLoadbalancerGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleLoadbalancerBody) + }) +} + +// HandleLoadbalancerGetStatusesTree sets up the test server to respond to a loadbalancer Get statuses tree request. +func HandleLoadbalancerGetStatusesTree(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/statuses", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, LoadbalancerStatuesesTree) + }) +} + +// HandleLoadbalancerDeletionSuccessfully sets up the test server to respond to a loadbalancer deletion request. +func HandleLoadbalancerDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleLoadbalancerUpdateSuccessfully sets up the test server to respond to a loadbalancer Update request. +func HandleLoadbalancerUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "loadbalancer": { + "name": "NewLoadbalancerName" + } + }`) + + fmt.Fprintf(w, PostUpdateLoadbalancerBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/requests_test.go new file mode 100644 index 00000000..51374e04 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/testing/requests_test.go @@ -0,0 +1,162 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" + fake "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListLoadbalancers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerListSuccessfully(t) + + pages := 0 + err := loadbalancers.List(fake.ServiceClient(), loadbalancers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := loadbalancers.ExtractLoadBalancers(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 loadbalancers, got %d", len(actual)) + } + th.CheckDeepEquals(t, LoadbalancerWeb, actual[0]) + th.CheckDeepEquals(t, LoadbalancerDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllLoadbalancers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerListSuccessfully(t) + + allPages, err := loadbalancers.List(fake.ServiceClient(), loadbalancers.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := loadbalancers.ExtractLoadBalancers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, LoadbalancerWeb, actual[0]) + th.CheckDeepEquals(t, LoadbalancerDb, actual[1]) +} + +func TestCreateLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerCreationSuccessfully(t, SingleLoadbalancerBody) + + actual, err := loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{ + Name: "db_lb", + AdminStateUp: gophercloud.Enabled, + VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + VipAddress: "10.30.176.48", + Flavor: "medium", + Provider: "haproxy", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, LoadbalancerDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo", Description: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo", Description: "bar", VipAddress: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.Get(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerDb, *actual) +} + +func TestGetLoadbalancerStatusesTree(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerGetStatusesTree(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.GetStatuses(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerStatusesTree, *(actual.Loadbalancer)) +} + +func TestDeleteLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerDeletionSuccessfully(t) + + res := loadbalancers.Delete(fake.ServiceClient(), "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", nil) + th.AssertNoErr(t, res.Err) +} + +func TestUpdateLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.Update(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", loadbalancers.UpdateOpts{ + Name: "NewLoadbalancerName", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerUpdated, *actual) +} + +func TestCascadingDeleteLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerDeletionSuccessfully(t) + + sc := fake.ServiceClient() + deleteOpts := loadbalancers.DeleteOpts{ + Cascade: true, + } + + query, err := deleteOpts.ToLoadBalancerDeleteQuery() + th.AssertNoErr(t, err) + th.AssertEquals(t, query, "?cascade=true") + + err = loadbalancers.Delete(sc, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", deleteOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/urls.go new file mode 100644 index 00000000..73cf5dc1 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers/urls.go @@ -0,0 +1,21 @@ +package loadbalancers + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "lbaas" + resourcePath = "loadbalancers" + statusPath = "statuses" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} + +func statusRootURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id, statusPath) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/doc.go new file mode 100644 index 00000000..6ed8c8fb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/doc.go @@ -0,0 +1,69 @@ +/* +Package monitors provides information and interaction with Monitors +of the LBaaS v2 extension for the OpenStack Networking service. + +Example to List Monitors + + listOpts := monitors.ListOpts{ + PoolID: "c79a4468-d788-410c-bf79-9a8ef6354852", + } + + allPages, err := monitors.List(networkClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allMonitors, err := monitors.ExtractMonitors(allPages) + if err != nil { + panic(err) + } + + for _, monitor := range allMonitors { + fmt.Printf("%+v\n", monitor) + } + +Example to Create a Monitor + + createOpts := monitors.CreateOpts{ + Type: "HTTP", + Name: "db", + PoolID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d", + Delay: 20, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + } + + monitor, err := monitors.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Monitor + + monitorID := "d67d56a6-4a86-4688-a282-f46444705c64" + + updateOpts := monitors.UpdateOpts{ + Name: "NewHealthmonitorName", + Delay: 3, + Timeout: 20, + MaxRetries: 10, + URLPath: "/another_check", + ExpectedCodes: "301", + } + + monitor, err := monitors.Update(networkClient, monitorID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Monitor + + monitorID := "d67d56a6-4a86-4688-a282-f46444705c64" + err := monitors.Delete(networkClient, monitorID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package monitors diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/requests.go new file mode 100644 index 00000000..c173e1c6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/requests.go @@ -0,0 +1,257 @@ +package monitors + +import ( + "fmt" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToMonitorListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the Monitor attributes you want to see returned. SortKey allows you to +// sort by a particular Monitor attribute. SortDir sets the direction, and is +// either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + ID string `q:"id"` + Name string `q:"name"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + PoolID string `q:"pool_id"` + Type string `q:"type"` + Delay int `q:"delay"` + Timeout int `q:"timeout"` + MaxRetries int `q:"max_retries"` + HTTPMethod string `q:"http_method"` + URLPath string `q:"url_path"` + ExpectedCodes string `q:"expected_codes"` + AdminStateUp *bool `q:"admin_state_up"` + Status string `q:"status"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToMonitorListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToMonitorListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), nil +} + +// List returns a Pager which allows you to iterate over a collection of +// health monitors. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those health monitors that are owned by the +// tenant who submits the request, unless an admin user submits the request. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToMonitorListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return MonitorPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Constants that represent approved monitoring types. +const ( + TypePING = "PING" + TypeTCP = "TCP" + TypeHTTP = "HTTP" + TypeHTTPS = "HTTPS" +) + +var ( + errDelayMustGETimeout = fmt.Errorf("Delay must be greater than or equal to timeout") +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// List request. +type CreateOptsBuilder interface { + ToMonitorCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + // The Pool to Monitor. + PoolID string `json:"pool_id" required:"true"` + + // The type of probe, which is PING, TCP, HTTP, or HTTPS, that is + // sent by the load balancer to verify the member state. + Type string `json:"type" required:"true"` + + // The time, in seconds, between sending probes to members. + Delay int `json:"delay" required:"true"` + + // Maximum number of seconds for a Monitor to wait for a ping reply + // before it times out. The value must be less than the delay value. + Timeout int `json:"timeout" required:"true"` + + // Number of permissible ping failures before changing the member's + // status to INACTIVE. Must be a number between 1 and 10. + MaxRetries int `json:"max_retries" required:"true"` + + // URI path that will be accessed if Monitor type is HTTP or HTTPS. + // Required for HTTP(S) types. + URLPath string `json:"url_path,omitempty"` + + // The HTTP method used for requests by the Monitor. If this attribute + // is not specified, it defaults to "GET". Required for HTTP(S) types. + HTTPMethod string `json:"http_method,omitempty"` + + // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify + // a single status like "200", or a range like "200-202". Required for HTTP(S) + // types. + ExpectedCodes string `json:"expected_codes,omitempty"` + + // TenantID is the UUID of the project who owns the Monitor. + // Only administrative users can specify a project UUID other than their own. + TenantID string `json:"tenant_id,omitempty"` + + // ProjectID is the UUID of the project who owns the Monitor. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // The Name of the Monitor. + Name string `json:"name,omitempty"` + + // The administrative state of the Monitor. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMonitorCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToMonitorCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "healthmonitor") + if err != nil { + return nil, err + } + + switch opts.Type { + case TypeHTTP, TypeHTTPS: + switch opts.URLPath { + case "": + return nil, fmt.Errorf("URLPath must be provided for HTTP and HTTPS") + } + switch opts.ExpectedCodes { + case "": + return nil, fmt.Errorf("ExpectedCodes must be provided for HTTP and HTTPS") + } + } + + return b, nil +} + +/* + Create is an operation which provisions a new Health Monitor. There are + different types of Monitor you can provision: PING, TCP or HTTP(S). Below + are examples of how to create each one. + + Here is an example config struct to use when creating a PING or TCP Monitor: + + CreateOpts{Type: TypePING, Delay: 20, Timeout: 10, MaxRetries: 3} + CreateOpts{Type: TypeTCP, Delay: 20, Timeout: 10, MaxRetries: 3} + + Here is an example config struct to use when creating a HTTP(S) Monitor: + + CreateOpts{Type: TypeHTTP, Delay: 20, Timeout: 10, MaxRetries: 3, + HttpMethod: "HEAD", ExpectedCodes: "200", PoolID: "2c946bfc-1804-43ab-a2ff-58f6a762b505"} +*/ +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToMonitorCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular Health Monitor based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToMonitorUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options struct used in this package's Update +// operation. +type UpdateOpts struct { + // The time, in seconds, between sending probes to members. + Delay int `json:"delay,omitempty"` + + // Maximum number of seconds for a Monitor to wait for a ping reply + // before it times out. The value must be less than the delay value. + Timeout int `json:"timeout,omitempty"` + + // Number of permissible ping failures before changing the member's + // status to INACTIVE. Must be a number between 1 and 10. + MaxRetries int `json:"max_retries,omitempty"` + + // URI path that will be accessed if Monitor type is HTTP or HTTPS. + // Required for HTTP(S) types. + URLPath string `json:"url_path,omitempty"` + + // The HTTP method used for requests by the Monitor. If this attribute + // is not specified, it defaults to "GET". Required for HTTP(S) types. + HTTPMethod string `json:"http_method,omitempty"` + + // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify + // a single status like "200", or a range like "200-202". Required for HTTP(S) + // types. + ExpectedCodes string `json:"expected_codes,omitempty"` + + // The Name of the Monitor. + Name string `json:"name,omitempty"` + + // The administrative state of the Monitor. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMonitorUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToMonitorUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "healthmonitor") +} + +// Update is an operation which modifies the attributes of the specified +// Monitor. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToMonitorUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} + +// Delete will permanently delete a particular Monitor based on its unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/results.go new file mode 100644 index 00000000..ccf7d985 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/results.go @@ -0,0 +1,153 @@ +package monitors + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type PoolID struct { + ID string `json:"id"` +} + +// Monitor represents a load balancer health monitor. A health monitor is used +// to determine whether or not back-end members of the VIP's pool are usable +// for processing a request. A pool can have several health monitors associated +// with it. There are different types of health monitors supported: +// +// PING: used to ping the members using ICMP. +// TCP: used to connect to the members using TCP. +// HTTP: used to send an HTTP request to the member. +// HTTPS: used to send a secure HTTP request to the member. +// +// When a pool has several monitors associated with it, each member of the pool +// is monitored by all these monitors. If any monitor declares the member as +// unhealthy, then the member status is changed to INACTIVE and the member +// won't participate in its pool's load balancing. In other words, ALL monitors +// must declare the member to be healthy for it to stay ACTIVE. +type Monitor struct { + // The unique ID for the Monitor. + ID string `json:"id"` + + // The Name of the Monitor. + Name string `json:"name"` + + // The owner of the Monitor. + ProjectID string `json:"project_id"` + + // The type of probe sent by the load balancer to verify the member state, + // which is PING, TCP, HTTP, or HTTPS. + Type string `json:"type"` + + // The time, in seconds, between sending probes to members. + Delay int `json:"delay"` + + // The maximum number of seconds for a monitor to wait for a connection to be + // established before it times out. This value must be less than the delay + // value. + Timeout int `json:"timeout"` + + // Number of allowed connection failures before changing the status of the + // member to INACTIVE. A valid value is from 1 to 10. + MaxRetries int `json:"max_retries"` + + // The HTTP method that the monitor uses for requests. + HTTPMethod string `json:"http_method"` + + // The HTTP path of the request sent by the monitor to test the health of a + // member. Must be a string beginning with a forward slash (/). + URLPath string `json:"url_path" ` + + // Expected HTTP codes for a passing HTTP(S) monitor. + ExpectedCodes string `json:"expected_codes"` + + // The administrative state of the health monitor, which is up (true) or + // down (false). + AdminStateUp bool `json:"admin_state_up"` + + // The status of the health monitor. Indicates whether the health monitor is + // operational. + Status string `json:"status"` + + // List of pools that are associated with the health monitor. + Pools []PoolID `json:"pools"` + + // The provisioning status of the Monitor. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` +} + +// MonitorPage is the page returned by a pager when traversing over a +// collection of health monitors. +type MonitorPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of monitors has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r MonitorPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"healthmonitors_links"` + } + + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a MonitorPage struct is empty. +func (r MonitorPage) IsEmpty() (bool, error) { + is, err := ExtractMonitors(r) + return len(is) == 0, err +} + +// ExtractMonitors accepts a Page struct, specifically a MonitorPage struct, +// and extracts the elements into a slice of Monitor structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractMonitors(r pagination.Page) ([]Monitor, error) { + var s struct { + Monitors []Monitor `json:"healthmonitors"` + } + err := (r.(MonitorPage)).ExtractInto(&s) + return s.Monitors, err +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a monitor. +func (r commonResult) Extract() (*Monitor, error) { + var s struct { + Monitor *Monitor `json:"healthmonitor"` + } + err := r.ExtractInto(&s) + return s.Monitor, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a Monitor. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a Monitor. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a Monitor. +type UpdateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the result succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/doc.go new file mode 100644 index 00000000..e2b6f12a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/doc.go @@ -0,0 +1,2 @@ +// monitors unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/fixtures.go new file mode 100644 index 00000000..23c097b9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/fixtures.go @@ -0,0 +1,215 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// HealthmonitorsListBody contains the canned body of a healthmonitor list response. +const HealthmonitorsListBody = ` +{ + "healthmonitors":[ + { + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":10, + "name":"web", + "max_retries":1, + "timeout":1, + "type":"PING", + "pools": [{"id": "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d"}], + "id":"466c8345-28d8-4f84-a246-e04380b0461d" + }, + { + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":5, + "name":"db", + "expected_codes":"200", + "max_retries":2, + "http_method":"GET", + "timeout":2, + "url_path":"/", + "type":"HTTP", + "pools": [{"id": "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}], + "id":"5d4b5228-33b0-4e60-b225-9b727c1a20e7" + } + ] +} +` + +// SingleHealthmonitorBody is the canned body of a Get request on an existing healthmonitor. +const SingleHealthmonitorBody = ` +{ + "healthmonitor": { + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":5, + "name":"db", + "expected_codes":"200", + "max_retries":2, + "http_method":"GET", + "timeout":2, + "url_path":"/", + "type":"HTTP", + "pools": [{"id": "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}], + "id":"5d4b5228-33b0-4e60-b225-9b727c1a20e7" + } +} +` + +// PostUpdateHealthmonitorBody is the canned response body of a Update request on an existing healthmonitor. +const PostUpdateHealthmonitorBody = ` +{ + "healthmonitor": { + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":3, + "name":"NewHealthmonitorName", + "expected_codes":"301", + "max_retries":10, + "http_method":"GET", + "timeout":20, + "url_path":"/another_check", + "type":"HTTP", + "pools": [{"id": "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}], + "id":"5d4b5228-33b0-4e60-b225-9b727c1a20e7" + } +} +` + +var ( + HealthmonitorWeb = monitors.Monitor{ + AdminStateUp: true, + Name: "web", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + Delay: 10, + MaxRetries: 1, + Timeout: 1, + Type: "PING", + ID: "466c8345-28d8-4f84-a246-e04380b0461d", + Pools: []monitors.PoolID{{ID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d"}}, + } + HealthmonitorDb = monitors.Monitor{ + AdminStateUp: true, + Name: "db", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + Delay: 5, + ExpectedCodes: "200", + MaxRetries: 2, + Timeout: 2, + URLPath: "/", + Type: "HTTP", + HTTPMethod: "GET", + ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7", + Pools: []monitors.PoolID{{ID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}}, + } + HealthmonitorUpdated = monitors.Monitor{ + AdminStateUp: true, + Name: "NewHealthmonitorName", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + Delay: 3, + ExpectedCodes: "301", + MaxRetries: 10, + Timeout: 20, + URLPath: "/another_check", + Type: "HTTP", + HTTPMethod: "GET", + ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7", + Pools: []monitors.PoolID{{ID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}}, + } +) + +// HandleHealthmonitorListSuccessfully sets up the test server to respond to a healthmonitor List request. +func HandleHealthmonitorListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, HealthmonitorsListBody) + case "556c8345-28d8-4f84-a246-e04380b0461d": + fmt.Fprintf(w, `{ "healthmonitors": [] }`) + default: + t.Fatalf("/v2.0/lbaas/healthmonitors invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleHealthmonitorCreationSuccessfully sets up the test server to respond to a healthmonitor creation request +// with a given response. +func HandleHealthmonitorCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "healthmonitor": { + "type":"HTTP", + "pool_id":"84f1b61f-58c4-45bf-a8a9-2dafb9e5214d", + "project_id":"453105b9-1754-413f-aab1-55f1af620750", + "delay":20, + "name":"db", + "timeout":10, + "max_retries":5, + "url_path":"/check", + "expected_codes":"200-299" + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// HandleHealthmonitorGetSuccessfully sets up the test server to respond to a healthmonitor Get request. +func HandleHealthmonitorGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleHealthmonitorBody) + }) +} + +// HandleHealthmonitorDeletionSuccessfully sets up the test server to respond to a healthmonitor deletion request. +func HandleHealthmonitorDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleHealthmonitorUpdateSuccessfully sets up the test server to respond to a healthmonitor Update request. +func HandleHealthmonitorUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "healthmonitor": { + "name": "NewHealthmonitorName", + "delay": 3, + "timeout": 20, + "max_retries": 10, + "url_path": "/another_check", + "expected_codes": "301" + } + }`) + + fmt.Fprintf(w, PostUpdateHealthmonitorBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/requests_test.go new file mode 100644 index 00000000..d850fe19 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/testing/requests_test.go @@ -0,0 +1,154 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + fake "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListHealthmonitors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorListSuccessfully(t) + + pages := 0 + err := monitors.List(fake.ServiceClient(), monitors.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := monitors.ExtractMonitors(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 healthmonitors, got %d", len(actual)) + } + th.CheckDeepEquals(t, HealthmonitorWeb, actual[0]) + th.CheckDeepEquals(t, HealthmonitorDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllHealthmonitors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorListSuccessfully(t) + + allPages, err := monitors.List(fake.ServiceClient(), monitors.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := monitors.ExtractMonitors(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, HealthmonitorWeb, actual[0]) + th.CheckDeepEquals(t, HealthmonitorDb, actual[1]) +} + +func TestCreateHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorCreationSuccessfully(t, SingleHealthmonitorBody) + + actual, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + Name: "db", + PoolID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d", + ProjectID: "453105b9-1754-413f-aab1-55f1af620750", + Delay: 20, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, HealthmonitorDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = monitors.Create(fake.ServiceClient(), monitors.CreateOpts{Type: monitors.TypeHTTP}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := monitors.Get(client, "5d4b5228-33b0-4e60-b225-9b727c1a20e7").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, HealthmonitorDb, *actual) +} + +func TestDeleteHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorDeletionSuccessfully(t) + + res := monitors.Delete(fake.ServiceClient(), "5d4b5228-33b0-4e60-b225-9b727c1a20e7") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := monitors.Update(client, "5d4b5228-33b0-4e60-b225-9b727c1a20e7", monitors.UpdateOpts{ + Name: "NewHealthmonitorName", + Delay: 3, + Timeout: 20, + MaxRetries: 10, + URLPath: "/another_check", + ExpectedCodes: "301", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, HealthmonitorUpdated, *actual) +} + +func TestDelayMustBeGreaterOrEqualThanTimeout(t *testing.T) { + _, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + PoolID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d", + Delay: 1, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } + + _, err = monitors.Update(fake.ServiceClient(), "453105b9-1754-413f-aab1-55f1af620750", monitors.UpdateOpts{ + Delay: 1, + Timeout: 10, + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/urls.go new file mode 100644 index 00000000..a222e52a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors/urls.go @@ -0,0 +1,16 @@ +package monitors + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "lbaas" + resourcePath = "healthmonitors" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/doc.go new file mode 100644 index 00000000..2d57ed43 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/doc.go @@ -0,0 +1,124 @@ +/* +Package pools provides information and interaction with Pools and +Members of the LBaaS v2 extension for the OpenStack Networking service. + +Example to List Pools + + listOpts := pools.ListOpts{ + LoadbalancerID: "c79a4468-d788-410c-bf79-9a8ef6354852", + } + + allPages, err := pools.List(networkClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allPools, err := pools.ExtractMonitors(allPages) + if err != nil { + panic(err) + } + + for _, pools := range allPools { + fmt.Printf("%+v\n", pool) + } + +Example to Create a Pool + + createOpts := pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: "HTTP", + Name: "Example pool", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + } + + pool, err := pools.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Pool + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + + updateOpts := pools.UpdateOpts{ + Name: "new-name", + } + + pool, err := pools.Update(networkClient, poolID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Pool + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + err := pools.Delete(networkClient, poolID).ExtractErr() + if err != nil { + panic(err) + } + +Example to List Pool Members + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + + listOpts := pools.ListMemberOpts{ + ProtocolPort: 80, + } + + allPages, err := pools.ListMembers(networkClient, poolID, listOpts).AllPages() + if err != nil { + panic(err) + } + + allMembers, err := pools.ExtractMembers(allPages) + if err != nil { + panic(err) + } + + for _, member := allMembers { + fmt.Printf("%+v\n", member) + } + +Example to Create a Member + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + + createOpts := pools.CreateMemberOpts{ + Name: "db", + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + Address: "10.0.2.11", + ProtocolPort: 80, + Weight: 10, + } + + member, err := pools.CreateMember(networkClient, poolID, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Member + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + memberID := "64dba99f-8af8-4200-8882-e32a0660f23e" + + updateOpts := pools.UpdateMemberOpts{ + Name: "new-name", + Weight: 4, + } + + member, err := pools.UpdateMember(networkClient, poolID, memberID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Member + + poolID := "d67d56a6-4a86-4688-a282-f46444705c64" + memberID := "64dba99f-8af8-4200-8882-e32a0660f23e" + + err := pools.DeleteMember(networkClient, poolID, memberID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package pools diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/requests.go new file mode 100644 index 00000000..538b2f1b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/requests.go @@ -0,0 +1,346 @@ +package pools + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToPoolListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the Pool attributes you want to see returned. SortKey allows you to +// sort by a particular Pool attribute. SortDir sets the direction, and is +// either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + LBMethod string `q:"lb_algorithm"` + Protocol string `q:"protocol"` + ProjectID string `q:"project_id"` + AdminStateUp *bool `q:"admin_state_up"` + Name string `q:"name"` + ID string `q:"id"` + LoadbalancerID string `q:"loadbalancer_id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToPoolListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPoolListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// pools. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those pools that are owned by the +// project who submits the request, unless an admin user submits the request. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToPoolListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return PoolPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +type LBMethod string +type Protocol string + +// Supported attributes for create/update operations. +const ( + LBMethodRoundRobin LBMethod = "ROUND_ROBIN" + LBMethodLeastConnections LBMethod = "LEAST_CONNECTIONS" + LBMethodSourceIp LBMethod = "SOURCE_IP" + + ProtocolTCP Protocol = "TCP" + ProtocolHTTP Protocol = "HTTP" + ProtocolHTTPS Protocol = "HTTPS" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToPoolCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + // The algorithm used to distribute load between the members of the pool. The + // current specification supports LBMethodRoundRobin, LBMethodLeastConnections + // and LBMethodSourceIp as valid values for this attribute. + LBMethod LBMethod `json:"lb_algorithm" required:"true"` + + // The protocol used by the pool members, you can use either + // ProtocolTCP, ProtocolHTTP, or ProtocolHTTPS. + Protocol Protocol `json:"protocol" required:"true"` + + // The Loadbalancer on which the members of the pool will be associated with. + // Note: one of LoadbalancerID or ListenerID must be provided. + LoadbalancerID string `json:"loadbalancer_id,omitempty" xor:"ListenerID"` + + // The Listener on which the members of the pool will be associated with. + // Note: one of LoadbalancerID or ListenerID must be provided. + ListenerID string `json:"listener_id,omitempty" xor:"LoadbalancerID"` + + // ProjectID is the UUID of the project who owns the Pool. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // Name of the pool. + Name string `json:"name,omitempty"` + + // Human-readable description for the pool. + Description string `json:"description,omitempty"` + + // Persistence is the session persistence of the pool. + // Omit this field to prevent session persistence. + Persistence *SessionPersistence `json:"session_persistence,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToPoolCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToPoolCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "pool") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// load balancer pool. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPoolCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular pool based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToPoolUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options struct used in this package's Update +// operation. +type UpdateOpts struct { + // Name of the pool. + Name string `json:"name,omitempty"` + + // Human-readable description for the pool. + Description string `json:"description,omitempty"` + + // The algorithm used to distribute load between the members of the pool. The + // current specification supports LBMethodRoundRobin, LBMethodLeastConnections + // and LBMethodSourceIp as valid values for this attribute. + LBMethod LBMethod `json:"lb_algorithm,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToPoolUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToPoolUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "pool") +} + +// Update allows pools to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPoolUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Delete will permanently delete a particular pool based on its unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// ListMemberOptsBuilder allows extensions to add additional parameters to the +// ListMembers request. +type ListMembersOptsBuilder interface { + ToMembersListQuery() (string, error) +} + +// ListMembersOpts allows the filtering and sorting of paginated collections +// through the API. Filtering is achieved by passing in struct field values +// that map to the Member attributes you want to see returned. SortKey allows +// you to sort by a particular Member attribute. SortDir sets the direction, +// and is either `asc' or `desc'. Marker and Limit are used for pagination. +type ListMembersOpts struct { + Name string `q:"name"` + Weight int `q:"weight"` + AdminStateUp *bool `q:"admin_state_up"` + ProjectID string `q:"project_id"` + Address string `q:"address"` + ProtocolPort int `q:"protocol_port"` + ID string `q:"id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToMemberListQuery formats a ListOpts into a query string. +func (opts ListMembersOpts) ToMembersListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListMembers returns a Pager which allows you to iterate over a collection of +// members. It accepts a ListMembersOptsBuilder, which allows you to filter and +// sort the returned collection for greater efficiency. +// +// Default policy settings return only those members that are owned by the +// project who submits the request, unless an admin user submits the request. +func ListMembers(c *gophercloud.ServiceClient, poolID string, opts ListMembersOptsBuilder) pagination.Pager { + url := memberRootURL(c, poolID) + if opts != nil { + query, err := opts.ToMembersListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return MemberPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// CreateMemberOptsBuilder allows extensions to add additional parameters to the +// CreateMember request. +type CreateMemberOptsBuilder interface { + ToMemberCreateMap() (map[string]interface{}, error) +} + +// CreateMemberOpts is the common options struct used in this package's CreateMember +// operation. +type CreateMemberOpts struct { + // The IP address of the member to receive traffic from the load balancer. + Address string `json:"address" required:"true"` + + // The port on which to listen for client traffic. + ProtocolPort int `json:"protocol_port" required:"true"` + + // Name of the Member. + Name string `json:"name,omitempty"` + + // ProjectID is the UUID of the project who owns the Member. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // A positive integer value that indicates the relative portion of traffic + // that this member should receive from the pool. For example, a member with + // a weight of 10 receives five times as much traffic as a member with a + // weight of 2. + Weight int `json:"weight,omitempty"` + + // If you omit this parameter, LBaaS uses the vip_subnet_id parameter value + // for the subnet UUID. + SubnetID string `json:"subnet_id,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMemberCreateMap builds a request body from CreateMemberOpts. +func (opts CreateMemberOpts) ToMemberCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "member") +} + +// CreateMember will create and associate a Member with a particular Pool. +func CreateMember(c *gophercloud.ServiceClient, poolID string, opts CreateMemberOpts) (r CreateMemberResult) { + b, err := opts.ToMemberCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(memberRootURL(c, poolID), b, &r.Body, nil) + return +} + +// GetMember retrieves a particular Pool Member based on its unique ID. +func GetMember(c *gophercloud.ServiceClient, poolID string, memberID string) (r GetMemberResult) { + _, r.Err = c.Get(memberResourceURL(c, poolID, memberID), &r.Body, nil) + return +} + +// UpdateMemberOptsBuilder allows extensions to add additional parameters to the +// List request. +type UpdateMemberOptsBuilder interface { + ToMemberUpdateMap() (map[string]interface{}, error) +} + +// UpdateMemberOpts is the common options struct used in this package's Update +// operation. +type UpdateMemberOpts struct { + // Name of the Member. + Name string `json:"name,omitempty"` + + // A positive integer value that indicates the relative portion of traffic + // that this member should receive from the pool. For example, a member with + // a weight of 10 receives five times as much traffic as a member with a + // weight of 2. + Weight int `json:"weight,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMemberUpdateMap builds a request body from UpdateMemberOpts. +func (opts UpdateMemberOpts) ToMemberUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "member") +} + +// Update allows Member to be updated. +func UpdateMember(c *gophercloud.ServiceClient, poolID string, memberID string, opts UpdateMemberOptsBuilder) (r UpdateMemberResult) { + b, err := opts.ToMemberUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(memberResourceURL(c, poolID, memberID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + return +} + +// DisassociateMember will remove and disassociate a Member from a particular +// Pool. +func DeleteMember(c *gophercloud.ServiceClient, poolID string, memberID string) (r DeleteMemberResult) { + _, r.Err = c.Delete(memberResourceURL(c, poolID, memberID), nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/results.go new file mode 100644 index 00000000..fe0d9332 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/results.go @@ -0,0 +1,281 @@ +package pools + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/pagination" +) + +// SessionPersistence represents the session persistence feature of the load +// balancing service. It attempts to force connections or requests in the same +// session to be processed by the same member as long as it is ative. Three +// types of persistence are supported: +// +// SOURCE_IP: With this mode, all connections originating from the same source +// IP address, will be handled by the same Member of the Pool. +// HTTP_COOKIE: With this persistence mode, the load balancing function will +// create a cookie on the first request from a client. Subsequent +// requests containing the same cookie value will be handled by +// the same Member of the Pool. +// APP_COOKIE: With this persistence mode, the load balancing function will +// rely on a cookie established by the backend application. All +// requests carrying the same cookie value will be handled by the +// same Member of the Pool. +type SessionPersistence struct { + // The type of persistence mode. + Type string `json:"type"` + + // Name of cookie if persistence mode is set appropriately. + CookieName string `json:"cookie_name,omitempty"` +} + +// LoadBalancerID represents a load balancer. +type LoadBalancerID struct { + ID string `json:"id"` +} + +// ListenerID represents a listener. +type ListenerID struct { + ID string `json:"id"` +} + +// Pool represents a logical set of devices, such as web servers, that you +// group together to receive and process traffic. The load balancing function +// chooses a Member of the Pool according to the configured load balancing +// method to handle the new requests or connections received on the VIP address. +type Pool struct { + // The load-balancer algorithm, which is round-robin, least-connections, and + // so on. This value, which must be supported, is dependent on the provider. + // Round-robin must be supported. + LBMethod string `json:"lb_algorithm"` + + // The protocol of the Pool, which is TCP, HTTP, or HTTPS. + Protocol string `json:"protocol"` + + // Description for the Pool. + Description string `json:"description"` + + // A list of listeners objects IDs. + Listeners []ListenerID `json:"listeners"` //[]map[string]interface{} + + // A list of member objects IDs. + Members []Member `json:"members"` + + // The ID of associated health monitor. + MonitorID string `json:"healthmonitor_id"` + + // The network on which the members of the Pool will be located. Only members + // that are on this network can be added to the Pool. + SubnetID string `json:"subnet_id"` + + // Owner of the Pool. + ProjectID string `json:"project_id"` + + // The administrative state of the Pool, which is up (true) or down (false). + AdminStateUp bool `json:"admin_state_up"` + + // Pool name. Does not have to be unique. + Name string `json:"name"` + + // The unique ID for the Pool. + ID string `json:"id"` + + // A list of load balancer objects IDs. + Loadbalancers []LoadBalancerID `json:"loadbalancers"` + + // Indicates whether connections in the same session will be processed by the + // same Pool member or not. + Persistence SessionPersistence `json:"session_persistence"` + + // The load balancer provider. + Provider string `json:"provider"` + + // The Monitor associated with this Pool. + Monitor monitors.Monitor `json:"healthmonitor"` + + // The provisioning status of the pool. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` +} + +// PoolPage is the page returned by a pager when traversing over a +// collection of pools. +type PoolPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of pools has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r PoolPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"pools_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a PoolPage struct is empty. +func (r PoolPage) IsEmpty() (bool, error) { + is, err := ExtractPools(r) + return len(is) == 0, err +} + +// ExtractPools accepts a Page struct, specifically a PoolPage struct, +// and extracts the elements into a slice of Pool structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractPools(r pagination.Page) ([]Pool, error) { + var s struct { + Pools []Pool `json:"pools"` + } + err := (r.(PoolPage)).ExtractInto(&s) + return s.Pools, err +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts a pool. +func (r commonResult) Extract() (*Pool, error) { + var s struct { + Pool *Pool `json:"pool"` + } + err := r.ExtractInto(&s) + return s.Pool, err +} + +// CreateResult represents the result of a Create operation. Call its Extract +// method to interpret the result as a Pool. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a Get operation. Call its Extract +// method to interpret the result as a Pool. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an Update operation. Call its Extract +// method to interpret the result as a Pool. +type UpdateResult struct { + commonResult +} + +// DeleteResult represents the result of a Delete operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// Member represents the application running on a backend server. +type Member struct { + // Name of the Member. + Name string `json:"name"` + + // Weight of Member. + Weight int `json:"weight"` + + // The administrative state of the member, which is up (true) or down (false). + AdminStateUp bool `json:"admin_state_up"` + + // Owner of the Member. + ProjectID string `json:"project_id"` + + // Parameter value for the subnet UUID. + SubnetID string `json:"subnet_id"` + + // The Pool to which the Member belongs. + PoolID string `json:"pool_id"` + + // The IP address of the Member. + Address string `json:"address"` + + // The port on which the application is hosted. + ProtocolPort int `json:"protocol_port"` + + // The unique ID for the Member. + ID string `json:"id"` + + // The provisioning status of the pool. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` +} + +// MemberPage is the page returned by a pager when traversing over a +// collection of Members in a Pool. +type MemberPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of members has reached +// the end of a page and the pager seeks to traverse over a new one. In order +// to do this, it needs to construct the next page's URL. +func (r MemberPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"members_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a MemberPage struct is empty. +func (r MemberPage) IsEmpty() (bool, error) { + is, err := ExtractMembers(r) + return len(is) == 0, err +} + +// ExtractMembers accepts a Page struct, specifically a MemberPage struct, +// and extracts the elements into a slice of Members structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractMembers(r pagination.Page) ([]Member, error) { + var s struct { + Members []Member `json:"members"` + } + err := (r.(MemberPage)).ExtractInto(&s) + return s.Members, err +} + +type commonMemberResult struct { + gophercloud.Result +} + +// ExtractMember is a function that accepts a result and extracts a member. +func (r commonMemberResult) Extract() (*Member, error) { + var s struct { + Member *Member `json:"member"` + } + err := r.ExtractInto(&s) + return s.Member, err +} + +// CreateMemberResult represents the result of a CreateMember operation. +// Call its Extract method to interpret it as a Member. +type CreateMemberResult struct { + commonMemberResult +} + +// GetMemberResult represents the result of a GetMember operation. +// Call its Extract method to interpret it as a Member. +type GetMemberResult struct { + commonMemberResult +} + +// UpdateMemberResult represents the result of an UpdateMember operation. +// Call its Extract method to interpret it as a Member. +type UpdateMemberResult struct { + commonMemberResult +} + +// DeleteMemberResult represents the result of a DeleteMember operation. +// Call its ExtractErr method to determine if the request succeeded or failed. +type DeleteMemberResult struct { + gophercloud.ErrResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/doc.go new file mode 100644 index 00000000..46e335f3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/doc.go @@ -0,0 +1,2 @@ +// pools unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/fixtures.go new file mode 100644 index 00000000..9d929525 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/fixtures.go @@ -0,0 +1,388 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// PoolsListBody contains the canned body of a pool list response. +const PoolsListBody = ` +{ + "pools":[ + { + "lb_algorithm":"ROUND_ROBIN", + "protocol":"HTTP", + "description":"", + "healthmonitor_id": "466c8345-28d8-4f84-a246-e04380b0461d", + "members":[{"id": "53306cda-815d-4354-9fe4-59e09da9c3c5"}], + "listeners":[{"id": "2a280670-c202-4b0b-a562-34077415aabf"}], + "loadbalancers":[{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "id":"72741b06-df4d-4715-b142-276b6bce75ab", + "name":"web", + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "provider": "haproxy" + }, + { + "lb_algorithm":"LEAST_CONNECTION", + "protocol":"HTTP", + "description":"", + "healthmonitor_id": "5f6c8345-28d8-4f84-a246-e04380b0461d", + "members":[{"id": "67306cda-815d-4354-9fe4-59e09da9c3c5"}], + "listeners":[{"id": "2a280670-c202-4b0b-a562-34077415aabf"}], + "loadbalancers":[{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "id":"c3741b06-df4d-4715-b142-276b6bce75ab", + "name":"db", + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "provider": "haproxy" + } + ] +} +` + +// SinglePoolBody is the canned body of a Get request on an existing pool. +const SinglePoolBody = ` +{ + "pool": { + "lb_algorithm":"LEAST_CONNECTION", + "protocol":"HTTP", + "description":"", + "healthmonitor_id": "5f6c8345-28d8-4f84-a246-e04380b0461d", + "members":[{"id": "67306cda-815d-4354-9fe4-59e09da9c3c5"}], + "listeners":[{"id": "2a280670-c202-4b0b-a562-34077415aabf"}], + "loadbalancers":[{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "id":"c3741b06-df4d-4715-b142-276b6bce75ab", + "name":"db", + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "provider": "haproxy" + } +} +` + +// PostUpdatePoolBody is the canned response body of a Update request on an existing pool. +const PostUpdatePoolBody = ` +{ + "pool": { + "lb_algorithm":"LEAST_CONNECTION", + "protocol":"HTTP", + "description":"", + "healthmonitor_id": "5f6c8345-28d8-4f84-a246-e04380b0461d", + "members":[{"id": "67306cda-815d-4354-9fe4-59e09da9c3c5"}], + "listeners":[{"id": "2a280670-c202-4b0b-a562-34077415aabf"}], + "loadbalancers":[{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}], + "id":"c3741b06-df4d-4715-b142-276b6bce75ab", + "name":"db", + "admin_state_up":true, + "project_id":"83657cfcdfe44cd5920adaf26c48ceea", + "provider": "haproxy" + } +} +` + +var ( + PoolWeb = pools.Pool{ + LBMethod: "ROUND_ROBIN", + Protocol: "HTTP", + Description: "", + MonitorID: "466c8345-28d8-4f84-a246-e04380b0461d", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + AdminStateUp: true, + Name: "web", + Members: []pools.Member{{ID: "53306cda-815d-4354-9fe4-59e09da9c3c5"}}, + ID: "72741b06-df4d-4715-b142-276b6bce75ab", + Loadbalancers: []pools.LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}}, + Listeners: []pools.ListenerID{{ID: "2a280670-c202-4b0b-a562-34077415aabf"}}, + Provider: "haproxy", + } + PoolDb = pools.Pool{ + LBMethod: "LEAST_CONNECTION", + Protocol: "HTTP", + Description: "", + MonitorID: "5f6c8345-28d8-4f84-a246-e04380b0461d", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + AdminStateUp: true, + Name: "db", + Members: []pools.Member{{ID: "67306cda-815d-4354-9fe4-59e09da9c3c5"}}, + ID: "c3741b06-df4d-4715-b142-276b6bce75ab", + Loadbalancers: []pools.LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}}, + Listeners: []pools.ListenerID{{ID: "2a280670-c202-4b0b-a562-34077415aabf"}}, + Provider: "haproxy", + } + PoolUpdated = pools.Pool{ + LBMethod: "LEAST_CONNECTION", + Protocol: "HTTP", + Description: "", + MonitorID: "5f6c8345-28d8-4f84-a246-e04380b0461d", + ProjectID: "83657cfcdfe44cd5920adaf26c48ceea", + AdminStateUp: true, + Name: "db", + Members: []pools.Member{{ID: "67306cda-815d-4354-9fe4-59e09da9c3c5"}}, + ID: "c3741b06-df4d-4715-b142-276b6bce75ab", + Loadbalancers: []pools.LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}}, + Listeners: []pools.ListenerID{{ID: "2a280670-c202-4b0b-a562-34077415aabf"}}, + Provider: "haproxy", + } +) + +// HandlePoolListSuccessfully sets up the test server to respond to a pool List request. +func HandlePoolListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, PoolsListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "pools": [] }`) + default: + t.Fatalf("/v2.0/lbaas/pools invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandlePoolCreationSuccessfully sets up the test server to respond to a pool creation request +// with a given response. +func HandlePoolCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/pools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "pool": { + "lb_algorithm": "ROUND_ROBIN", + "protocol": "HTTP", + "name": "Example pool", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "loadbalancer_id": "79e05663-7f03-45d2-a092-8b94062f22ab" + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// HandlePoolGetSuccessfully sets up the test server to respond to a pool Get request. +func HandlePoolGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/c3741b06-df4d-4715-b142-276b6bce75ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SinglePoolBody) + }) +} + +// HandlePoolDeletionSuccessfully sets up the test server to respond to a pool deletion request. +func HandlePoolDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/c3741b06-df4d-4715-b142-276b6bce75ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandlePoolUpdateSuccessfully sets up the test server to respond to a pool Update request. +func HandlePoolUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/c3741b06-df4d-4715-b142-276b6bce75ab", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "pool": { + "name": "NewPoolName", + "lb_algorithm": "LEAST_CONNECTIONS" + } + }`) + + fmt.Fprintf(w, PostUpdatePoolBody) + }) +} + +// MembersListBody contains the canned body of a member list response. +const MembersListBody = ` +{ + "members":[ + { + "id": "2a280670-c202-4b0b-a562-34077415aabf", + "address": "10.0.2.10", + "weight": 5, + "name": "web", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "admin_state_up":true, + "protocol_port": 80 + }, + { + "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", + "address": "10.0.2.11", + "weight": 10, + "name": "db", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "admin_state_up":false, + "protocol_port": 80 + } + ] +} +` + +// SingleMemberBody is the canned body of a Get request on an existing member. +const SingleMemberBody = ` +{ + "member": { + "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", + "address": "10.0.2.11", + "weight": 10, + "name": "db", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "admin_state_up":false, + "protocol_port": 80 + } +} +` + +// PostUpdateMemberBody is the canned response body of a Update request on an existing member. +const PostUpdateMemberBody = ` +{ + "member": { + "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", + "address": "10.0.2.11", + "weight": 10, + "name": "db", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "admin_state_up":false, + "protocol_port": 80 + } +} +` + +var ( + MemberWeb = pools.Member{ + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + ProjectID: "2ffc6e22aae24e4795f87155d24c896f", + AdminStateUp: true, + Name: "web", + ID: "2a280670-c202-4b0b-a562-34077415aabf", + Address: "10.0.2.10", + Weight: 5, + ProtocolPort: 80, + } + MemberDb = pools.Member{ + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + ProjectID: "2ffc6e22aae24e4795f87155d24c896f", + AdminStateUp: false, + Name: "db", + ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", + Address: "10.0.2.11", + Weight: 10, + ProtocolPort: 80, + } + MemberUpdated = pools.Member{ + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + ProjectID: "2ffc6e22aae24e4795f87155d24c896f", + AdminStateUp: false, + Name: "db", + ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", + Address: "10.0.2.11", + Weight: 10, + ProtocolPort: 80, + } +) + +// HandleMemberListSuccessfully sets up the test server to respond to a member List request. +func HandleMemberListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.Header().Add("Content-Type", "application/json") + r.ParseForm() + marker := r.Form.Get("marker") + switch marker { + case "": + fmt.Fprintf(w, MembersListBody) + case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": + fmt.Fprintf(w, `{ "members": [] }`) + default: + t.Fatalf("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members invoked with unexpected marker=[%s]", marker) + } + }) +} + +// HandleMemberCreationSuccessfully sets up the test server to respond to a member creation request +// with a given response. +func HandleMemberCreationSuccessfully(t *testing.T, response string) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestJSONRequest(t, r, `{ + "member": { + "address": "10.0.2.11", + "weight": 10, + "name": "db", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "project_id": "2ffc6e22aae24e4795f87155d24c896f", + "protocol_port": 80 + } + }`) + + w.WriteHeader(http.StatusAccepted) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, response) + }) +} + +// HandleMemberGetSuccessfully sets up the test server to respond to a member Get request. +func HandleMemberGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members/2a280670-c202-4b0b-a562-34077415aabf", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, SingleMemberBody) + }) +} + +// HandleMemberDeletionSuccessfully sets up the test server to respond to a member deletion request. +func HandleMemberDeletionSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members/2a280670-c202-4b0b-a562-34077415aabf", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleMemberUpdateSuccessfully sets up the test server to respond to a member Update request. +func HandleMemberUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members/2a280670-c202-4b0b-a562-34077415aabf", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestJSONRequest(t, r, `{ + "member": { + "name": "newMemberName", + "weight": 4 + } + }`) + + fmt.Fprintf(w, PostUpdateMemberBody) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/requests_test.go new file mode 100644 index 00000000..33c5c736 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/testing/requests_test.go @@ -0,0 +1,262 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + fake "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListPools(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolListSuccessfully(t) + + pages := 0 + err := pools.List(fake.ServiceClient(), pools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := pools.ExtractPools(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 pools, got %d", len(actual)) + } + th.CheckDeepEquals(t, PoolWeb, actual[0]) + th.CheckDeepEquals(t, PoolDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllPools(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolListSuccessfully(t) + + allPages, err := pools.List(fake.ServiceClient(), pools.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := pools.ExtractPools(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, PoolWeb, actual[0]) + th.CheckDeepEquals(t, PoolDb, actual[1]) +} + +func TestCreatePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolCreationSuccessfully(t, SinglePoolBody) + + actual, err := pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: "HTTP", + Name: "Example pool", + ProjectID: "2ffc6e22aae24e4795f87155d24c896f", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, PoolDb, *actual) +} + +func TestGetPool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.Get(client, "c3741b06-df4d-4715-b142-276b6bce75ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, PoolDb, *actual) +} + +func TestDeletePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolDeletionSuccessfully(t) + + res := pools.Delete(fake.ServiceClient(), "c3741b06-df4d-4715-b142-276b6bce75ab") + th.AssertNoErr(t, res.Err) +} + +func TestUpdatePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.Update(client, "c3741b06-df4d-4715-b142-276b6bce75ab", pools.UpdateOpts{ + Name: "NewPoolName", + LBMethod: pools.LBMethodLeastConnections, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, PoolUpdated, *actual) +} + +func TestRequiredPoolCreateOpts(t *testing.T) { + res := pools.Create(fake.ServiceClient(), pools.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethod("invalid"), + Protocol: pools.ProtocolHTTPS, + LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: pools.Protocol("invalid"), + LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: pools.ProtocolHTTPS, + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestListMembers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberListSuccessfully(t) + + pages := 0 + err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := pools.ExtractMembers(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 members, got %d", len(actual)) + } + th.CheckDeepEquals(t, MemberWeb, actual[0]) + th.CheckDeepEquals(t, MemberDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllMembers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberListSuccessfully(t) + + allPages, err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := pools.ExtractMembers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, MemberWeb, actual[0]) + th.CheckDeepEquals(t, MemberDb, actual[1]) +} + +func TestCreateMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberCreationSuccessfully(t, SingleMemberBody) + + actual, err := pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{ + Name: "db", + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + ProjectID: "2ffc6e22aae24e4795f87155d24c896f", + Address: "10.0.2.11", + ProtocolPort: 80, + Weight: 10, + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, MemberDb, *actual) +} + +func TestRequiredMemberCreateOpts(t *testing.T) { + res := pools.CreateMember(fake.ServiceClient(), "", pools.CreateMemberOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = pools.CreateMember(fake.ServiceClient(), "", pools.CreateMemberOpts{Address: "1.2.3.4", ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{Address: "1.2.3.4"}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestGetMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.GetMember(client, "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, MemberDb, *actual) +} + +func TestDeleteMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberDeletionSuccessfully(t) + + res := pools.DeleteMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.UpdateMember(client, "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf", pools.UpdateMemberOpts{ + Name: "newMemberName", + Weight: 4, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, MemberUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/urls.go new file mode 100644 index 00000000..bceca677 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools/urls.go @@ -0,0 +1,25 @@ +package pools + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "lbaas" + resourcePath = "pools" + memberPath = "members" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} + +func memberRootURL(c *gophercloud.ServiceClient, poolId string) string { + return c.ServiceURL(rootPath, resourcePath, poolId, memberPath) +} + +func memberResourceURL(c *gophercloud.ServiceClient, poolID string, memeberID string) string { + return c.ServiceURL(rootPath, resourcePath, poolID, memberPath, memeberID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper/client.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper/client.go new file mode 100644 index 00000000..7e1d9172 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper/client.go @@ -0,0 +1,14 @@ +package common + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +const TokenID = client.TokenID + +func ServiceClient() *gophercloud.ServiceClient { + sc := client.ServiceClient() + sc.ResourceBase = sc.Endpoint + "v2.0/" + return sc +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/doc.go new file mode 100644 index 00000000..1d9b1d0e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/doc.go @@ -0,0 +1,53 @@ +/* +Package claims provides information and interaction with the Zaqar API +claims resource for the OpenStack Messaging service. + +Example to Create a Claim on a specified Zaqar queue + + createOpts := claims.CreateOpts{ + TTL: 60, + Grace: 120, + Limit: 20, + } + + queueName := "my_queue" + + messages, err := claims.Create(messagingClient, queueName, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to get a claim for a specified Zaqar queue + + queueName := "my_queue" + claimID := "123456789012345678" + + claim, err := claims.Get(messagingClient, queueName, claimID).Extract() + if err != nil { + panic(err) + } + +Example to update a claim for a specified Zaqar queue + + updateOpts := claims.UpdateOpts{ + TTL: 600 + Grace: 1200 + } + + queueName := "my_queue" + + err := claims.Update(messagingClient, queueName, claimID, updateOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to delete a claim for a specified Zaqar queue + + queueName := "my_queue" + + err := claims.Delete(messagingClient, queueName, claimID).ExtractErr() + if err != nil { + panic(err) + } +*/ +package claims diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/requests.go new file mode 100644 index 00000000..21492e52 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/requests.go @@ -0,0 +1,120 @@ +package claims + +import ( + "net/http" + + "github.com/gophercloud/gophercloud" +) + +// CreateOptsBuilder Builder. +type CreateOptsBuilder interface { + ToClaimCreateRequest() (map[string]interface{}, string, error) +} + +// CreateOpts params to be used with Create. +type CreateOpts struct { + // Sets the TTL for the claim. When the claim expires un-deleted messages will be able to be claimed again. + TTL int `json:"ttl,omitempty"` + + // Sets the Grace period for the claimed messages. The server extends the lifetime of claimed messages + // to be at least as long as the lifetime of the claim itself, plus the specified grace period. + Grace int `json:"grace,omitempty"` + + // Set the limit of messages returned by create. + Limit int `q:"limit" json:"-"` +} + +// ToClaimCreateRequest assembles a body and URL for a Create request based on +// the contents of a CreateOpts. +func (opts CreateOpts) ToClaimCreateRequest() (map[string]interface{}, string, error) { + q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return nil, q.String(), err + } + + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return b, "", err + } + return b, q.String(), err +} + +// Create creates a Claim that claims messages on a specified queue. +func Create(client *gophercloud.ServiceClient, queueName string, opts CreateOptsBuilder) (r CreateResult) { + b, q, err := opts.ToClaimCreateRequest() + if err != nil { + r.Err = err + return + } + + url := createURL(client, queueName) + if q != "" { + url += q + } + + var resp *http.Response + resp, r.Err = client.Post(url, b, nil, &gophercloud.RequestOpts{ + OkCodes: []int{201, 204}, + }) + // If the Claim has no content return an empty CreateResult + if resp.StatusCode == 204 { + r.Body = CreateResult{} + } else { + r.Body = resp.Body + } + return +} + +// Get queries the specified claim for the specified queue. +func Get(client *gophercloud.ServiceClient, queueName string, claimID string) (r GetResult) { + _, r.Err = client.Get(getURL(client, queueName, claimID), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToClaimUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts implements UpdateOpts. +type UpdateOpts struct { + // Update the TTL for the specified Claim. + TTL int `json:"ttl,omitempty"` + + // Update the grace period for Messages in a specified Claim. + Grace int `json:"grace,omitempty"` +} + +// ToClaimUpdateMap assembles a request body based on the contents of +// UpdateOpts. +func (opts UpdateOpts) ToClaimUpdateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +// Update will update the options for a specified claim. +func Update(client *gophercloud.ServiceClient, queueName string, claimID string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToClaimUpdateMap() + if err != nil { + r.Err = err + return r + } + _, r.Err = client.Patch(updateURL(client, queueName, claimID), &b, nil, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + +// Delete will delete a Claim for a specified Queue. +func Delete(client *gophercloud.ServiceClient, queueName string, claimID string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, queueName, claimID), &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/results.go new file mode 100644 index 00000000..ec43e582 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/results.go @@ -0,0 +1,52 @@ +package claims + +import "github.com/gophercloud/gophercloud" + +func (r CreateResult) Extract() ([]Messages, error) { + var s struct { + Messages []Messages `json:"messages"` + } + err := r.ExtractInto(&s) + return s.Messages, err +} + +func (r GetResult) Extract() (*Claim, error) { + var s *Claim + err := r.ExtractInto(&s) + return s, err +} + +// CreateResult is the response of a Create operations. +type CreateResult struct { + gophercloud.Result +} + +// GetResult is the response of a Get operations. +type GetResult struct { + gophercloud.Result +} + +// UpdateResult is the response of a Update operations. +type UpdateResult struct { + gophercloud.ErrResult +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +type Messages struct { + Age float32 `json:"age"` + Href string `json:"href"` + TTL int `json:"ttl"` + Body map[string]interface{} `json:"body"` +} + +type Claim struct { + Age float32 `json:"age"` + Href string `json:"href"` + Messages []Messages `json:"messages"` + TTL int `json:"ttl"` +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/doc.go new file mode 100644 index 00000000..787309df --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/doc.go @@ -0,0 +1,2 @@ +// Claims unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/fixtures.go new file mode 100644 index 00000000..95ef1468 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/fixtures.go @@ -0,0 +1,133 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/claims" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +// QueueName is the name of the queue +var QueueName = "FakeTestQueue" + +var ClaimID = "51db7067821e727dc24df754" + +// CreateClaimResponse is a sample response to a create claim +const CreateClaimResponse = ` +{ + "messages": [ + { + "body": {"event": "BackupStarted"}, + "href": "/v2/queues/FakeTestQueue/messages/51db6f78c508f17ddc924357?claim_id=51db7067821e727dc24df754", + "age": 57, + "ttl": 300 + } + ] +}` + +// GetClaimResponse is a sample response to a get claim +const GetClaimResponse = ` +{ + "age": 50, + "href": "/v2/queues/demoqueue/claims/51db7067821e727dc24df754", + "messages": [ + { + "body": {"event": "BackupStarted"}, + "href": "/v2/queues/FakeTestQueue/messages/51db6f78c508f17ddc924357?claim_id=51db7067821e727dc24df754", + "age": 57, + "ttl": 300 + } + ], + "ttl": 50 +}` + +// CreateClaimRequest is a sample request to create a claim. +const CreateClaimRequest = ` +{ + "ttl": 3600, + "grace": 3600 +}` + +// UpdateClaimRequest is a sample request to update a claim. +const UpdateClaimRequest = ` +{ + "ttl": 1200, + "grace": 1600 +}` + +// CreatedClaim is the result of a create request. +var CreatedClaim = []claims.Messages{ + { + Age: 57, + Href: fmt.Sprintf("/v2/queues/%s/messages/51db6f78c508f17ddc924357?claim_id=%s", QueueName, ClaimID), + TTL: 300, + Body: map[string]interface{}{"event": "BackupStarted"}, + }, +} + +// FirstClaim is the result of a get claim. +var FirstClaim = claims.Claim{ + Age: 50, + Href: "/v2/queues/demoqueue/claims/51db7067821e727dc24df754", + Messages: []claims.Messages{ + { + Age: 57, + Href: fmt.Sprintf("/v2/queues/%s/messages/51db6f78c508f17ddc924357?claim_id=%s", QueueName, ClaimID), + TTL: 300, + Body: map[string]interface{}{"event": "BackupStarted"}, + }, + }, + TTL: 50, +} + +// HandleCreateSuccessfully configures the test server to respond to a Create request. +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/claims", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreateClaimRequest) + + w.WriteHeader(http.StatusCreated) + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, CreateClaimResponse) + }) +} + +// HandleGetSuccessfully configures the test server to respond to a Get request. +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/claims/%s", QueueName, ClaimID), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, GetClaimResponse) + }) +} + +// HandleUpdateSuccessfully configures the test server to respond to a Update request. +func HandleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/claims/%s", QueueName, ClaimID), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, UpdateClaimRequest) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleDeleteSuccessfully configures the test server to respond to an Delete request. +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/claims/%s", QueueName, ClaimID), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/requests_test.go new file mode 100644 index 00000000..e3ee3d39 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/testing/requests_test.go @@ -0,0 +1,58 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/claims" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + createOpts := claims.CreateOpts{ + TTL: 3600, + Grace: 3600, + Limit: 10, + } + + actual, err := claims.Create(fake.ServiceClient(), QueueName, createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, CreatedClaim, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := claims.Get(fake.ServiceClient(), QueueName, ClaimID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &FirstClaim, actual) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + updateOpts := claims.UpdateOpts{ + Grace: 1600, + TTL: 1200, + } + + err := claims.Update(fake.ServiceClient(), QueueName, ClaimID, updateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := claims.Delete(fake.ServiceClient(), QueueName, ClaimID).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/urls.go new file mode 100644 index 00000000..fae8fb4f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/claims/urls.go @@ -0,0 +1,24 @@ +package claims + +import "github.com/gophercloud/gophercloud" + +const ( + apiVersion = "v2" + apiName = "queues" +) + +func createURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "claims") +} + +func getURL(client *gophercloud.ServiceClient, queueName string, claimID string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "claims", claimID) +} + +func updateURL(client *gophercloud.ServiceClient, queueName string, claimID string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "claims", claimID) +} + +func deleteURL(client *gophercloud.ServiceClient, queueName string, claimID string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "claims", claimID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/doc.go new file mode 100644 index 00000000..e5f5bce6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/doc.go @@ -0,0 +1,121 @@ +/* +Package messages provides information and interaction with the messages through +the OpenStack Messaging(Zaqar) service. + +Example to List Messages + + listOpts := messages.ListOpts{ + Limit: 10, + } + + queueName := "my_queue" + + pager := messages.List(client, queueName, listOpts) + + err = pager.EachPage(func(page pagination.Page) (bool, error) { + allMessages, err := queues.ExtractQueues(page) + if err != nil { + panic(err) + } + + for _, message := range allMessages { + fmt.Printf("%+v\n", message) + } + + return true, nil + }) + +Example to Create Messages + + queueName = "my_queue" + + createOpts := messages.CreateOpts{ + Messages: []messages.Messages{ + { + TTL: 300, + Delay: 20, + Body: map[string]interface{}{ + "event": "BackupStarted", + "backup_id": "c378813c-3f0b-11e2-ad92-7823d2b0f3ce", + }, + }, + { + Body: map[string]interface{}{ + "event": "BackupProgress", + "current_bytes": "0", + "total_bytes": "99614720", + }, + }, + }, + } + + resources, err := messages.Create(client, queueName, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Get a set of Messages + + queueName := "my_queue" + + getMessageOpts := messages.GetMessagesOpts{ + IDs: "123456", + } + + messagesList, err := messages.GetMessages(client, createdQueueName, getMessageOpts).Extract() + if err != nil { + panic(err) + } + +Example to get a singular Message + + queueName := "my_queue" + messageID := "123456" + + message, err := messages.Get(client, queueName, messageID).Extract() + if err != nil { + panic(err) + } + +Example to Delete a set of Messages + + queueName := "my_queue" + + deleteMessagesOpts := messages.DeleteMessagesOpts{ + IDs: []string{"9988776655"}, + } + + err := messages.DeleteMessages(client, queueName, deleteMessagesOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to Pop a set of Messages + + queueName := "my_queue" + + popMessagesOpts := messages.PopMessagesOpts{ + Pop: 5, + } + + resources, err := messages.PopMessages(client, queueName, popMessagesOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a singular Message + + clientID := "3381af92-2b9e-11e3-b191-71861300734d" + queueName := "my_queue" + messageID := "123456" + + deleteOpts := messages.DeleteOpts{ + ClaimID: "12345", + } + + err := messages.Delete(client), queueName, messageID, deleteOpts).ExtractErr() + if err != nil { + panic(err) + } +*/ +package messages diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/requests.go new file mode 100644 index 00000000..6aac4ac3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/requests.go @@ -0,0 +1,253 @@ +package messages + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToMessageListQuery() (string, error) +} + +// ListOpts params to be used with List. +type ListOpts struct { + // Limit instructs List to refrain from sending excessively large lists of queues + Limit int `q:"limit,omitempty"` + + // Marker and Limit control paging. Marker instructs List where to start listing from. + Marker string `q:"marker,omitempty"` + + // Indicate if the messages can be echoed back to the client that posted them. + Echo bool `q:"echo,omitempty"` + + // Indicate if the messages list should include the claimed messages. + IncludeClaimed bool `q:"include_claimed,omitempty"` + + //Indicate if the messages list should include the delayed messages. + IncludeDelayed bool `q:"include_delayed,omitempty"` +} + +func (opts ListOpts) ToMessageListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListMessages lists messages on a specific queue based off queue name. +func List(client *gophercloud.ServiceClient, queueName string, opts ListOptsBuilder) pagination.Pager { + url := listURL(client, queueName) + if opts != nil { + query, err := opts.ToMessageListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + pager := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return MessagePage{pagination.LinkedPageBase{PageResult: r}} + }) + return pager +} + +// CreateOptsBuilder Builder. +type CreateOptsBuilder interface { + ToMessageCreateMap() (map[string]interface{}, error) +} + +// BatchCreateOpts is an array of CreateOpts. +type BatchCreateOpts []CreateOpts + +// CreateOpts params to be used with Create. +type CreateOpts struct { + // TTL specifies how long the server waits before marking the message + // as expired and removing it from the queue. + TTL int `json:"ttl,omitempty"` + + // Delay specifies how long the message can be claimed. + Delay int `json:"delay,omitempty"` + + // Body specifies an arbitrary document that constitutes the body of the message being sent. + Body map[string]interface{} `json:"body" required:"true"` +} + +// ToMessageCreateMap constructs a request body from BatchCreateOpts. +func (opts BatchCreateOpts) ToMessageCreateMap() (map[string]interface{}, error) { + messages := make([]map[string]interface{}, len(opts)) + for i, message := range opts { + messageMap, err := message.ToMap() + if err != nil { + return nil, err + } + messages[i] = messageMap + } + return map[string]interface{}{"messages": messages}, nil +} + +// ToMap constructs a request body from UpdateOpts. +func (opts CreateOpts) ToMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// Create creates a message on a specific queue based of off queue name. +func Create(client *gophercloud.ServiceClient, queueName string, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToMessageCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client, queueName), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201}, + }) + return +} + +// DeleteMessagesOptsBuilder allows extensions to add additional parameters to the +// DeleteMessages request. +type DeleteMessagesOptsBuilder interface { + ToMessagesDeleteQuery() (string, error) +} + +// DeleteMessagesOpts params to be used with DeleteMessages. +type DeleteMessagesOpts struct { + IDs []string `q:"ids,omitempty"` +} + +// ToMessagesDeleteQuery formats a DeleteMessagesOpts structure into a query string. +func (opts DeleteMessagesOpts) ToMessagesDeleteQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// DeleteMessages deletes multiple messages based off of ID. +func DeleteMessages(client *gophercloud.ServiceClient, queueName string, opts DeleteMessagesOptsBuilder) (r DeleteResult) { + url := deleteURL(client, queueName) + if opts != nil { + query, err := opts.ToMessagesDeleteQuery() + if err != nil { + r.Err = err + return + } + url += query + } + _, r.Err = client.Delete(url, &gophercloud.RequestOpts{ + OkCodes: []int{200, 204}, + }) + return +} + +// PopMessagesOptsBuilder allows extensions to add additional parameters to the +// DeleteMessages request. +type PopMessagesOptsBuilder interface { + ToMessagesPopQuery() (string, error) +} + +// PopMessagesOpts params to be used with PopMessages. +type PopMessagesOpts struct { + Pop int `q:"pop,omitempty"` +} + +// ToMessagesPopQuery formats a PopMessagesOpts structure into a query string. +func (opts PopMessagesOpts) ToMessagesPopQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// PopMessages deletes and returns multiple messages based off of number of messages. +func PopMessages(client *gophercloud.ServiceClient, queueName string, opts PopMessagesOptsBuilder) (r PopResult) { + url := deleteURL(client, queueName) + if opts != nil { + query, err := opts.ToMessagesPopQuery() + if err != nil { + r.Err = err + return + } + url += query + } + result, err := client.Delete(url, &gophercloud.RequestOpts{ + OkCodes: []int{200, 204}, + }) + r.Body = result.Body + r.Header = result.Header + r.Err = err + return +} + +// GetMessagesOptsBuilder allows extensions to add additional parameters to the +// GetMessages request. +type GetMessagesOptsBuilder interface { + ToGetMessagesListQuery() (string, error) +} + +// GetMessagesOpts params to be used with GetMessages. +type GetMessagesOpts struct { + IDs []string `q:"ids,omitempty"` +} + +// ToGetMessagesListQuery formats a GetMessagesOpts structure into a query string. +func (opts GetMessagesOpts) ToGetMessagesListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// GetMessages requests details on a multiple messages, by IDs. +func GetMessages(client *gophercloud.ServiceClient, queueName string, opts GetMessagesOptsBuilder) (r GetMessagesResult) { + url := getURL(client, queueName) + if opts != nil { + query, err := opts.ToGetMessagesListQuery() + if err != nil { + r.Err = err + return + } + url += query + } + _, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Get requests details on a single message, by ID. +func Get(client *gophercloud.ServiceClient, queueName string, messageID string) (r GetResult) { + _, r.Err = client.Get(messageURL(client, queueName, messageID), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// DeleteOptsBuilder allows extensions to add additional parameters to the +// delete request. +type DeleteOptsBuilder interface { + ToMessageDeleteQuery() (string, error) +} + +// DeleteOpts params to be used with Delete. +type DeleteOpts struct { + // ClaimID instructs Delete to delete a message that is associated with a claim ID + ClaimID string `q:"claim_id,omitempty"` +} + +// ToMessageDeleteQuery formats a DeleteOpts structure into a query string. +func (opts DeleteOpts) ToMessageDeleteQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// Delete deletes a specific message from the queue. +func Delete(client *gophercloud.ServiceClient, queueName string, messageID string, opts DeleteOptsBuilder) (r DeleteResult) { + url := DeleteMessageURL(client, queueName, messageID) + if opts != nil { + query, err := opts.ToMessageDeleteQuery() + if err != nil { + r.Err = err + return + } + url += query + } + _, r.Err = client.Delete(url, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/results.go new file mode 100644 index 00000000..1c361e3f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/results.go @@ -0,0 +1,132 @@ +package messages + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// CreateResult is the response of a Create operations. +type CreateResult struct { + gophercloud.Result +} + +// MessagePage contains a single page of all clusters from a ListDetails call. +type MessagePage struct { + pagination.LinkedPageBase +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// CreateResult is the response of a Create operations. +type PopResult struct { + gophercloud.Result +} + +// GetMessagesResult is the response of a GetMessages operations. +type GetMessagesResult struct { + gophercloud.Result +} + +// GetResult is the response of a Get operations. +type GetResult struct { + gophercloud.Result +} + +// Message represents a message on a queue. +type Message struct { + Body map[string]interface{} `json:"body"` + Age int `json:"age"` + Href string `json:"href"` + ID string `json:"id"` + TTL int `json:"ttl"` + Checksum string `json:"checksum"` +} + +// PopMessage represents a message returned from PopMessages. +type PopMessage struct { + Body map[string]interface{} `json:"body"` + Age int `json:"age"` + ID string `json:"id"` + TTL int `json:"ttl"` + ClaimCount int `json:"claim_count"` + ClaimID string `json:"claim_id"` +} + +// ResourceList represents the result of creating a message. +type ResourceList struct { + Resources []string `json:"resources"` +} + +// Extract interprets any CreateResult as a ResourceList. +func (r CreateResult) Extract() (ResourceList, error) { + var s ResourceList + err := r.ExtractInto(&s) + return s, err +} + +// Extract interprets any PopResult as a list of PopMessage. +func (r PopResult) Extract() ([]PopMessage, error) { + var s struct { + PopMessages []PopMessage `json:"messages"` + } + err := r.ExtractInto(&s) + return s.PopMessages, err +} + +// Extract interprets any GetMessagesResult as a list of Message. +func (r GetMessagesResult) Extract() ([]Message, error) { + var s struct { + Messages []Message `json:"messages"` + } + err := r.ExtractInto(&s) + return s.Messages, err +} + +// Extract interprets any GetResult as a Message. +func (r GetResult) Extract() (Message, error) { + var s Message + err := r.ExtractInto(&s) + return s, err +} + +// ExtractMessage extracts message into a list of Message. +func ExtractMessages(r pagination.Page) ([]Message, error) { + var s struct { + Messages []Message `json:"messages"` + } + err := (r.(MessagePage)).ExtractInto(&s) + return s.Messages, err +} + +// IsEmpty determines if a MessagePage contains any results. +func (r MessagePage) IsEmpty() (bool, error) { + s, err := ExtractMessages(r) + return len(s) == 0, err +} + +// NextPageURL uses the response's embedded link reference to navigate to the +// next page of results. +func (r MessagePage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + + next, err := gophercloud.ExtractNextURL(s.Links) + if err != nil { + return "", err + } + return nextPageURL(r.URL.String(), next) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/doc.go new file mode 100644 index 00000000..05931e02 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/doc.go @@ -0,0 +1,2 @@ +// messages unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/fixtures.go new file mode 100644 index 00000000..000f887f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/fixtures.go @@ -0,0 +1,316 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/messages" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +// QueueName is the name of the queue +var QueueName = "FakeTestQueue" + +// MessageID is the id of the message +var MessageID = "9988776655" + +// CreateMessageResponse is a sample response to a Create message. +const CreateMessageResponse = ` +{ + "resources": [ + "/v2/queues/demoqueue/messages/51db6f78c508f17ddc924357", + "/v2/queues/demoqueue/messages/51db6f78c508f17ddc924358" + ] +}` + +// CreateMessageRequest is a sample request to create a message. +const CreateMessageRequest = ` +{ + "messages": [ + { + "body": { + "backup_id": "c378813c-3f0b-11e2-ad92-7823d2b0f3ce", + "event": "BackupStarted" + }, + "delay": 20, + "ttl": 300 + }, + { + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + } + } + ] +}` + +// ListMessagesResponse is a sample response to list messages. +const ListMessagesResponse1 = ` +{ + "messages": [ + { + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + }, + "age": 482, + "href": "/v2/queues/FakeTestQueue/messages/578edfe6508f153f256f717b", + "id": "578edfe6508f153f256f717b", + "ttl": 3600, + "checksum": "MD5:abf7213555626e29c3cb3e5dc58b3515" + } + ], + "links": [ + { + "href": "/v2/queues/FakeTestQueue/messages?marker=1", + "rel": "next" + } + ] +}` + +// ListMessagesResponse is a sample response to list messages. +const ListMessagesResponse2 = ` +{ + "messages": [ + { + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + }, + "age": 456, + "href": "/v2/queues/FakeTestQueue/messages/578ee000508f153f256f717d", + "id": "578ee000508f153f256f717d", + "ttl": 3600, + "checksum": "MD5:abf7213555626e29c3cb3e5dc58b3515" + } + ], + "links": [ + { + "href": "/v2/queues/FakeTestQueue/messages?marker=2", + "rel": "next" + } + ] + +}` + +// GetMessagesResponse is a sample response to GetMessages. +const GetMessagesResponse = ` +{ + "messages": [ + { + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + }, + "age": 443, + "href": "/v2/queues/beijing/messages/578f0055508f153f256f717f", + "id": "578f0055508f153f256f717f", + "ttl": 3600 + } + ] +}` + +// GetMessageResponse is a sample response to Get. +const GetMessageResponse = ` +{ + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + }, + "age": 482, + "href": "/v2/queues/FakeTestQueue/messages/578edfe6508f153f256f717b", + "id": "578edfe6508f153f256f717b", + "ttl": 3600, + "checksum": "MD5:abf7213555626e29c3cb3e5dc58b3515" +}` + +// PopMessageResponse is a sample reponse to pop messages +const PopMessageResponse = ` +{ + "messages": [ + { + "body": { + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720" + }, + "age": 20, + "ttl": 120, + "claim_count": 55, + "claim_id": "123456", + "id": "5ae7972599352b436763aee7" + } + ] +}` + +// ExpectedResources is the expected result in Create +var ExpectedResources = messages.ResourceList{ + Resources: []string{ + "/v2/queues/demoqueue/messages/51db6f78c508f17ddc924357", + "/v2/queues/demoqueue/messages/51db6f78c508f17ddc924358", + }, +} + +// FirstMessage is the first result in a List. +var FirstMessage = messages.Message{ + Body: map[string]interface{}{ + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720", + }, + Age: 482, + Href: fmt.Sprintf("/v2/queues/%s/messages/578edfe6508f153f256f717b", QueueName), + ID: "578edfe6508f153f256f717b", + TTL: 3600, + Checksum: "MD5:abf7213555626e29c3cb3e5dc58b3515", +} + +// SecondMessage is the second result in a List. +var SecondMessage = messages.Message{ + Body: map[string]interface{}{ + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720", + }, + Age: 456, + Href: fmt.Sprintf("/v2/queues/%s/messages/578ee000508f153f256f717d", QueueName), + ID: "578ee000508f153f256f717d", + TTL: 3600, + Checksum: "MD5:abf7213555626e29c3cb3e5dc58b3515", +} + +// ExpectedMessagesSlice is the expected result in a List. +var ExpectedMessagesSlice = [][]messages.Message{{FirstMessage}, {SecondMessage}} + +// ExpectedMessagesSet is the expected result in GetMessages +var ExpectedMessagesSet = []messages.Message{ + { + Body: map[string]interface{}{ + "total_bytes": "99614720", + "current_bytes": "0", + "event": "BackupProgress", + }, + Age: 443, + Href: "/v2/queues/beijing/messages/578f0055508f153f256f717f", + ID: "578f0055508f153f256f717f", + TTL: 3600, + Checksum: "", + }, +} + +// ExpectedPopMessage is the expected result of a Pop. +var ExpectedPopMessage = []messages.PopMessage{{ + Body: map[string]interface{}{ + "current_bytes": "0", + "event": "BackupProgress", + "total_bytes": "99614720", + }, + Age: 20, + TTL: 120, + ClaimID: "123456", + ClaimCount: 55, + ID: "5ae7972599352b436763aee7", +}} + +// HandleCreateSuccessfully configures the test server to respond to a Create request. +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreateMessageRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, CreateMessageResponse) + }) +} + +// HandleListSuccessfully configures the test server to respond to a List request. +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + next := r.RequestURI + + switch next { + case fmt.Sprintf("/v2/queues/%s/messages?limit=1", QueueName): + fmt.Fprintf(w, ListMessagesResponse1) + case fmt.Sprintf("/v2/queues/%s/messages?marker=1", QueueName): + fmt.Fprint(w, ListMessagesResponse2) + case fmt.Sprintf("/v2/queues/%s/messages?marker=2", QueueName): + fmt.Fprint(w, `{ "messages": [] }`) + } + }) +} + +// HandleGetMessagesSuccessfully configures the test server to respond to a GetMessages request. +func HandleGetMessagesSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, GetMessagesResponse) + }) +} + +// HandleGetSuccessfully configures the test server to respond to a Get request. +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages/%s", QueueName, MessageID), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, GetMessageResponse) + }) +} + +// HandleDeleteMessagesSuccessfully configures the test server to respond to a Delete request. +func HandleDeleteMessagesSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandlePopSuccessfully configures the test server to respond to a Pop request. +func HandlePopSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, PopMessageResponse) + }) +} + +// HandleGetSuccessfully configures the test server to respond to a Get request. +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/messages/%s", QueueName, MessageID), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/requests_test.go new file mode 100644 index 00000000..eb839262 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/testing/requests_test.go @@ -0,0 +1,126 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/messages" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + listOpts := messages.ListOpts{ + Limit: 1, + } + + count := 0 + err := messages.List(fake.ServiceClient(), QueueName, listOpts).EachPage(func(page pagination.Page) (bool, error) { + actual, err := messages.ExtractMessages(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedMessagesSlice[count], actual) + count++ + + return true, nil + }) + th.AssertNoErr(t, err) + + th.CheckEquals(t, 2, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + createOpts := messages.BatchCreateOpts{ + messages.CreateOpts{ + TTL: 300, + Delay: 20, + Body: map[string]interface{}{ + "event": "BackupStarted", + "backup_id": "c378813c-3f0b-11e2-ad92-7823d2b0f3ce", + }, + }, + messages.CreateOpts{ + Body: map[string]interface{}{ + "event": "BackupProgress", + "current_bytes": "0", + "total_bytes": "99614720", + }, + }, + } + + actual, err := messages.Create(fake.ServiceClient(), QueueName, createOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedResources, actual) +} + +func TestGetMessages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetMessagesSuccessfully(t) + + getMessagesOpts := messages.GetMessagesOpts{ + IDs: []string{"9988776655"}, + } + + actual, err := messages.GetMessages(fake.ServiceClient(), QueueName, getMessagesOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedMessagesSet, actual) +} + +func TestGetMessage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := messages.Get(fake.ServiceClient(), QueueName, MessageID).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, FirstMessage, actual) +} + +func TestDeleteMessages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteMessagesSuccessfully(t) + + deleteMessagesOpts := messages.DeleteMessagesOpts{ + IDs: []string{"9988776655"}, + } + + err := messages.DeleteMessages(fake.ServiceClient(), QueueName, deleteMessagesOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestPopMessages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePopSuccessfully(t) + + popMessagesOpts := messages.PopMessagesOpts{ + Pop: 1, + } + + actual, err := messages.PopMessages(fake.ServiceClient(), QueueName, popMessagesOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedPopMessage, actual) +} + +func TestDeleteMessage(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + deleteOpts := messages.DeleteOpts{ + ClaimID: "12345", + } + + err := messages.Delete(fake.ServiceClient(), QueueName, MessageID, deleteOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/urls.go new file mode 100644 index 00000000..a00dd562 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/messages/urls.go @@ -0,0 +1,49 @@ +package messages + +import ( + "net/url" + + "github.com/gophercloud/gophercloud" +) + +const ( + apiVersion = "v2" + apiName = "queues" +) + +func createURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages") +} + +func listURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages") +} + +func getURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages") +} + +func deleteURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages") +} + +func DeleteMessageURL(client *gophercloud.ServiceClient, queueName string, messageID string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages", messageID) +} + +func messageURL(client *gophercloud.ServiceClient, queueName string, messageID string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "messages", messageID) +} + +// Builds next page full url based on current url. +func nextPageURL(currentURL string, next string) (string, error) { + base, err := url.Parse(currentURL) + if err != nil { + return "", err + } + rel, err := url.Parse(next) + if err != nil { + return "", err + } + return base.ResolveReference(rel).String(), nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/doc.go new file mode 100644 index 00000000..ca97c52a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/doc.go @@ -0,0 +1,111 @@ +/* +Package queues provides information and interaction with the queues through +the OpenStack Messaging (Zaqar) service. + +Lists all queues and creates, shows information for updates, deletes, and actions on a queue. + +Example to List Queues + + listOpts := queues.ListOpts{ + Limit: 10, + } + + pager := queues.List(client, listOpts) + + err = pager.EachPage(func(page pagination.Page) (bool, error) { + queues, err := queues.ExtractQueues(page) + if err != nil { + panic(err) + } + + for _, queue := range queues { + fmt.Printf("%+v\n", queue) + } + + return true, nil + }) + +Example to Create a Queue + + createOpts := queues.CreateOpts{ + QueueName: "My_Queue", + MaxMessagesPostSize: 262143, + DefaultMessageTTL: 3700, + DefaultMessageDelay: 25, + DeadLetterQueueMessageTTL: 3500, + MaxClaimCount: 10, + Extra: map[string]interface{}{"description": "Test queue."}, + } + + err := queues.Create(client, createOpts).ExtractErr() + if err != nil { + panic(err) + } + +Example to Update a Queue + + updateOpts := queues.BatchUpdateOpts{ + queues.UpdateOpts{ + Op: "replace", + Path: "/metadata/_max_claim_count", + Value: 15, + }, + queues.UpdateOpts{ + Op: "replace", + Path: "/metadata/description", + Value: "Updated description test queue.", + }, + } + + updateResult, err := queues.Update(client, queueName, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Get a Queue + + queue, err := queues.Get(client, queueName).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Queue + + err := queues.Delete(client, queueName).ExtractErr() + if err != nil { + panic(err) + } + +Example to Get Message Stats of a Queue + + queueStats, err := queues.GetStats(client, queueName).Extract() + if err != nil { + panic(err) + } + +Example to Share a queue + + shareOpts := queues.ShareOpts{ + Paths: []queues.SharePath{queues.ShareMessages}, + Methods: []queues.ShareMethod{queues.MethodGet}, + } + + queueShare, err := queues.Share(client, queueName, shareOpts).Extract() + if err != nil { + panic(err) + } + +Example to Purge a queue + + purgeOpts := queues.PurgeOpts{ + ResourceTypes: []queues.PurgeResource{ + queues.ResourceMessages, + }, + } + + err := queues.Purge(client, queueName, purgeOpts).ExtractErr() + if err != nil { + panic(err) + } +*/ +package queues diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/requests.go new file mode 100644 index 00000000..6ef53947 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/requests.go @@ -0,0 +1,292 @@ +package queues + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToQueueListQuery() (string, error) +} + +// ListOpts params to be used with List +type ListOpts struct { + // Limit instructs List to refrain from sending excessively large lists of queues + Limit int `q:"limit,omitempty"` + + // Marker and Limit control paging. Marker instructs List where to start listing from. + Marker string `q:"marker,omitempty"` + + // Specifies if showing the detailed information when querying queues + Detailed bool `q:"detailed,omitempty"` +} + +// ToQueueListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToQueueListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List instructs OpenStack to provide a list of queues. +func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(client) + if opts != nil { + query, err := opts.ToQueueListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + pager := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return QueuePage{pagination.LinkedPageBase{PageResult: r}} + + }) + return pager +} + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToQueueCreateMap() (map[string]interface{}, error) +} + +// CreateOpts specifies the queue creation parameters. +type CreateOpts struct { + // The name of the queue to create. + QueueName string `json:"queue_name" required:"true"` + + // The target incoming messages will be moved to when a message can’t + // processed successfully after meet the max claim count is met. + DeadLetterQueue string `json:"_dead_letter_queue,omitempty"` + + // The new TTL setting for messages when moved to dead letter queue. + DeadLetterQueueMessagesTTL int `json:"_dead_letter_queue_messages_ttl,omitempty"` + + // The delay of messages defined for a queue. When the messages send to + // the queue, it will be delayed for some times and means it can not be + // claimed until the delay expired. + DefaultMessageDelay int `json:"_default_message_delay,omitempty"` + + // The default TTL of messages defined for a queue, which will effect for + // any messages posted to the queue. + DefaultMessageTTL int `json:"_default_message_ttl" required:"true"` + + // The flavor name which can tell Zaqar which storage pool will be used + // to create the queue. + Flavor string `json:"_flavor,omitempty"` + + // The max number the message can be claimed. + MaxClaimCount int `json:"_max_claim_count,omitempty"` + + // The max post size of messages defined for a queue, which will effect + // for any messages posted to the queue. + MaxMessagesPostSize int `json:"_max_messages_post_size,omitempty"` + + // Extra is free-form extra key/value pairs to describe the queue. + Extra map[string]interface{} `json:"-"` +} + +// ToQueueCreateMap constructs a request body from CreateOpts. +func (opts CreateOpts) ToQueueCreateMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + if opts.Extra != nil { + for key, value := range opts.Extra { + b[key] = value + } + + } + return b, nil +} + +// Create requests the creation of a new queue. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToQueueCreateMap() + if err != nil { + r.Err = err + return + } + + queueName := b["queue_name"].(string) + delete(b, "queue_name") + + _, r.Err = client.Put(createURL(client, queueName), b, r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{201, 204}, + }) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// update request. +type UpdateOptsBuilder interface { + ToQueueUpdateMap() ([]map[string]interface{}, error) +} + +// BatchUpdateOpts is an array of UpdateOpts. +type BatchUpdateOpts []UpdateOpts + +// UpdateOpts is the struct responsible for updating a property of a queue. +type UpdateOpts struct { + Op UpdateOp `json:"op" required:"true"` + Path string `json:"path" required:"true"` + Value interface{} `json:"value" required:"true"` +} + +type UpdateOp string + +const ( + ReplaceOp UpdateOp = "replace" + AddOp UpdateOp = "add" + RemoveOp UpdateOp = "remove" +) + +// ToQueueUpdateMap constructs a request body from UpdateOpts. +func (opts BatchUpdateOpts) ToQueueUpdateMap() ([]map[string]interface{}, error) { + queuesUpdates := make([]map[string]interface{}, len(opts)) + for i, queue := range opts { + queueMap, err := queue.ToMap() + if err != nil { + return nil, err + } + queuesUpdates[i] = queueMap + } + return queuesUpdates, nil +} + +// ToMap constructs a request body from UpdateOpts. +func (opts UpdateOpts) ToMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "") +} + +// Update Updates the specified queue. +func Update(client *gophercloud.ServiceClient, queueName string, opts UpdateOptsBuilder) (r UpdateResult) { + _, r.Err = client.Patch(updateURL(client, queueName), opts, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201, 204}, + MoreHeaders: map[string]string{ + "Content-Type": "application/openstack-messaging-v2.0-json-patch"}, + }) + return +} + +// Get requests details on a single queue, by name. +func Get(client *gophercloud.ServiceClient, queueName string) (r GetResult) { + _, r.Err = client.Get(getURL(client, queueName), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Delete deletes the specified queue. +func Delete(client *gophercloud.ServiceClient, queueName string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, queueName), &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + +// GetStats returns statistics for the specified queue. +func GetStats(client *gophercloud.ServiceClient, queueName string) (r StatResult) { + _, r.Err = client.Get(statURL(client, queueName), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}}) + return +} + +type SharePath string + +const ( + PathMessages SharePath = "messages" + PathClaims SharePath = "claims" + PathSubscriptions SharePath = "subscriptions" +) + +type ShareMethod string + +const ( + MethodGet ShareMethod = "GET" + MethodPatch ShareMethod = "PATCH" + MethodPost ShareMethod = "POST" + MethodPut ShareMethod = "PUT" +) + +// ShareOpts specifies share creation parameters. +type ShareOpts struct { + Paths []SharePath `json:"paths,omitempty"` + Methods []ShareMethod `json:"methods,omitempty"` + Expires string `json:"expires,omitempty"` +} + +// ShareOptsBuilder allows extensions to add additional attributes to the +// Share request. +type ShareOptsBuilder interface { + ToQueueShareMap() (map[string]interface{}, error) +} + +// ToShareQueueMap formats a ShareOpts structure into a request body. +func (opts ShareOpts) ToQueueShareMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +// Share creates a pre-signed URL for a given queue. +func Share(client *gophercloud.ServiceClient, queueName string, opts ShareOptsBuilder) (r ShareResult) { + b, err := opts.ToQueueShareMap() + if err != nil { + r.Err = err + return r + } + _, r.Err = client.Post(shareURL(client, queueName), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +type PurgeResource string + +const ( + ResourceMessages PurgeResource = "messages" + ResourceSubscriptions PurgeResource = "subscriptions" +) + +// PurgeOpts specifies the purge parameters. +type PurgeOpts struct { + ResourceTypes []PurgeResource `json:"resource_types" required:"true"` +} + +// PurgeOptsBuilder allows extensions to add additional attributes to the +// Purge request. +type PurgeOptsBuilder interface { + ToQueuePurgeMap() (map[string]interface{}, error) +} + +// ToPurgeQueueMap formats a PurgeOpts structure into a request body +func (opts PurgeOpts) ToQueuePurgeMap() (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + return b, nil +} + +// Purge purges particular resource of the queue. +func Purge(client *gophercloud.ServiceClient, queueName string, opts PurgeOptsBuilder) (r PurgeResult) { + b, err := opts.ToQueuePurgeMap() + if err != nil { + r.Err = err + return r + } + + _, r.Err = client.Post(purgeURL(client, queueName), b, nil, &gophercloud.RequestOpts{ + OkCodes: []int{204}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/results.go new file mode 100644 index 00000000..61005da7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/results.go @@ -0,0 +1,201 @@ +package queues + +import ( + "encoding/json" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/internal" + "github.com/gophercloud/gophercloud/pagination" +) + +// commonResult is the response of a base result. +type commonResult struct { + gophercloud.Result +} + +// QueuePage contains a single page of all queues from a List operation. +type QueuePage struct { + pagination.LinkedPageBase +} + +// CreateResult is the response of a Create operation. +type CreateResult struct { + gophercloud.ErrResult +} + +// UpdateResult is the response of a Update operation. +type UpdateResult struct { + commonResult +} + +// GetResult is the response of a Get operation. +type GetResult struct { + commonResult +} + +// StatResult contains the result of a Share operation. +type StatResult struct { + gophercloud.Result +} + +// DeleteResult is the result from a Delete operation. Call its ExtractErr +// method to determine if the call succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// ShareResult contains the result of a Share operation. +type ShareResult struct { + gophercloud.Result +} + +// PurgeResult is the response of a Purge operation. +type PurgeResult struct { + gophercloud.ErrResult +} + +// Queue represents a messaging queue. +type Queue struct { + Href string `json:"href"` + Methods []string `json:"methods"` + Name string `json:"name"` + Paths []string `json:"paths"` + ResourceTypes []string `json:"resource_types"` + Metadata QueueDetails `json:"metadata"` +} + +// QueueDetails represents the metadata of a queue. +type QueueDetails struct { + // The queue the message will be moved to when the message can’t + // be processed successfully after the max claim count is met. + DeadLetterQueue string `json:"_dead_letter_queue"` + + // The TTL setting for messages when moved to dead letter queue. + DeadLetterQueueMessageTTL int `json:"_dead_letter_queue_messages_ttl"` + + // The delay of messages defined for the queue. + DefaultMessageDelay int `json:"_default_message_delay"` + + // The default TTL of messages defined for the queue. + DefaultMessageTTL int `json:"_default_message_ttl"` + + // Extra is a collection of miscellaneous key/values. + Extra map[string]interface{} `json:"-"` + + // The max number the message can be claimed from the queue. + MaxClaimCount int `json:"_max_claim_count"` + + // The max post size of messages defined for the queue. + MaxMessagesPostSize int `json:"_max_messages_post_size"` + + // The flavor defined for the queue. + Flavor string `json:"flavor"` +} + +// Stats represents a stats response. +type Stats struct { + // Number of Claimed messages for a queue + Claimed int `json:"claimed"` + + // Total Messages for a queue + Total int `json:"total"` + + // Number of free messages + Free int `json:"free"` +} + +// QueueShare represents a share response. +type QueueShare struct { + Project string `json:"project"` + Paths []string `json:"paths"` + Expires string `json:"expires"` + Methods []string `json:"methods"` + Signature string `json:"signature"` +} + +// Extract interprets any commonResult as a Queue. +func (r commonResult) Extract() (QueueDetails, error) { + var s QueueDetails + err := r.ExtractInto(&s) + return s, err +} + +// Extract interprets any StatResult as a Stats. +func (r StatResult) Extract() (Stats, error) { + var s struct { + Stats Stats `json:"messages"` + } + err := r.ExtractInto(&s) + return s.Stats, err +} + +// Extract interprets any ShareResult as a QueueShare. +func (r ShareResult) Extract() (QueueShare, error) { + var s QueueShare + err := r.ExtractInto(&s) + return s, err +} + +// ExtractQueues interprets the results of a single page from a +// List() call, producing a map of queues. +func ExtractQueues(r pagination.Page) ([]Queue, error) { + var s struct { + Queues []Queue `json:"queues"` + } + err := (r.(QueuePage)).ExtractInto(&s) + return s.Queues, err +} + +// IsEmpty determines if a QueuesPage contains any results. +func (r QueuePage) IsEmpty() (bool, error) { + s, err := ExtractQueues(r) + return len(s) == 0, err +} + +// NextPageURL uses the response's embedded link reference to navigate to the +// next page of results. +func (r QueuePage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + + next, err := gophercloud.ExtractNextURL(s.Links) + if err != nil { + return "", err + } + return nextPageURL(r.URL.String(), next) +} + +func (r *QueueDetails) UnmarshalJSON(b []byte) error { + type tmp QueueDetails + var s struct { + tmp + Extra map[string]interface{} `json:"extra"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = QueueDetails(s.tmp) + + // Collect other fields and bundle them into Extra + // but only if a field titled "extra" wasn't sent. + if s.Extra != nil { + r.Extra = s.Extra + } else { + var result interface{} + err := json.Unmarshal(b, &result) + if err != nil { + return err + } + if resultMap, ok := result.(map[string]interface{}); ok { + r.Extra = internal.RemainingKeys(QueueDetails{}, resultMap) + } + } + + return err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/doc.go new file mode 100644 index 00000000..09370088 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/doc.go @@ -0,0 +1,2 @@ +// queues unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/fixtures.go new file mode 100644 index 00000000..50e7bd4c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/fixtures.go @@ -0,0 +1,315 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/queues" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +// QueueName is the name of the queue +var QueueName = "FakeTestQueue" + +// CreateQueueRequest is a sample request to create a queue. +const CreateQueueRequest = ` +{ + "_max_messages_post_size": 262144, + "_default_message_ttl": 3600, + "_default_message_delay": 30, + "_dead_letter_queue": "dead_letter", + "_dead_letter_queue_messages_ttl": 3600, + "_max_claim_count": 10, + "description": "Queue for unit testing." +}` + +// CreateShareRequest is a sample request to a share. +const CreateShareRequest = ` +{ + "paths": ["messages", "claims", "subscriptions"], + "methods": ["GET", "POST", "PUT", "PATCH"], + "expires": "2016-09-01T00:00:00" +}` + +// CreatePurgeRequest is a sample request to a purge. +const CreatePurgeRequest = ` +{ + "resource_types": ["messages", "subscriptions"] +}` + +// ListQueuesResponse1 is a sample response to a List queues. +const ListQueuesResponse1 = ` +{ + "queues":[ + { + "href":"/v2/queues/london", + "name":"london", + "metadata":{ + "_dead_letter_queue":"fake_queue", + "_dead_letter_queue_messages_ttl":3500, + "_default_message_delay":25, + "_default_message_ttl":3700, + "_max_claim_count":10, + "_max_messages_post_size":262143, + "description":"Test queue." + } + } + ], + "links":[ + { + "href":"/v2/queues?marker=london", + "rel":"next" + } + ] +}` + +// ListQueuesResponse2 is a sample response to a List queues. +const ListQueuesResponse2 = ` +{ + "queues":[ + { + "href":"/v2/queues/beijing", + "name":"beijing", + "metadata":{ + "_dead_letter_queue":"fake_queue", + "_dead_letter_queue_messages_ttl":3500, + "_default_message_delay":25, + "_default_message_ttl":3700, + "_max_claim_count":10, + "_max_messages_post_size":262143, + "description":"Test queue." + } + } + ], + "links":[ + { + "href":"/v2/queues?marker=beijing", + "rel":"next" + } + ] +}` + +// UpdateQueueRequest is a sample request to update a queue. +const UpdateQueueRequest = ` +[ + { + "op": "replace", + "path": "/metadata/description", + "value": "Update queue description" + } +]` + +// UpdateQueueResponse is a sample response to a update queue. +const UpdateQueueResponse = ` +{ + "description": "Update queue description" +}` + +// GetQueueResponse is a sample response to a get queue. +const GetQueueResponse = ` +{ + "_max_messages_post_size": 262144, + "_default_message_ttl": 3600, + "description": "Queue used for unit testing." +}` + +// GetStatsResponse is a sample response to a stats request. +const GetStatsResponse = ` +{ + "messages":{ + "claimed": 10, + "total": 20, + "free": 10 + } +}` + +// CreateShareResponse is a sample response to a share request. +const CreateShareResponse = ` +{ + "project": "2887aabf368046a3bb0070f1c0413470", + "paths": [ + "/v2/queues/test/messages", + "/v2/queues/test/claims", + "/v2/queues/test/subscriptions" + ], + "expires": "2016-09-01T00:00:00", + "methods": [ + "GET", + "PATCH", + "POST", + "PUT" + ], + "signature": "6a63d63242ebd18c3518871dda6fdcb6273db2672c599bf985469241e9a1c799" +}` + +// FirstQueue is the first result in a List. +var FirstQueue = queues.Queue{ + Href: "/v2/queues/london", + Name: "london", + Metadata: queues.QueueDetails{ + DeadLetterQueue: "fake_queue", + DeadLetterQueueMessageTTL: 3500, + DefaultMessageDelay: 25, + DefaultMessageTTL: 3700, + MaxClaimCount: 10, + MaxMessagesPostSize: 262143, + Extra: map[string]interface{}{"description": "Test queue."}, + }, +} + +// SecondQueue is the second result in a List. +var SecondQueue = queues.Queue{ + Href: "/v2/queues/beijing", + Name: "beijing", + Metadata: queues.QueueDetails{ + DeadLetterQueue: "fake_queue", + DeadLetterQueueMessageTTL: 3500, + DefaultMessageDelay: 25, + DefaultMessageTTL: 3700, + MaxClaimCount: 10, + MaxMessagesPostSize: 262143, + Extra: map[string]interface{}{"description": "Test queue."}, + }, +} + +// ExpectedQueueSlice is the expected result in a List. +var ExpectedQueueSlice = [][]queues.Queue{{FirstQueue}, {SecondQueue}} + +// QueueDetails is the expected result in a Get. +var QueueDetails = queues.QueueDetails{ + DefaultMessageTTL: 3600, + MaxMessagesPostSize: 262144, + Extra: map[string]interface{}{"description": "Queue used for unit testing."}, +} + +// ExpectedStats is the expected result in a GetStats. +var ExpectedStats = queues.Stats{ + Claimed: 10, + Total: 20, + Free: 10, +} + +// ExpectedShare is the expected result in Share. +var ExpectedShare = queues.QueueShare{ + Project: "2887aabf368046a3bb0070f1c0413470", + Paths: []string{ + "/v2/queues/test/messages", + "/v2/queues/test/claims", + "/v2/queues/test/subscriptions", + }, + Expires: "2016-09-01T00:00:00", + Methods: []string{ + "GET", + "PATCH", + "POST", + "PUT", + }, + Signature: "6a63d63242ebd18c3518871dda6fdcb6273db2672c599bf985469241e9a1c799", +} + +// HandleListSuccessfully configures the test server to respond to a List request. +func HandleListSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/v2/queues", + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + next := r.RequestURI + + switch next { + case "/v2/queues?limit=1": + fmt.Fprintf(w, ListQueuesResponse1) + case "/v2/queues?marker=london": + fmt.Fprint(w, ListQueuesResponse2) + case "/v2/queues?marker=beijing": + fmt.Fprint(w, `{ "queues": [] }`) + } + }) +} + +// HandleCreateSuccessfully configures the test server to respond to a Create request. +func HandleCreateSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreateQueueRequest) + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleUpdateSuccessfully configures the test server to respond to an Update request. +func HandleUpdateSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, UpdateQueueRequest) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, UpdateQueueResponse) + }) +} + +// HandleGetSuccessfully configures the test server to respond to a Get request. +func HandleGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, GetQueueResponse) + }) +} + +// HandleDeleteSuccessfully configures the test server to respond to a Delete request. +func HandleDeleteSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleGetSuccessfully configures the test server to respond to a Get request. +func HandleGetStatsSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/stats", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, GetStatsResponse) + }) +} + +// HandleShareSuccessfully configures the test server to respond to a Share request. +func HandleShareSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/share", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreateShareRequest) + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, CreateShareResponse) + }) +} + +// HandlePurgeSuccessfully configures the test server to respond to a Purge request. +func HandlePurgeSuccessfully(t *testing.T) { + th.Mux.HandleFunc(fmt.Sprintf("/v2/queues/%s/purge", QueueName), + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestJSONRequest(t, r, CreatePurgeRequest) + + w.WriteHeader(http.StatusNoContent) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/requests_test.go new file mode 100644 index 00000000..c4502cda --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/testing/requests_test.go @@ -0,0 +1,133 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/messaging/v2/queues" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t) + + listOpts := queues.ListOpts{ + Limit: 1, + } + + count := 0 + err := queues.List(fake.ServiceClient(), listOpts).EachPage(func(page pagination.Page) (bool, error) { + actual, err := queues.ExtractQueues(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedQueueSlice[count], actual) + count++ + + return true, nil + }) + th.AssertNoErr(t, err) + + th.CheckEquals(t, 2, count) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t) + + createOpts := queues.CreateOpts{ + QueueName: QueueName, + MaxMessagesPostSize: 262144, + DefaultMessageTTL: 3600, + DefaultMessageDelay: 30, + DeadLetterQueue: "dead_letter", + DeadLetterQueueMessagesTTL: 3600, + MaxClaimCount: 10, + Extra: map[string]interface{}{"description": "Queue for unit testing."}, + } + + err := queues.Create(fake.ServiceClient(), createOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + updateOpts := queues.BatchUpdateOpts{ + queues.UpdateOpts{ + Op: queues.ReplaceOp, + Path: "/metadata/description", + Value: "Update queue description", + }, + } + updatedQueueResult := queues.QueueDetails{ + Extra: map[string]interface{}{"description": "Update queue description"}, + } + + actual, err := queues.Update(fake.ServiceClient(), QueueName, updateOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, updatedQueueResult, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t) + + actual, err := queues.Get(fake.ServiceClient(), QueueName).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, QueueDetails, actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := queues.Delete(fake.ServiceClient(), QueueName).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestGetStat(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetStatsSuccessfully(t) + + actual, err := queues.GetStats(fake.ServiceClient(), QueueName).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedStats, actual) +} + +func TestShare(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleShareSuccessfully(t) + + shareOpts := queues.ShareOpts{ + Paths: []queues.SharePath{queues.PathMessages, queues.PathClaims, queues.PathSubscriptions}, + Methods: []queues.ShareMethod{queues.MethodGet, queues.MethodPost, queues.MethodPut, queues.MethodPatch}, + Expires: "2016-09-01T00:00:00", + } + + actual, err := queues.Share(fake.ServiceClient(), QueueName, shareOpts).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedShare, actual) +} + +func TestPurge(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePurgeSuccessfully(t) + + purgeOpts := queues.PurgeOpts{ + ResourceTypes: []queues.PurgeResource{queues.ResourceMessages, queues.ResourceSubscriptions}, + } + + err := queues.Purge(fake.ServiceClient(), QueueName, purgeOpts).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/urls.go new file mode 100644 index 00000000..6b5a0e32 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/messaging/v2/queues/urls.go @@ -0,0 +1,61 @@ +package queues + +import ( + "net/url" + + "github.com/gophercloud/gophercloud" +) + +const ( + apiVersion = "v2" + apiName = "queues" +) + +func commonURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL(apiVersion, apiName) +} + +func createURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName) +} + +func listURL(client *gophercloud.ServiceClient) string { + return commonURL(client) +} + +func updateURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName) +} + +func getURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName) +} + +func deleteURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName) +} + +func statURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "stats") +} + +func shareURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "share") +} + +func purgeURL(client *gophercloud.ServiceClient, queueName string) string { + return client.ServiceURL(apiVersion, apiName, queueName, "purge") +} + +// builds next page full url based on current url +func nextPageURL(currentURL string, next string) (string, error) { + base, err := url.Parse(currentURL) + if err != nil { + return "", err + } + rel, err := url.Parse(next) + if err != nil { + return "", err + } + return base.ResolveReference(rel).String(), nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions/testing/requests_test.go new file mode 100644 index 00000000..5a66a2a0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions/testing/requests_test.go @@ -0,0 +1,183 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/apiversions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "versions": [ + { + "status": "CURRENT", + "id": "v2.0", + "links": [ + { + "href": "http://23.253.228.211:9696/v2.0", + "rel": "self" + } + ] + } + ] +}`) + }) + + count := 0 + + apiversions.ListVersions(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := apiversions.ExtractAPIVersions(page) + if err != nil { + t.Errorf("Failed to extract API versions: %v", err) + return false, err + } + + expected := []apiversions.APIVersion{ + { + Status: "CURRENT", + ID: "v2.0", + }, + } + + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestNonJSONCannotBeExtractedIntoAPIVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + apiversions.ListVersions(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + if _, err := apiversions.ExtractAPIVersions(page); err == nil { + t.Fatalf("Expected error, got nil") + } + return true, nil + }) +} + +func TestAPIInfo(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "resources": [ + { + "links": [ + { + "href": "http://23.253.228.211:9696/v2.0/subnets", + "rel": "self" + } + ], + "name": "subnet", + "collection": "subnets" + }, + { + "links": [ + { + "href": "http://23.253.228.211:9696/v2.0/networks", + "rel": "self" + } + ], + "name": "network", + "collection": "networks" + }, + { + "links": [ + { + "href": "http://23.253.228.211:9696/v2.0/ports", + "rel": "self" + } + ], + "name": "port", + "collection": "ports" + } + ] +} + `) + }) + + count := 0 + + apiversions.ListVersionResources(fake.ServiceClient(), "v2.0").EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := apiversions.ExtractVersionResources(page) + if err != nil { + t.Errorf("Failed to extract version resources: %v", err) + return false, err + } + + expected := []apiversions.APIVersionResource{ + { + Name: "subnet", + Collection: "subnets", + }, + { + Name: "network", + Collection: "networks", + }, + { + Name: "port", + Collection: "ports", + }, + } + + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestNonJSONCannotBeExtractedIntoAPIVersionResources(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + apiversions.ListVersionResources(fake.ServiceClient(), "v2.0").EachPage(func(page pagination.Page) (bool, error) { + if _, err := apiversions.ExtractVersionResources(page); err == nil { + t.Fatalf("Expected error, got nil") + } + return true, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go index b8261684..eda010cb 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go @@ -4,6 +4,13 @@ extension for the OpenStack Networking service. Example to List Networks with External Information + iTrue := true + networkListOpts := networks.ListOpts{} + listOpts := external.ListOptsExt{ + ListOptsBuilder: networkListOpts, + External: &iTrue, + } + type NetworkWithExternalExt struct { networks.Network external.NetworkExternalExt @@ -11,7 +18,7 @@ Example to List Networks with External Information var allNetworks []NetworkWithExternalExt - allPages, err := networks.List(networkClient, nil).AllPages() + allPages, err := networks.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go index f28e5746..ced5efed 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go @@ -1,9 +1,37 @@ package external import ( + "net/url" + "strconv" + + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" ) +// ListOptsExt adds the external network options to the base ListOpts. +type ListOptsExt struct { + networks.ListOptsBuilder + External *bool `q:"router:external"` +} + +// ToNetworkListQuery adds the router:external option to the base network +// list options. +func (opts ListOptsExt) ToNetworkListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts.ListOptsBuilder) + if err != nil { + return "", err + } + + params := q.Query() + if opts.External != nil { + v := strconv.FormatBool(*opts.External) + params.Add("router:external", v) + } + + q = &url.URL{RawQuery: params.Encode()} + return q.String(), err +} + // CreateOptsExt is the structure used when creating new external network // resources. It embeds networks.CreateOpts and so inherits all of its required // and optional fields, with the addition of the External field. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/fixtures.go index 8739236d..f23bbea4 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/fixtures.go @@ -57,3 +57,5 @@ const UpdateResponse = ` "router:external": false } }` + +const ExpectedListOpts = "?id=d32019d3-bc6e-4319-9c1d-6722fc136a22&router%3Aexternal=true" diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/requests_test.go new file mode 100644 index 00000000..29236b89 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/requests_test.go @@ -0,0 +1,26 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListExternal(t *testing.T) { + var iTrue bool = true + + networkListOpts := networks.ListOpts{ + ID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", + } + + listOpts := external.ListOptsExt{ + ListOptsBuilder: networkListOpts, + External: &iTrue, + } + + actual, err := listOpts.ToNetworkListQuery() + th.AssertNoErr(t, err) + th.AssertEquals(t, ExpectedListOpts, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/results_test.go new file mode 100644 index 00000000..64a50882 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/testing/results_test.go @@ -0,0 +1,138 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + nettest "github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, nettest.ListResponse) + }) + + type NetworkWithExternalExt struct { + networks.Network + external.NetworkExternalExt + } + var actual []NetworkWithExternalExt + + allPages, err := networks.List(fake.ServiceClient(), networks.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = networks.ExtractNetworksInto(allPages, &actual) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "d32019d3-bc6e-4319-9c1d-6722fc136a22", actual[0].ID) + th.AssertEquals(t, true, actual[0].External) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, nettest.GetResponse) + }) + + var s struct { + networks.Network + external.NetworkExternalExt + } + + err := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "d32019d3-bc6e-4319-9c1d-6722fc136a22", s.ID) + th.AssertEquals(t, true, s.External) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateResponse) + }) + + iTrue := true + iFalse := false + networkCreateOpts := networks.CreateOpts{ + Name: "private", + AdminStateUp: &iTrue, + } + + externalCreateOpts := external.CreateOptsExt{ + CreateOptsBuilder: &networkCreateOpts, + External: &iFalse, + } + + _, err := networks.Create(fake.ServiceClient(), externalCreateOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateResponse) + }) + + iTrue := true + iFalse := false + networkUpdateOpts := networks.UpdateOpts{ + Name: "new_network_name", + AdminStateUp: &iFalse, + Shared: &iTrue, + } + + externalUpdateOpts := external.UpdateOptsExt{ + UpdateOptsBuilder: &networkUpdateOpts, + External: &iFalse, + } + + _, err := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", externalUpdateOpts).Extract() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/doc.go new file mode 100644 index 00000000..ec5d6181 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/doc.go @@ -0,0 +1,80 @@ +/* +Package extradhcpopts allow to work with extra DHCP functionality of Neutron ports. + +Example to Get a Port with Extra DHCP Options + + portID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + err := ports.Get(networkClient, portID).ExtractInto(&s) + if err != nil { + panic(err) + } + +Example to Create a Port with Extra DHCP Options + + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + adminStateUp := true + portCreateOpts := ports.CreateOpts{ + Name: "dhcp-conf-port", + AdminStateUp: &adminStateUp, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + } + + createOpts := extradhcpopts.CreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + ExtraDHCPOpts: []extradhcpopts.CreateExtraDHCPOpt{ + { + OptName: "optionA", + OptValue: "valueA", + }, + }, + } + + err := ports.Create(networkClient, createOpts).ExtractInto(&s) + if err != nil { + panic(err) + } + +Example to Update a Port with Extra DHCP Options + + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + portUpdateOpts := ports.UpdateOpts{ + Name: "updated-dhcp-conf-port", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + } + + value := "valueB" + updateOpts := extradhcpopts.UpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + ExtraDHCPOpts: []extradhcpopts.UpdateExtraDHCPOpt{ + { + OptName: "optionB", + OptValue: &value, + }, + }, + } + + portID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" + err := ports.Update(networkClient, portID, updateOpts).ExtractInto(&s) + if err != nil { + panic(err) + } +*/ +package extradhcpopts diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/requests.go new file mode 100644 index 00000000..f3eb9bc4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/requests.go @@ -0,0 +1,102 @@ +package extradhcpopts + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" +) + +// CreateOptsExt adds extra DHCP options to the base ports.CreateOpts. +type CreateOptsExt struct { + // CreateOptsBuilder is the interface options structs have to satisfy in order + // to be used in the main Create operation in this package. + ports.CreateOptsBuilder + + // ExtraDHCPOpts field is a set of DHCP options for a single port. + ExtraDHCPOpts []CreateExtraDHCPOpt `json:"extra_dhcp_opts,omitempty"` +} + +// CreateExtraDHCPOpt represents the options required to create an extra DHCP +// option on a port. +type CreateExtraDHCPOpt struct { + // OptName is the name of a DHCP option. + OptName string `json:"opt_name" required:"true"` + + // OptValue is the value of the DHCP option. + OptValue string `json:"opt_value" required:"true"` + + // IPVersion is the IP protocol version of a DHCP option. + IPVersion gophercloud.IPVersion `json:"ip_version,omitempty"` +} + +// ToPortCreateMap casts a CreateOptsExt struct to a map. +func (opts CreateOptsExt) ToPortCreateMap() (map[string]interface{}, error) { + base, err := opts.CreateOptsBuilder.ToPortCreateMap() + if err != nil { + return nil, err + } + + port := base["port"].(map[string]interface{}) + + // Convert opts.ExtraDHCPOpts to a slice of maps. + if opts.ExtraDHCPOpts != nil { + extraDHCPOpts := make([]map[string]interface{}, len(opts.ExtraDHCPOpts)) + for i, opt := range opts.ExtraDHCPOpts { + b, err := gophercloud.BuildRequestBody(opt, "") + if err != nil { + return nil, err + } + extraDHCPOpts[i] = b + } + port["extra_dhcp_opts"] = extraDHCPOpts + } + + return base, nil +} + +// UpdateOptsExt adds extra DHCP options to the base ports.UpdateOpts. +type UpdateOptsExt struct { + // UpdateOptsBuilder is the interface options structs have to satisfy in order + // to be used in the main Update operation in this package. + ports.UpdateOptsBuilder + + // ExtraDHCPOpts field is a set of DHCP options for a single port. + ExtraDHCPOpts []UpdateExtraDHCPOpt `json:"extra_dhcp_opts,omitempty"` +} + +// UpdateExtraDHCPOpt represents the options required to update an extra DHCP +// option on a port. +type UpdateExtraDHCPOpt struct { + // OptName is the name of a DHCP option. + OptName string `json:"opt_name" required:"true"` + + // OptValue is the value of the DHCP option. + OptValue *string `json:"opt_value"` + + // IPVersion is the IP protocol version of a DHCP option. + IPVersion gophercloud.IPVersion `json:"ip_version,omitempty"` +} + +// ToPortUpdateMap casts an UpdateOpts struct to a map. +func (opts UpdateOptsExt) ToPortUpdateMap() (map[string]interface{}, error) { + base, err := opts.UpdateOptsBuilder.ToPortUpdateMap() + if err != nil { + return nil, err + } + + port := base["port"].(map[string]interface{}) + + // Convert opts.ExtraDHCPOpts to a slice of maps. + if opts.ExtraDHCPOpts != nil { + extraDHCPOpts := make([]map[string]interface{}, len(opts.ExtraDHCPOpts)) + for i, opt := range opts.ExtraDHCPOpts { + b, err := gophercloud.BuildRequestBody(opt, "") + if err != nil { + return nil, err + } + extraDHCPOpts[i] = b + } + port["extra_dhcp_opts"] = extraDHCPOpts + } + + return base, nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/results.go new file mode 100644 index 00000000..8e3132ea --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts/results.go @@ -0,0 +1,20 @@ +package extradhcpopts + +// ExtraDHCPOptsExt is a struct that contains different DHCP options for a +// single port. +type ExtraDHCPOptsExt struct { + ExtraDHCPOpts []ExtraDHCPOpt `json:"extra_dhcp_opts"` +} + +// ExtraDHCPOpt represents a single set of extra DHCP options for a single port. +type ExtraDHCPOpt struct { + // OptName is the name of a single DHCP option. + OptName string `json:"opt_name"` + + // OptValue is the value of a single DHCP option. + OptValue string `json:"opt_value"` + + // IPVersion is the IP protocol version of a single DHCP option. + // Valid value is 4 or 6. Default is 4. + IPVersion int `json:"ip_version"` +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/requests.go index aa301946..cbd6c1fb 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/requests.go @@ -18,6 +18,7 @@ type ListOptsBuilder interface { // `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Name string `q:"name"` Description string `q:"description"` AdminStateUp bool `q:"admin_state_up"` @@ -69,6 +70,7 @@ type CreateOpts struct { // an admin role in order to set this. Otherwise, this field is left unset // and the caller will be the owner. TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/results.go index f6786a44..9543f0fa 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/results.go @@ -14,6 +14,7 @@ type Firewall struct { Status string `json:"status"` PolicyID string `json:"firewall_policy_id"` TenantID string `json:"tenant_id"` + ProjectID string `json:"project_id"` } type commonResult struct { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/testing/requests_test.go new file mode 100644 index 00000000..13eca65b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls/testing/requests_test.go @@ -0,0 +1,341 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewalls":[ + { + "status": "ACTIVE", + "name": "fw1", + "admin_state_up": false, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e28a", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", + "description": "OpenStack firewall 1" + }, + { + "status": "PENDING_UPDATE", + "name": "fw2", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e299", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f99", + "description": "OpenStack firewall 2" + } + ] +} + `) + }) + + count := 0 + + firewalls.List(fake.ServiceClient(), firewalls.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := firewalls.ExtractFirewalls(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []firewalls.Firewall{ + { + Status: "ACTIVE", + Name: "fw1", + AdminStateUp: false, + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + PolicyID: "34be8c83-4d42-4dca-a74e-b77fffb8e28a", + ID: "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", + Description: "OpenStack firewall 1", + }, + { + Status: "PENDING_UPDATE", + Name: "fw2", + AdminStateUp: true, + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + PolicyID: "34be8c83-4d42-4dca-a74e-b77fffb8e299", + ID: "fb5b5315-64f6-4ea3-8e58-981cc37c6f99", + Description: "OpenStack firewall 2", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewalls":[ + { + "status": "ACTIVE", + "name": "fw1", + "admin_state_up": false, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e28a", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", + "description": "OpenStack firewall 1", + "router_ids": ["abcd1234"] + }, + { + "status": "PENDING_UPDATE", + "name": "fw2", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e299", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f99", + "description": "OpenStack firewall 2" + } + ] +} + `) + }) + + type FirewallsWithExt struct { + firewalls.Firewall + routerinsertion.FirewallExt + } + + allPages, err := firewalls.List(fake.ServiceClient(), nil).AllPages() + th.AssertNoErr(t, err) + + var actual []FirewallsWithExt + err = firewalls.ExtractFirewallsInto(allPages, &actual) + th.AssertNoErr(t, err) + th.AssertEquals(t, 2, len(actual)) + th.AssertEquals(t, "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", actual[0].ID) + th.AssertEquals(t, "abcd1234", actual[0].RouterIDs[0]) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall":{ + "status": "PENDING_CREATE", + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c" + } +} + `) + }) + + options := firewalls.CreateOpts{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "fw", + Description: "OpenStack firewall", + AdminStateUp: gophercloud.Enabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + _, err := firewalls.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/fb5b5315-64f6-4ea3-8e58-981cc37c6f61", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall": { + "status": "ACTIVE", + "name": "fw", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e28a", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", + "description": "OpenStack firewall" + } +} + `) + }) + + fw, err := firewalls.Get(fake.ServiceClient(), "fb5b5315-64f6-4ea3-8e58-981cc37c6f61").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "ACTIVE", fw.Status) + th.AssertEquals(t, "fw", fw.Name) + th.AssertEquals(t, "OpenStack firewall", fw.Description) + th.AssertEquals(t, true, fw.AdminStateUp) + th.AssertEquals(t, "34be8c83-4d42-4dca-a74e-b77fffb8e28a", fw.PolicyID) + th.AssertEquals(t, "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", fw.ID) + th.AssertEquals(t, "b4eedccc6fb74fa8a7ad6b08382b852b", fw.TenantID) +} + +func TestGetWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/fb5b5315-64f6-4ea3-8e58-981cc37c6f61", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall": { + "status": "ACTIVE", + "name": "fw", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e28a", + "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", + "description": "OpenStack firewall", + "router_ids": ["abcd1234"] + } +} + `) + }) + + var fw struct { + firewalls.Firewall + routerinsertion.FirewallExt + } + + err := firewalls.Get(fake.ServiceClient(), "fb5b5315-64f6-4ea3-8e58-981cc37c6f61").ExtractInto(&fw) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "ACTIVE", fw.Status) + th.AssertEquals(t, "fw", fw.Name) + th.AssertEquals(t, "OpenStack firewall", fw.Description) + th.AssertEquals(t, true, fw.AdminStateUp) + th.AssertEquals(t, "34be8c83-4d42-4dca-a74e-b77fffb8e28a", fw.PolicyID) + th.AssertEquals(t, "fb5b5315-64f6-4ea3-8e58-981cc37c6f61", fw.ID) + th.AssertEquals(t, "b4eedccc6fb74fa8a7ad6b08382b852b", fw.TenantID) + th.AssertEquals(t, "abcd1234", fw.RouterIDs[0]) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/ea5b5315-64f6-4ea3-8e58-981cc37c6576", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "updated fw", + "admin_state_up":false, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall": { + "status": "ACTIVE", + "name": "fw", + "admin_state_up": false, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "id": "ea5b5315-64f6-4ea3-8e58-981cc37c6576", + "description": "OpenStack firewall" + } +} + `) + }) + + options := firewalls.UpdateOpts{ + Name: "fw", + Description: "updated fw", + AdminStateUp: gophercloud.Disabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + + _, err := firewalls.Update(fake.ServiceClient(), "ea5b5315-64f6-4ea3-8e58-981cc37c6576", options).Extract() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := firewalls.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/requests.go index b1a6a559..40ab7a8c 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/requests.go @@ -18,6 +18,7 @@ type ListOptsBuilder interface { // and is either `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Name string `q:"name"` Description string `q:"description"` Shared *bool `q:"shared"` @@ -67,6 +68,7 @@ type CreateOpts struct { // an admin role in order to set this. Otherwise, this field is left unset // and the caller will be the owner. TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Shared *bool `json:"shared,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/results.go index bbe22b13..495cef2c 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/results.go @@ -11,6 +11,7 @@ type Policy struct { Name string `json:"name"` Description string `json:"description"` TenantID string `json:"tenant_id"` + ProjectID string `json:"project_id"` Audited bool `json:"audited"` Shared bool `json:"shared"` Rules []string `json:"firewall_rules,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/testing/requests_test.go new file mode 100644 index 00000000..11b9848f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies/testing/requests_test.go @@ -0,0 +1,274 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_policies": [ + { + "name": "policy1", + "firewall_rules": [ + "75452b36-268e-4e75-aaf4-f0e7ed50bc97", + "c9e77ca0-1bc8-497d-904d-948107873dc6" + ], + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": true, + "shared": false, + "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + "description": "Firewall policy 1" + }, + { + "name": "policy2", + "firewall_rules": [ + "03d2a6ad-633f-431a-8463-4370d06a22c8" + ], + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": false, + "shared": true, + "id": "c854fab5-bdaf-4a86-9359-78de93e5df01", + "description": "Firewall policy 2" + } + ] +} + `) + }) + + count := 0 + + policies.List(fake.ServiceClient(), policies.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := policies.ExtractPolicies(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []policies.Policy{ + { + Name: "policy1", + Rules: []string{ + "75452b36-268e-4e75-aaf4-f0e7ed50bc97", + "c9e77ca0-1bc8-497d-904d-948107873dc6", + }, + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + Audited: true, + Shared: false, + ID: "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + Description: "Firewall policy 1", + }, + { + Name: "policy2", + Rules: []string{ + "03d2a6ad-633f-431a-8463-4370d06a22c8", + }, + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + Audited: false, + Shared: true, + ID: "c854fab5-bdaf-4a86-9359-78de93e5df01", + Description: "Firewall policy 2", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall_policy":{ + "name": "policy", + "firewall_rules": [ + "98a58c87-76be-ae7c-a74e-b77fffb88d95", + "11a58c87-76be-ae7c-a74e-b77fffb88a32" + ], + "description": "Firewall policy", + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": true, + "shared": false + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall_policy":{ + "name": "policy", + "firewall_rules": [ + "98a58c87-76be-ae7c-a74e-b77fffb88d95", + "11a58c87-76be-ae7c-a74e-b77fffb88a32" + ], + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": false, + "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + "description": "Firewall policy" + } +} + `) + }) + + options := policies.CreateOpts{ + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + Name: "policy", + Description: "Firewall policy", + Shared: gophercloud.Disabled, + Audited: gophercloud.Enabled, + Rules: []string{ + "98a58c87-76be-ae7c-a74e-b77fffb88d95", + "11a58c87-76be-ae7c-a74e-b77fffb88a32", + }, + } + + _, err := policies.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_policies/bcab5315-64f6-4ea3-8e58-981cc37c6f61", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_policy":{ + "name": "www", + "firewall_rules": [ + "75452b36-268e-4e75-aaf4-f0e7ed50bc97", + "c9e77ca0-1bc8-497d-904d-948107873dc6", + "03d2a6ad-633f-431a-8463-4370d06a22c8" + ], + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": false, + "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + "description": "Firewall policy web" + } +} + `) + }) + + policy, err := policies.Get(fake.ServiceClient(), "bcab5315-64f6-4ea3-8e58-981cc37c6f61").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "www", policy.Name) + th.AssertEquals(t, "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", policy.ID) + th.AssertEquals(t, "Firewall policy web", policy.Description) + th.AssertEquals(t, 3, len(policy.Rules)) + th.AssertEquals(t, "75452b36-268e-4e75-aaf4-f0e7ed50bc97", policy.Rules[0]) + th.AssertEquals(t, "c9e77ca0-1bc8-497d-904d-948107873dc6", policy.Rules[1]) + th.AssertEquals(t, "03d2a6ad-633f-431a-8463-4370d06a22c8", policy.Rules[2]) + th.AssertEquals(t, "9145d91459d248b1b02fdaca97c6a75d", policy.TenantID) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_policies/f2b08c1e-aa81-4668-8ae1-1401bcb0576c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall_policy":{ + "name": "policy", + "firewall_rules": [ + "98a58c87-76be-ae7c-a74e-b77fffb88d95", + "11a58c87-76be-ae7c-a74e-b77fffb88a32" + ], + "description": "Firewall policy" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_policy":{ + "name": "policy", + "firewall_rules": [ + "75452b36-268e-4e75-aaf4-f0e7ed50bc97", + "c9e77ca0-1bc8-497d-904d-948107873dc6", + "03d2a6ad-633f-431a-8463-4370d06a22c8" + ], + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "audited": false, + "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + "description": "Firewall policy" + } +} + `) + }) + + options := policies.UpdateOpts{ + Name: "policy", + Description: "Firewall policy", + Rules: []string{ + "98a58c87-76be-ae7c-a74e-b77fffb88d95", + "11a58c87-76be-ae7c-a74e-b77fffb88a32", + }, + } + + _, err := policies.Update(fake.ServiceClient(), "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", options).Extract() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_policies/4ec89077-d057-4a2b-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := policies.Delete(fake.ServiceClient(), "4ec89077-d057-4a2b-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion/testing/requests_test.go new file mode 100644 index 00000000..ac7a2be8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion/testing/requests_test.go @@ -0,0 +1,235 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "router_ids": [ + "8a3a0d6a-34b5-4a92-b65d-6375a4c1e9e8" + ] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall":{ + "status": "PENDING_CREATE", + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c" + } +} + `) + }) + + firewallCreateOpts := firewalls.CreateOpts{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "fw", + Description: "OpenStack firewall", + AdminStateUp: gophercloud.Enabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + createOpts := routerinsertion.CreateOptsExt{ + CreateOptsBuilder: firewallCreateOpts, + RouterIDs: []string{"8a3a0d6a-34b5-4a92-b65d-6375a4c1e9e8"}, + } + + _, err := firewalls.Create(fake.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) +} + +func TestCreateWithNoRouters(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "router_ids": [] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall":{ + "status": "PENDING_CREATE", + "name": "fw", + "description": "OpenStack firewall", + "admin_state_up": true, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c" + } +} + `) + }) + + firewallCreateOpts := firewalls.CreateOpts{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "fw", + Description: "OpenStack firewall", + AdminStateUp: gophercloud.Enabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + createOpts := routerinsertion.CreateOptsExt{ + CreateOptsBuilder: firewallCreateOpts, + RouterIDs: []string{}, + } + + _, err := firewalls.Create(fake.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/ea5b5315-64f6-4ea3-8e58-981cc37c6576", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "updated fw", + "admin_state_up":false, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "router_ids": [ + "8a3a0d6a-34b5-4a92-b65d-6375a4c1e9e8" + ] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall": { + "status": "ACTIVE", + "name": "fw", + "admin_state_up": false, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "id": "ea5b5315-64f6-4ea3-8e58-981cc37c6576", + "description": "OpenStack firewall" + } +} + `) + }) + + firewallUpdateOpts := firewalls.UpdateOpts{ + Name: "fw", + Description: "updated fw", + AdminStateUp: gophercloud.Disabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + updateOpts := routerinsertion.UpdateOptsExt{ + UpdateOptsBuilder: firewallUpdateOpts, + RouterIDs: []string{"8a3a0d6a-34b5-4a92-b65d-6375a4c1e9e8"}, + } + + _, err := firewalls.Update(fake.ServiceClient(), "ea5b5315-64f6-4ea3-8e58-981cc37c6576", updateOpts).Extract() + th.AssertNoErr(t, err) +} + +func TestUpdateWithNoRouters(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewalls/ea5b5315-64f6-4ea3-8e58-981cc37c6576", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall":{ + "name": "fw", + "description": "updated fw", + "admin_state_up":false, + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "router_ids": [] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall": { + "status": "ACTIVE", + "name": "fw", + "admin_state_up": false, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + "id": "ea5b5315-64f6-4ea3-8e58-981cc37c6576", + "description": "OpenStack firewall" + } +} + `) + }) + + firewallUpdateOpts := firewalls.UpdateOpts{ + Name: "fw", + Description: "updated fw", + AdminStateUp: gophercloud.Disabled, + PolicyID: "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c", + } + updateOpts := routerinsertion.UpdateOptsExt{ + UpdateOptsBuilder: firewallUpdateOpts, + RouterIDs: []string{}, + } + + _, err := firewalls.Update(fake.ServiceClient(), "ea5b5315-64f6-4ea3-8e58-981cc37c6576", updateOpts).Extract() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/requests.go index 83bbe99b..17979b63 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/requests.go @@ -37,6 +37,7 @@ type ListOptsBuilder interface { // is either `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Name string `q:"name"` Description string `q:"description"` Protocol string `q:"protocol"` @@ -96,6 +97,7 @@ type CreateOpts struct { Protocol Protocol `json:"protocol" required:"true"` Action string `json:"action" required:"true"` TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` IPVersion gophercloud.IPVersion `json:"ip_version,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/results.go index 1af03e57..82bf4a36 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/results.go @@ -22,6 +22,7 @@ type Rule struct { PolicyID string `json:"firewall_policy_id"` Position int `json:"position"` TenantID string `json:"tenant_id"` + ProjectID string `json:"project_id"` } // RulePage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/testing/requests_test.go new file mode 100644 index 00000000..2fedfa8a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules/testing/requests_test.go @@ -0,0 +1,381 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_rules": [ + { + "protocol": "tcp", + "description": "ssh rule", + "source_port": null, + "source_ip_address": null, + "destination_ip_address": "192.168.1.0/24", + "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", + "position": 2, + "destination_port": "22", + "id": "f03bd950-6c56-4f5e-a307-45967078f507", + "name": "ssh_form_any", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": true, + "action": "allow", + "ip_version": 4, + "shared": false + }, + { + "protocol": "udp", + "description": "udp rule", + "source_port": null, + "source_ip_address": null, + "destination_ip_address": null, + "firewall_policy_id": "98d7fb51-698c-4123-87e8-f1eee6b5ab7e", + "position": 1, + "destination_port": null, + "id": "ab7bd950-6c56-4f5e-a307-45967078f890", + "name": "deny_all_udp", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": true, + "action": "deny", + "ip_version": 4, + "shared": false + } + ] +} + `) + }) + + count := 0 + + rules.List(fake.ServiceClient(), rules.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := rules.ExtractRules(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []rules.Rule{ + { + Protocol: "tcp", + Description: "ssh rule", + SourcePort: "", + SourceIPAddress: "", + DestinationIPAddress: "192.168.1.0/24", + PolicyID: "e2a5fb51-698c-4898-87e8-f1eee6b50919", + Position: 2, + DestinationPort: "22", + ID: "f03bd950-6c56-4f5e-a307-45967078f507", + Name: "ssh_form_any", + TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61", + Enabled: true, + Action: "allow", + IPVersion: 4, + Shared: false, + }, + { + Protocol: "udp", + Description: "udp rule", + SourcePort: "", + SourceIPAddress: "", + DestinationIPAddress: "", + PolicyID: "98d7fb51-698c-4123-87e8-f1eee6b5ab7e", + Position: 1, + DestinationPort: "", + ID: "ab7bd950-6c56-4f5e-a307-45967078f890", + Name: "deny_all_udp", + TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61", + Enabled: true, + Action: "deny", + IPVersion: 4, + Shared: false, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall_rule": { + "protocol": "tcp", + "description": "ssh rule", + "destination_ip_address": "192.168.1.0/24", + "destination_port": "22", + "name": "ssh_form_any", + "action": "allow", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall_rule":{ + "protocol": "tcp", + "description": "ssh rule", + "source_port": null, + "source_ip_address": null, + "destination_ip_address": "192.168.1.0/24", + "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", + "position": 2, + "destination_port": "22", + "id": "f03bd950-6c56-4f5e-a307-45967078f507", + "name": "ssh_form_any", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": true, + "action": "allow", + "ip_version": 4, + "shared": false + } +} + `) + }) + + options := rules.CreateOpts{ + TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61", + Protocol: rules.ProtocolTCP, + Description: "ssh rule", + DestinationIPAddress: "192.168.1.0/24", + DestinationPort: "22", + Name: "ssh_form_any", + Action: "allow", + } + + _, err := rules.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestCreateAnyProtocol(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall_rule": { + "protocol": null, + "description": "any to 192.168.1.0/24", + "destination_ip_address": "192.168.1.0/24", + "name": "any_to_192.168.1.0/24", + "action": "allow", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "firewall_rule":{ + "protocol": null, + "description": "any to 192.168.1.0/24", + "source_port": null, + "source_ip_address": null, + "destination_ip_address": "192.168.1.0/24", + "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", + "position": 2, + "destination_port": null, + "id": "f03bd950-6c56-4f5e-a307-45967078f507", + "name": "any_to_192.168.1.0/24", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": true, + "action": "allow", + "ip_version": 4, + "shared": false + } +} + `) + }) + + options := rules.CreateOpts{ + TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61", + Protocol: rules.ProtocolAny, + Description: "any to 192.168.1.0/24", + DestinationIPAddress: "192.168.1.0/24", + Name: "any_to_192.168.1.0/24", + Action: "allow", + } + + _, err := rules.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules/f03bd950-6c56-4f5e-a307-45967078f507", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_rule":{ + "protocol": "tcp", + "description": "ssh rule", + "source_port": null, + "source_ip_address": null, + "destination_ip_address": "192.168.1.0/24", + "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", + "position": 2, + "destination_port": "22", + "id": "f03bd950-6c56-4f5e-a307-45967078f507", + "name": "ssh_form_any", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": true, + "action": "allow", + "ip_version": 4, + "shared": false + } +} + `) + }) + + rule, err := rules.Get(fake.ServiceClient(), "f03bd950-6c56-4f5e-a307-45967078f507").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "tcp", rule.Protocol) + th.AssertEquals(t, "ssh rule", rule.Description) + th.AssertEquals(t, "192.168.1.0/24", rule.DestinationIPAddress) + th.AssertEquals(t, "e2a5fb51-698c-4898-87e8-f1eee6b50919", rule.PolicyID) + th.AssertEquals(t, 2, rule.Position) + th.AssertEquals(t, "22", rule.DestinationPort) + th.AssertEquals(t, "f03bd950-6c56-4f5e-a307-45967078f507", rule.ID) + th.AssertEquals(t, "ssh_form_any", rule.Name) + th.AssertEquals(t, "80cf934d6ffb4ef5b244f1c512ad1e61", rule.TenantID) + th.AssertEquals(t, true, rule.Enabled) + th.AssertEquals(t, "allow", rule.Action) + th.AssertEquals(t, 4, rule.IPVersion) + th.AssertEquals(t, false, rule.Shared) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules/f03bd950-6c56-4f5e-a307-45967078f507", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "firewall_rule":{ + "protocol": "tcp", + "description": "ssh rule", + "destination_ip_address": "192.168.1.0/24", + "destination_port": "22", + "name": "ssh_form_any", + "action": "allow", + "enabled": false + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "firewall_rule":{ + "protocol": "tcp", + "description": "ssh rule", + "destination_ip_address": "192.168.1.0/24", + "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", + "position": 2, + "destination_port": "22", + "id": "f03bd950-6c56-4f5e-a307-45967078f507", + "name": "ssh_form_any", + "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", + "enabled": false, + "action": "allow", + "ip_version": 4, + "shared": false + } +} + `) + }) + + newProtocol := "tcp" + newDescription := "ssh rule" + newDestinationIP := "192.168.1.0/24" + newDestintionPort := "22" + newName := "ssh_form_any" + newAction := "allow" + + options := rules.UpdateOpts{ + Protocol: &newProtocol, + Description: &newDescription, + DestinationIPAddress: &newDestinationIP, + DestinationPort: &newDestintionPort, + Name: &newName, + Action: &newAction, + Enabled: gophercloud.Disabled, + } + + _, err := rules.Update(fake.ServiceClient(), "f03bd950-6c56-4f5e-a307-45967078f507", options).Extract() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/fw/firewall_rules/4ec89077-d057-4a2b-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := rules.Delete(fake.ServiceClient(), "4ec89077-d057-4a2b-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go index 0a6eb62c..d82a1bc8 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go @@ -17,6 +17,7 @@ type ListOpts struct { FixedIP string `q:"fixed_ip_address"` FloatingIP string `q:"floating_ip_address"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Limit int `q:"limit"` Marker string `q:"marker"` SortKey string `q:"sort_key"` @@ -55,6 +56,7 @@ type CreateOpts struct { FixedIP string `json:"fixed_ip_address,omitempty"` SubnetID string `json:"subnet_id,omitempty"` TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` } // ToFloatingIPCreateMap allows CreateOpts to satisfy the CreateOptsBuilder diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/results.go index f1af23d4..8b1a5176 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/results.go @@ -30,10 +30,13 @@ type FloatingIP struct { // associated with the floating IP. FixedIP string `json:"fixed_ip_address"` - // TenantID is the Owner of the floating IP. Only admin users can specify a - // tenant identifier other than its own. + // TenantID is the project owner of the floating IP. Only admin users can + // specify a project identifier other than its own. TenantID string `json:"tenant_id"` + // ProjectID is the project owner of the floating IP. + ProjectID string `json:"project_id"` + // Status is the condition of the API resource. Status string `json:"status"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/testing/requests_test.go new file mode 100644 index 00000000..89c028e8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/testing/requests_test.go @@ -0,0 +1,415 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "floatingips": [ + { + "floating_network_id": "6d67c30a-ddb4-49a1-bec3-a65b286b4170", + "router_id": null, + "fixed_ip_address": null, + "floating_ip_address": "192.0.0.4", + "tenant_id": "017d8de156df4177889f31a9bd6edc00", + "status": "DOWN", + "port_id": null, + "id": "2f95fd2b-9f6a-4e8e-9e9a-2cbe286cbf9e", + "router_id": "1117c30a-ddb4-49a1-bec3-a65b286b4170" + }, + { + "floating_network_id": "90f742b1-6d17-487b-ba95-71881dbc0b64", + "router_id": "0a24cb83-faf5-4d7f-b723-3144ed8a2167", + "fixed_ip_address": "192.0.0.2", + "floating_ip_address": "10.0.0.3", + "tenant_id": "017d8de156df4177889f31a9bd6edc00", + "status": "DOWN", + "port_id": "74a342ce-8e07-4e91-880c-9f834b68fa25", + "id": "ada25a95-f321-4f59-b0e0-f3a970dd3d63", + "router_id": "2227c30a-ddb4-49a1-bec3-a65b286b4170" + } + ] +} + `) + }) + + count := 0 + + floatingips.List(fake.ServiceClient(), floatingips.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := floatingips.ExtractFloatingIPs(page) + if err != nil { + t.Errorf("Failed to extract floating IPs: %v", err) + return false, err + } + + expected := []floatingips.FloatingIP{ + { + FloatingNetworkID: "6d67c30a-ddb4-49a1-bec3-a65b286b4170", + FixedIP: "", + FloatingIP: "192.0.0.4", + TenantID: "017d8de156df4177889f31a9bd6edc00", + Status: "DOWN", + PortID: "", + ID: "2f95fd2b-9f6a-4e8e-9e9a-2cbe286cbf9e", + RouterID: "1117c30a-ddb4-49a1-bec3-a65b286b4170", + }, + { + FloatingNetworkID: "90f742b1-6d17-487b-ba95-71881dbc0b64", + FixedIP: "192.0.0.2", + FloatingIP: "10.0.0.3", + TenantID: "017d8de156df4177889f31a9bd6edc00", + Status: "DOWN", + PortID: "74a342ce-8e07-4e91-880c-9f834b68fa25", + ID: "ada25a95-f321-4f59-b0e0-f3a970dd3d63", + RouterID: "2227c30a-ddb4-49a1-bec3-a65b286b4170", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestInvalidNextPageURLs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, `{"floatingips": [{}], "floatingips_links": {}}`) + }) + + floatingips.List(fake.ServiceClient(), floatingips.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + floatingips.ExtractFloatingIPs(page) + return true, nil + }) +} + +func TestRequiredFieldsForCreate(t *testing.T) { + res1 := floatingips.Create(fake.ServiceClient(), floatingips.CreateOpts{FloatingNetworkID: ""}) + if res1.Err == nil { + t.Fatalf("Expected error, got none") + } + + res2 := floatingips.Create(fake.ServiceClient(), floatingips.CreateOpts{FloatingNetworkID: "foo", PortID: ""}) + if res2.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "floatingip": { + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "floatingip": { + "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f", + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": "10.0.0.3", + "floating_ip_address": "", + "port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab", + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7" + } +} + `) + }) + + options := floatingips.CreateOpts{ + FloatingNetworkID: "376da547-b977-4cfe-9cba-275c80debf57", + PortID: "ce705c24-c1ef-408a-bda3-7bbd946164ab", + } + + ip, err := floatingips.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "2f245a7b-796b-4f26-9cf9-9e82d248fda7", ip.ID) + th.AssertEquals(t, "4969c491a3c74ee4af974e6d800c62de", ip.TenantID) + th.AssertEquals(t, "376da547-b977-4cfe-9cba-275c80debf57", ip.FloatingNetworkID) + th.AssertEquals(t, "", ip.FloatingIP) + th.AssertEquals(t, "ce705c24-c1ef-408a-bda3-7bbd946164ab", ip.PortID) + th.AssertEquals(t, "10.0.0.3", ip.FixedIP) +} + +func TestCreateEmptyPort(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "floatingip": { + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57" + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` + { + "floatingip": { + "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f", + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": "10.0.0.3", + "floating_ip_address": "", + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7" + } + } + `) + }) + + options := floatingips.CreateOpts{ + FloatingNetworkID: "376da547-b977-4cfe-9cba-275c80debf57", + } + + ip, err := floatingips.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "2f245a7b-796b-4f26-9cf9-9e82d248fda7", ip.ID) + th.AssertEquals(t, "4969c491a3c74ee4af974e6d800c62de", ip.TenantID) + th.AssertEquals(t, "376da547-b977-4cfe-9cba-275c80debf57", ip.FloatingNetworkID) + th.AssertEquals(t, "", ip.FloatingIP) + th.AssertEquals(t, "", ip.PortID) + th.AssertEquals(t, "10.0.0.3", ip.FixedIP) +} + +func TestCreateWithSubnetID(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "floatingip": { + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "subnet_id": "37adf01c-24db-467a-b845-7ab1e8216c01" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "floatingip": { + "router_id": null, + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": null, + "floating_ip_address": "172.24.4.3", + "port_id": null, + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7" + } +} + `) + }) + + options := floatingips.CreateOpts{ + FloatingNetworkID: "376da547-b977-4cfe-9cba-275c80debf57", + SubnetID: "37adf01c-24db-467a-b845-7ab1e8216c01", + } + + ip, err := floatingips.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "2f245a7b-796b-4f26-9cf9-9e82d248fda7", ip.ID) + th.AssertEquals(t, "4969c491a3c74ee4af974e6d800c62de", ip.TenantID) + th.AssertEquals(t, "376da547-b977-4cfe-9cba-275c80debf57", ip.FloatingNetworkID) + th.AssertEquals(t, "172.24.4.3", ip.FloatingIP) + th.AssertEquals(t, "", ip.PortID) + th.AssertEquals(t, "", ip.FixedIP) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips/2f245a7b-796b-4f26-9cf9-9e82d248fda7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "floatingip": { + "floating_network_id": "90f742b1-6d17-487b-ba95-71881dbc0b64", + "fixed_ip_address": "192.0.0.2", + "floating_ip_address": "10.0.0.3", + "tenant_id": "017d8de156df4177889f31a9bd6edc00", + "status": "DOWN", + "port_id": "74a342ce-8e07-4e91-880c-9f834b68fa25", + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7", + "router_id": "1117c30a-ddb4-49a1-bec3-a65b286b4170" + } +} + `) + }) + + ip, err := floatingips.Get(fake.ServiceClient(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "90f742b1-6d17-487b-ba95-71881dbc0b64", ip.FloatingNetworkID) + th.AssertEquals(t, "10.0.0.3", ip.FloatingIP) + th.AssertEquals(t, "74a342ce-8e07-4e91-880c-9f834b68fa25", ip.PortID) + th.AssertEquals(t, "192.0.0.2", ip.FixedIP) + th.AssertEquals(t, "017d8de156df4177889f31a9bd6edc00", ip.TenantID) + th.AssertEquals(t, "DOWN", ip.Status) + th.AssertEquals(t, "2f245a7b-796b-4f26-9cf9-9e82d248fda7", ip.ID) + th.AssertEquals(t, "1117c30a-ddb4-49a1-bec3-a65b286b4170", ip.RouterID) +} + +func TestAssociate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips/2f245a7b-796b-4f26-9cf9-9e82d248fda7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "floatingip": { + "port_id": "423abc8d-2991-4a55-ba98-2aaea84cc72e" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "floatingip": { + "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f", + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": null, + "floating_ip_address": "172.24.4.228", + "port_id": "423abc8d-2991-4a55-ba98-2aaea84cc72e", + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7" + } +} + `) + }) + + portID := "423abc8d-2991-4a55-ba98-2aaea84cc72e" + ip, err := floatingips.Update(fake.ServiceClient(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7", floatingips.UpdateOpts{PortID: &portID}).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, portID, ip.PortID) +} + +func TestDisassociate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips/2f245a7b-796b-4f26-9cf9-9e82d248fda7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "floatingip": { + "port_id": null + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "floatingip": { + "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f", + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": null, + "floating_ip_address": "172.24.4.228", + "port_id": null, + "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7" + } +} + `) + }) + + ip, err := floatingips.Update(fake.ServiceClient(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7", floatingips.UpdateOpts{PortID: nil}).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, "", ip.FixedIP) + th.AssertDeepEquals(t, "", ip.PortID) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/floatingips/2f245a7b-796b-4f26-9cf9-9e82d248fda7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := floatingips.Delete(fake.ServiceClient(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go index fa346c85..8b2bde53 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go @@ -17,6 +17,7 @@ type ListOpts struct { Distributed *bool `q:"distributed"` Status string `q:"status"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Limit int `q:"limit"` Marker string `q:"marker"` SortKey string `q:"sort_key"` @@ -53,6 +54,7 @@ type CreateOpts struct { AdminStateUp *bool `json:"admin_state_up,omitempty"` Distributed *bool `json:"distributed,omitempty"` TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"` AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"` } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go index da1b9e4b..dffdce8f 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go @@ -54,10 +54,13 @@ type Router struct { // ID is the unique identifier for the router. ID string `json:"id"` - // TenantID is the owner of the router. Only admin users can specify a tenant - // identifier other than its own. + // TenantID is the project owner of the router. Only admin users can + // specify a project identifier other than its own. TenantID string `json:"tenant_id"` + // ProjectID is the project owner of the router. + ProjectID string `json:"project_id"` + // Routes are a collection of static routes that the router will host. Routes []Route `json:"routes"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/testing/requests_test.go new file mode 100644 index 00000000..2f7b93d4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers/testing/requests_test.go @@ -0,0 +1,471 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "routers": [ + { + "status": "ACTIVE", + "external_gateway_info": null, + "name": "second_routers", + "admin_state_up": true, + "tenant_id": "6b96ff0cb17a4b859e1e575d221683d3", + "distributed": false, + "id": "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b" + }, + { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "3c5bcddd-6af9-4e6b-9c3e-c153e521cab8" + }, + "name": "router1", + "admin_state_up": true, + "tenant_id": "33a40233088643acb66ff6eb0ebea679", + "distributed": false, + "id": "a9254bdb-2613-4a13-ac4c-adc581fba50d" + }, + { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "2b37576e-b050-4891-8b20-e1e37a93942a", + "external_fixed_ips": [ + {"ip_address": "192.0.2.17", "subnet_id": "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def"}, + {"ip_address": "198.51.100.33", "subnet_id": "1d699529-bdfd-43f8-bcaa-bff00c547af2"} + ] + }, + "name": "gateway", + "admin_state_up": true, + "tenant_id": "a3e881e0a6534880c5473d95b9442099", + "distributed": false, + "id": "308a035c-005d-4452-a9fe-6f8f2f0c28d8" + } + ] +} + `) + }) + + count := 0 + + routers.List(fake.ServiceClient(), routers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := routers.ExtractRouters(page) + if err != nil { + t.Errorf("Failed to extract routers: %v", err) + return false, err + } + + expected := []routers.Router{ + { + Status: "ACTIVE", + GatewayInfo: routers.GatewayInfo{NetworkID: ""}, + AdminStateUp: true, + Distributed: false, + Name: "second_routers", + ID: "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b", + TenantID: "6b96ff0cb17a4b859e1e575d221683d3", + }, + { + Status: "ACTIVE", + GatewayInfo: routers.GatewayInfo{NetworkID: "3c5bcddd-6af9-4e6b-9c3e-c153e521cab8"}, + AdminStateUp: true, + Distributed: false, + Name: "router1", + ID: "a9254bdb-2613-4a13-ac4c-adc581fba50d", + TenantID: "33a40233088643acb66ff6eb0ebea679", + }, + { + Status: "ACTIVE", + GatewayInfo: routers.GatewayInfo{ + NetworkID: "2b37576e-b050-4891-8b20-e1e37a93942a", + ExternalFixedIPs: []routers.ExternalFixedIP{ + {IPAddress: "192.0.2.17", SubnetID: "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def"}, + {IPAddress: "198.51.100.33", SubnetID: "1d699529-bdfd-43f8-bcaa-bff00c547af2"}, + }, + }, + AdminStateUp: true, + Distributed: false, + Name: "gateway", + ID: "308a035c-005d-4452-a9fe-6f8f2f0c28d8", + TenantID: "a3e881e0a6534880c5473d95b9442099", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "router":{ + "name": "foo_router", + "admin_state_up": false, + "external_gateway_info":{ + "enable_snat": false, + "network_id":"8ca37218-28ff-41cb-9b10-039601ea7e6b" + }, + "availability_zone_hints": ["zone1", "zone2"] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "router": { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b", + "enable_snat": false, + "external_fixed_ips": [ + {"ip_address": "192.0.2.17", "subnet_id": "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def"} + ] + }, + "name": "foo_router", + "admin_state_up": false, + "tenant_id": "6b96ff0cb17a4b859e1e575d221683d3", + "distributed": false, + "availability_zone_hints": ["zone1", "zone2"], + "id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e" + } +} + `) + }) + + asu := false + enableSNAT := false + gwi := routers.GatewayInfo{ + NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b", + EnableSNAT: &enableSNAT, + } + options := routers.CreateOpts{ + Name: "foo_router", + AdminStateUp: &asu, + GatewayInfo: &gwi, + AvailabilityZoneHints: []string{"zone1", "zone2"}, + } + r, err := routers.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + gwi.ExternalFixedIPs = []routers.ExternalFixedIP{{ + IPAddress: "192.0.2.17", + SubnetID: "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def", + }} + + th.AssertEquals(t, "foo_router", r.Name) + th.AssertEquals(t, false, r.AdminStateUp) + th.AssertDeepEquals(t, gwi, r.GatewayInfo) + th.AssertDeepEquals(t, []string{"zone1", "zone2"}, r.AvailabilityZoneHints) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/a07eea83-7710-4860-931b-5fe220fae533", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "router": { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "85d76829-6415-48ff-9c63-5c5ca8c61ac6", + "external_fixed_ips": [ + {"ip_address": "198.51.100.33", "subnet_id": "1d699529-bdfd-43f8-bcaa-bff00c547af2"} + ] + }, + "routes": [ + { + "nexthop": "10.1.0.10", + "destination": "40.0.1.0/24" + } + ], + "name": "router1", + "admin_state_up": true, + "tenant_id": "d6554fe62e2f41efbb6e026fad5c1542", + "distributed": false, + "availability_zone_hints": ["zone1", "zone2"], + "id": "a07eea83-7710-4860-931b-5fe220fae533" + } +} + `) + }) + + n, err := routers.Get(fake.ServiceClient(), "a07eea83-7710-4860-931b-5fe220fae533").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "ACTIVE") + th.AssertDeepEquals(t, n.GatewayInfo, routers.GatewayInfo{ + NetworkID: "85d76829-6415-48ff-9c63-5c5ca8c61ac6", + ExternalFixedIPs: []routers.ExternalFixedIP{ + {IPAddress: "198.51.100.33", SubnetID: "1d699529-bdfd-43f8-bcaa-bff00c547af2"}, + }, + }) + th.AssertEquals(t, n.Name, "router1") + th.AssertEquals(t, n.AdminStateUp, true) + th.AssertEquals(t, n.TenantID, "d6554fe62e2f41efbb6e026fad5c1542") + th.AssertEquals(t, n.ID, "a07eea83-7710-4860-931b-5fe220fae533") + th.AssertDeepEquals(t, n.Routes, []routers.Route{{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}}) + th.AssertDeepEquals(t, n.AvailabilityZoneHints, []string{"zone1", "zone2"}) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "router": { + "name": "new_name", + "external_gateway_info": { + "network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b" + }, + "routes": [ + { + "nexthop": "10.1.0.10", + "destination": "40.0.1.0/24" + } + ] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "router": { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b", + "external_fixed_ips": [ + {"ip_address": "192.0.2.17", "subnet_id": "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def"} + ] + }, + "name": "new_name", + "admin_state_up": true, + "tenant_id": "6b96ff0cb17a4b859e1e575d221683d3", + "distributed": false, + "id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e", + "routes": [ + { + "nexthop": "10.1.0.10", + "destination": "40.0.1.0/24" + } + ] + } +} + `) + }) + + gwi := routers.GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"} + r := []routers.Route{{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}} + options := routers.UpdateOpts{Name: "new_name", GatewayInfo: &gwi, Routes: r} + + n, err := routers.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).Extract() + th.AssertNoErr(t, err) + + gwi.ExternalFixedIPs = []routers.ExternalFixedIP{ + {IPAddress: "192.0.2.17", SubnetID: "ab561bc4-1a8e-48f2-9fbd-376fcb1a1def"}, + } + + th.AssertEquals(t, n.Name, "new_name") + th.AssertDeepEquals(t, n.GatewayInfo, gwi) + th.AssertDeepEquals(t, n.Routes, []routers.Route{{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}}) +} + +func TestAllRoutesRemoved(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "router": { + "routes": [] + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "router": { + "status": "ACTIVE", + "external_gateway_info": { + "network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b" + }, + "name": "name", + "admin_state_up": true, + "tenant_id": "6b96ff0cb17a4b859e1e575d221683d3", + "distributed": false, + "id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e", + "routes": [] + } +} + `) + }) + + r := []routers.Route{} + options := routers.UpdateOpts{Routes: r} + + n, err := routers.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, n.Routes, []routers.Route{}) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := routers.Delete(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c") + th.AssertNoErr(t, res.Err) +} + +func TestAddInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/4e8e5957-649f-477b-9e5b-f1f75b21c03c/add_router_interface", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "subnet_id": "a2f1f29d-571b-4533-907f-5803ab96ead1" +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "subnet_id": "0d32a837-8069-4ec3-84c4-3eef3e10b188", + "tenant_id": "017d8de156df4177889f31a9bd6edc00", + "port_id": "3f990102-4485-4df1-97a0-2c35bdb85b31", + "id": "9a83fa11-8da5-436e-9afe-3d3ac5ce7770" +} +`) + }) + + opts := routers.AddInterfaceOpts{SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1"} + res, err := routers.AddInterface(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "0d32a837-8069-4ec3-84c4-3eef3e10b188", res.SubnetID) + th.AssertEquals(t, "017d8de156df4177889f31a9bd6edc00", res.TenantID) + th.AssertEquals(t, "3f990102-4485-4df1-97a0-2c35bdb85b31", res.PortID) + th.AssertEquals(t, "9a83fa11-8da5-436e-9afe-3d3ac5ce7770", res.ID) +} + +func TestAddInterfaceRequiredOpts(t *testing.T) { + _, err := routers.AddInterface(fake.ServiceClient(), "foo", routers.AddInterfaceOpts{}).Extract() + if err == nil { + t.Fatalf("Expected error, got none") + } + _, err = routers.AddInterface(fake.ServiceClient(), "foo", routers.AddInterfaceOpts{SubnetID: "bar", PortID: "baz"}).Extract() + if err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestRemoveInterface(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/routers/4e8e5957-649f-477b-9e5b-f1f75b21c03c/remove_router_interface", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "subnet_id": "a2f1f29d-571b-4533-907f-5803ab96ead1" +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "subnet_id": "0d32a837-8069-4ec3-84c4-3eef3e10b188", + "tenant_id": "017d8de156df4177889f31a9bd6edc00", + "port_id": "3f990102-4485-4df1-97a0-2c35bdb85b31", + "id": "9a83fa11-8da5-436e-9afe-3d3ac5ce7770" +} +`) + }) + + opts := routers.RemoveInterfaceOpts{SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1"} + res, err := routers.RemoveInterface(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "0d32a837-8069-4ec3-84c4-3eef3e10b188", res.SubnetID) + th.AssertEquals(t, "017d8de156df4177889f31a9bd6edc00", res.TenantID) + th.AssertEquals(t, "3f990102-4485-4df1-97a0-2c35bdb85b31", res.PortID) + th.AssertEquals(t, "9a83fa11-8da5-436e-9afe-3d3ac5ce7770", res.ID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members/testing/requests_test.go new file mode 100644 index 00000000..3e4f1d43 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members/testing/requests_test.go @@ -0,0 +1,238 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/members", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "members":[ + { + "status":"ACTIVE", + "weight":1, + "admin_state_up":true, + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "pool_id":"72741b06-df4d-4715-b142-276b6bce75ab", + "address":"10.0.0.4", + "protocol_port":80, + "id":"701b531b-111a-4f21-ad85-4795b7b12af6" + }, + { + "status":"ACTIVE", + "weight":1, + "admin_state_up":true, + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "pool_id":"72741b06-df4d-4715-b142-276b6bce75ab", + "address":"10.0.0.3", + "protocol_port":80, + "id":"beb53b4d-230b-4abd-8118-575b8fa006ef" + } + ] +} + `) + }) + + count := 0 + + members.List(fake.ServiceClient(), members.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := members.ExtractMembers(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []members.Member{ + { + Status: "ACTIVE", + Weight: 1, + AdminStateUp: true, + TenantID: "83657cfcdfe44cd5920adaf26c48ceea", + PoolID: "72741b06-df4d-4715-b142-276b6bce75ab", + Address: "10.0.0.4", + ProtocolPort: 80, + ID: "701b531b-111a-4f21-ad85-4795b7b12af6", + }, + { + Status: "ACTIVE", + Weight: 1, + AdminStateUp: true, + TenantID: "83657cfcdfe44cd5920adaf26c48ceea", + PoolID: "72741b06-df4d-4715-b142-276b6bce75ab", + Address: "10.0.0.3", + ProtocolPort: 80, + ID: "beb53b4d-230b-4abd-8118-575b8fa006ef", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/members", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "member": { + "tenant_id": "453105b9-1754-413f-aab1-55f1af620750", + "pool_id": "foo", + "address": "192.0.2.14", + "protocol_port":8080 + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "member": { + "id": "975592ca-e308-48ad-8298-731935ee9f45", + "address": "192.0.2.14", + "protocol_port": 8080, + "tenant_id": "453105b9-1754-413f-aab1-55f1af620750", + "admin_state_up":true, + "weight": 1, + "status": "DOWN" + } +} + `) + }) + + options := members.CreateOpts{ + TenantID: "453105b9-1754-413f-aab1-55f1af620750", + Address: "192.0.2.14", + ProtocolPort: 8080, + PoolID: "foo", + } + _, err := members.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/members/975592ca-e308-48ad-8298-731935ee9f45", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "member":{ + "id":"975592ca-e308-48ad-8298-731935ee9f45", + "address":"192.0.2.14", + "protocol_port":8080, + "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", + "admin_state_up":true, + "weight":1, + "status":"DOWN" + } +} + `) + }) + + m, err := members.Get(fake.ServiceClient(), "975592ca-e308-48ad-8298-731935ee9f45").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "975592ca-e308-48ad-8298-731935ee9f45", m.ID) + th.AssertEquals(t, "192.0.2.14", m.Address) + th.AssertEquals(t, 8080, m.ProtocolPort) + th.AssertEquals(t, "453105b9-1754-413f-aab1-55f1af620750", m.TenantID) + th.AssertEquals(t, true, m.AdminStateUp) + th.AssertEquals(t, 1, m.Weight) + th.AssertEquals(t, "DOWN", m.Status) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/members/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "member":{ + "admin_state_up":false + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "member":{ + "status":"PENDING_UPDATE", + "protocol_port":8080, + "weight":1, + "admin_state_up":false, + "tenant_id":"4fd44f30292945e481c7b8a0c8908869", + "pool_id":"7803631d-f181-4500-b3a2-1b68ba2a75fd", + "address":"10.0.0.5", + "status_description":null, + "id":"48a471ea-64f1-4eb6-9be7-dae6bbe40a0f" + } +} + `) + }) + + options := members.UpdateOpts{AdminStateUp: gophercloud.Disabled} + + _, err := members.Update(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", options).Extract() + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/members/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := members.Delete(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors/testing/requests_test.go new file mode 100644 index 00000000..f7360743 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors/testing/requests_test.go @@ -0,0 +1,310 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/health_monitors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "health_monitors":[ + { + "admin_state_up":true, + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":10, + "max_retries":1, + "timeout":1, + "type":"PING", + "id":"466c8345-28d8-4f84-a246-e04380b0461d" + }, + { + "admin_state_up":true, + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "delay":5, + "expected_codes":"200", + "max_retries":2, + "http_method":"GET", + "timeout":2, + "url_path":"/", + "type":"HTTP", + "id":"5d4b5228-33b0-4e60-b225-9b727c1a20e7" + } + ] +} + `) + }) + + count := 0 + + monitors.List(fake.ServiceClient(), monitors.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := monitors.ExtractMonitors(page) + if err != nil { + t.Errorf("Failed to extract monitors: %v", err) + return false, err + } + + expected := []monitors.Monitor{ + { + AdminStateUp: true, + TenantID: "83657cfcdfe44cd5920adaf26c48ceea", + Delay: 10, + MaxRetries: 1, + Timeout: 1, + Type: "PING", + ID: "466c8345-28d8-4f84-a246-e04380b0461d", + }, + { + AdminStateUp: true, + TenantID: "83657cfcdfe44cd5920adaf26c48ceea", + Delay: 5, + ExpectedCodes: "200", + MaxRetries: 2, + Timeout: 2, + URLPath: "/", + Type: "HTTP", + HTTPMethod: "GET", + ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestDelayMustBeGreaterOrEqualThanTimeout(t *testing.T) { + _, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + Delay: 1, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } + + _, err = monitors.Update(fake.ServiceClient(), "453105b9-1754-413f-aab1-55f1af620750", monitors.UpdateOpts{ + Delay: 1, + Timeout: 10, + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/health_monitors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "health_monitor":{ + "type":"HTTP", + "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", + "delay":20, + "timeout":10, + "max_retries":5, + "url_path":"/check", + "expected_codes":"200-299" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "health_monitor":{ + "id":"f3eeab00-8367-4524-b662-55e64d4cacb5", + "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", + "type":"HTTP", + "delay":20, + "timeout":10, + "max_retries":5, + "http_method":"GET", + "url_path":"/check", + "expected_codes":"200-299", + "admin_state_up":true, + "status":"ACTIVE" + } +} + `) + }) + + _, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + TenantID: "453105b9-1754-413f-aab1-55f1af620750", + Delay: 20, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + + th.AssertNoErr(t, err) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = monitors.Create(fake.ServiceClient(), monitors.CreateOpts{Type: monitors.TypeHTTP}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/health_monitors/f3eeab00-8367-4524-b662-55e64d4cacb5", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "health_monitor":{ + "id":"f3eeab00-8367-4524-b662-55e64d4cacb5", + "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", + "type":"HTTP", + "delay":20, + "timeout":10, + "max_retries":5, + "http_method":"GET", + "url_path":"/check", + "expected_codes":"200-299", + "admin_state_up":true, + "status":"ACTIVE" + } +} + `) + }) + + hm, err := monitors.Get(fake.ServiceClient(), "f3eeab00-8367-4524-b662-55e64d4cacb5").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "f3eeab00-8367-4524-b662-55e64d4cacb5", hm.ID) + th.AssertEquals(t, "453105b9-1754-413f-aab1-55f1af620750", hm.TenantID) + th.AssertEquals(t, "HTTP", hm.Type) + th.AssertEquals(t, 20, hm.Delay) + th.AssertEquals(t, 10, hm.Timeout) + th.AssertEquals(t, 5, hm.MaxRetries) + th.AssertEquals(t, "GET", hm.HTTPMethod) + th.AssertEquals(t, "/check", hm.URLPath) + th.AssertEquals(t, "200-299", hm.ExpectedCodes) + th.AssertEquals(t, true, hm.AdminStateUp) + th.AssertEquals(t, "ACTIVE", hm.Status) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/health_monitors/b05e44b5-81f9-4551-b474-711a722698f7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "health_monitor":{ + "delay": 30, + "timeout": 20, + "max_retries": 10, + "url_path": "/another_check", + "expected_codes": "301", + "admin_state_up": true + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusAccepted) + + fmt.Fprintf(w, ` +{ + "health_monitor": { + "admin_state_up": true, + "tenant_id": "4fd44f30292945e481c7b8a0c8908869", + "delay": 30, + "max_retries": 10, + "http_method": "GET", + "timeout": 20, + "pools": [ + { + "status": "PENDING_CREATE", + "status_description": null, + "pool_id": "6e55751f-6ad4-4e53-b8d4-02e442cd21df" + } + ], + "type": "PING", + "id": "b05e44b5-81f9-4551-b474-711a722698f7" + } +} + `) + }) + + _, err := monitors.Update(fake.ServiceClient(), "b05e44b5-81f9-4551-b474-711a722698f7", monitors.UpdateOpts{ + Delay: 30, + Timeout: 20, + MaxRetries: 10, + URLPath: "/another_check", + ExpectedCodes: "301", + AdminStateUp: gophercloud.Enabled, + }).Extract() + + th.AssertNoErr(t, err) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/health_monitors/b05e44b5-81f9-4551-b474-711a722698f7", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := monitors.Delete(fake.ServiceClient(), "b05e44b5-81f9-4551-b474-711a722698f7") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools/testing/requests_test.go new file mode 100644 index 00000000..de038cb8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools/testing/requests_test.go @@ -0,0 +1,316 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "pools":[ + { + "status":"ACTIVE", + "lb_method":"ROUND_ROBIN", + "protocol":"HTTP", + "description":"", + "health_monitors":[ + "466c8345-28d8-4f84-a246-e04380b0461d", + "5d4b5228-33b0-4e60-b225-9b727c1a20e7" + ], + "members":[ + "701b531b-111a-4f21-ad85-4795b7b12af6", + "beb53b4d-230b-4abd-8118-575b8fa006ef" + ], + "status_description": null, + "id":"72741b06-df4d-4715-b142-276b6bce75ab", + "vip_id":"4ec89087-d057-4e2c-911f-60a3b47ee304", + "name":"app_pool", + "admin_state_up":true, + "subnet_id":"8032909d-47a1-4715-90af-5153ffe39861", + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "health_monitors_status": [], + "provider": "haproxy" + } + ] +} + `) + }) + + count := 0 + + pools.List(fake.ServiceClient(), pools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := pools.ExtractPools(page) + if err != nil { + t.Errorf("Failed to extract pools: %v", err) + return false, err + } + + expected := []pools.Pool{ + { + Status: "ACTIVE", + LBMethod: "ROUND_ROBIN", + Protocol: "HTTP", + Description: "", + MonitorIDs: []string{ + "466c8345-28d8-4f84-a246-e04380b0461d", + "5d4b5228-33b0-4e60-b225-9b727c1a20e7", + }, + SubnetID: "8032909d-47a1-4715-90af-5153ffe39861", + TenantID: "83657cfcdfe44cd5920adaf26c48ceea", + AdminStateUp: true, + Name: "app_pool", + MemberIDs: []string{ + "701b531b-111a-4f21-ad85-4795b7b12af6", + "beb53b4d-230b-4abd-8118-575b8fa006ef", + }, + ID: "72741b06-df4d-4715-b142-276b6bce75ab", + VIPID: "4ec89087-d057-4e2c-911f-60a3b47ee304", + Provider: "haproxy", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "pool": { + "lb_method": "ROUND_ROBIN", + "protocol": "HTTP", + "name": "Example pool", + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "tenant_id": "2ffc6e22aae24e4795f87155d24c896f", + "provider": "haproxy" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "pool": { + "status": "PENDING_CREATE", + "lb_method": "ROUND_ROBIN", + "protocol": "HTTP", + "description": "", + "health_monitors": [], + "members": [], + "status_description": null, + "id": "69055154-f603-4a28-8951-7cc2d9e54a9a", + "vip_id": null, + "name": "Example pool", + "admin_state_up": true, + "subnet_id": "1981f108-3c48-48d2-b908-30f7d28532c9", + "tenant_id": "2ffc6e22aae24e4795f87155d24c896f", + "health_monitors_status": [], + "provider": "haproxy" + } +} + `) + }) + + options := pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: "HTTP", + Name: "Example pool", + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + TenantID: "2ffc6e22aae24e4795f87155d24c896f", + Provider: "haproxy", + } + p, err := pools.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "PENDING_CREATE", p.Status) + th.AssertEquals(t, "ROUND_ROBIN", p.LBMethod) + th.AssertEquals(t, "HTTP", p.Protocol) + th.AssertEquals(t, "", p.Description) + th.AssertDeepEquals(t, []string{}, p.MonitorIDs) + th.AssertDeepEquals(t, []string{}, p.MemberIDs) + th.AssertEquals(t, "69055154-f603-4a28-8951-7cc2d9e54a9a", p.ID) + th.AssertEquals(t, "Example pool", p.Name) + th.AssertEquals(t, "1981f108-3c48-48d2-b908-30f7d28532c9", p.SubnetID) + th.AssertEquals(t, "2ffc6e22aae24e4795f87155d24c896f", p.TenantID) + th.AssertEquals(t, "haproxy", p.Provider) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "pool":{ + "id":"332abe93-f488-41ba-870b-2ac66be7f853", + "tenant_id":"19eaa775-cf5d-49bc-902e-2f85f668d995", + "name":"Example pool", + "description":"", + "protocol":"tcp", + "lb_algorithm":"ROUND_ROBIN", + "session_persistence":{ + }, + "healthmonitor_id":null, + "members":[ + ], + "admin_state_up":true, + "status":"ACTIVE" + } +} + `) + }) + + n, err := pools.Get(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.ID, "332abe93-f488-41ba-870b-2ac66be7f853") +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "pool":{ + "name":"SuperPool", + "lb_method": "LEAST_CONNECTIONS" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "pool":{ + "status":"PENDING_UPDATE", + "lb_method":"LEAST_CONNECTIONS", + "protocol":"TCP", + "description":"", + "health_monitors":[ + + ], + "subnet_id":"8032909d-47a1-4715-90af-5153ffe39861", + "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea", + "admin_state_up":true, + "name":"SuperPool", + "members":[ + + ], + "id":"61b1f87a-7a21-4ad3-9dda-7f81d249944f", + "vip_id":null + } +} + `) + }) + + options := pools.UpdateOpts{Name: "SuperPool", LBMethod: pools.LBMethodLeastConnections} + + n, err := pools.Update(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "SuperPool", n.Name) + th.AssertDeepEquals(t, "LEAST_CONNECTIONS", n.LBMethod) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := pools.Delete(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853") + th.AssertNoErr(t, res.Err) +} + +func TestAssociateHealthMonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "health_monitor":{ + "id":"b624decf-d5d3-4c66-9a3d-f047e7786181" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{}`) + }) + + _, err := pools.AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract() + th.AssertNoErr(t, err) +} + +func TestDisassociateHealthMonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors/b624decf-d5d3-4c66-9a3d-f047e7786181", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := pools.DisassociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips/testing/requests_test.go new file mode 100644 index 00000000..7f9b6ddb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips/testing/requests_test.go @@ -0,0 +1,330 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/vips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "vips":[ + { + "id": "db902c0c-d5ff-4753-b465-668ad9656918", + "tenant_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "web_vip", + "description": "lb config for the web tier", + "subnet_id": "96a4386a-f8c3-42ed-afce-d7954eee77b3", + "address" : "10.30.176.47", + "port_id" : "cd1f7a47-4fa6-449c-9ee7-632838aedfea", + "protocol": "HTTP", + "protocol_port": 80, + "pool_id" : "cfc6589d-f949-4c66-99d2-c2da56ef3764", + "admin_state_up": true, + "status": "ACTIVE" + }, + { + "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + "tenant_id": "310df60f-2a10-4ee5-9554-98393092194c", + "name": "db_vip", + "description": "lb config for the db tier", + "subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + "address" : "10.30.176.48", + "port_id" : "cd1f7a47-4fa6-449c-9ee7-632838aedfea", + "protocol": "TCP", + "protocol_port": 3306, + "pool_id" : "41efe233-7591-43c5-9cf7-923964759f9e", + "session_persistence" : {"type" : "SOURCE_IP"}, + "connection_limit" : 2000, + "admin_state_up": true, + "status": "INACTIVE" + } + ] +} + `) + }) + + count := 0 + + vips.List(fake.ServiceClient(), vips.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := vips.ExtractVIPs(page) + if err != nil { + t.Errorf("Failed to extract LBs: %v", err) + return false, err + } + + expected := []vips.VirtualIP{ + { + ID: "db902c0c-d5ff-4753-b465-668ad9656918", + TenantID: "310df60f-2a10-4ee5-9554-98393092194c", + Name: "web_vip", + Description: "lb config for the web tier", + SubnetID: "96a4386a-f8c3-42ed-afce-d7954eee77b3", + Address: "10.30.176.47", + PortID: "cd1f7a47-4fa6-449c-9ee7-632838aedfea", + Protocol: "HTTP", + ProtocolPort: 80, + PoolID: "cfc6589d-f949-4c66-99d2-c2da56ef3764", + Persistence: vips.SessionPersistence{}, + ConnLimit: 0, + AdminStateUp: true, + Status: "ACTIVE", + }, + { + ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", + TenantID: "310df60f-2a10-4ee5-9554-98393092194c", + Name: "db_vip", + Description: "lb config for the db tier", + SubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + Address: "10.30.176.48", + PortID: "cd1f7a47-4fa6-449c-9ee7-632838aedfea", + Protocol: "TCP", + ProtocolPort: 3306, + PoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + Persistence: vips.SessionPersistence{Type: "SOURCE_IP"}, + ConnLimit: 2000, + AdminStateUp: true, + Status: "INACTIVE", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/vips", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "vip": { + "protocol": "HTTP", + "name": "NewVip", + "admin_state_up": true, + "subnet_id": "8032909d-47a1-4715-90af-5153ffe39861", + "pool_id": "61b1f87a-7a21-4ad3-9dda-7f81d249944f", + "protocol_port": 80, + "session_persistence": {"type": "SOURCE_IP"} + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "vip": { + "status": "PENDING_CREATE", + "protocol": "HTTP", + "description": "", + "admin_state_up": true, + "subnet_id": "8032909d-47a1-4715-90af-5153ffe39861", + "tenant_id": "83657cfcdfe44cd5920adaf26c48ceea", + "connection_limit": -1, + "pool_id": "61b1f87a-7a21-4ad3-9dda-7f81d249944f", + "address": "10.0.0.11", + "protocol_port": 80, + "port_id": "f7e6fe6a-b8b5-43a8-8215-73456b32e0f5", + "id": "c987d2be-9a3c-4ac9-a046-e8716b1350e2", + "name": "NewVip" + } +} + `) + }) + + opts := vips.CreateOpts{ + Protocol: "HTTP", + Name: "NewVip", + AdminStateUp: gophercloud.Enabled, + SubnetID: "8032909d-47a1-4715-90af-5153ffe39861", + PoolID: "61b1f87a-7a21-4ad3-9dda-7f81d249944f", + ProtocolPort: 80, + Persistence: &vips.SessionPersistence{Type: "SOURCE_IP"}, + } + + r, err := vips.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "PENDING_CREATE", r.Status) + th.AssertEquals(t, "HTTP", r.Protocol) + th.AssertEquals(t, "", r.Description) + th.AssertEquals(t, true, r.AdminStateUp) + th.AssertEquals(t, "8032909d-47a1-4715-90af-5153ffe39861", r.SubnetID) + th.AssertEquals(t, "83657cfcdfe44cd5920adaf26c48ceea", r.TenantID) + th.AssertEquals(t, -1, r.ConnLimit) + th.AssertEquals(t, "61b1f87a-7a21-4ad3-9dda-7f81d249944f", r.PoolID) + th.AssertEquals(t, "10.0.0.11", r.Address) + th.AssertEquals(t, 80, r.ProtocolPort) + th.AssertEquals(t, "f7e6fe6a-b8b5-43a8-8215-73456b32e0f5", r.PortID) + th.AssertEquals(t, "c987d2be-9a3c-4ac9-a046-e8716b1350e2", r.ID) + th.AssertEquals(t, "NewVip", r.Name) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := vips.Create(fake.ServiceClient(), vips.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = vips.Create(fake.ServiceClient(), vips.CreateOpts{Name: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = vips.Create(fake.ServiceClient(), vips.CreateOpts{Name: "foo", SubnetID: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = vips.Create(fake.ServiceClient(), vips.CreateOpts{Name: "foo", SubnetID: "bar", Protocol: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = vips.Create(fake.ServiceClient(), vips.CreateOpts{Name: "foo", SubnetID: "bar", Protocol: "bar", ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/vips/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "vip": { + "status": "ACTIVE", + "protocol": "HTTP", + "description": "", + "admin_state_up": true, + "subnet_id": "8032909d-47a1-4715-90af-5153ffe39861", + "tenant_id": "83657cfcdfe44cd5920adaf26c48ceea", + "connection_limit": 1000, + "pool_id": "72741b06-df4d-4715-b142-276b6bce75ab", + "session_persistence": { + "cookie_name": "MyAppCookie", + "type": "APP_COOKIE" + }, + "address": "10.0.0.10", + "protocol_port": 80, + "port_id": "b5a743d6-056b-468b-862d-fb13a9aa694e", + "id": "4ec89087-d057-4e2c-911f-60a3b47ee304", + "name": "my-vip" + } +} + `) + }) + + vip, err := vips.Get(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "ACTIVE", vip.Status) + th.AssertEquals(t, "HTTP", vip.Protocol) + th.AssertEquals(t, "", vip.Description) + th.AssertEquals(t, true, vip.AdminStateUp) + th.AssertEquals(t, 1000, vip.ConnLimit) + th.AssertEquals(t, vips.SessionPersistence{Type: "APP_COOKIE", CookieName: "MyAppCookie"}, vip.Persistence) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/vips/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "vip": { + "connection_limit": 1000, + "session_persistence": {"type": "SOURCE_IP"} + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusAccepted) + + fmt.Fprintf(w, ` +{ + "vip": { + "status": "PENDING_UPDATE", + "protocol": "HTTP", + "description": "", + "admin_state_up": true, + "subnet_id": "8032909d-47a1-4715-90af-5153ffe39861", + "tenant_id": "83657cfcdfe44cd5920adaf26c48ceea", + "connection_limit": 1000, + "pool_id": "61b1f87a-7a21-4ad3-9dda-7f81d249944f", + "address": "10.0.0.11", + "protocol_port": 80, + "port_id": "f7e6fe6a-b8b5-43a8-8215-73456b32e0f5", + "id": "c987d2be-9a3c-4ac9-a046-e8716b1350e2", + "name": "NewVip" + } +} + `) + }) + + i1000 := 1000 + options := vips.UpdateOpts{ + ConnLimit: &i1000, + Persistence: &vips.SessionPersistence{Type: "SOURCE_IP"}, + } + vip, err := vips.Update(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "PENDING_UPDATE", vip.Status) + th.AssertEquals(t, 1000, vip.ConnLimit) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/lb/vips/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := vips.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/requests.go index 625748fd..dd190f60 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/requests.go @@ -31,6 +31,7 @@ type ListOpts struct { Name string `q:"name"` AdminStateUp *bool `q:"admin_state_up"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` LoadbalancerID string `q:"loadbalancer_id"` DefaultPoolID string `q:"default_pool_id"` Protocol string `q:"protocol"` @@ -86,9 +87,13 @@ type CreateOpts struct { ProtocolPort int `json:"protocol_port" required:"true"` // TenantID is only required if the caller has an admin role and wants - // to create a pool for another tenant. + // to create a pool for another project. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is only required if the caller has an admin role and wants + // to create a pool for another project. + ProjectID string `json:"project_id,omitempty"` + // Human-readable name for the Listener. Does not have to be unique. Name string `json:"name,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/results.go index e0c134ed..81cda903 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/results.go @@ -54,6 +54,10 @@ type Listener struct { // Pools are the pools which are part of this listener. Pools []pools.Pool `json:"pools"` + + // The provisioning status of the listener. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` } // ListenerPage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/testing/requests_test.go new file mode 100644 index 00000000..d463f6e8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners/testing/requests_test.go @@ -0,0 +1,137 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListListeners(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerListSuccessfully(t) + + pages := 0 + err := listeners.List(fake.ServiceClient(), listeners.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := listeners.ExtractListeners(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 listeners, got %d", len(actual)) + } + th.CheckDeepEquals(t, ListenerWeb, actual[0]) + th.CheckDeepEquals(t, ListenerDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllListeners(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerListSuccessfully(t) + + allPages, err := listeners.List(fake.ServiceClient(), listeners.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := listeners.ExtractListeners(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ListenerWeb, actual[0]) + th.CheckDeepEquals(t, ListenerDb, actual[1]) +} + +func TestCreateListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerCreationSuccessfully(t, SingleListenerBody) + + actual, err := listeners.Create(fake.ServiceClient(), listeners.CreateOpts{ + Protocol: "TCP", + Name: "db", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + AdminStateUp: gophercloud.Enabled, + DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76", + DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e", + ProtocolPort: 3306, + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListenerDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := listeners.Create(fake.ServiceClient(), listeners.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", TenantID: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", TenantID: "bar", Protocol: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = listeners.Create(fake.ServiceClient(), listeners.CreateOpts{Name: "foo", TenantID: "bar", Protocol: "bar", ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := listeners.Get(client, "4ec89087-d057-4e2c-911f-60a3b47ee304").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, ListenerDb, *actual) +} + +func TestDeleteListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerDeletionSuccessfully(t) + + res := listeners.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateListener(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListenerUpdateSuccessfully(t) + + client := fake.ServiceClient() + i1001 := 1001 + actual, err := listeners.Update(client, "4ec89087-d057-4e2c-911f-60a3b47ee304", listeners.UpdateOpts{ + Name: "NewListenerName", + ConnLimit: &i1001, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, ListenerUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/requests.go index 839776dd..1ed23c3c 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/requests.go @@ -1,6 +1,8 @@ package loadbalancers import ( + "fmt" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" ) @@ -20,6 +22,7 @@ type ListOpts struct { Description string `q:"description"` AdminStateUp *bool `q:"admin_state_up"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` ProvisioningStatus string `q:"provisioning_status"` VipAddress string `q:"vip_address"` VipPortID string `q:"vip_port_id"` @@ -35,7 +38,7 @@ type ListOpts struct { SortDir string `q:"sort_dir"` } -// ToLoadbalancerListQuery formats a ListOpts into a query string. +// ToLoadBalancerListQuery formats a ListOpts into a query string. func (opts ListOpts) ToLoadBalancerListQuery() (string, error) { q, err := gophercloud.BuildQueryString(opts) return q.String(), err @@ -81,10 +84,14 @@ type CreateOpts struct { // that belong to them or networks that are shared). VipSubnetID string `json:"vip_subnet_id" required:"true"` - // The UUID of the tenant who owns the Loadbalancer. Only administrative users - // can specify a tenant UUID other than their own. + // TenantID is the UUID of the project who owns the Loadbalancer. + // Only administrative users can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is the UUID of the project who owns the Loadbalancer. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // The IP address of the Loadbalancer. VipAddress string `json:"vip_address,omitempty"` @@ -170,6 +177,20 @@ func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { return } +// CascadingDelete is like `Delete`, but will also delete any of the load balancer's +// children (listener, monitor, etc). +// NOTE: This function will only work with Octavia load balancers; Neutron does not +// support this. +func CascadingDelete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + if c.Type != "load-balancer" { + r.Err = fmt.Errorf("error prior to running cascade delete: only Octavia LBs supported") + return + } + u := fmt.Sprintf("%s?cascade=true", resourceURL(c, id)) + _, r.Err = c.Delete(u, nil) + return +} + // GetStatuses will return the status of a particular LoadBalancer. func GetStatuses(c *gophercloud.ServiceClient, id string) (r GetStatusesResult) { _, r.Err = c.Get(statusRootURL(c, id), &r.Body, nil) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go index 9f8f19d7..42fff571 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go @@ -79,8 +79,8 @@ func (r LoadBalancerPage) NextPageURL() (string, error) { } // IsEmpty checks whether a LoadBalancerPage struct is empty. -func (p LoadBalancerPage) IsEmpty() (bool, error) { - is, err := ExtractLoadBalancers(p) +func (r LoadBalancerPage) IsEmpty() (bool, error) { + is, err := ExtractLoadBalancers(r) return len(is) == 0, err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/fixtures.go index a4522365..2bc949b9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/fixtures.go @@ -102,18 +102,22 @@ const LoadbalancerStatuesesTree = ` "listeners": [{ "id": "db902c0c-d5ff-4753-b465-668ad9656918", "name": "db", + "provisioning_status": "PENDING_UPDATE", "pools": [{ "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", "name": "db", + "provisioning_status": "PENDING_UPDATE", "healthmonitor": { "id": "67306cda-815d-4354-9fe4-59e09da9c3c5", - "type":"PING" + "type":"PING", + "provisioning_status": "PENDING_UPDATE" }, "members":[{ "id": "2a280670-c202-4b0b-a562-34077415aabf", "name": "db", "address": "10.0.2.11", - "protocol_port": 80 + "protocol_port": 80, + "provisioning_status": "PENDING_UPDATE" }] }] }] @@ -171,20 +175,24 @@ var ( ProvisioningStatus: "PENDING_UPDATE", OperatingStatus: "ACTIVE", Listeners: []listeners.Listener{{ - ID: "db902c0c-d5ff-4753-b465-668ad9656918", - Name: "db", + ID: "db902c0c-d5ff-4753-b465-668ad9656918", + Name: "db", + ProvisioningStatus: "PENDING_UPDATE", Pools: []pools.Pool{{ - ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", - Name: "db", + ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", + Name: "db", + ProvisioningStatus: "PENDING_UPDATE", Monitor: monitors.Monitor{ - ID: "67306cda-815d-4354-9fe4-59e09da9c3c5", - Type: "PING", + ID: "67306cda-815d-4354-9fe4-59e09da9c3c5", + Type: "PING", + ProvisioningStatus: "PENDING_UPDATE", }, Members: []pools.Member{{ - ID: "2a280670-c202-4b0b-a562-34077415aabf", - Name: "db", - Address: "10.0.2.11", - ProtocolPort: 80, + ID: "2a280670-c202-4b0b-a562-34077415aabf", + Name: "db", + Address: "10.0.2.11", + ProtocolPort: 80, + ProvisioningStatus: "PENDING_UPDATE", }}, }}, }}, diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/requests_test.go new file mode 100644 index 00000000..e370c669 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/testing/requests_test.go @@ -0,0 +1,161 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListLoadbalancers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerListSuccessfully(t) + + pages := 0 + err := loadbalancers.List(fake.ServiceClient(), loadbalancers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := loadbalancers.ExtractLoadBalancers(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 loadbalancers, got %d", len(actual)) + } + th.CheckDeepEquals(t, LoadbalancerWeb, actual[0]) + th.CheckDeepEquals(t, LoadbalancerDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllLoadbalancers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerListSuccessfully(t) + + allPages, err := loadbalancers.List(fake.ServiceClient(), loadbalancers.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := loadbalancers.ExtractLoadBalancers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, LoadbalancerWeb, actual[0]) + th.CheckDeepEquals(t, LoadbalancerDb, actual[1]) +} + +func TestCreateLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerCreationSuccessfully(t, SingleLoadbalancerBody) + + actual, err := loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{ + Name: "db_lb", + AdminStateUp: gophercloud.Enabled, + VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", + VipAddress: "10.30.176.48", + Flavor: "medium", + Provider: "haproxy", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, LoadbalancerDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo", Description: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = loadbalancers.Create(fake.ServiceClient(), loadbalancers.CreateOpts{Name: "foo", Description: "bar", VipAddress: "bar"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.Get(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerDb, *actual) +} + +func TestGetLoadbalancerStatusesTree(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerGetStatusesTree(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.GetStatuses(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerStatusesTree, *(actual.Loadbalancer)) +} + +func TestDeleteLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerDeletionSuccessfully(t) + + res := loadbalancers.Delete(fake.ServiceClient(), "36e08a3e-a78f-4b40-a229-1e7e23eee1ab") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := loadbalancers.Update(client, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", loadbalancers.UpdateOpts{ + Name: "NewLoadbalancerName", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, LoadbalancerUpdated, *actual) +} + +func TestCascadingDeleteLoadbalancer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleLoadbalancerDeletionSuccessfully(t) + + sc := fake.ServiceClient() + sc.Type = "network" + err := loadbalancers.CascadingDelete(sc, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").ExtractErr() + if err == nil { + t.Fatalf("expected error running CascadingDelete with Neutron service client but didn't get one") + } + + sc.Type = "load-balancer" + err = loadbalancers.CascadingDelete(sc, "36e08a3e-a78f-4b40-a229-1e7e23eee1ab").ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/requests.go index 6d9ab8ba..c173e1c6 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/requests.go @@ -22,6 +22,7 @@ type ListOpts struct { ID string `q:"id"` Name string `q:"name"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` PoolID string `q:"pool_id"` Type string `q:"type"` Delay int `q:"delay"` @@ -119,10 +120,14 @@ type CreateOpts struct { // types. ExpectedCodes string `json:"expected_codes,omitempty"` - // The UUID of the tenant who owns the Monitor. Only administrative users - // can specify a tenant UUID other than their own. + // TenantID is the UUID of the project who owns the Monitor. + // Only administrative users can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is the UUID of the project who owns the Monitor. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // The Name of the Monitor. Name string `json:"name,omitempty"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/results.go index ea832cc5..a78f7aeb 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/results.go @@ -70,6 +70,10 @@ type Monitor struct { // List of pools that are associated with the health monitor. Pools []PoolID `json:"pools"` + + // The provisioning status of the monitor. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` } // MonitorPage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/testing/requests_test.go new file mode 100644 index 00000000..743d9c1c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors/testing/requests_test.go @@ -0,0 +1,154 @@ +package testing + +import ( + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListHealthmonitors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorListSuccessfully(t) + + pages := 0 + err := monitors.List(fake.ServiceClient(), monitors.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := monitors.ExtractMonitors(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 healthmonitors, got %d", len(actual)) + } + th.CheckDeepEquals(t, HealthmonitorWeb, actual[0]) + th.CheckDeepEquals(t, HealthmonitorDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllHealthmonitors(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorListSuccessfully(t) + + allPages, err := monitors.List(fake.ServiceClient(), monitors.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := monitors.ExtractMonitors(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, HealthmonitorWeb, actual[0]) + th.CheckDeepEquals(t, HealthmonitorDb, actual[1]) +} + +func TestCreateHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorCreationSuccessfully(t, SingleHealthmonitorBody) + + actual, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + Name: "db", + PoolID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d", + TenantID: "453105b9-1754-413f-aab1-55f1af620750", + Delay: 20, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, HealthmonitorDb, *actual) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = monitors.Create(fake.ServiceClient(), monitors.CreateOpts{Type: monitors.TypeHTTP}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGetHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := monitors.Get(client, "5d4b5228-33b0-4e60-b225-9b727c1a20e7").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, HealthmonitorDb, *actual) +} + +func TestDeleteHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorDeletionSuccessfully(t) + + res := monitors.Delete(fake.ServiceClient(), "5d4b5228-33b0-4e60-b225-9b727c1a20e7") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateHealthmonitor(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleHealthmonitorUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := monitors.Update(client, "5d4b5228-33b0-4e60-b225-9b727c1a20e7", monitors.UpdateOpts{ + Name: "NewHealthmonitorName", + Delay: 3, + Timeout: 20, + MaxRetries: 10, + URLPath: "/another_check", + ExpectedCodes: "301", + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, HealthmonitorUpdated, *actual) +} + +func TestDelayMustBeGreaterOrEqualThanTimeout(t *testing.T) { + _, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ + Type: "HTTP", + PoolID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d", + Delay: 1, + Timeout: 10, + MaxRetries: 5, + URLPath: "/check", + ExpectedCodes: "200-299", + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } + + _, err = monitors.Update(fake.ServiceClient(), "453105b9-1754-413f-aab1-55f1af620750", monitors.UpdateOpts{ + Delay: 1, + Timeout: 10, + }).Extract() + + if err == nil { + t.Fatalf("Expected error, got none") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/requests.go index 2173ee81..11564be8 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/requests.go @@ -20,6 +20,7 @@ type ListOpts struct { LBMethod string `q:"lb_algorithm"` Protocol string `q:"protocol"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` AdminStateUp *bool `q:"admin_state_up"` Name string `q:"name"` ID string `q:"id"` @@ -97,10 +98,14 @@ type CreateOpts struct { // Note: one of LoadbalancerID or ListenerID must be provided. ListenerID string `json:"listener_id,omitempty" xor:"LoadbalancerID"` - // The UUID of the tenant who owns the Pool. Only administrative users - // can specify a tenant UUID other than their own. + // TenantID is the UUID of the project who owns the Pool. + // Only administrative users can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is the UUID of the project who owns the Pool. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // Name of the pool. Name string `json:"name,omitempty"` @@ -257,10 +262,14 @@ type CreateMemberOpts struct { // Name of the Member. Name string `json:"name,omitempty"` - // The UUID of the tenant who owns the Member. Only administrative users - // can specify a tenant UUID other than their own. + // TenantID is the UUID of the project who owns the Member. + // Only administrative users can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is the UUID of the project who owns the Member. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // A positive integer value that indicates the relative portion of traffic // that this member should receive from the pool. For example, a member with // a weight of 10 receives five times as much traffic as a member with a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/results.go index 56790fff..01efc768 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/results.go @@ -92,6 +92,10 @@ type Pool struct { // The Monitor associated with this Pool. Monitor monitors.Monitor `json:"healthmonitor"` + + // The provisioning status of the pool. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` } // PoolPage is the page returned by a pager when traversing over a @@ -196,6 +200,10 @@ type Member struct { // The unique ID for the Member. ID string `json:"id"` + + // The provisioning status of the member. + // This value is ACTIVE, PENDING_* or ERROR. + ProvisioningStatus string `json:"provisioning_status"` } // MemberPage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/testing/requests_test.go new file mode 100644 index 00000000..4af00ecc --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools/testing/requests_test.go @@ -0,0 +1,262 @@ +package testing + +import ( + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestListPools(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolListSuccessfully(t) + + pages := 0 + err := pools.List(fake.ServiceClient(), pools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := pools.ExtractPools(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 pools, got %d", len(actual)) + } + th.CheckDeepEquals(t, PoolWeb, actual[0]) + th.CheckDeepEquals(t, PoolDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllPools(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolListSuccessfully(t) + + allPages, err := pools.List(fake.ServiceClient(), pools.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := pools.ExtractPools(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, PoolWeb, actual[0]) + th.CheckDeepEquals(t, PoolDb, actual[1]) +} + +func TestCreatePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolCreationSuccessfully(t, SinglePoolBody) + + actual, err := pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: "HTTP", + Name: "Example pool", + TenantID: "2ffc6e22aae24e4795f87155d24c896f", + LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab", + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, PoolDb, *actual) +} + +func TestGetPool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.Get(client, "c3741b06-df4d-4715-b142-276b6bce75ab").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, PoolDb, *actual) +} + +func TestDeletePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolDeletionSuccessfully(t) + + res := pools.Delete(fake.ServiceClient(), "c3741b06-df4d-4715-b142-276b6bce75ab") + th.AssertNoErr(t, res.Err) +} + +func TestUpdatePool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePoolUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.Update(client, "c3741b06-df4d-4715-b142-276b6bce75ab", pools.UpdateOpts{ + Name: "NewPoolName", + LBMethod: pools.LBMethodLeastConnections, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, PoolUpdated, *actual) +} + +func TestRequiredPoolCreateOpts(t *testing.T) { + res := pools.Create(fake.ServiceClient(), pools.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethod("invalid"), + Protocol: pools.ProtocolHTTPS, + LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: pools.Protocol("invalid"), + LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + + res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ + LBMethod: pools.LBMethodRoundRobin, + Protocol: pools.ProtocolHTTPS, + }) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestListMembers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberListSuccessfully(t) + + pages := 0 + err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) { + pages++ + + actual, err := pools.ExtractMembers(page) + if err != nil { + return false, err + } + + if len(actual) != 2 { + t.Fatalf("Expected 2 members, got %d", len(actual)) + } + th.CheckDeepEquals(t, MemberWeb, actual[0]) + th.CheckDeepEquals(t, MemberDb, actual[1]) + + return true, nil + }) + + th.AssertNoErr(t, err) + + if pages != 1 { + t.Errorf("Expected 1 page, saw %d", pages) + } +} + +func TestListAllMembers(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberListSuccessfully(t) + + allPages, err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := pools.ExtractMembers(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, MemberWeb, actual[0]) + th.CheckDeepEquals(t, MemberDb, actual[1]) +} + +func TestCreateMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberCreationSuccessfully(t, SingleMemberBody) + + actual, err := pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{ + Name: "db", + SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9", + TenantID: "2ffc6e22aae24e4795f87155d24c896f", + Address: "10.0.2.11", + ProtocolPort: 80, + Weight: 10, + }).Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, MemberDb, *actual) +} + +func TestRequiredMemberCreateOpts(t *testing.T) { + res := pools.CreateMember(fake.ServiceClient(), "", pools.CreateMemberOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = pools.CreateMember(fake.ServiceClient(), "", pools.CreateMemberOpts{Address: "1.2.3.4", ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{ProtocolPort: 80}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } + res = pools.CreateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.CreateMemberOpts{Address: "1.2.3.4"}) + if res.Err == nil { + t.Fatalf("Expected error, but got none") + } +} + +func TestGetMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberGetSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.GetMember(client, "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf").Extract() + if err != nil { + t.Fatalf("Unexpected Get error: %v", err) + } + + th.CheckDeepEquals(t, MemberDb, *actual) +} + +func TestDeleteMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberDeletionSuccessfully(t) + + res := pools.DeleteMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf") + th.AssertNoErr(t, res.Err) +} + +func TestUpdateMember(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMemberUpdateSuccessfully(t) + + client := fake.ServiceClient() + actual, err := pools.UpdateMember(client, "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf", pools.UpdateMemberOpts{ + Name: "newMemberName", + Weight: 4, + }).Extract() + if err != nil { + t.Fatalf("Unexpected Update error: %v", err) + } + + th.CheckDeepEquals(t, MemberUpdated, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/doc.go new file mode 100644 index 00000000..91094736 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/doc.go @@ -0,0 +1,30 @@ +/* +Package networkipavailabilities provides the ability to retrieve and manage +networkipavailabilities through the Neutron API. + +Example of Listing NetworkIPAvailabilities + + allPages, err := networkipavailabilities.List(networkClient, networkipavailabilities.ListOpts{}).AllPages() + if err != nil { + panic(err) + } + + allAvailabilities, err := subnetpools.ExtractSubnetPools(allPages) + if err != nil { + panic(err) + } + + for _, availability := range allAvailabilities { + fmt.Printf("%+v\n", availability) + } + +Example of Getting a single NetworkIPAvailability + + availability, err := networkipavailabilities.Get(networkClient, "cf11ab78-2302-49fa-870f-851a08c7afb8").Extract() + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", availability) +*/ +package networkipavailabilities diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/requests.go new file mode 100644 index 00000000..c024d7a7 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/requests.go @@ -0,0 +1,61 @@ +package networkipavailabilities + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToNetworkIPAvailabilityListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the Neutron API. +type ListOpts struct { + // NetworkName allows to filter on the identifier of a network. + NetworkID string `q:"network_id"` + + // NetworkName allows to filter on the name of a network. + NetworkName string `q:"network_name"` + + // IPVersion allows to filter on the version of the IP protocol. + // You can use the well-known IP versions with the gophercloud.IPVersion type. + IPVersion string `q:"ip_version"` + + // ProjectID allows to filter on the Identity project field. + ProjectID string `q:"project_id"` + + // TenantID allows to filter on the Identity project field. + TenantID string `q:"tenant_id"` +} + +// ToNetworkIPAvailabilityListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToNetworkIPAvailabilityListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// networkipavailabilities. It accepts a ListOpts struct, which allows you to +// filter the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(c) + if opts != nil { + query, err := opts.ToNetworkIPAvailabilityListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return NetworkIPAvailabilityPage{pagination.SinglePageBase(r)} + }) +} + +// Get retrieves a specific NetworkIPAvailability based on its ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(getURL(c, id), &r.Body, nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/results.go new file mode 100644 index 00000000..4bcf10f4 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/results.go @@ -0,0 +1,96 @@ +package networkipavailabilities + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type commonResult struct { + gophercloud.Result +} + +// GetResult represents the result of a Get operation. Call its Extract +// method to interpret it as a NetworkIPAvailability. +type GetResult struct { + commonResult +} + +// Extract is a function that accepts a result and extracts a NetworkIPAvailability. +func (r commonResult) Extract() (*NetworkIPAvailability, error) { + var s struct { + NetworkIPAvailability *NetworkIPAvailability `json:"network_ip_availability"` + } + err := r.ExtractInto(&s) + return s.NetworkIPAvailability, err +} + +// NetworkIPAvailability represents availability details for a single network. +type NetworkIPAvailability struct { + // NetworkID contains an unique identifier of the network. + NetworkID string `json:"network_id"` + + // NetworkName represents human-readable name of the network. + NetworkName string `json:"network_name"` + + // ProjectID is the ID of the Identity project. + ProjectID string `json:"project_id"` + + // TenantID is the ID of the Identity project. + TenantID string `json:"tenant_id"` + + // SubnetIPAvailabilities contains availability details for every subnet + // that is associated to the network. + SubnetIPAvailabilities []SubnetIPAvailability `json:"subnet_ip_availability"` + + // TotalIPs represents a number of IP addresses in the network. + TotalIPs int `json:"total_ips"` + + // UsedIPs represents a number of used IP addresses in the network. + UsedIPs int `json:"used_ips"` +} + +// SubnetIPAvailability represents availability details for a single subnet. +type SubnetIPAvailability struct { + // SubnetID contains an unique identifier of the subnet. + SubnetID string `json:"subnet_id"` + + // SubnetName represents human-readable name of the subnet. + SubnetName string `json:"subnet_name"` + + // CIDR represents prefix in the CIDR format. + CIDR string `json:"cidr"` + + // IPVersion is the IP protocol version. + IPVersion int `json:"ip_version"` + + // TotalIPs represents a number of IP addresses in the subnet. + TotalIPs int `json:"total_ips"` + + // UsedIPs represents a number of used IP addresses in the subnet. + UsedIPs int `json:"used_ips"` +} + +// NetworkIPAvailabilityPage stores a single page of NetworkIPAvailabilities +// from the List call. +type NetworkIPAvailabilityPage struct { + pagination.SinglePageBase +} + +// IsEmpty determines whether or not a NetworkIPAvailability is empty. +func (r NetworkIPAvailabilityPage) IsEmpty() (bool, error) { + networkipavailabilities, err := ExtractNetworkIPAvailabilities(r) + return len(networkipavailabilities) == 0, err +} + +// ExtractNetworkIPAvailabilities interprets the results of a single page from +// a List() API call, producing a slice of NetworkIPAvailabilities structures. +func ExtractNetworkIPAvailabilities(r pagination.Page) ([]NetworkIPAvailability, error) { + var s struct { + NetworkIPAvailabilities []NetworkIPAvailability `json:"network_ip_availabilities"` + } + err := (r.(NetworkIPAvailabilityPage)).ExtractInto(&s) + if err != nil { + return nil, err + } + return s.NetworkIPAvailabilities, nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/doc.go new file mode 100644 index 00000000..baf115fc --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/doc.go @@ -0,0 +1,2 @@ +// networkipavailabilities unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/fixtures.go new file mode 100644 index 00000000..2cd993d6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/fixtures.go @@ -0,0 +1,130 @@ +package testing + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities" +) + +// NetworkIPAvailabilityListResult represents raw server response from a server to a list call. +const NetworkIPAvailabilityListResult = ` +{ + "network_ip_availabilities": [ + { + "network_id": "080ee064-036d-405a-a307-3bde4a213a1b", + "network_name": "private", + "project_id": "fb57277ef2f84a0e85b9018ec2dedbf7", + "subnet_ip_availability": [ + { + "cidr": "10.0.0.64/26", + "ip_version": 4, + "subnet_id": "497ac4d3-0b92-42cf-82de-71302ab2b656", + "subnet_name": "second-private-subnet", + "total_ips": 61, + "used_ips": 12 + }, + { + "cidr": "10.0.0.0/26", + "ip_version": 4, + "subnet_id": "521f47e7-c4fb-452c-b71a-851da38cc571", + "subnet_name": "private-subnet", + "total_ips": 61, + "used_ips": 2 + } + ], + "tenant_id": "fb57277ef2f84a0e85b9018ec2dedbf7", + "total_ips": 122, + "used_ips": 14 + }, + { + "network_id": "cf11ab78-2302-49fa-870f-851a08c7afb8", + "network_name": "public", + "project_id": "424e7cf0243c468ca61732ba45973b3e", + "subnet_ip_availability": [ + { + "cidr": "203.0.113.0/24", + "ip_version": 4, + "subnet_id": "4afe6e5f-9649-40db-b18f-64c7ead942bd", + "subnet_name": "public-subnet", + "total_ips": 253, + "used_ips": 3 + } + ], + "tenant_id": "424e7cf0243c468ca61732ba45973b3e", + "total_ips": 253, + "used_ips": 3 + } + ] +} +` + +// NetworkIPAvailability1 is an expected representation of a first object from the ResourceListResult. +var NetworkIPAvailability1 = networkipavailabilities.NetworkIPAvailability{ + NetworkID: "080ee064-036d-405a-a307-3bde4a213a1b", + NetworkName: "private", + ProjectID: "fb57277ef2f84a0e85b9018ec2dedbf7", + TenantID: "fb57277ef2f84a0e85b9018ec2dedbf7", + TotalIPs: 122, + UsedIPs: 14, + SubnetIPAvailabilities: []networkipavailabilities.SubnetIPAvailability{ + { + SubnetID: "497ac4d3-0b92-42cf-82de-71302ab2b656", + SubnetName: "second-private-subnet", + CIDR: "10.0.0.64/26", + IPVersion: int(gophercloud.IPv4), + TotalIPs: 61, + UsedIPs: 12, + }, + { + SubnetID: "521f47e7-c4fb-452c-b71a-851da38cc571", + SubnetName: "private-subnet", + CIDR: "10.0.0.0/26", + IPVersion: int(gophercloud.IPv4), + TotalIPs: 61, + UsedIPs: 2, + }, + }, +} + +// NetworkIPAvailability2 is an expected representation of a first object from the ResourceListResult. +var NetworkIPAvailability2 = networkipavailabilities.NetworkIPAvailability{ + NetworkID: "cf11ab78-2302-49fa-870f-851a08c7afb8", + NetworkName: "public", + ProjectID: "424e7cf0243c468ca61732ba45973b3e", + TenantID: "424e7cf0243c468ca61732ba45973b3e", + TotalIPs: 253, + UsedIPs: 3, + SubnetIPAvailabilities: []networkipavailabilities.SubnetIPAvailability{ + { + SubnetID: "4afe6e5f-9649-40db-b18f-64c7ead942bd", + SubnetName: "public-subnet", + CIDR: "203.0.113.0/24", + IPVersion: int(gophercloud.IPv4), + TotalIPs: 253, + UsedIPs: 3, + }, + }, +} + +// NetworkIPAvailabilityGetResult represents raw server response from a server to a get call. +const NetworkIPAvailabilityGetResult = ` +{ + "network_ip_availability": { + "network_id": "cf11ab78-2302-49fa-870f-851a08c7afb8", + "network_name": "public", + "project_id": "424e7cf0243c468ca61732ba45973b3e", + "subnet_ip_availability": [ + { + "cidr": "203.0.113.0/24", + "ip_version": 4, + "subnet_id": "4afe6e5f-9649-40db-b18f-64c7ead942bd", + "subnet_name": "public-subnet", + "total_ips": 253, + "used_ips": 3 + } + ], + "tenant_id": "424e7cf0243c468ca61732ba45973b3e", + "total_ips": 253, + "used_ips": 3 + } +} +` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/requests_test.go new file mode 100644 index 00000000..820debb2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/testing/requests_test.go @@ -0,0 +1,87 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/network-ip-availabilities", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, NetworkIPAvailabilityListResult) + }) + + count := 0 + + networkipavailabilities.List(fake.ServiceClient(), networkipavailabilities.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := networkipavailabilities.ExtractNetworkIPAvailabilities(page) + if err != nil { + t.Errorf("Failed to extract network IP availabilities: %v", err) + return false, nil + } + + expected := []networkipavailabilities.NetworkIPAvailability{ + NetworkIPAvailability1, + NetworkIPAvailability2, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/network-ip-availabilities/cf11ab78-2302-49fa-870f-851a08c7afb8", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, NetworkIPAvailabilityGetResult) + }) + + s, err := networkipavailabilities.Get(fake.ServiceClient(), "cf11ab78-2302-49fa-870f-851a08c7afb8").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.NetworkID, "cf11ab78-2302-49fa-870f-851a08c7afb8") + th.AssertEquals(t, s.NetworkName, "public") + th.AssertEquals(t, s.ProjectID, "424e7cf0243c468ca61732ba45973b3e") + th.AssertEquals(t, s.TenantID, "424e7cf0243c468ca61732ba45973b3e") + th.AssertEquals(t, s.TotalIPs, 253) + th.AssertEquals(t, s.UsedIPs, 3) + th.AssertDeepEquals(t, s.SubnetIPAvailabilities, []networkipavailabilities.SubnetIPAvailability{ + { + SubnetID: "4afe6e5f-9649-40db-b18f-64c7ead942bd", + SubnetName: "public-subnet", + CIDR: "203.0.113.0/24", + IPVersion: int(gophercloud.IPv4), + TotalIPs: 253, + UsedIPs: 3, + }, + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/urls.go new file mode 100644 index 00000000..5e3228ff --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/networkipavailabilities/urls.go @@ -0,0 +1,21 @@ +package networkipavailabilities + +import "github.com/gophercloud/gophercloud" + +const resourcePath = "network-ip-availabilities" + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, networkIPAvailabilityID string) string { + return c.ServiceURL(resourcePath, networkIPAvailabilityID) +} + +func listURL(c *gophercloud.ServiceClient) string { + return rootURL(c) +} + +func getURL(c *gophercloud.ServiceClient, networkIPAvailabilityID string) string { + return resourceURL(c, networkIPAvailabilityID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding/testing/requests_test.go new file mode 100644 index 00000000..57901a6b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding/testing/requests_test.go @@ -0,0 +1,183 @@ +package testing + +import ( + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleListSuccessfully(t) + + type PortWithExt struct { + ports.Port + portsbinding.PortsBindingExt + } + var actual []PortWithExt + + expected := []PortWithExt{ + { + Port: ports.Port{ + Status: "ACTIVE", + Name: "", + AdminStateUp: true, + NetworkID: "70c1db1f-b701-45bd-96e0-a313ee3430b3", + TenantID: "", + DeviceOwner: "network:router_gateway", + MACAddress: "fa:16:3e:58:42:ed", + FixedIPs: []ports.IP{ + { + SubnetID: "008ba151-0b8c-4a67-98b5-0d2b87666062", + IPAddress: "172.24.4.2", + }, + }, + ID: "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b", + SecurityGroups: []string{}, + DeviceID: "9ae135f4-b6e0-4dad-9e91-3c223e385824", + }, + PortsBindingExt: portsbinding.PortsBindingExt{ + VNICType: "normal", + HostID: "devstack", + }, + }, + } + + allPages, err := ports.List(fake.ServiceClient(), ports.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = ports.ExtractPortsInto(allPages, &actual) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, expected, actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleGet(t) + + var s struct { + ports.Port + portsbinding.PortsBindingExt + } + + err := ports.Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, "ACTIVE") + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.AdminStateUp, true) + th.AssertEquals(t, s.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, s.TenantID, "7e02058126cc4950b75f9970368ba177") + th.AssertEquals(t, s.DeviceOwner, "network:router_interface") + th.AssertEquals(t, s.MACAddress, "fa:16:3e:23:fd:d7") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"}, + }) + th.AssertEquals(t, s.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2") + th.AssertDeepEquals(t, s.SecurityGroups, []string{}) + th.AssertEquals(t, s.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e") + + th.AssertEquals(t, s.HostID, "devstack") + th.AssertEquals(t, s.VNICType, "normal") + th.AssertEquals(t, s.VIFType, "ovs") + th.AssertDeepEquals(t, s.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true}) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleCreate(t) + + var s struct { + ports.Port + portsbinding.PortsBindingExt + } + + asu := true + portCreateOpts := ports.CreateOpts{ + Name: "private-port", + AdminStateUp: &asu, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + SecurityGroups: &[]string{"foo"}, + } + + createOpts := portsbinding.CreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + HostID: "HOST1", + VNICType: "normal", + } + + err := ports.Create(fake.ServiceClient(), createOpts).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, "DOWN") + th.AssertEquals(t, s.Name, "private-port") + th.AssertEquals(t, s.AdminStateUp, true) + th.AssertEquals(t, s.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, s.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, s.DeviceOwner, "") + th.AssertEquals(t, s.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }) + th.AssertEquals(t, s.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) + th.AssertEquals(t, s.HostID, "HOST1") + th.AssertEquals(t, s.VNICType, "normal") +} + +func TestRequiredCreateOpts(t *testing.T) { + res := ports.Create(fake.ServiceClient(), portsbinding.CreateOptsExt{CreateOptsBuilder: ports.CreateOpts{}}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + HandleUpdate(t) + + var s struct { + ports.Port + portsbinding.PortsBindingExt + } + + portUpdateOpts := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + SecurityGroups: &[]string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}, + } + + updateOpts := portsbinding.UpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + HostID: "HOST1", + VNICType: "normal", + } + + err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) + th.AssertEquals(t, s.HostID, "HOST1") + th.AssertEquals(t, s.VNICType, "normal") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/doc.go index 9de4fcf7..2b9a3916 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/doc.go @@ -29,20 +29,117 @@ Example to List Networks with Port Security Information fmt.Println("%+v\n", network) } +Example to Create a Network without Port Security + + var networkWithPortSecurityExt struct { + networks.Network + portsecurity.PortSecurityExt + } + + networkCreateOpts := networks.CreateOpts{ + Name: "private", + } + + iFalse := false + createOpts := portsecurity.NetworkCreateOptsExt{ + CreateOptsBuilder: networkCreateOpts, + PortSecurityEnabled: &iFalse, + } + + err := networks.Create(networkClient, createOpts).ExtractInto(&networkWithPortSecurityExt) + if err != nil { + panic(err) + } + + fmt.Println("%+v\n", networkWithPortSecurityExt) + +Example to Disable Port Security on an Existing Network + + var networkWithPortSecurityExt struct { + networks.Network + portsecurity.PortSecurityExt + } + + iFalse := false + networkID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" + networkUpdateOpts := networks.UpdateOpts{} + updateOpts := portsecurity.NetworkUpdateOptsExt{ + UpdateOptsBuilder: networkUpdateOpts, + PortSecurityEnabled: &iFalse, + } + + err := networks.Update(networkClient, networkID, updateOpts).ExtractInto(&networkWithPortSecurityExt) + if err != nil { + panic(err) + } + + fmt.Println("%+v\n", networkWithPortSecurityExt) + Example to Get a Port with Port Security Information - var portWithExtensions struct { + var portWithPortSecurityExtensions struct { ports.Port portsecurity.PortSecurityExt } portID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" - err := ports.Get(networkingClient, portID).ExtractInto(&portWithExtensions) + err := ports.Get(networkingClient, portID).ExtractInto(&portWithPortSecurityExtensions) + if err != nil { + panic(err) + } + + fmt.Println("%+v\n", portWithPortSecurityExtensions) + +Example to Create a Port Without Port Security + + var portWithPortSecurityExtensions struct { + ports.Port + portsecurity.PortSecurityExt + } + + iFalse := false + networkID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" + subnetID := "a87cc70a-3e15-4acf-8205-9b711a3531b7" + + portCreateOpts := ports.CreateOpts{ + NetworkID: networkID, + FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, + } + + createOpts := portsecurity.PortCreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + PortSecurityEnabled: &iFalse, + } + + err := ports.Create(networkingClient, createOpts).ExtractInto(&portWithPortSecurityExtensions) + if err != nil { + panic(err) + } + + fmt.Println("%+v\n", portWithPortSecurityExtensions) + +Example to Disable Port Security on an Existing Port + + var portWithPortSecurityExtensions struct { + ports.Port + portsecurity.PortSecurityExt + } + + iFalse := false + portID := "65c0ee9f-d634-4522-8954-51021b570b0d" + + portUpdateOpts := ports.UpdateOpts{} + updateOpts := portsecurity.PortUpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + PortSecurityEnabled: &iFalse, + } + + err := ports.Update(networkingClient, portID, updateOpts).ExtractInto(&portWithPortSecurityExtensions) if err != nil { panic(err) } - fmt.Println("%+v\n", portWithExtensions) + fmt.Println("%+v\n", portWithPortSecurityExtensions) */ package portsecurity diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/requests.go new file mode 100644 index 00000000..c80f47cf --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity/requests.go @@ -0,0 +1,104 @@ +package portsecurity + +import ( + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" +) + +// PortCreateOptsExt adds port security options to the base ports.CreateOpts. +type PortCreateOptsExt struct { + ports.CreateOptsBuilder + + // PortSecurityEnabled toggles port security on a port. + PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"` +} + +// ToPortCreateMap casts a CreateOpts struct to a map. +func (opts PortCreateOptsExt) ToPortCreateMap() (map[string]interface{}, error) { + base, err := opts.CreateOptsBuilder.ToPortCreateMap() + if err != nil { + return nil, err + } + + port := base["port"].(map[string]interface{}) + + if opts.PortSecurityEnabled != nil { + port["port_security_enabled"] = &opts.PortSecurityEnabled + } + + return base, nil +} + +// PortUpdateOptsExt adds port security options to the base ports.UpdateOpts. +type PortUpdateOptsExt struct { + ports.UpdateOptsBuilder + + // PortSecurityEnabled toggles port security on a port. + PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"` +} + +// ToPortUpdateMap casts a UpdateOpts struct to a map. +func (opts PortUpdateOptsExt) ToPortUpdateMap() (map[string]interface{}, error) { + base, err := opts.UpdateOptsBuilder.ToPortUpdateMap() + if err != nil { + return nil, err + } + + port := base["port"].(map[string]interface{}) + + if opts.PortSecurityEnabled != nil { + port["port_security_enabled"] = &opts.PortSecurityEnabled + } + + return base, nil +} + +// NetworkCreateOptsExt adds port security options to the base +// networks.CreateOpts. +type NetworkCreateOptsExt struct { + networks.CreateOptsBuilder + + // PortSecurityEnabled toggles port security on a port. + PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"` +} + +// ToNetworkCreateMap casts a CreateOpts struct to a map. +func (opts NetworkCreateOptsExt) ToNetworkCreateMap() (map[string]interface{}, error) { + base, err := opts.CreateOptsBuilder.ToNetworkCreateMap() + if err != nil { + return nil, err + } + + network := base["network"].(map[string]interface{}) + + if opts.PortSecurityEnabled != nil { + network["port_security_enabled"] = &opts.PortSecurityEnabled + } + + return base, nil +} + +// NetworkUpdateOptsExt adds port security options to the base +// networks.UpdateOpts. +type NetworkUpdateOptsExt struct { + networks.UpdateOptsBuilder + + // PortSecurityEnabled toggles port security on a port. + PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"` +} + +// ToNetworkUpdateMap casts a UpdateOpts struct to a map. +func (opts NetworkUpdateOptsExt) ToNetworkUpdateMap() (map[string]interface{}, error) { + base, err := opts.UpdateOptsBuilder.ToNetworkUpdateMap() + if err != nil { + return nil, err + } + + network := base["network"].(map[string]interface{}) + + if opts.PortSecurityEnabled != nil { + network["port_security_enabled"] = &opts.PortSecurityEnabled + } + + return base, nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider/testing/results_test.go new file mode 100644 index 00000000..709f8306 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider/testing/results_test.go @@ -0,0 +1,222 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + nettest "github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, nettest.ListResponse) + }) + + type NetworkWithExt struct { + networks.Network + provider.NetworkProviderExt + } + var actual []NetworkWithExt + + allPages, err := networks.List(fake.ServiceClient(), networks.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = networks.ExtractNetworksInto(allPages, &actual) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "d32019d3-bc6e-4319-9c1d-6722fc136a22", actual[0].ID) + th.AssertEquals(t, "db193ab3-96e3-4cb3-8fc5-05f4296d0324", actual[1].ID) + th.AssertEquals(t, "local", actual[1].NetworkType) + th.AssertEquals(t, "1234567890", actual[1].SegmentationID) + th.AssertEquals(t, actual[0].Subnets[0], "54d6f61d-db07-451c-9ab3-b9609b6b6f0b") + th.AssertEquals(t, actual[1].Subnets[0], "08eae331-0402-425a-923c-34f7cfe39c1b") + +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, nettest.GetResponse) + }) + + var s struct { + networks.Network + provider.NetworkProviderExt + } + + err := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "d32019d3-bc6e-4319-9c1d-6722fc136a22", s.ID) + th.AssertEquals(t, "", s.PhysicalNetwork) + th.AssertEquals(t, "local", s.NetworkType) + th.AssertEquals(t, "9876543210", s.SegmentationID) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, nettest.CreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, nettest.CreateResponse) + }) + + var s struct { + networks.Network + provider.NetworkProviderExt + } + + options := networks.CreateOpts{Name: "private", AdminStateUp: gophercloud.Enabled} + err := networks.Create(fake.ServiceClient(), options).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "db193ab3-96e3-4cb3-8fc5-05f4296d0324", s.ID) + th.AssertEquals(t, "", s.PhysicalNetwork) + th.AssertEquals(t, "local", s.NetworkType) + th.AssertEquals(t, "9876543210", s.SegmentationID) +} + +func TestCreateWithMultipleProvider(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "network": { + "name": "sample_network", + "admin_state_up": true, + "shared": true, + "tenant_id": "12345", + "segments": [ + { + "provider:segmentation_id": 666, + "provider:physical_network": "br-ex", + "provider:network_type": "vxlan" + }, + { + "provider:segmentation_id": 615, + "provider:physical_network": "br-ex", + "provider:network_type": "vxlan" + } + ] + } +} + `) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, ` +{ + "network": { + "status": "ACTIVE", + "name": "sample_network", + "admin_state_up": true, + "shared": true, + "tenant_id": "12345", + "segments": [ + { + "provider:segmentation_id": 666, + "provider:physical_network": "br-ex", + "provider:network_type": "vlan" + }, + { + "provider:segmentation_id": 615, + "provider:physical_network": "br-ex", + "provider:network_type": "vlan" + } + ] + } +} + `) + }) + + iTrue := true + segments := []provider.Segment{ + provider.Segment{NetworkType: "vxlan", PhysicalNetwork: "br-ex", SegmentationID: 666}, + provider.Segment{NetworkType: "vxlan", PhysicalNetwork: "br-ex", SegmentationID: 615}, + } + + networkCreateOpts := networks.CreateOpts{ + Name: "sample_network", + AdminStateUp: &iTrue, + Shared: &iTrue, + TenantID: "12345", + } + + providerCreateOpts := provider.CreateOptsExt{ + CreateOptsBuilder: networkCreateOpts, + Segments: segments, + } + + _, err := networks.Create(fake.ServiceClient(), providerCreateOpts).Extract() + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, nettest.UpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, nettest.UpdateResponse) + }) + + var s struct { + networks.Network + provider.NetworkProviderExt + } + + iTrue := true + options := networks.UpdateOpts{Name: "new_network_name", AdminStateUp: gophercloud.Disabled, Shared: &iTrue} + err := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, "4e8e5957-649f-477b-9e5b-f1f75b21c03c", s.ID) + th.AssertEquals(t, "", s.PhysicalNetwork) + th.AssertEquals(t, "local", s.NetworkType) + th.AssertEquals(t, "1234567890", s.SegmentationID) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/doc.go new file mode 100644 index 00000000..5cfc6884 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/doc.go @@ -0,0 +1,19 @@ +/* +Package ruletypes contains functionality for working with Neutron 'quality of service' rule-type resources. + +Example: You can list rule-types in the following way: + + page, err := ruletypes.ListRuleTypes(client).AllPages() + if err != nil { + return + } + + rules, err := ruletypes.ExtractRuleTypes(page) + if err != nil { + return + } + + fmt.Printf("%v <- Rule Types\n", rules) + +*/ +package ruletypes diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/requests.go new file mode 100644 index 00000000..e193cea5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/requests.go @@ -0,0 +1,13 @@ +package ruletypes + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListRuleTypes returns the list of rule types from the server +func ListRuleTypes(c *gophercloud.ServiceClient) (result pagination.Pager) { + return pagination.NewPager(c, listRuleTypesURL(c), func(r pagination.PageResult) pagination.Page { + return ListRuleTypesPage{pagination.SinglePageBase(r)} + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/results.go new file mode 100644 index 00000000..f6281881 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/results.go @@ -0,0 +1,26 @@ +package ruletypes + +import "github.com/gophercloud/gophercloud/pagination" + +// The result of listing the qos rule types +type RuleType struct { + Type string `json:"type"` +} + +type ListRuleTypesPage struct { + pagination.SinglePageBase +} + +func (r ListRuleTypesPage) IsEmpty() (bool, error) { + v, err := ExtractRuleTypes(r) + return len(v) == 0, err +} + +func ExtractRuleTypes(r pagination.Page) ([]RuleType, error) { + var s struct { + RuleTypes []RuleType `json:"rule_types"` + } + + err := (r.(ListRuleTypesPage)).ExtractInto(&s) + return s.RuleTypes, err +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/doc.go new file mode 100644 index 00000000..1e9c71e8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/doc.go @@ -0,0 +1,2 @@ +// qos unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/fixtures.go new file mode 100644 index 00000000..63556695 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/fixtures.go @@ -0,0 +1,19 @@ +package testing + +const ( + ListRuleTypesResponse = ` +{ + "rule_types": [ + { + "type": "bandwidth_limit" + }, + { + "type": "dscp_marking" + }, + { + "type": "minimum_bandwidth" + } + ] +} +` +) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/requests_test.go new file mode 100644 index 00000000..79559efe --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/testing/requests_test.go @@ -0,0 +1,41 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListRuleTypes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprint(w, ListRuleTypesResponse) + }) + + page, err := ruletypes.ListRuleTypes(fake.ServiceClient()).AllPages() + if err != nil { + t.Errorf("Failed to list rule types pages: %v", err) + return + } + + rules, err := ruletypes.ExtractRuleTypes(page) + if err != nil { + t.Errorf("Failed to list rule types: %v", err) + return + } + + expected := []ruletypes.RuleType{{Type: "bandwidth_limit"}, {Type: "dscp_marking"}, {Type: "minimum_bandwidth"}} + th.AssertDeepEquals(t, expected, rules) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/urls.go new file mode 100644 index 00000000..15795100 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/ruletypes/urls.go @@ -0,0 +1,7 @@ +package ruletypes + +import "github.com/gophercloud/gophercloud" + +func listRuleTypesURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL("qos", "rule-types") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/doc.go new file mode 100644 index 00000000..f0ddbc0f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/doc.go @@ -0,0 +1,79 @@ +/* +Package rbacpolicies contains functionality for working with Neutron RBAC Policies. +Role-Based Access Control (RBAC) policy framework enables both operators +and users to grant access to resources for specific projects. + +Sharing an object with a specific project is accomplished by creating a +policy entry that permits the target project the access_as_shared action +on that object. + +To make a network available as an external network for specific projects +rather than all projects, use the access_as_external action. +If a network is marked as external during creation, it now implicitly creates +a wildcard RBAC policy granting everyone access to preserve previous behavior +before this feature was added. + +Example to Create a RBAC Policy + + createOpts := rbacpolicies.CreateOpts{ + Action: rbacpolicies.ActionAccessShared, + ObjectType: "network", + TargetTenant: "6e547a3bcfe44702889fdeff3c3520c3", + ObjectID: "240d22bf-bd17-4238-9758-25f72610ecdc" + } + + rbacPolicy, err := rbacpolicies.Create(rbacClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to List RBAC Policies + + listOpts := rbacpolicies.ListOpts{ + TenantID: "a99e9b4e620e4db09a2dfb6e42a01e66", + } + + allPages, err := rbacpolicies.List(rbacClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allRBACPolicies, err := rbacpolicies.ExtractRBACPolicies(allPages) + if err != nil { + panic(err) + } + + for _, rbacpolicy := range allRBACPolicies { + fmt.Printf("%+v", rbacpolicy) + } + +Example to Delete a RBAC Policy + + rbacPolicyID := "94fe107f-da78-4d92-a9d7-5611b06dad8d" + err := rbacpolicies.Delete(rbacClient, rbacPolicyID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Get RBAC Policy by ID + + rbacPolicyID := "94fe107f-da78-4d92-a9d7-5611b06dad8d" + rbacpolicy, err := rbacpolicies.Get(rbacClient, rbacPolicyID).Extract() + if err != nil { + panic(err) + } + fmt.Printf("%+v", rbacpolicy) + +Example to Update a RBAC Policy + + rbacPolicyID := "570b0306-afb5-4d3b-ab47-458fdc16baaa" + updateOpts := rbacpolicies.UpdateOpts{ + TargetTenant: "9d766060b6354c9e8e2da44cab0e8f38", + } + rbacPolicy, err := rbacpolicies.Update(rbacClient, rbacPolicyID, updateOpts).Extract() + if err != nil { + panic(err) + } + +*/ +package rbacpolicies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/requests.go new file mode 100644 index 00000000..532a2f23 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/requests.go @@ -0,0 +1,142 @@ +package rbacpolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToRBACPolicyListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the rbac attributes you want to see returned. SortKey allows you to sort +// by a particular rbac attribute. SortDir sets the direction, and is either +// `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + TargetTenant string `q:"target_tenant"` + ObjectType string `q:"object_type"` + ObjectID string `q:"object_id"` + Action PolicyAction `q:"action"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + Marker string `q:"marker"` + Limit int `q:"limit"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToRBACPolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToRBACPolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// rbac policies. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listURL(c) + if opts != nil { + query, err := opts.ToRBACPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return RBACPolicyPage{pagination.LinkedPageBase{PageResult: r}} + + }) +} + +// Get retrieves a specific rbac policy based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(getURL(c, id), &r.Body, nil) + return +} + +// PolicyAction maps to Action for the RBAC policy. +// Which allows access_as_external or access_as_shared. +type PolicyAction string + +const ( + // ActionAccessExternal returns Action for the RBAC policy as access_as_external. + ActionAccessExternal PolicyAction = "access_as_external" + + // ActionAccessShared returns Action for the RBAC policy as access_as_shared. + ActionAccessShared PolicyAction = "access_as_shared" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToRBACPolicyCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options used to create a rbac-policy. +type CreateOpts struct { + Action PolicyAction `json:"action" required:"true"` + ObjectType string `json:"object_type" required:"true"` + TargetTenant string `json:"target_tenant" required:"true"` + ObjectID string `json:"object_id" required:"true"` +} + +// ToRBACPolicyCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToRBACPolicyCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "rbac_policy") +} + +// Create accepts a CreateOpts struct and creates a new rbac-policy using the values +// provided. +// +// The tenant ID that is contained in the URI is the tenant that creates the +// rbac-policy. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToRBACPolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(createURL(c), b, &r.Body, nil) + return +} + +// Delete accepts a unique ID and deletes the rbac-policy associated with it. +func Delete(c *gophercloud.ServiceClient, rbacPolicyID string) (r DeleteResult) { + _, r.Err = c.Delete(deleteURL(c, rbacPolicyID), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToRBACPolicyUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options used to update a rbac-policy. +type UpdateOpts struct { + TargetTenant string `json:"target_tenant" required:"true"` +} + +// ToRBACPolicyUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToRBACPolicyUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "rbac_policy") +} + +// Update accepts a UpdateOpts struct and updates an existing rbac-policy using the +// values provided. +func Update(c *gophercloud.ServiceClient, rbacPolicyID string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToRBACPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(updateURL(c, rbacPolicyID), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/results.go new file mode 100644 index 00000000..a62facc0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/results.go @@ -0,0 +1,98 @@ +package rbacpolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts RBAC Policy resource. +func (r commonResult) Extract() (*RBACPolicy, error) { + var s RBACPolicy + err := r.ExtractInto(&s) + return &s, err +} + +func (r commonResult) ExtractInto(v interface{}) error { + return r.Result.ExtractIntoStructPtr(v, "rbac_policy") +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a RBAC Policy. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a RBAC Policy. +type GetResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the request succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a RBAC Policy. +type UpdateResult struct { + commonResult +} + +// RBACPolicy represents a RBAC policy. +type RBACPolicy struct { + // UUID of the RBAC policy. + ID string `json:"id"` + + // Action for the RBAC policy which is access_as_external or access_as_shared. + Action PolicyAction `json:"action"` + + // ObjectID is the ID of the object_type resource. + // An object_type of network returns a network ID and + // object_type of qos-policy returns a QoS ID. + ObjectID string `json:"object_id"` + + // ObjectType is the type of the object that the RBAC policy affects. + // Types include qos-policy or network. + ObjectType string `json:"object_type"` + + // TenantID is the ID of the project that owns the resource. + TenantID string `json:"tenant_id"` + + // TargetTenant is the ID of the tenant to which the RBAC policy will be enforced. + TargetTenant string `json:"target_tenant"` + + // ProjectID is the ID of the project. + ProjectID string `json:"project_id"` +} + +// RBACPolicyPage is the page returned by a pager when traversing over a +// collection of rbac policies. +type RBACPolicyPage struct { + pagination.LinkedPageBase +} + +// IsEmpty checks whether a RBACPolicyPage struct is empty. +func (r RBACPolicyPage) IsEmpty() (bool, error) { + is, err := ExtractRBACPolicies(r) + return len(is) == 0, err +} + +// ExtractRBACPolicies accepts a Page struct, specifically a RBAC Policy struct, +// and extracts the elements into a slice of RBAC Policy structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractRBACPolicies(r pagination.Page) ([]RBACPolicy, error) { + var s []RBACPolicy + err := ExtractRBACPolicesInto(r, &s) + return s, err +} + +// ExtractRBACPolicesInto extracts the elements into a slice of RBAC Policy structs. +func ExtractRBACPolicesInto(r pagination.Page, v interface{}) error { + return r.(RBACPolicyPage).Result.ExtractIntoSlicePtr(v, "rbac_policies") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/doc.go new file mode 100644 index 00000000..e95610ae --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/doc.go @@ -0,0 +1,2 @@ +// Package testing includes rbac unit tests +package testing diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/fixtures.go new file mode 100644 index 00000000..f63fa2b8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/fixtures.go @@ -0,0 +1,112 @@ +package testing + +import ( + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" +) + +const ListResponse = ` +{ + "rbac_policies": [ + { + "target_tenant": "6e547a3bcfe44702889fdeff3c3520c3", + "tenant_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "object_type": "network", + "object_id": "240d22bf-bd17-4238-9758-25f72610ecdc", + "action": "access_as_shared", + "project_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "id": "2cf7523a-93b5-4e69-9360-6c6bf986bb7c" + }, + { + "target_tenant": "1a547a3bcfe44702889fdeff3c3520c3", + "tenant_id": "1ae27ce0a2a54cc6ae06dc62dd0ec832", + "object_type": "network", + "object_id": "120d22bf-bd17-4238-9758-25f72610ecdc", + "action": "access_as_shared", + "project_id": "1ae27ce0a2a54cc6ae06dc62dd0ec832", + "id":"1ab7523a-93b5-4e69-9360-6c6bf986bb7c" + } + ] +}` + +// CreateRequest is the structure of request body to create rbac-policy. +const CreateRequest = ` +{ + "rbac_policy": { + "action": "access_as_shared", + "object_type": "network", + "target_tenant": "6e547a3bcfe44702889fdeff3c3520c3", + "object_id": "240d22bf-bd17-4238-9758-25f72610ecdc" + } +}` + +// CreateResponse is the structure of response body of rbac-policy create. +const CreateResponse = ` +{ + "rbac_policy": { + "target_tenant": "6e547a3bcfe44702889fdeff3c3520c3", + "tenant_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "object_type": "network", + "object_id": "240d22bf-bd17-4238-9758-25f72610ecdc", + "action": "access_as_shared", + "project_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "id": "2cf7523a-93b5-4e69-9360-6c6bf986bb7c" + } +}` + +// GetResponse is the structure of the response body of rbac-policy get operation. +const GetResponse = ` +{ + "rbac_policy": { + "target_tenant": "6e547a3bcfe44702889fdeff3c3520c3", + "tenant_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "object_type": "network", + "object_id": "240d22bf-bd17-4238-9758-25f72610ecdc", + "action": "access_as_shared", + "project_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "id": "2cf7523a-93b5-4e69-9360-6c6bf986bb7c" + } +}` + +// UpdateRequest is the structure of request body to update rbac-policy. +const UpdateRequest = ` +{ + "rbac_policy": { + "target_tenant": "9d766060b6354c9e8e2da44cab0e8f38" + } +}` + +// UpdateResponse is the structure of response body of rbac-policy update. +const UpdateResponse = ` +{ + "rbac_policy": { + "target_tenant": "9d766060b6354c9e8e2da44cab0e8f38", + "tenant_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "object_type": "network", + "object_id": "240d22bf-bd17-4238-9758-25f72610ecdc", + "action": "access_as_shared", + "project_id": "3de27ce0a2a54cc6ae06dc62dd0ec832", + "id": "2cf7523a-93b5-4e69-9360-6c6bf986bb7c" + } +}` + +var rbacPolicy1 = rbacpolicies.RBACPolicy{ + ID: "2cf7523a-93b5-4e69-9360-6c6bf986bb7c", + Action: rbacpolicies.ActionAccessShared, + ObjectID: "240d22bf-bd17-4238-9758-25f72610ecdc", + ObjectType: "network", + TenantID: "3de27ce0a2a54cc6ae06dc62dd0ec832", + TargetTenant: "6e547a3bcfe44702889fdeff3c3520c3", + ProjectID: "3de27ce0a2a54cc6ae06dc62dd0ec832", +} + +var rbacPolicy2 = rbacpolicies.RBACPolicy{ + ID: "1ab7523a-93b5-4e69-9360-6c6bf986bb7c", + Action: rbacpolicies.ActionAccessShared, + ObjectID: "120d22bf-bd17-4238-9758-25f72610ecdc", + ObjectType: "network", + TenantID: "1ae27ce0a2a54cc6ae06dc62dd0ec832", + TargetTenant: "1a547a3bcfe44702889fdeff3c3520c3", + ProjectID: "1ae27ce0a2a54cc6ae06dc62dd0ec832", +} + +var ExpectedRBACPoliciesSlice = []rbacpolicies.RBACPolicy{rbacPolicy1, rbacPolicy2} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/requests_test.go new file mode 100644 index 00000000..8aad8434 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/testing/requests_test.go @@ -0,0 +1,169 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateRequest) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateResponse) + }) + + options := rbacpolicies.CreateOpts{ + Action: rbacpolicies.ActionAccessShared, + ObjectType: "network", + TargetTenant: "6e547a3bcfe44702889fdeff3c3520c3", + ObjectID: "240d22bf-bd17-4238-9758-25f72610ecdc", + } + rbacResult, err := rbacpolicies.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, &rbacPolicy1, rbacResult) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies/2cf7523a-93b5-4e69-9360-6c6bf986bb7c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) + + n, err := rbacpolicies.Get(fake.ServiceClient(), "2cf7523a-93b5-4e69-9360-6c6bf986bb7c").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &rbacPolicy1, n) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + client := fake.ServiceClient() + count := 0 + + rbacpolicies.List(client, rbacpolicies.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := rbacpolicies.ExtractRBACPolicies(page) + if err != nil { + t.Errorf("Failed to extract rbac policies: %v", err) + return false, err + } + + th.CheckDeepEquals(t, ExpectedRBACPoliciesSlice, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListWithAllPages(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + client := fake.ServiceClient() + + type newRBACPolicy struct { + rbacpolicies.RBACPolicy + } + + var allRBACpolicies []newRBACPolicy + + allPages, err := rbacpolicies.List(client, rbacpolicies.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = rbacpolicies.ExtractRBACPolicesInto(allPages, &allRBACpolicies) + th.AssertNoErr(t, err) + + th.AssertEquals(t, allRBACpolicies[0].ObjectType, "network") + th.AssertEquals(t, allRBACpolicies[0].Action, rbacpolicies.ActionAccessShared) + + th.AssertEquals(t, allRBACpolicies[1].ProjectID, "1ae27ce0a2a54cc6ae06dc62dd0ec832") + th.AssertEquals(t, allRBACpolicies[1].TargetTenant, "1a547a3bcfe44702889fdeff3c3520c3") + +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies/71d55b18-d2f8-4c76-a5e6-e0a3dd114361", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := rbacpolicies.Delete(fake.ServiceClient(), "71d55b18-d2f8-4c76-a5e6-e0a3dd114361").ExtractErr() + th.AssertNoErr(t, res) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/rbac-policies/2cf7523a-93b5-4e69-9360-6c6bf986bb7c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateResponse) + }) + + options := rbacpolicies.UpdateOpts{TargetTenant: "9d766060b6354c9e8e2da44cab0e8f38"} + rbacResult, err := rbacpolicies.Update(fake.ServiceClient(), "2cf7523a-93b5-4e69-9360-6c6bf986bb7c", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, rbacResult.TargetTenant, "9d766060b6354c9e8e2da44cab0e8f38") + th.AssertEquals(t, rbacResult.ID, "2cf7523a-93b5-4e69-9360-6c6bf986bb7c") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/urls.go new file mode 100644 index 00000000..8beeed9a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies/urls.go @@ -0,0 +1,31 @@ +package rbacpolicies + +import "github.com/gophercloud/gophercloud" + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL("rbac-policies", id) +} + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL("rbac-policies") +} + +func createURL(c *gophercloud.ServiceClient) string { + return rootURL(c) +} + +func listURL(c *gophercloud.ServiceClient) string { + return rootURL(c) +} + +func getURL(c *gophercloud.ServiceClient, id string) string { + return resourceURL(c, id) +} + +func deleteURL(c *gophercloud.ServiceClient, id string) string { + return resourceURL(c, id) +} + +func updateURL(c *gophercloud.ServiceClient, id string) string { + return resourceURL(c, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/requests.go index 0a7ef79c..2a46ce6a 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/requests.go @@ -11,13 +11,14 @@ import ( // sort by a particular network attribute. SortDir sets the direction, and is // either `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { - ID string `q:"id"` - Name string `q:"name"` - TenantID string `q:"tenant_id"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` + ID string `q:"id"` + Name string `q:"name"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` } // List returns a Pager which allows you to iterate over a collection of @@ -45,10 +46,14 @@ type CreateOpts struct { // Human-readable name for the Security Group. Does not have to be unique. Name string `json:"name" required:"true"` - // The UUID of the tenant who owns the Group. Only administrative users - // can specify a tenant UUID other than their own. + // TenantID is the UUID of the project who owns the Group. + // Only administrative users can specify a tenant UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // ProjectID is the UUID of the project who owns the Group. + // Only administrative users can specify a tenant UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // Describes the security group. Description string `json:"description,omitempty"` } @@ -123,7 +128,12 @@ func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, ListOpts{}).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/results.go index 8a8e0ffc..66915e6e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/results.go @@ -22,8 +22,11 @@ type SecGroup struct { // traffic entering and leaving the group. Rules []rules.SecGroupRule `json:"security_group_rules"` - // Owner of the security group. + // TenantID is the project owner of the security group. TenantID string `json:"tenant_id"` + + // ProjectID is the project owner of the security group. + ProjectID string `json:"project_id"` } // SecGroupPage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/testing/requests_test.go new file mode 100644 index 00000000..5bb8c70c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups/testing/requests_test.go @@ -0,0 +1,134 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-groups", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SecurityGroupListResponse) + }) + + count := 0 + + groups.List(fake.ServiceClient(), groups.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := groups.ExtractGroups(page) + if err != nil { + t.Errorf("Failed to extract secgroups: %v", err) + return false, err + } + + expected := []groups.SecGroup{SecurityGroup1} + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-groups", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SecurityGroupCreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SecurityGroupCreateResponse) + }) + + opts := groups.CreateOpts{Name: "new-webservers", Description: "security group for webservers"} + _, err := groups.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-groups/2076db17-a522-4506-91de-c6dd8e837028", + func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SecurityGroupUpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SecurityGroupUpdateResponse) + }) + + opts := groups.UpdateOpts{Name: "newer-webservers"} + sg, err := groups.Update(fake.ServiceClient(), "2076db17-a522-4506-91de-c6dd8e837028", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "newer-webservers", sg.Name) + th.AssertEquals(t, "security group for webservers", sg.Description) + th.AssertEquals(t, "2076db17-a522-4506-91de-c6dd8e837028", sg.ID) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-groups/85cc3048-abc3-43cc-89b3-377341426ac5", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SecurityGroupGetResponse) + }) + + sg, err := groups.Get(fake.ServiceClient(), "85cc3048-abc3-43cc-89b3-377341426ac5").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "default", sg.Description) + th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sg.ID) + th.AssertEquals(t, "default", sg.Name) + th.AssertEquals(t, 2, len(sg.Rules)) + th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sg.TenantID) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-groups/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := groups.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/requests.go index 197710fc..96cce281 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/requests.go @@ -21,6 +21,7 @@ type ListOpts struct { RemoteIPPrefix string `q:"remote_ip_prefix"` SecGroupID string `q:"security_group_id"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Limit int `q:"limit"` Marker string `q:"marker"` SortKey string `q:"sort_key"` @@ -118,9 +119,9 @@ type CreateOpts struct { // specified IP prefix as the source IP address of the IP packet. RemoteIPPrefix string `json:"remote_ip_prefix,omitempty"` - // The UUID of the tenant who owns the Rule. Only administrative users - // can specify a tenant UUID other than their own. - TenantID string `json:"tenant_id,omitempty"` + // TenantID is the UUID of the project who owns the Rule. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` } // ToSecGroupRuleCreateMap builds a request body from CreateOpts. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/results.go index 0d8c43f8..377e7531 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/results.go @@ -48,8 +48,11 @@ type SecGroupRule struct { // matches the specified IP prefix as the source IP address of the IP packet. RemoteIPPrefix string `json:"remote_ip_prefix"` - // The owner of this security group rule. + // TenantID is the project owner of this security group rule. TenantID string `json:"tenant_id"` + + // ProjectID is the project owner of this security group rule. + ProjectID string `json:"project_id"` } // SecGroupRulePage is the page returned by a pager when traversing over a diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/testing/requests_test.go new file mode 100644 index 00000000..968fd04d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules/testing/requests_test.go @@ -0,0 +1,236 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-group-rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "security_group_rules": [ + { + "direction": "egress", + "ethertype": "IPv6", + "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff", + "port_range_max": null, + "port_range_min": null, + "protocol": null, + "remote_group_id": null, + "remote_ip_prefix": null, + "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + }, + { + "direction": "egress", + "ethertype": "IPv4", + "id": "93aa42e5-80db-4581-9391-3a608bd0e448", + "port_range_max": null, + "port_range_min": null, + "protocol": null, + "remote_group_id": null, + "remote_ip_prefix": null, + "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + } + ] +} + `) + }) + + count := 0 + + rules.List(fake.ServiceClient(), rules.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := rules.ExtractRules(page) + if err != nil { + t.Errorf("Failed to extract secrules: %v", err) + return false, err + } + + expected := []rules.SecGroupRule{ + { + Direction: "egress", + EtherType: "IPv6", + ID: "3c0e45ff-adaf-4124-b083-bf390e5482ff", + PortRangeMax: 0, + PortRangeMin: 0, + Protocol: "", + RemoteGroupID: "", + RemoteIPPrefix: "", + SecGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5", + TenantID: "e4f50856753b4dc6afee5fa6b9b6c550", + }, + { + Direction: "egress", + EtherType: "IPv4", + ID: "93aa42e5-80db-4581-9391-3a608bd0e448", + PortRangeMax: 0, + PortRangeMin: 0, + Protocol: "", + RemoteGroupID: "", + RemoteIPPrefix: "", + SecGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5", + TenantID: "e4f50856753b4dc6afee5fa6b9b6c550", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-group-rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "security_group_rule": { + "direction": "ingress", + "port_range_min": 80, + "ethertype": "IPv4", + "port_range_max": 80, + "protocol": "tcp", + "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", + "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "security_group_rule": { + "direction": "ingress", + "ethertype": "IPv4", + "id": "2bc0accf-312e-429a-956e-e4407625eb62", + "port_range_max": 80, + "port_range_min": 80, + "protocol": "tcp", + "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", + "remote_ip_prefix": null, + "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a", + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + } +} + `) + }) + + opts := rules.CreateOpts{ + Direction: "ingress", + PortRangeMin: 80, + EtherType: rules.EtherType4, + PortRangeMax: 80, + Protocol: "tcp", + RemoteGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5", + SecGroupID: "a7734e61-b545-452d-a3cd-0189cbd9747a", + } + _, err := rules.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := rules.Create(fake.ServiceClient(), rules.CreateOpts{Direction: rules.DirIngress}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = rules.Create(fake.ServiceClient(), rules.CreateOpts{Direction: rules.DirIngress, EtherType: rules.EtherType4}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = rules.Create(fake.ServiceClient(), rules.CreateOpts{Direction: rules.DirIngress, EtherType: rules.EtherType4}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + res = rules.Create(fake.ServiceClient(), rules.CreateOpts{Direction: rules.DirIngress, EtherType: rules.EtherType4, SecGroupID: "something", Protocol: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-group-rules/3c0e45ff-adaf-4124-b083-bf390e5482ff", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "security_group_rule": { + "direction": "egress", + "ethertype": "IPv6", + "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff", + "port_range_max": null, + "port_range_min": null, + "protocol": null, + "remote_group_id": null, + "remote_ip_prefix": null, + "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + } +} + `) + }) + + sr, err := rules.Get(fake.ServiceClient(), "3c0e45ff-adaf-4124-b083-bf390e5482ff").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, "egress", sr.Direction) + th.AssertEquals(t, "IPv6", sr.EtherType) + th.AssertEquals(t, "3c0e45ff-adaf-4124-b083-bf390e5482ff", sr.ID) + th.AssertEquals(t, 0, sr.PortRangeMax) + th.AssertEquals(t, 0, sr.PortRangeMin) + th.AssertEquals(t, "", sr.Protocol) + th.AssertEquals(t, "", sr.RemoteGroupID) + th.AssertEquals(t, "", sr.RemoteIPPrefix) + th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sr.SecGroupID) + th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sr.TenantID) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/security-group-rules/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := rules.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/requests.go index 61f660d5..e7ee96ae 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/requests.go @@ -18,27 +18,24 @@ type ListOptsBuilder interface { // SortDir sets the direction, and is either `asc' or `desc'. // Marker and Limit are used for the pagination. type ListOpts struct { - ID string `q:"id"` - Name string `q:"name"` - DefaultQuota int `q:"default_quota"` - TenantID string `q:"tenant_id"` - ProjectID string `q:"project_id"` - CreatedAt string `q:"created_at"` - UpdatedAt string `q:"updated_at"` - Prefixes []string `q:"prefixes"` - DefaultPrefixLen int `q:"default_prefixlen"` - MinPrefixLen int `q:"min_prefixlen"` - MaxPrefixLen int `q:"max_prefixlen"` - AddressScopeID string `q:"address_scope_id"` - IPversion int `q:"ip_version"` - Shared bool `q:"shared"` - Description string `q:"description"` - IsDefault bool `q:"is_default"` - RevisionNumber int `q:"revision_number"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` + ID string `q:"id"` + Name string `q:"name"` + DefaultQuota int `q:"default_quota"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + DefaultPrefixLen int `q:"default_prefixlen"` + MinPrefixLen int `q:"min_prefixlen"` + MaxPrefixLen int `q:"max_prefixlen"` + AddressScopeID string `q:"address_scope_id"` + IPVersion int `q:"ip_version"` + Shared *bool `q:"shared"` + Description string `q:"description"` + IsDefault *bool `q:"is_default"` + RevisionNumber int `q:"revision_number"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` } // ToSubnetPoolListQuery formats a ListOpts into a query string. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/results.go index a490f054..e761eac4 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/results.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strconv" + "time" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/pagination" @@ -66,10 +67,10 @@ type SubnetPool struct { ProjectID string `json:"project_id"` // CreatedAt is the time at which subnetpool has been created. - CreatedAt string `json:"created_at"` + CreatedAt time.Time `json:"created_at"` // UpdatedAt is the time at which subnetpool has been created. - UpdatedAt string `json:"updated_at"` + UpdatedAt time.Time `json:"updated_at"` // Prefixes is the list of subnet prefixes to assign to the subnetpool. // Neutron API merges adjacent prefixes and treats them as a single prefix. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/fixtures.go index f70b4177..27420289 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/fixtures.go @@ -1,6 +1,8 @@ package testing import ( + "time" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" ) @@ -78,7 +80,7 @@ const SubnetPoolsListResult = ` var SubnetPool1 = subnetpools.SubnetPool{ AddressScopeID: "", - CreatedAt: "2017-12-28T07:21:41Z", + CreatedAt: time.Date(2017, 12, 28, 7, 21, 41, 0, time.UTC), DefaultPrefixLen: 8, DefaultQuota: 0, Description: "IPv4", @@ -96,12 +98,12 @@ var SubnetPool1 = subnetpools.SubnetPool{ TenantID: "1e2b9857295a4a3e841809ef492812c5", RevisionNumber: 1, Shared: false, - UpdatedAt: "2017-12-28T07:21:41Z", + UpdatedAt: time.Date(2017, 12, 28, 7, 21, 41, 0, time.UTC), } var SubnetPool2 = subnetpools.SubnetPool{ AddressScopeID: "0bc38e22-be49-4e67-969e-fec3f36508bd", - CreatedAt: "2017-12-28T07:21:34Z", + CreatedAt: time.Date(2017, 12, 28, 7, 21, 34, 0, time.UTC), DefaultPrefixLen: 64, DefaultQuota: 0, Description: "IPv6", @@ -119,12 +121,12 @@ var SubnetPool2 = subnetpools.SubnetPool{ TenantID: "1e2b9857295a4a3e841809ef492812c5", RevisionNumber: 1, Shared: false, - UpdatedAt: "2017-12-28T07:21:34Z", + UpdatedAt: time.Date(2017, 12, 28, 7, 21, 34, 0, time.UTC), } var SubnetPool3 = subnetpools.SubnetPool{ AddressScopeID: "", - CreatedAt: "2017-12-28T07:21:27Z", + CreatedAt: time.Date(2017, 12, 28, 7, 21, 27, 0, time.UTC), DefaultPrefixLen: 64, DefaultQuota: 4, Description: "PublicPool", @@ -141,7 +143,7 @@ var SubnetPool3 = subnetpools.SubnetPool{ TenantID: "ceb366d50ad54fe39717df3af60f9945", RevisionNumber: 1, Shared: true, - UpdatedAt: "2017-12-28T07:21:27Z", + UpdatedAt: time.Date(2017, 12, 28, 7, 21, 27, 0, time.UTC), } const SubnetPoolGetResult = ` @@ -157,11 +159,11 @@ const SubnetPoolGetResult = ` "is_default": true, "project_id": "1e2b9857295a4a3e841809ef492812c5", "tenant_id": "1e2b9857295a4a3e841809ef492812c5", - "created_at": "2018-01-01T00:00:01", + "created_at": "2018-01-01T00:00:01Z", "prefixes": [ "2001:db8::a3/64" ], - "updated_at": "2018-01-01T00:10:10", + "updated_at": "2018-01-01T00:10:10Z", "ip_version": 6, "shared": false, "description": "ipv6 prefixes", diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/requests_test.go new file mode 100644 index 00000000..3d138d37 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools/testing/requests_test.go @@ -0,0 +1,192 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + "time" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnetpools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SubnetPoolsListResult) + }) + + count := 0 + + subnetpools.List(fake.ServiceClient(), subnetpools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := subnetpools.ExtractSubnetPools(page) + if err != nil { + t.Errorf("Failed to extract subnetpools: %v", err) + return false, nil + } + + expected := []subnetpools.SubnetPool{ + SubnetPool1, + SubnetPool2, + SubnetPool3, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnetpools/0a738452-8057-4ad3-89c2-92f6a74afa76", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SubnetPoolGetResult) + }) + + s, err := subnetpools.Get(fake.ServiceClient(), "0a738452-8057-4ad3-89c2-92f6a74afa76").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.ID, "0a738452-8057-4ad3-89c2-92f6a74afa76") + th.AssertEquals(t, s.Name, "my-ipv6-pool") + th.AssertEquals(t, s.DefaultQuota, 2) + th.AssertEquals(t, s.TenantID, "1e2b9857295a4a3e841809ef492812c5") + th.AssertEquals(t, s.ProjectID, "1e2b9857295a4a3e841809ef492812c5") + th.AssertEquals(t, s.CreatedAt, time.Date(2018, 1, 1, 0, 0, 1, 0, time.UTC)) + th.AssertEquals(t, s.UpdatedAt, time.Date(2018, 1, 1, 0, 10, 10, 0, time.UTC)) + th.AssertDeepEquals(t, s.Prefixes, []string{ + "2001:db8::a3/64", + }) + th.AssertEquals(t, s.DefaultPrefixLen, 64) + th.AssertEquals(t, s.MinPrefixLen, 64) + th.AssertEquals(t, s.MaxPrefixLen, 128) + th.AssertEquals(t, s.AddressScopeID, "") + th.AssertEquals(t, s.IPversion, 6) + th.AssertEquals(t, s.Shared, false) + th.AssertEquals(t, s.Description, "ipv6 prefixes") + th.AssertEquals(t, s.IsDefault, true) + th.AssertEquals(t, s.RevisionNumber, 2) +} +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnetpools", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetPoolCreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetPoolCreateResult) + }) + + opts := subnetpools.CreateOpts{ + Name: "my_ipv4_pool", + Prefixes: []string{ + "10.10.0.0/16", + "10.11.11.0/24", + }, + MinPrefixLen: 25, + MaxPrefixLen: 30, + AddressScopeID: "3d4e2e2a-552b-42ad-a16d-820bbf3edaf3", + Description: "ipv4 prefixes", + } + s, err := subnetpools.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_ipv4_pool") + th.AssertDeepEquals(t, s.Prefixes, []string{ + "10.10.0.0/16", + "10.11.11.0/24", + }) + th.AssertEquals(t, s.MinPrefixLen, 25) + th.AssertEquals(t, s.MaxPrefixLen, 30) + th.AssertEquals(t, s.AddressScopeID, "3d4e2e2a-552b-42ad-a16d-820bbf3edaf3") + th.AssertEquals(t, s.Description, "ipv4 prefixes") +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnetpools/099546ca-788d-41e5-a76d-17d8cd282d3e", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetPoolUpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SubnetPoolUpdateResponse) + }) + + nullString := "" + nullInt := 0 + updateOpts := subnetpools.UpdateOpts{ + Name: "new_subnetpool_name", + Prefixes: []string{ + "10.11.12.0/24", + "10.24.0.0/16", + }, + MaxPrefixLen: 16, + AddressScopeID: &nullString, + DefaultQuota: &nullInt, + Description: &nullString, + } + n, err := subnetpools.Update(fake.ServiceClient(), "099546ca-788d-41e5-a76d-17d8cd282d3e", updateOpts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Name, "new_subnetpool_name") + th.AssertDeepEquals(t, n.Prefixes, []string{ + "10.8.0.0/16", + "10.11.12.0/24", + "10.24.0.0/16", + }) + th.AssertEquals(t, n.MaxPrefixLen, 16) + th.AssertEquals(t, n.ID, "099546ca-788d-41e5-a76d-17d8cd282d3e") + th.AssertEquals(t, n.AddressScopeID, "") + th.AssertEquals(t, n.DefaultQuota, 0) + th.AssertEquals(t, n.Description, "") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnetpools/099546ca-788d-41e5-a76d-17d8cd282d3e", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := subnetpools.Delete(fake.ServiceClient(), "099546ca-788d-41e5-a76d-17d8cd282d3e") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/testing/delegate_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/testing/delegate_test.go new file mode 100644 index 00000000..20a85f95 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/testing/delegate_test.go @@ -0,0 +1,106 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + common "github.com/gophercloud/gophercloud/openstack/common/extensions" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/extensions", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + + fmt.Fprintf(w, ` +{ + "extensions": [ + { + "updated": "2013-01-20T00:00:00-00:00", + "name": "Neutron Service Type Management", + "links": [], + "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", + "alias": "service-type", + "description": "API for retrieving service providers for Neutron advanced services" + } + ] +} + `) + }) + + count := 0 + + extensions.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := extensions.ExtractExtensions(page) + if err != nil { + t.Errorf("Failed to extract extensions: %v", err) + } + + expected := []extensions.Extension{ + { + Extension: common.Extension{ + Updated: "2013-01-20T00:00:00-00:00", + Name: "Neutron Service Type Management", + Links: []interface{}{}, + Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", + Alias: "service-type", + Description: "API for retrieving service providers for Neutron advanced services", + }, + }, + } + + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/extensions/agent", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "extension": { + "updated": "2013-02-03T10:00:00-00:00", + "name": "agent", + "links": [], + "namespace": "http://docs.openstack.org/ext/agent/api/v2.0", + "alias": "agent", + "description": "The agent management extension." + } +} + `) + }) + + ext, err := extensions.Get(fake.ServiceClient(), "agent").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00") + th.AssertEquals(t, ext.Name, "agent") + th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0") + th.AssertEquals(t, ext.Alias, "agent") + th.AssertEquals(t, ext.Description, "The agent management extension.") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/doc.go new file mode 100644 index 00000000..5f49bd1d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/doc.go @@ -0,0 +1,58 @@ +/* +Package endpointgroups allows management of endpoint groups in the Openstack Network Service + +Example to create an Endpoint Group + + createOpts := endpointgroups.CreateOpts{ + Name: groupName, + Type: endpointgroups.TypeCIDR, + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + } + group, err := endpointgroups.Create(client, createOpts).Extract() + if err != nil { + return group, err + } + +Example to retrieve an Endpoint Group + + group, err := endpointgroups.Get(client, "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a").Extract() + if err != nil { + panic(err) + } + +Example to Delete an Endpoint Group + + err := endpointgroups.Delete(client, "5291b189-fd84-46e5-84bd-78f40c05d69c").ExtractErr() + if err != nil { + panic(err) + } + +Example to List Endpoint groups + + allPages, err := endpointgroups.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allGroups, err := endpointgroups.ExtractEndpointGroups(allPages) + if err != nil { + panic(err) + } + +Example to Update an endpoint group + + name := "updatedname" + description := "updated description" + updateOpts := endpointgroups.UpdateOpts{ + Name: &name, + Description: &description, + } + updatedPolicy, err := endpointgroups.Update(client, "5c561d9d-eaea-45f6-ae3e-08d1a7080828", updateOpts).Extract() + if err != nil { + panic(err) + } +*/ +package endpointgroups diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/requests.go new file mode 100644 index 00000000..c12d0a80 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/requests.go @@ -0,0 +1,144 @@ +package endpointgroups + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type EndpointType string + +const ( + TypeSubnet EndpointType = "subnet" + TypeCIDR EndpointType = "cidr" + TypeVLAN EndpointType = "vlan" + TypeNetwork EndpointType = "network" + TypeRouter EndpointType = "router" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToEndpointGroupCreateMap() (map[string]interface{}, error) +} + +// CreateOpts contains all the values needed to create a new endpoint group +type CreateOpts struct { + // TenantID specifies a tenant to own the endpoint group. The caller must have + // an admin role in order to set this. Otherwise, this field is left unset + // and the caller will be the owner. + TenantID string `json:"tenant_id,omitempty"` + + // Description is the human readable description of the endpoint group. + Description string `json:"description,omitempty"` + + // Name is the human readable name of the endpoint group. + Name string `json:"name,omitempty"` + + // The type of the endpoints in the group. + // A valid value is subnet, cidr, network, router, or vlan. + Type EndpointType `json:"type,omitempty"` + + // List of endpoints of the same type, for the endpoint group. + // The values will depend on the type. + Endpoints []string `json:"endpoints"` +} + +// ToEndpointGroupCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToEndpointGroupCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "endpoint_group") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// endpoint group. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToEndpointGroupCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular endpoint group based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToEndpointGroupListQuery() (string, error) +} + +// ListOpts allows the filtering of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the Endpoint group attributes you want to see returned. +type ListOpts struct { + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + Description string `q:"description"` + Name string `q:"name"` + Type string `q:"type"` +} + +// ToEndpointGroupListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToEndpointGroupListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// Endpoint groups. It accepts a ListOpts struct, which allows you to filter +// the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToEndpointGroupListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return EndpointGroupPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Delete will permanently delete a particular endpoint group based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToEndpointGroupUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts contains the values used when updating an endpoint group. +type UpdateOpts struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` +} + +// ToEndpointGroupUpdateMap casts an UpdateOpts struct to a map. +func (opts UpdateOpts) ToEndpointGroupUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "endpoint_group") +} + +// Update allows endpoint groups to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToEndpointGroupUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/results.go new file mode 100644 index 00000000..822b7000 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/results.go @@ -0,0 +1,104 @@ +package endpointgroups + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// EndpointGroup is an endpoint group. +type EndpointGroup struct { + // TenantID specifies a tenant to own the endpoint group. + TenantID string `json:"tenant_id"` + + // TenantID specifies a tenant to own the endpoint group. + ProjectID string `json:"project_id"` + + // Description is the human readable description of the endpoint group. + Description string `json:"description"` + + // Name is the human readable name of the endpoint group. + Name string `json:"name"` + + // Type is the type of the endpoints in the group. + Type string `json:"type"` + + // Endpoints is a list of endpoints. + Endpoints []string `json:"endpoints"` + + // ID is the id of the endpoint group + ID string `json:"id"` +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts an endpoint group. +func (r commonResult) Extract() (*EndpointGroup, error) { + var s struct { + Service *EndpointGroup `json:"endpoint_group"` + } + err := r.ExtractInto(&s) + return s.Service, err +} + +// EndpointGroupPage is the page returned by a pager when traversing over a +// collection of Policies. +type EndpointGroupPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of Endpoint groups has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r EndpointGroupPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"endpoint_groups_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether an EndpointGroupPage struct is empty. +func (r EndpointGroupPage) IsEmpty() (bool, error) { + is, err := ExtractEndpointGroups(r) + return len(is) == 0, err +} + +// ExtractEndpointGroups accepts a Page struct, specifically an EndpointGroupPage struct, +// and extracts the elements into a slice of Endpoint group structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractEndpointGroups(r pagination.Page) ([]EndpointGroup, error) { + var s struct { + EndpointGroups []EndpointGroup `json:"endpoint_groups"` + } + err := (r.(EndpointGroupPage)).ExtractInto(&s) + return s.EndpointGroups, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as an endpoint group. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as an EndpointGroup. +type GetResult struct { + commonResult +} + +// DeleteResult represents the results of a Delete operation. Call its ExtractErr method +// to determine whether the operation succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult represents the result of an update operation. Call its Extract method +// to interpret it as an EndpointGroup. +type UpdateResult struct { + commonResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/testing/requests_test.go new file mode 100644 index 00000000..7feac37f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/testing/requests_test.go @@ -0,0 +1,265 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/endpoint-groups", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "endpoint_group": { + "endpoints": [ + "10.2.0.0/24", + "10.3.0.0/24" + ], + "type": "cidr", + "name": "peers" + } +} `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "endpoint_group": { + "description": "", + "tenant_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "project_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "endpoints": [ + "10.2.0.0/24", + "10.3.0.0/24" + ], + "type": "cidr", + "id": "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + "name": "peers" + } +} + `) + }) + + options := endpointgroups.CreateOpts{ + Name: "peers", + Type: endpointgroups.TypeCIDR, + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + } + actual, err := endpointgroups.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + expected := endpointgroups.EndpointGroup{ + Name: "peers", + TenantID: "4ad57e7ce0b24fca8f12b9834d91079d", + ProjectID: "4ad57e7ce0b24fca8f12b9834d91079d", + ID: "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + Description: "", + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + Type: "cidr", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/endpoint-groups/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "endpoint_group": { + "description": "", + "tenant_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "project_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "endpoints": [ + "10.2.0.0/24", + "10.3.0.0/24" + ], + "type": "cidr", + "id": "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + "name": "peers" + } +} + `) + }) + + actual, err := endpointgroups.Get(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828").Extract() + th.AssertNoErr(t, err) + expected := endpointgroups.EndpointGroup{ + Name: "peers", + TenantID: "4ad57e7ce0b24fca8f12b9834d91079d", + ProjectID: "4ad57e7ce0b24fca8f12b9834d91079d", + ID: "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + Description: "", + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + Type: "cidr", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/endpoint-groups", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "endpoint_groups": [ + { + "description": "", + "tenant_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "project_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "endpoints": [ + "10.2.0.0/24", + "10.3.0.0/24" + ], + "type": "cidr", + "id": "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + "name": "peers" + } + ] +} + `) + }) + + count := 0 + + endpointgroups.List(fake.ServiceClient(), endpointgroups.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := endpointgroups.ExtractEndpointGroups(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + expected := []endpointgroups.EndpointGroup{ + { + Name: "peers", + TenantID: "4ad57e7ce0b24fca8f12b9834d91079d", + ProjectID: "4ad57e7ce0b24fca8f12b9834d91079d", + ID: "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + Description: "", + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + Type: "cidr", + }, + } + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/endpoint-groups/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := endpointgroups.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/endpoint-groups/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "endpoint_group": { + "description": "updated description", + "name": "updatedname" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "endpoint_group": { + "description": "updated description", + "tenant_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "project_id": "4ad57e7ce0b24fca8f12b9834d91079d", + "endpoints": [ + "10.2.0.0/24", + "10.3.0.0/24" + ], + "type": "cidr", + "id": "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + "name": "updatedname" + } +} +`) + }) + + updatedName := "updatedname" + updatedDescription := "updated description" + options := endpointgroups.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + } + + actual, err := endpointgroups.Update(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828", options).Extract() + th.AssertNoErr(t, err) + expected := endpointgroups.EndpointGroup{ + Name: "updatedname", + TenantID: "4ad57e7ce0b24fca8f12b9834d91079d", + ProjectID: "4ad57e7ce0b24fca8f12b9834d91079d", + ID: "6ecd9cf3-ca64-46c7-863f-f2eb1b9e838a", + Description: "updated description", + Endpoints: []string{ + "10.2.0.0/24", + "10.3.0.0/24", + }, + Type: "cidr", + } + th.AssertDeepEquals(t, expected, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/urls.go new file mode 100644 index 00000000..9e83563c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups/urls.go @@ -0,0 +1,16 @@ +package endpointgroups + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "vpn" + resourcePath = "endpoint-groups" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/doc.go new file mode 100644 index 00000000..ee44279a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/doc.go @@ -0,0 +1,64 @@ +/* +Package ikepolicies allows management and retrieval of IKE policies in the +OpenStack Networking Service. + + +Example to Create an IKE policy + + createOpts := ikepolicies.CreateOpts{ + Name: "ikepolicy1", + Description: "Description of ikepolicy1", + EncryptionAlgorithm: ikepolicies.EncryptionAlgorithm3DES, + PFS: ikepolicies.PFSGroup5, + } + + policy, err := ikepolicies.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Show the details of a specific IKE policy by ID + + policy, err := ikepolicies.Get(client, "f2b08c1e-aa81-4668-8ae1-1401bcb0576c").Extract() + if err != nil { + panic(err) + } + + +Example to Delete a Policy + + err := ikepolicies.Delete(client, "5291b189-fd84-46e5-84bd-78f40c05d69c").ExtractErr() + if err != nil { + panic(err) + +Example to Update an IKE policy + + name := "updatedname" + description := "updated policy" + updateOpts := ikepolicies.UpdateOpts{ + Name: &name, + Description: &description, + Lifetime: &ikepolicies.LifetimeUpdateOpts{ + Value: 7000, + }, + } + updatedPolicy, err := ikepolicies.Update(client, "5c561d9d-eaea-45f6-ae3e-08d1a7080828", updateOpts).Extract() + if err != nil { + panic(err) + } + + +Example to List IKE policies + + allPages, err := ikepolicies.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allPolicies, err := ikepolicies.ExtractPolicies(allPages) + if err != nil { + panic(err) + } + +*/ +package ikepolicies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/requests.go new file mode 100644 index 00000000..6b084ff6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/requests.go @@ -0,0 +1,209 @@ +package ikepolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type AuthAlgorithm string +type EncryptionAlgorithm string +type PFS string +type Unit string +type IKEVersion string +type Phase1NegotiationMode string + +const ( + AuthAlgorithmSHA1 AuthAlgorithm = "sha1" + AuthAlgorithmSHA256 AuthAlgorithm = "sha256" + AuthAlgorithmSHA384 AuthAlgorithm = "sha384" + AuthAlgorithmSHA512 AuthAlgorithm = "sha512" + EncryptionAlgorithm3DES EncryptionAlgorithm = "3des" + EncryptionAlgorithmAES128 EncryptionAlgorithm = "aes-128" + EncryptionAlgorithmAES256 EncryptionAlgorithm = "aes-256" + EncryptionAlgorithmAES192 EncryptionAlgorithm = "aes-192" + UnitSeconds Unit = "seconds" + UnitKilobytes Unit = "kilobytes" + PFSGroup2 PFS = "group2" + PFSGroup5 PFS = "group5" + PFSGroup14 PFS = "group14" + IKEVersionv1 IKEVersion = "v1" + IKEVersionv2 IKEVersion = "v2" + Phase1NegotiationModeMain Phase1NegotiationMode = "main" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToPolicyCreateMap() (map[string]interface{}, error) +} + +// CreateOpts contains all the values needed to create a new IKE policy +type CreateOpts struct { + // TenantID specifies a tenant to own the IKE policy. The caller must have + // an admin role in order to set this. Otherwise, this field is left unset + // and the caller will be the owner. + TenantID string `json:"tenant_id,omitempty"` + + // Description is the human readable description of the policy. + Description string `json:"description,omitempty"` + + // Name is the human readable name of the policy. + // Does not have to be unique. + Name string `json:"name,omitempty"` + + // AuthAlgorithm is the authentication hash algorithm. + // Valid values are sha1, sha256, sha384, sha512. + // The default is sha1. + AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` + + // EncryptionAlgorithm is the encryption algorithm. + // A valid value is 3des, aes-128, aes-192, aes-256, and so on. + // Default is aes-128. + EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` + + // PFS is the Perfect forward secrecy mode. + // A valid value is Group2, Group5, Group14, and so on. + // Default is Group5. + PFS PFS `json:"pfs,omitempty"` + + // The IKE mode. + // A valid value is main, which is the default. + Phase1NegotiationMode Phase1NegotiationMode `json:"phase1_negotiation_mode,omitempty"` + + // The IKE version. + // A valid value is v1 or v2. + // Default is v1. + IKEVersion IKEVersion `json:"ike_version,omitempty"` + + //Lifetime is the lifetime of the security association + Lifetime *LifetimeCreateOpts `json:"lifetime,omitempty"` +} + +// The lifetime consists of a unit and integer value +// You can omit either the unit or value portion of the lifetime +type LifetimeCreateOpts struct { + // Units is the units for the lifetime of the security association + // Default unit is seconds + Units Unit `json:"units,omitempty"` + + // The lifetime value. + // Must be a positive integer. + // Default value is 3600. + Value int `json:"value,omitempty"` +} + +// ToPolicyCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ikepolicy") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// IKE policy +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular IKE policy based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// Delete will permanently delete a particular IKE policy based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToPolicyListQuery() (string, error) +} + +// ListOpts allows the filtering of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the IKE policy attributes you want to see returned. +type ListOpts struct { + TenantID string `q:"tenant_id"` + Name string `q:"name"` + Description string `q:"description"` + ProjectID string `q:"project_id"` + AuthAlgorithm string `q:"auth_algorithm"` + EncapsulationMode string `q:"encapsulation_mode"` + EncryptionAlgorithm string `q:"encryption_algorithm"` + PFS string `q:"pfs"` + Phase1NegotiationMode string `q:"phase_1_negotiation_mode"` + IKEVersion string `q:"ike_version"` +} + +// ToPolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// IKE policies. It accepts a ListOpts struct, which allows you to filter +// the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return PolicyPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToPolicyUpdateMap() (map[string]interface{}, error) +} + +type LifetimeUpdateOpts struct { + Units Unit `json:"units,omitempty"` + Value int `json:"value,omitempty"` +} + +// UpdateOpts contains the values used when updating an IKE policy +type UpdateOpts struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` + EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` + PFS PFS `json:"pfs,omitempty"` + Lifetime *LifetimeUpdateOpts `json:"lifetime,omitempty"` + Phase1NegotiationMode Phase1NegotiationMode `json:"phase_1_negotiation_mode,omitempty"` + IKEVersion IKEVersion `json:"ike_version,omitempty"` +} + +// ToPolicyUpdateMap casts an UpdateOpts struct to a map. +func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ikepolicy") +} + +// Update allows IKE policies to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go new file mode 100644 index 00000000..b825f575 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go @@ -0,0 +1,125 @@ +package ikepolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Policy is an IKE Policy +type Policy struct { + // TenantID is the ID of the project + TenantID string `json:"tenant_id"` + + // ProjectID is the ID of the project + ProjectID string `json:"project_id"` + + // Description is the human readable description of the policy + Description string `json:"description"` + + // Name is the human readable name of the policy + Name string `json:"name"` + + // AuthAlgorithm is the authentication hash algorithm + AuthAlgorithm string `json:"auth_algorithm"` + + // EncryptionAlgorithm is the encryption algorithm + EncryptionAlgorithm string `json:"encryption_algorithm"` + + // PFS is the Perfect forward secrecy (PFS) mode + PFS string `json:"pfs"` + + // Lifetime is the lifetime of the security association + Lifetime Lifetime `json:"lifetime"` + + // ID is the ID of the policy + ID string `json:"id"` + + // Phase1NegotiationMode is the IKE mode + Phase1NegotiationMode string `json:"phase1_negotiation_mode"` + + // IKEVersion is the IKE version. + IKEVersion string `json:"ike_version"` +} + +type commonResult struct { + gophercloud.Result +} +type Lifetime struct { + // Units is the unit for the lifetime + // Default is seconds + Units string `json:"units"` + + // Value is the lifetime + // Default is 3600 + Value int `json:"value"` +} + +// Extract is a function that accepts a result and extracts an IKE Policy. +func (r commonResult) Extract() (*Policy, error) { + var s struct { + Policy *Policy `json:"ikepolicy"` + } + err := r.ExtractInto(&s) + return s.Policy, err +} + +// PolicyPage is the page returned by a pager when traversing over a +// collection of Policies. +type PolicyPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of IKE policies has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r PolicyPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"ikepolicies_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a PolicyPage struct is empty. +func (r PolicyPage) IsEmpty() (bool, error) { + is, err := ExtractPolicies(r) + return len(is) == 0, err +} + +// ExtractPolicies accepts a Page struct, specifically a Policy struct, +// and extracts the elements into a slice of Policy structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractPolicies(r pagination.Page) ([]Policy, error) { + var s struct { + Policies []Policy `json:"ikepolicies"` + } + err := (r.(PolicyPage)).ExtractInto(&s) + return s.Policies, err +} + +// CreateResult represents the result of a Create operation. Call its Extract method to +// interpret it as a Policy. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a Get operation. Call its Extract method to +// interpret it as a Policy. +type GetResult struct { + commonResult +} + +// DeleteResult represents the results of a Delete operation. Call its ExtractErr method +// to determine whether the operation succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult represents the result of an update operation. Call its Extract method +// to interpret it as a Policy. +type UpdateResult struct { + commonResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go new file mode 100644 index 00000000..b3ec548d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go @@ -0,0 +1,304 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ikepolicies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "ikepolicy":{ + "name": "policy", + "description": "IKE policy", + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "ike_version": "v2" + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "ikepolicy":{ + "name": "policy", + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "project_id": "9145d91459d248b1b02fdaca97c6a75d", + "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + "description": "IKE policy", + "auth_algorithm": "sha1", + "encryption_algorithm": "aes-128", + "pfs": "Group5", + "lifetime": { + "value": 3600, + "units": "seconds" + }, + "phase1_negotiation_mode": "main", + "ike_version": "v2" + } +} + `) + }) + + options := ikepolicies.CreateOpts{ + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + Name: "policy", + Description: "IKE policy", + IKEVersion: ikepolicies.IKEVersionv2, + } + + actual, err := ikepolicies.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + expectedLifetime := ikepolicies.Lifetime{ + Units: "seconds", + Value: 3600, + } + expected := ikepolicies.Policy{ + AuthAlgorithm: "sha1", + IKEVersion: "v2", + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + Phase1NegotiationMode: "main", + PFS: "Group5", + EncryptionAlgorithm: "aes-128", + Description: "IKE policy", + Name: "policy", + ID: "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", + Lifetime: expectedLifetime, + ProjectID: "9145d91459d248b1b02fdaca97c6a75d", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ikepolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "ikepolicy":{ + "name": "policy", + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "project_id": "9145d91459d248b1b02fdaca97c6a75d", + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "IKE policy", + "auth_algorithm": "sha1", + "encryption_algorithm": "aes-128", + "pfs": "Group5", + "lifetime": { + "value": 3600, + "units": "seconds" + }, + "phase1_negotiation_mode": "main", + "ike_version": "v2" + } +} + `) + }) + + actual, err := ikepolicies.Get(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828").Extract() + th.AssertNoErr(t, err) + expectedLifetime := ikepolicies.Lifetime{ + Units: "seconds", + Value: 3600, + } + expected := ikepolicies.Policy{ + AuthAlgorithm: "sha1", + IKEVersion: "v2", + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + ProjectID: "9145d91459d248b1b02fdaca97c6a75d", + Phase1NegotiationMode: "main", + PFS: "Group5", + EncryptionAlgorithm: "aes-128", + Description: "IKE policy", + Name: "policy", + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + Lifetime: expectedLifetime, + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ikepolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := ikepolicies.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828") + th.AssertNoErr(t, res.Err) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ikepolicies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "ikepolicies": [ + { + "name": "policy", + "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", + "project_id": "9145d91459d248b1b02fdaca97c6a75d", + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "IKE policy", + "auth_algorithm": "sha1", + "encryption_algorithm": "aes-128", + "pfs": "Group5", + "lifetime": { + "value": 3600, + "units": "seconds" + }, + "phase1_negotiation_mode": "main", + "ike_version": "v2" + } + ] +} + `) + }) + + count := 0 + + ikepolicies.List(fake.ServiceClient(), ikepolicies.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := ikepolicies.ExtractPolicies(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + expectedLifetime := ikepolicies.Lifetime{ + Units: "seconds", + Value: 3600, + } + expected := []ikepolicies.Policy{ + { + AuthAlgorithm: "sha1", + IKEVersion: "v2", + TenantID: "9145d91459d248b1b02fdaca97c6a75d", + ProjectID: "9145d91459d248b1b02fdaca97c6a75d", + Phase1NegotiationMode: "main", + PFS: "Group5", + EncryptionAlgorithm: "aes-128", + Description: "IKE policy", + Name: "policy", + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + Lifetime: expectedLifetime, + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ikepolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "ikepolicy":{ + "name": "updatedname", + "description": "updated policy", + "lifetime": { + "value": 7000 + } + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "ikepolicy": { + "name": "updatedname", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "project_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "lifetime": { + "units": "seconds", + "value": 7000 + }, + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "updated policy" + } +} +`) + }) + + updatedName := "updatedname" + updatedDescription := "updated policy" + options := ikepolicies.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + Lifetime: &ikepolicies.LifetimeUpdateOpts{ + Value: 7000, + }, + } + + actual, err := ikepolicies.Update(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828", options).Extract() + th.AssertNoErr(t, err) + expectedLifetime := ikepolicies.Lifetime{ + Units: "seconds", + Value: 7000, + } + expected := ikepolicies.Policy{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + ProjectID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "updatedname", + AuthAlgorithm: "sha1", + EncryptionAlgorithm: "aes-128", + PFS: "group5", + Description: "updated policy", + Lifetime: expectedLifetime, + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + } + th.AssertDeepEquals(t, expected, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/urls.go new file mode 100644 index 00000000..a364a881 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies/urls.go @@ -0,0 +1,16 @@ +package ikepolicies + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "vpn" + resourcePath = "ikepolicies" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/doc.go new file mode 100644 index 00000000..91d5451a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/doc.go @@ -0,0 +1,56 @@ +/* +Package ipsecpolicies allows management and retrieval of IPSec Policies in the +OpenStack Networking Service. + +Example to Create a Policy + + createOpts := ipsecpolicies.CreateOpts{ + Name: "IPSecPolicy_1", + } + + policy, err := policies.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Policy + + err := ipsecpolicies.Delete(client, "5291b189-fd84-46e5-84bd-78f40c05d69c").ExtractErr() + if err != nil { + panic(err) + } + +Example to Show the details of a specific IPSec policy by ID + + policy, err := ipsecpolicies.Get(client, "f2b08c1e-aa81-4668-8ae1-1401bcb0576c").Extract() + if err != nil { + panic(err) + } + +Example to Update an IPSec policy + + name := "updatedname" + description := "updated policy" + updateOpts := ipsecpolicies.UpdateOpts{ + Name: &name, + Description: &description, + } + updatedPolicy, err := ipsecpolicies.Update(client, "5c561d9d-eaea-45f6-ae3e-08d1a7080828", updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to List IPSec policies + + allPages, err := ipsecpolicies.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allPolicies, err := ipsecpolicies.ExtractPolicies(allPages) + if err != nil { + panic(err) + } + +*/ +package ipsecpolicies diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/requests.go new file mode 100644 index 00000000..9496365c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/requests.go @@ -0,0 +1,211 @@ +package ipsecpolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type TransformProtocol string +type AuthAlgorithm string +type EncapsulationMode string +type EncryptionAlgorithm string +type PFS string +type Unit string + +const ( + TransformProtocolESP TransformProtocol = "esp" + TransformProtocolAH TransformProtocol = "ah" + TransformProtocolAHESP TransformProtocol = "ah-esp" + AuthAlgorithmSHA1 AuthAlgorithm = "sha1" + AuthAlgorithmSHA256 AuthAlgorithm = "sha256" + AuthAlgorithmSHA384 AuthAlgorithm = "sha384" + AuthAlgorithmSHA512 AuthAlgorithm = "sha512" + EncryptionAlgorithm3DES EncryptionAlgorithm = "3des" + EncryptionAlgorithmAES128 EncryptionAlgorithm = "aes-128" + EncryptionAlgorithmAES256 EncryptionAlgorithm = "aes-256" + EncryptionAlgorithmAES192 EncryptionAlgorithm = "aes-192" + EncapsulationModeTunnel EncapsulationMode = "tunnel" + EncapsulationModeTransport EncapsulationMode = "transport" + UnitSeconds Unit = "seconds" + UnitKilobytes Unit = "kilobytes" + PFSGroup2 PFS = "group2" + PFSGroup5 PFS = "group5" + PFSGroup14 PFS = "group14" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToPolicyCreateMap() (map[string]interface{}, error) +} + +// CreateOpts contains all the values needed to create a new IPSec policy +type CreateOpts struct { + // TenantID specifies a tenant to own the IPSec policy. The caller must have + // an admin role in order to set this. Otherwise, this field is left unset + // and the caller will be the owner. + TenantID string `json:"tenant_id,omitempty"` + + // Description is the human readable description of the policy. + Description string `json:"description,omitempty"` + + // Name is the human readable name of the policy. + // Does not have to be unique. + Name string `json:"name,omitempty"` + + // AuthAlgorithm is the authentication hash algorithm. + // Valid values are sha1, sha256, sha384, sha512. + // The default is sha1. + AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` + + // EncapsulationMode is the encapsulation mode. + // A valid value is tunnel or transport. + // Default is tunnel. + EncapsulationMode EncapsulationMode `json:"encapsulation_mode,omitempty"` + + // EncryptionAlgorithm is the encryption algorithm. + // A valid value is 3des, aes-128, aes-192, aes-256, and so on. + // Default is aes-128. + EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` + + // PFS is the Perfect forward secrecy mode. + // A valid value is Group2, Group5, Group14, and so on. + // Default is Group5. + PFS PFS `json:"pfs,omitempty"` + + // TransformProtocol is the transform protocol. + // A valid value is ESP, AH, or AH- ESP. + // Default is ESP. + TransformProtocol TransformProtocol `json:"transform_protocol,omitempty"` + + //Lifetime is the lifetime of the security association + Lifetime *LifetimeCreateOpts `json:"lifetime,omitempty"` +} + +// The lifetime consists of a unit and integer value +// You can omit either the unit or value portion of the lifetime +type LifetimeCreateOpts struct { + // Units is the units for the lifetime of the security association + // Default unit is seconds + Units Unit `json:"units,omitempty"` + + // The lifetime value. + // Must be a positive integer. + // Default value is 3600. + Value int `json:"value,omitempty"` +} + +// ToPolicyCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ipsecpolicy") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// IPSec policy +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Delete will permanently delete a particular IPSec policy based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// Get retrieves a particular IPSec policy based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToPolicyListQuery() (string, error) +} + +// ListOpts allows the filtering of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the IPSec policy attributes you want to see returned. +type ListOpts struct { + TenantID string `q:"tenant_id"` + Name string `q:"name"` + Description string `q:"description"` + ProjectID string `q:"project_id"` + AuthAlgorithm string `q:"auth_algorithm"` + EncapsulationMode string `q:"encapsulation_mode"` + EncryptionAlgorithm string `q:"encryption_algorithm"` + PFS string `q:"pfs"` + TransformProtocol string `q:"transform_protocol"` +} + +// ToPolicyListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPolicyListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// IPSec policies. It accepts a ListOpts struct, which allows you to filter +// the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return PolicyPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToPolicyUpdateMap() (map[string]interface{}, error) +} + +type LifetimeUpdateOpts struct { + Units Unit `json:"units,omitempty"` + Value int `json:"value,omitempty"` +} + +// UpdateOpts contains the values used when updating an IPSec policy +type UpdateOpts struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` + EncapsulationMode EncapsulationMode `json:"encapsulation_mode,omitempty"` + EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` + PFS PFS `json:"pfs,omitempty"` + TransformProtocol TransformProtocol `json:"transform_protocol,omitempty"` + Lifetime *LifetimeUpdateOpts `json:"lifetime,omitempty"` +} + +// ToPolicyUpdateMap casts an UpdateOpts struct to a map. +func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ipsecpolicy") +} + +// Update allows IPSec policies to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/results.go new file mode 100644 index 00000000..eda4a1bd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/results.go @@ -0,0 +1,126 @@ +package ipsecpolicies + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Policy is an IPSec Policy +type Policy struct { + // TenantID is the ID of the project + TenantID string `json:"tenant_id"` + + // ProjectID is the ID of the project + ProjectID string `json:"project_id"` + + // Description is the human readable description of the policy + Description string `json:"description"` + + // Name is the human readable name of the policy + Name string `json:"name"` + + // AuthAlgorithm is the authentication hash algorithm + AuthAlgorithm string `json:"auth_algorithm"` + + // EncapsulationMode is the encapsulation mode + EncapsulationMode string `json:"encapsulation_mode"` + + // EncryptionAlgorithm is the encryption algorithm + EncryptionAlgorithm string `json:"encryption_algorithm"` + + // PFS is the Perfect forward secrecy (PFS) mode + PFS string `json:"pfs"` + + // TransformProtocol is the transform protocol + TransformProtocol string `json:"transform_protocol"` + + // Lifetime is the lifetime of the security association + Lifetime Lifetime `json:"lifetime"` + + // ID is the ID of the policy + ID string `json:"id"` +} + +type Lifetime struct { + // Units is the unit for the lifetime + // Default is seconds + Units string `json:"units"` + + // Value is the lifetime + // Default is 3600 + Value int `json:"value"` +} + +type commonResult struct { + gophercloud.Result +} + +// Extract is a function that accepts a result and extracts an IPSec Policy. +func (r commonResult) Extract() (*Policy, error) { + var s struct { + Policy *Policy `json:"ipsecpolicy"` + } + err := r.ExtractInto(&s) + return s.Policy, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a Policy. +type CreateResult struct { + commonResult +} + +// CreateResult represents the result of a delete operation. Call its ExtractErr method +// to determine if the operation succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a Policy. +type GetResult struct { + commonResult +} + +// PolicyPage is the page returned by a pager when traversing over a +// collection of Policies. +type PolicyPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of IPSec policies has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r PolicyPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"ipsecpolicies_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a PolicyPage struct is empty. +func (r PolicyPage) IsEmpty() (bool, error) { + is, err := ExtractPolicies(r) + return len(is) == 0, err +} + +// ExtractPolicies accepts a Page struct, specifically a Policy struct, +// and extracts the elements into a slice of Policy structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractPolicies(r pagination.Page) ([]Policy, error) { + var s struct { + Policies []Policy `json:"ipsecpolicies"` + } + err := (r.(PolicyPage)).ExtractInto(&s) + return s.Policies, err +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a Policy. +type UpdateResult struct { + commonResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/testing/requests_test.go new file mode 100644 index 00000000..702bd383 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/testing/requests_test.go @@ -0,0 +1,321 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "ipsecpolicy": { + "name": "ipsecpolicy1", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "lifetime": { + "units": "seconds", + "value": 7200 + }, + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b" +} +} `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "ipsecpolicy": { + "name": "ipsecpolicy1", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "project_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "lifetime": { + "units": "seconds", + "value": 7200 + }, + "id": "5291b189-fd84-46e5-84bd-78f40c05d69c", + "description": "" + } +} + `) + }) + + lifetime := ipsecpolicies.LifetimeCreateOpts{ + Units: ipsecpolicies.UnitSeconds, + Value: 7200, + } + options := ipsecpolicies.CreateOpts{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "ipsecpolicy1", + TransformProtocol: ipsecpolicies.TransformProtocolESP, + AuthAlgorithm: ipsecpolicies.AuthAlgorithmSHA1, + EncapsulationMode: ipsecpolicies.EncapsulationModeTunnel, + EncryptionAlgorithm: ipsecpolicies.EncryptionAlgorithmAES128, + PFS: ipsecpolicies.PFSGroup5, + Lifetime: &lifetime, + Description: "", + } + actual, err := ipsecpolicies.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + expectedLifetime := ipsecpolicies.Lifetime{ + Units: "seconds", + Value: 7200, + } + expected := ipsecpolicies.Policy{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "ipsecpolicy1", + TransformProtocol: "esp", + AuthAlgorithm: "sha1", + EncapsulationMode: "tunnel", + EncryptionAlgorithm: "aes-128", + PFS: "group5", + Description: "", + Lifetime: expectedLifetime, + ID: "5291b189-fd84-46e5-84bd-78f40c05d69c", + ProjectID: "b4eedccc6fb74fa8a7ad6b08382b852b", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "ipsecpolicy": { + "name": "ipsecpolicy1", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "project_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "lifetime": { + "units": "seconds", + "value": 7200 + }, + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "" + } +} + `) + }) + + actual, err := ipsecpolicies.Get(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828").Extract() + th.AssertNoErr(t, err) + expectedLifetime := ipsecpolicies.Lifetime{ + Units: "seconds", + Value: 7200, + } + expected := ipsecpolicies.Policy{ + Name: "ipsecpolicy1", + TransformProtocol: "esp", + Description: "", + AuthAlgorithm: "sha1", + EncapsulationMode: "tunnel", + EncryptionAlgorithm: "aes-128", + PFS: "group5", + Lifetime: expectedLifetime, + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + ProjectID: "b4eedccc6fb74fa8a7ad6b08382b852b", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := ipsecpolicies.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828") + th.AssertNoErr(t, res.Err) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + { + "ipsecpolicies": [ + { + "name": "ipsecpolicy1", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "project_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "lifetime": { + "units": "seconds", + "value": 7200 + }, + "id": "5291b189-fd84-46e5-84bd-78f40c05d69c", + "description": "" + } + ] +} + `) + }) + + count := 0 + + ipsecpolicies.List(fake.ServiceClient(), ipsecpolicies.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := ipsecpolicies.ExtractPolicies(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []ipsecpolicies.Policy{ + { + Name: "ipsecpolicy1", + TransformProtocol: "esp", + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + ProjectID: "b4eedccc6fb74fa8a7ad6b08382b852b", + AuthAlgorithm: "sha1", + EncapsulationMode: "tunnel", + EncryptionAlgorithm: "aes-128", + PFS: "group5", + Lifetime: ipsecpolicies.Lifetime{ + Value: 7200, + Units: "seconds", + }, + Description: "", + ID: "5291b189-fd84-46e5-84bd-78f40c05d69c", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "ipsecpolicy":{ + "name": "updatedname", + "description": "updated policy", + "lifetime": { + "value": 7000 + } + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + + { + "ipsecpolicy": { + "name": "updatedname", + "transform_protocol": "esp", + "auth_algorithm": "sha1", + "encapsulation_mode": "tunnel", + "encryption_algorithm": "aes-128", + "pfs": "group5", + "project_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b", + "lifetime": { + "units": "seconds", + "value": 7000 + }, + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "updated policy" + } +} +`) + }) + updatedName := "updatedname" + updatedDescription := "updated policy" + options := ipsecpolicies.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + Lifetime: &ipsecpolicies.LifetimeUpdateOpts{ + Value: 7000, + }, + } + + actual, err := ipsecpolicies.Update(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828", options).Extract() + th.AssertNoErr(t, err) + expectedLifetime := ipsecpolicies.Lifetime{ + Units: "seconds", + Value: 7000, + } + expected := ipsecpolicies.Policy{ + TenantID: "b4eedccc6fb74fa8a7ad6b08382b852b", + ProjectID: "b4eedccc6fb74fa8a7ad6b08382b852b", + Name: "updatedname", + TransformProtocol: "esp", + AuthAlgorithm: "sha1", + EncapsulationMode: "tunnel", + EncryptionAlgorithm: "aes-128", + PFS: "group5", + Description: "updated policy", + Lifetime: expectedLifetime, + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + } + th.AssertDeepEquals(t, expected, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/urls.go new file mode 100644 index 00000000..8781cc44 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/urls.go @@ -0,0 +1,16 @@ +package ipsecpolicies + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "vpn" + resourcePath = "ipsecpolicies" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/doc.go new file mode 100644 index 00000000..6bd3236c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/doc.go @@ -0,0 +1,68 @@ +/* +Package services allows management and retrieval of VPN services in the +OpenStack Networking Service. + +Example to List Services + + listOpts := services.ListOpts{ + TenantID: "966b3c7d36a24facaf20b7e458bf2192", + } + + allPages, err := services.List(networkClient, listOpts).AllPages() + if err != nil { + panic(err) + } + + allPolicies, err := services.ExtractServices(allPages) + if err != nil { + panic(err) + } + + for _, service := range allServices { + fmt.Printf("%+v\n", service) + } + +Example to Create a Service + + createOpts := services.CreateOpts{ + Name: "vpnservice1", + Description: "A service", + RouterID: "2512e759-e8d7-4eea-a0af-4a85927a2e59", + AdminStateUp: gophercloud.Enabled, + } + + service, err := services.Create(networkClient, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Update a Service + + serviceID := "38aee955-6283-4279-b091-8b9c828000ec" + + updateOpts := services.UpdateOpts{ + Description: "New Description", + } + + service, err := services.Update(networkClient, serviceID, updateOpts).Extract() + if err != nil { + panic(err) + } + +Example to Delete a Service + + serviceID := "38aee955-6283-4279-b091-8b9c828000ec" + err := services.Delete(networkClient, serviceID).ExtractErr() + if err != nil { + panic(err) + } + +Example to Show the details of a specific Service by ID + + service, err := services.Get(client, "f2b08c1e-aa81-4668-8ae1-1401bcb0576c").Extract() + if err != nil { + panic(err) + } + +*/ +package services diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/requests.go new file mode 100644 index 00000000..8d642197 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/requests.go @@ -0,0 +1,150 @@ +package services + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToServiceCreateMap() (map[string]interface{}, error) +} + +// CreateOpts contains all the values needed to create a new VPN service +type CreateOpts struct { + // TenantID specifies a tenant to own the VPN service. The caller must have + // an admin role in order to set this. Otherwise, this field is left unset + // and the caller will be the owner. + TenantID string `json:"tenant_id,omitempty"` + + // SubnetID is the ID of the subnet. + SubnetID string `json:"subnet_id,omitempty"` + + // RouterID is the ID of the router. + RouterID string `json:"router_id" required:"true"` + + // Description is the human readable description of the service. + Description string `json:"description,omitempty"` + + // AdminStateUp is the administrative state of the resource, which is up (true) or down (false). + AdminStateUp *bool `json:"admin_state_up"` + + // Name is the human readable name of the service. + Name string `json:"name,omitempty"` + + // The ID of the flavor. + FlavorID string `json:"flavor_id,omitempty"` +} + +// ToServiceCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToServiceCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "vpnservice") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// VPN service. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToServiceCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Delete will permanently delete a particular VPN service based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToServiceUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts contains the values used when updating a VPN service +type UpdateOpts struct { + // Name is the human readable name of the service. + Name *string `json:"name,omitempty"` + + // Description is the human readable description of the service. + Description *string `json:"description,omitempty"` + + // AdminStateUp is the administrative state of the resource, which is up (true) or down (false). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToServiceUpdateMap casts aa UodateOpts struct to a map. +func (opts UpdateOpts) ToServiceUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "vpnservice") +} + +// Update allows VPN services to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToServiceUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToServiceListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the VPN service attributes you want to see returned. +type ListOpts struct { + TenantID string `q:"tenant_id"` + Name string `q:"name"` + Description string `q:"description"` + AdminStateUp *bool `q:"admin_state_up"` + Status string `q:"status"` + SubnetID string `q:"subnet_id"` + RouterID string `q:"router_id"` + ProjectID string `q:"project_id"` + ExternalV6IP string `q:"external_v6_ip"` + ExternalV4IP string `q:"external_v4_ip"` + FlavorID string `q:"flavor_id"` +} + +// ToServiceListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToServiceListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// VPN services. It accepts a ListOpts struct, which allows you to filter +// and sort the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToServiceListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return ServicePage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// Get retrieves a particular VPN service based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/results.go new file mode 100644 index 00000000..5e555699 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/results.go @@ -0,0 +1,121 @@ +package services + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// Service is a VPN Service +type Service struct { + // TenantID is the ID of the project. + TenantID string `json:"tenant_id"` + + // ProjectID is the ID of the project. + ProjectID string `json:"project_id"` + + // SubnetID is the ID of the subnet. + SubnetID string `json:"subnet_id"` + + // RouterID is the ID of the router. + RouterID string `json:"router_id"` + + // Description is a human-readable description for the resource. + // Default is an empty string + Description string `json:"description"` + + // AdminStateUp is the administrative state of the resource, which is up (true) or down (false). + AdminStateUp bool `json:"admin_state_up"` + + // Name is the human readable name of the service. + Name string `json:"name"` + + // Status indicates whether IPsec VPN service is currently operational. + // Values are ACTIVE, DOWN, BUILD, ERROR, PENDING_CREATE, PENDING_UPDATE, or PENDING_DELETE. + Status string `json:"status"` + + // ID is the unique ID of the VPN service. + ID string `json:"id"` + + // ExternalV6IP is the read-only external (public) IPv6 address that is used for the VPN service. + ExternalV6IP string `json:"external_v6_ip"` + + // ExternalV4IP is the read-only external (public) IPv4 address that is used for the VPN service. + ExternalV4IP string `json:"external_v4_ip"` + + // FlavorID is the ID of the flavor. + FlavorID string `json:"flavor_id"` +} + +type commonResult struct { + gophercloud.Result +} + +// ServicePage is the page returned by a pager when traversing over a +// collection of VPN services. +type ServicePage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of VPN services has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r ServicePage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"vpnservices_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a ServicePage struct is empty. +func (r ServicePage) IsEmpty() (bool, error) { + is, err := ExtractServices(r) + return len(is) == 0, err +} + +// ExtractServices accepts a Page struct, specifically a Service struct, +// and extracts the elements into a slice of Service structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractServices(r pagination.Page) ([]Service, error) { + var s struct { + Services []Service `json:"vpnservices"` + } + err := (r.(ServicePage)).ExtractInto(&s) + return s.Services, err +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a Service. +type GetResult struct { + commonResult +} + +// Extract is a function that accepts a result and extracts a VPN service. +func (r commonResult) Extract() (*Service, error) { + var s struct { + Service *Service `json:"vpnservice"` + } + err := r.ExtractInto(&s) + return s.Service, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a Service. +type CreateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the operation succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a service. +type UpdateResult struct { + commonResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/testing/requests_test.go new file mode 100644 index 00000000..ca7adf32 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/testing/requests_test.go @@ -0,0 +1,267 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/vpnservices", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "vpnservice": { + "router_id": "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + "name": "vpn", + "admin_state_up": true, + "description": "OpenStack VPN service", + "tenant_id": "10039663455a446d8ba2cbb058b0f578" + } +} `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "vpnservice": { + "router_id": "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + "status": "PENDING_CREATE", + "name": "vpn", + "external_v6_ip": "2001:db8::1", + "admin_state_up": true, + "subnet_id": null, + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "external_v4_ip": "172.32.1.11", + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "OpenStack VPN service", + "project_id": "10039663455a446d8ba2cbb058b0f578" + } +} + `) + }) + + options := services.CreateOpts{ + TenantID: "10039663455a446d8ba2cbb058b0f578", + Name: "vpn", + Description: "OpenStack VPN service", + AdminStateUp: gophercloud.Enabled, + RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + } + actual, err := services.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + expected := services.Service{ + RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + Status: "PENDING_CREATE", + Name: "vpn", + ExternalV6IP: "2001:db8::1", + AdminStateUp: true, + SubnetID: "", + TenantID: "10039663455a446d8ba2cbb058b0f578", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + ExternalV4IP: "172.32.1.11", + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + Description: "OpenStack VPN service", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/vpnservices", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "vpnservices":[ + { + "router_id": "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + "status": "PENDING_CREATE", + "name": "vpnservice1", + "admin_state_up": true, + "subnet_id": null, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "description": "Test VPN service" + } + ] +} + `) + }) + + count := 0 + + services.List(fake.ServiceClient(), services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := services.ExtractServices(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expected := []services.Service{ + { + Status: "PENDING_CREATE", + Name: "vpnservice1", + AdminStateUp: true, + TenantID: "10039663455a446d8ba2cbb058b0f578", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + Description: "Test VPN service", + SubnetID: "", + RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/vpnservices/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "vpnservice": { + "router_id": "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + "status": "PENDING_CREATE", + "name": "vpnservice1", + "admin_state_up": true, + "subnet_id": null, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "VPN test service" + } +} + `) + }) + + actual, err := services.Get(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828").Extract() + th.AssertNoErr(t, err) + expected := services.Service{ + Status: "PENDING_CREATE", + Name: "vpnservice1", + Description: "VPN test service", + AdminStateUp: true, + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + TenantID: "10039663455a446d8ba2cbb058b0f578", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + SubnetID: "", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/vpnservices/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + res := services.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828") + th.AssertNoErr(t, res.Err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/vpnservices/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + "vpnservice":{ + "name": "updatedname", + "description": "updated service", + "admin_state_up": false + } +} + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "vpnservice": { + "router_id": "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + "status": "PENDING_CREATE", + "name": "updatedname", + "admin_state_up": false, + "subnet_id": null, + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "project_id": "10039663455a446d8ba2cbb058b0f578", + "id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "description": "updated service", + "external_v4_ip": "172.32.1.11", + "external_v6_ip": "2001:db8::1" + } +} + `) + }) + updatedName := "updatedname" + updatedServiceDescription := "updated service" + options := services.UpdateOpts{ + Name: &updatedName, + Description: &updatedServiceDescription, + AdminStateUp: gophercloud.Disabled, + } + + actual, err := services.Update(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828", options).Extract() + th.AssertNoErr(t, err) + expected := services.Service{ + RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa", + Status: "PENDING_CREATE", + Name: "updatedname", + ExternalV6IP: "2001:db8::1", + AdminStateUp: false, + SubnetID: "", + TenantID: "10039663455a446d8ba2cbb058b0f578", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + ExternalV4IP: "172.32.1.11", + ID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + Description: "updated service", + } + th.AssertDeepEquals(t, expected, *actual) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/urls.go new file mode 100644 index 00000000..fe8b343f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services/urls.go @@ -0,0 +1,16 @@ +package services + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "vpn" + resourcePath = "vpnservices" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/doc.go new file mode 100644 index 00000000..66befd3b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/doc.go @@ -0,0 +1,68 @@ +/* +Package siteconnections allows management and retrieval of IPSec site connections in the +OpenStack Networking Service. + + +Example to create an IPSec site connection + +createOpts := siteconnections.CreateOpts{ + Name: "Connection1", + PSK: "secret", + Initiator: siteconnections.InitiatorBiDirectional, + AdminStateUp: gophercloud.Enabled, + IPSecPolicyID: "4ab0a72e-64ef-4809-be43-c3f7e0e5239b", + PeerEPGroupID: "5f5801b1-b383-4cf0-bf61-9e85d4044b2d", + IKEPolicyID: "47a880f9-1da9-468c-b289-219c9eca78f0", + VPNServiceID: "692c1ec8-a7cd-44d9-972b-8ed3fe4cc476", + LocalEPGroupID: "498bb96a-1517-47ea-b1eb-c4a53db46a16", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + MTU: 1500, + } + connection, err := siteconnections.Create(client, createOpts).Extract() + if err != nil { + panic(err) + } + +Example to Show the details of a specific IPSec site connection by ID + + conn, err := siteconnections.Get(client, "f2b08c1e-aa81-4668-8ae1-1401bcb0576c").Extract() + if err != nil { + panic(err) + } + +Example to Delete a site connection + + connID := "38aee955-6283-4279-b091-8b9c828000ec" + err := siteconnections.Delete(networkClient, connID).ExtractErr() + if err != nil { + panic(err) + } + +Example to List site connections + + allPages, err := siteconnections.List(client, nil).AllPages() + if err != nil { + panic(err) + } + + allConnections, err := siteconnections.ExtractConnections(allPages) + if err != nil { + panic(err) + } + +Example to Update an IPSec site connection + + description := "updated connection" + name := "updatedname" + updateOpts := siteconnections.UpdateOpts{ + Name: &name, + Description: &description, + } + updatedConnection, err := siteconnections.Update(client, "5c561d9d-eaea-45f6-ae3e-08d1a7080828", updateOpts).Extract() + if err != nil { + panic(err) + } + +*/ +package siteconnections diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/requests.go new file mode 100644 index 00000000..15ce54b5 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/requests.go @@ -0,0 +1,243 @@ +package siteconnections + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToConnectionCreateMap() (map[string]interface{}, error) +} +type Action string +type Initiator string + +const ( + ActionHold Action = "hold" + ActionClear Action = "clear" + ActionRestart Action = "restart" + ActionDisabled Action = "disabled" + ActionRestartByPeer Action = "restart-by-peer" + InitiatorBiDirectional Initiator = "bi-directional" + InitiatorResponseOnly Initiator = "response-only" +) + +// DPDCreateOpts contains all the values needed to create a valid configuration for Dead Peer detection protocols +type DPDCreateOpts struct { + // The dead peer detection (DPD) action. + // A valid value is clear, hold, restart, disabled, or restart-by-peer. + // Default value is hold. + Action Action `json:"action,omitempty"` + + // The dead peer detection (DPD) timeout in seconds. + // A valid value is a positive integer that is greater than the DPD interval value. + // Default is 120. + Timeout int `json:"timeout,omitempty"` + + // The dead peer detection (DPD) interval, in seconds. + // A valid value is a positive integer. + // Default is 30. + Interval int `json:"interval,omitempty"` +} + +// CreateOpts contains all the values needed to create a new IPSec site connection +type CreateOpts struct { + // The ID of the IKE policy + IKEPolicyID string `json:"ikepolicy_id"` + + // The ID of the VPN Service + VPNServiceID string `json:"vpnservice_id"` + + // The ID for the endpoint group that contains private subnets for the local side of the connection. + // You must specify this parameter with the peer_ep_group_id parameter unless + // in backward- compatible mode where peer_cidrs is provided with a subnet_id for the VPN service. + LocalEPGroupID string `json:"local_ep_group_id,omitempty"` + + // The ID of the IPsec policy. + IPSecPolicyID string `json:"ipsecpolicy_id"` + + // The peer router identity for authentication. + // A valid value is an IPv4 address, IPv6 address, e-mail address, key ID, or FQDN. + // Typically, this value matches the peer_address value. + PeerID string `json:"peer_id"` + + // The ID of the project + TenantID string `json:"tenant_id,omitempty"` + + // The ID for the endpoint group that contains private CIDRs in the form < net_address > / < prefix > + // for the peer side of the connection. + // You must specify this parameter with the local_ep_group_id parameter unless in backward-compatible mode + // where peer_cidrs is provided with a subnet_id for the VPN service. + PeerEPGroupID string `json:"peer_ep_group_id,omitempty"` + + // An ID to be used instead of the external IP address for a virtual router used in traffic between instances on different networks in east-west traffic. + // Most often, local ID would be domain name, email address, etc. + // If this is not configured then the external IP address will be used as the ID. + LocalID string `json:"local_id,omitempty"` + + // The human readable name of the connection. + // Does not have to be unique. + // Default is an empty string + Name string `json:"name,omitempty"` + + // The human readable description of the connection. + // Does not have to be unique. + // Default is an empty string + Description string `json:"description,omitempty"` + + // The peer gateway public IPv4 or IPv6 address or FQDN. + PeerAddress string `json:"peer_address"` + + // The pre-shared key. + // A valid value is any string. + PSK string `json:"psk"` + + // Indicates whether this VPN can only respond to connections or both respond to and initiate connections. + // A valid value is response-only or bi-directional. Default is bi-directional. + Initiator Initiator `json:"initiator,omitempty"` + + // Unique list of valid peer private CIDRs in the form < net_address > / < prefix > . + PeerCIDRs []string `json:"peer_cidrs,omitempty"` + + // The administrative state of the resource, which is up (true) or down (false). + // Default is false + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // A dictionary with dead peer detection (DPD) protocol controls. + DPD *DPDCreateOpts `json:"dpd,omitempty"` + + // The maximum transmission unit (MTU) value to address fragmentation. + // Minimum value is 68 for IPv4, and 1280 for IPv6. + MTU int `json:"mtu,omitempty"` +} + +// ToConnectionCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToConnectionCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ipsec_site_connection") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// IPSec site connection. +func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToConnectionCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + + return +} + +// Delete will permanently delete a particular IPSec site connection based on its +// unique ID. +func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} + +// Get retrieves a particular IPSec site connection based on its unique ID. +func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToConnectionListQuery() (string, error) +} + +// ListOpts allows the filtering and sorting of paginated collections through +// the API. Filtering is achieved by passing in struct field values that map to +// the IPSec site connection attributes you want to see returned. +type ListOpts struct { + IKEPolicyID string `q:"ikepolicy_id"` + VPNServiceID string `q:"vpnservice_id"` + LocalEPGroupID string `q:"local_ep_group_id"` + IPSecPolicyID string `q:"ipsecpolicy_id"` + PeerID string `q:"peer_id"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + PeerEPGroupID string `q:"peer_ep_group_id"` + LocalID string `q:"local_id"` + Name string `q:"name"` + Description string `q:"description"` + PeerAddress string `q:"peer_address"` + PSK string `q:"psk"` + Initiator Initiator `q:"initiator"` + AdminStateUp *bool `q:"admin_state_up"` + MTU int `q:"mtu"` +} + +// ToConnectionListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToConnectionListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// IPSec site connections. It accepts a ListOpts struct, which allows you to filter +// and sort the returned collection for greater efficiency. +func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := rootURL(c) + if opts != nil { + query, err := opts.ToConnectionListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { + return ConnectionPage{pagination.LinkedPageBase{PageResult: r}} + }) +} + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToConnectionUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts contains the values used when updating the DPD of an IPSec site connection +type DPDUpdateOpts struct { + Action Action `json:"action,omitempty"` + Timeout int `json:"timeout,omitempty"` + Interval int `json:"interval,omitempty"` +} + +// UpdateOpts contains the values used when updating an IPSec site connection +type UpdateOpts struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + LocalID string `json:"local_id,omitempty"` + PeerAddress string `json:"peer_address,omitempty"` + PeerID string `json:"peer_id,omitempty"` + PeerCIDRs []string `json:"peer_cidrs,omitempty"` + LocalEPGroupID string `json:"local_ep_group_id,omitempty"` + PeerEPGroupID string `json:"peer_ep_group_id,omitempty"` + MTU int `json:"mtu,omitempty"` + Initiator Initiator `json:"initiator,omitempty"` + PSK string `json:"psk,omitempty"` + DPD *DPDUpdateOpts `json:"dpd,omitempty"` + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToConnectionUpdateMap casts an UpdateOpts struct to a map. +func (opts UpdateOpts) ToConnectionUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "ipsec_site_connection") +} + +// Update allows IPSec site connections to be updated. +func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToConnectionUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/results.go new file mode 100644 index 00000000..3c09e4d0 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/results.go @@ -0,0 +1,163 @@ +package siteconnections + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +type DPD struct { + // Action is the dead peer detection (DPD) action. + Action string `json:"action"` + + // Timeout is the dead peer detection (DPD) timeout in seconds. + Timeout int `json:"timeout"` + + // Interval is the dead peer detection (DPD) interval in seconds. + Interval int `json:"interval"` +} + +// Connection is an IPSec site connection +type Connection struct { + // IKEPolicyID is the ID of the IKE policy. + IKEPolicyID string `json:"ikepolicy_id"` + + // VPNServiceID is the ID of the VPN service. + VPNServiceID string `json:"vpnservice_id"` + + // LocalEPGroupID is the ID for the endpoint group that contains private subnets for the local side of the connection. + LocalEPGroupID string `json:"local_ep_group_id"` + + // IPSecPolicyID is the ID of the IPSec policy + IPSecPolicyID string `json:"ipsecpolicy_id"` + + // PeerID is the peer router identity for authentication. + PeerID string `json:"peer_id"` + + // TenantID is the ID of the project. + TenantID string `json:"tenant_id"` + + // ProjectID is the ID of the project. + ProjectID string `json:"project_id"` + + // PeerEPGroupID is the ID for the endpoint group that contains private CIDRs in the form < net_address > / < prefix > + // for the peer side of the connection. + PeerEPGroupID string `json:"peer_ep_group_id"` + + // LocalID is an ID to be used instead of the external IP address for a virtual router used in traffic + // between instances on different networks in east-west traffic. + LocalID string `json:"local_id"` + + // Name is the human readable name of the connection. + Name string `json:"name"` + + // Description is the human readable description of the connection. + Description string `json:"description"` + + // PeerAddress is the peer gateway public IPv4 or IPv6 address or FQDN. + PeerAddress string `json:"peer_address"` + + // RouteMode is the route mode. + RouteMode string `json:"route_mode"` + + // PSK is the pre-shared key. + PSK string `json:"psk"` + + // Initiator indicates whether this VPN can only respond to connections or both respond to and initiate connections. + Initiator string `json:"initiator"` + + // PeerCIDRs is a unique list of valid peer private CIDRs in the form < net_address > / < prefix > . + PeerCIDRs []string `json:"peer_cidrs"` + + // AdminStateUp is the administrative state of the connection. + AdminStateUp bool `json:"admin_state_up"` + + // DPD is the dead peer detection (DPD) protocol controls. + DPD DPD `json:"dpd"` + + // AuthMode is the authentication mode. + AuthMode string `json:"auth_mode"` + + // MTU is the maximum transmission unit (MTU) value to address fragmentation. + MTU int `json:"mtu"` + + // Status indicates whether the IPsec connection is currently operational. + // Values are ACTIVE, DOWN, BUILD, ERROR, PENDING_CREATE, PENDING_UPDATE, or PENDING_DELETE. + Status string `json:"status"` + + // ID is the id of the connection + ID string `json:"id"` +} + +type commonResult struct { + gophercloud.Result +} + +// ConnectionPage is the page returned by a pager when traversing over a +// collection of IPSec site connections. +type ConnectionPage struct { + pagination.LinkedPageBase +} + +// NextPageURL is invoked when a paginated collection of IPSec site connections has +// reached the end of a page and the pager seeks to traverse over a new one. +// In order to do this, it needs to construct the next page's URL. +func (r ConnectionPage) NextPageURL() (string, error) { + var s struct { + Links []gophercloud.Link `json:"ipsec_site_connections_links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return gophercloud.ExtractNextURL(s.Links) +} + +// IsEmpty checks whether a ConnectionPage struct is empty. +func (r ConnectionPage) IsEmpty() (bool, error) { + is, err := ExtractConnections(r) + return len(is) == 0, err +} + +// ExtractConnections accepts a Page struct, specifically a Connection struct, +// and extracts the elements into a slice of Connection structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractConnections(r pagination.Page) ([]Connection, error) { + var s struct { + Connections []Connection `json:"ipsec_site_connections"` + } + err := (r.(ConnectionPage)).ExtractInto(&s) + return s.Connections, err +} + +// Extract is a function that accepts a result and extracts an IPSec site connection. +func (r commonResult) Extract() (*Connection, error) { + var s struct { + Connection *Connection `json:"ipsec_site_connection"` + } + err := r.ExtractInto(&s) + return s.Connection, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as a Connection. +type CreateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its +// ExtractErr method to determine if the operation succeeded or failed. +type DeleteResult struct { + gophercloud.ErrResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as a Connection. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as a connection +type UpdateResult struct { + commonResult +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/testing/requests_test.go new file mode 100644 index 00000000..3db27364 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/testing/requests_test.go @@ -0,0 +1,413 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsec-site-connections", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` +{ + + "ipsec_site_connection": { + "psk": "secret", + "initiator": "bi-directional", + "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + "admin_state_up": true, + "mtu": 1500, + "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", + "peer_address": "172.24.4.233", + "peer_id": "172.24.4.233", + "name": "vpnconnection1" + +} +} `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, ` +{ + "ipsec_site_connection": { + "status": "PENDING_CREATE", + "psk": "secret", + "initiator": "bi-directional", + "name": "vpnconnection1", + "admin_state_up": true, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "auth_mode": "psk", + "peer_cidrs": [], + "mtu": 1500, + "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "dpd": { + "action": "hold", + "interval": 30, + "timeout": 120 + }, + "route_mode": "static", + "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", + "peer_address": "172.24.4.233", + "peer_id": "172.24.4.233", + "id": "851f280f-5639-4ea3-81aa-e298525ab74b", + "description": "" + } +} + `) + }) + + options := siteconnections.CreateOpts{ + Name: "vpnconnection1", + AdminStateUp: gophercloud.Enabled, + PSK: "secret", + Initiator: siteconnections.InitiatorBiDirectional, + IPSecPolicyID: "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + MTU: 1500, + PeerEPGroupID: "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + IKEPolicyID: "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + VPNServiceID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + LocalEPGroupID: "3e1815dd-e212-43d0-8f13-b494fa553e68", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + } + actual, err := siteconnections.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + expectedDPD := siteconnections.DPD{ + Action: "hold", + Interval: 30, + Timeout: 120, + } + expected := siteconnections.Connection{ + TenantID: "10039663455a446d8ba2cbb058b0f578", + Name: "vpnconnection1", + AdminStateUp: true, + PSK: "secret", + Initiator: "bi-directional", + IPSecPolicyID: "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + MTU: 1500, + PeerEPGroupID: "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + IKEPolicyID: "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + VPNServiceID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + LocalEPGroupID: "3e1815dd-e212-43d0-8f13-b494fa553e68", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + Status: "PENDING_CREATE", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + AuthMode: "psk", + PeerCIDRs: []string{}, + DPD: expectedDPD, + RouteMode: "static", + ID: "851f280f-5639-4ea3-81aa-e298525ab74b", + Description: "", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsec-site-connections/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := siteconnections.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828") + th.AssertNoErr(t, res.Err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsec-site-connections/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "ipsec_site_connection": { + "status": "PENDING_CREATE", + "psk": "secret", + "initiator": "bi-directional", + "name": "vpnconnection1", + "admin_state_up": true, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "auth_mode": "psk", + "peer_cidrs": [], + "mtu": 1500, + "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "dpd": { + "action": "hold", + "interval": 30, + "timeout": 120 + }, + "route_mode": "static", + "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", + "peer_address": "172.24.4.233", + "peer_id": "172.24.4.233", + "id": "851f280f-5639-4ea3-81aa-e298525ab74b", + "description": "" + } +} + `) + }) + + actual, err := siteconnections.Get(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828").Extract() + th.AssertNoErr(t, err) + expectedDPD := siteconnections.DPD{ + Action: "hold", + Interval: 30, + Timeout: 120, + } + expected := siteconnections.Connection{ + TenantID: "10039663455a446d8ba2cbb058b0f578", + Name: "vpnconnection1", + AdminStateUp: true, + PSK: "secret", + Initiator: "bi-directional", + IPSecPolicyID: "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + MTU: 1500, + PeerEPGroupID: "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + IKEPolicyID: "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + VPNServiceID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + LocalEPGroupID: "3e1815dd-e212-43d0-8f13-b494fa553e68", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + Status: "PENDING_CREATE", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + AuthMode: "psk", + PeerCIDRs: []string{}, + DPD: expectedDPD, + RouteMode: "static", + ID: "851f280f-5639-4ea3-81aa-e298525ab74b", + Description: "", + } + th.AssertDeepEquals(t, expected, *actual) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsec-site-connections", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "ipsec_site_connections":[ + { + "status": "PENDING_CREATE", + "psk": "secret", + "initiator": "bi-directional", + "name": "vpnconnection1", + "admin_state_up": true, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "auth_mode": "psk", + "peer_cidrs": [], + "mtu": 1500, + "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "dpd": { + "action": "hold", + "interval": 30, + "timeout": 120 + }, + "route_mode": "static", + "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", + "peer_address": "172.24.4.233", + "peer_id": "172.24.4.233", + "id": "851f280f-5639-4ea3-81aa-e298525ab74b", + "description": "" + }] +} + `) + }) + + count := 0 + + siteconnections.List(fake.ServiceClient(), siteconnections.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := siteconnections.ExtractConnections(page) + if err != nil { + t.Errorf("Failed to extract members: %v", err) + return false, err + } + + expectedDPD := siteconnections.DPD{ + Action: "hold", + Interval: 30, + Timeout: 120, + } + expected := []siteconnections.Connection{ + { + TenantID: "10039663455a446d8ba2cbb058b0f578", + Name: "vpnconnection1", + AdminStateUp: true, + PSK: "secret", + Initiator: "bi-directional", + IPSecPolicyID: "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + MTU: 1500, + PeerEPGroupID: "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + IKEPolicyID: "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + VPNServiceID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + LocalEPGroupID: "3e1815dd-e212-43d0-8f13-b494fa553e68", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + Status: "PENDING_CREATE", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + AuthMode: "psk", + PeerCIDRs: []string{}, + DPD: expectedDPD, + RouteMode: "static", + ID: "851f280f-5639-4ea3-81aa-e298525ab74b", + Description: "", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/vpn/ipsec-site-connections/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, ` + { + "ipsec_site_connection": { + "psk": "updatedsecret", + "initiator": "response-only", + "name": "updatedconnection", + "description": "updateddescription" + } + } + `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` + + { + "ipsec_site_connection": { + "status": "ACTIVE", + "psk": "updatedsecret", + "initiator": "response-only", + "name": "updatedconnection", + "admin_state_up": true, + "project_id": "10039663455a446d8ba2cbb058b0f578", + "tenant_id": "10039663455a446d8ba2cbb058b0f578", + "auth_mode": "psk", + "peer_cidrs": [], + "mtu": 1500, + "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + "dpd": { + "action": "hold", + "interval": 30, + "timeout": 120 + }, + "route_mode": "static", + "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", + "peer_address": "172.24.4.233", + "peer_id": "172.24.4.233", + "id": "851f280f-5639-4ea3-81aa-e298525ab74b", + "description": "updateddescription" + } +} +} +`) + }) + updatedName := "updatedconnection" + updatedDescription := "updateddescription" + options := siteconnections.UpdateOpts{ + Name: &updatedName, + Description: &updatedDescription, + Initiator: siteconnections.InitiatorResponseOnly, + PSK: "updatedsecret", + } + + actual, err := siteconnections.Update(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828", options).Extract() + th.AssertNoErr(t, err) + + expectedDPD := siteconnections.DPD{ + Action: "hold", + Interval: 30, + Timeout: 120, + } + + expected := siteconnections.Connection{ + TenantID: "10039663455a446d8ba2cbb058b0f578", + Name: "updatedconnection", + AdminStateUp: true, + PSK: "updatedsecret", + Initiator: "response-only", + IPSecPolicyID: "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", + MTU: 1500, + PeerEPGroupID: "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", + IKEPolicyID: "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", + VPNServiceID: "5c561d9d-eaea-45f6-ae3e-08d1a7080828", + LocalEPGroupID: "3e1815dd-e212-43d0-8f13-b494fa553e68", + PeerAddress: "172.24.4.233", + PeerID: "172.24.4.233", + Status: "ACTIVE", + ProjectID: "10039663455a446d8ba2cbb058b0f578", + AuthMode: "psk", + PeerCIDRs: []string{}, + DPD: expectedDPD, + RouteMode: "static", + ID: "851f280f-5639-4ea3-81aa-e298525ab74b", + Description: "updateddescription", + } + th.AssertDeepEquals(t, expected, *actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/urls.go new file mode 100644 index 00000000..5c8ee9a3 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections/urls.go @@ -0,0 +1,16 @@ +package siteconnections + +import "github.com/gophercloud/gophercloud" + +const ( + rootPath = "vpn" + resourcePath = "ipsec-site-connections" +) + +func rootURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/requests.go index 040f3218..1fbf6209 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/requests.go @@ -21,6 +21,7 @@ type ListOpts struct { Name string `q:"name"` AdminStateUp *bool `q:"admin_state_up"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` Shared *bool `q:"shared"` ID string `q:"id"` Marker string `q:"marker"` @@ -70,6 +71,7 @@ type CreateOpts struct { Name string `json:"name,omitempty"` Shared *bool `json:"shared,omitempty"` TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"` } @@ -138,7 +140,12 @@ func Delete(c *gophercloud.ServiceClient, networkID string) (r DeleteResult) { func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/results.go index c73f9e1a..62f4b3c3 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/results.go @@ -64,9 +64,12 @@ type Network struct { // Subnets associated with this network. Subnets []string `json:"subnets"` - // Owner of network. + // TenantID is the project owner of the network. TenantID string `json:"tenant_id"` + // ProjectID is the project owner of the network. + ProjectID string `json:"project_id"` + // Specifies whether the network resource can be accessed by any tenant. Shared bool `json:"shared"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/fixtures.go index 3edbe8f3..9632d448 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/fixtures.go @@ -86,6 +86,32 @@ const CreateResponse = ` } }` +const CreatePortSecurityRequest = ` +{ + "network": { + "name": "private", + "admin_state_up": true, + "port_security_enabled": false + } +}` + +const CreatePortSecurityResponse = ` +{ + "network": { + "status": "ACTIVE", + "subnets": ["08eae331-0402-425a-923c-34f7cfe39c1b"], + "name": "private", + "admin_state_up": true, + "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "shared": false, + "id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", + "provider:segmentation_id": 9876543210, + "provider:physical_network": null, + "provider:network_type": "local", + "port_security_enabled": false + } +}` + const CreateOptionalFieldsRequest = ` { "network": { @@ -122,6 +148,30 @@ const UpdateResponse = ` } }` +const UpdatePortSecurityRequest = ` +{ + "network": { + "port_security_enabled": false + } +}` + +const UpdatePortSecurityResponse = ` +{ + "network": { + "status": "ACTIVE", + "subnets": ["08eae331-0402-425a-923c-34f7cfe39c1b"], + "name": "private", + "admin_state_up": true, + "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "shared": false, + "id": "4e8e5957-649f-477b-9e5b-f1f75b21c03c", + "provider:segmentation_id": 9876543210, + "provider:physical_network": null, + "provider:network_type": "local", + "port_security_enabled": false + } +}` + var Network1 = networks.Network{ Status: "ACTIVE", Subnets: []string{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"}, diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/requests_test.go new file mode 100644 index 00000000..adf88d59 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing/requests_test.go @@ -0,0 +1,297 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" + "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + client := fake.ServiceClient() + count := 0 + + networks.List(client, networks.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := networks.ExtractNetworks(page) + if err != nil { + t.Errorf("Failed to extract networks: %v", err) + return false, err + } + + th.CheckDeepEquals(t, ExpectedNetworkSlice, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + client := fake.ServiceClient() + + type networkWithExt struct { + networks.Network + portsecurity.PortSecurityExt + } + + var allNetworks []networkWithExt + + allPages, err := networks.List(client, networks.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = networks.ExtractNetworksInto(allPages, &allNetworks) + th.AssertNoErr(t, err) + + th.AssertEquals(t, allNetworks[0].Status, "ACTIVE") + th.AssertEquals(t, allNetworks[0].PortSecurityEnabled, true) + th.AssertEquals(t, allNetworks[0].Subnets[0], "54d6f61d-db07-451c-9ab3-b9609b6b6f0b") + th.AssertEquals(t, allNetworks[1].Subnets[0], "08eae331-0402-425a-923c-34f7cfe39c1b") +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) + + n, err := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &Network1, n) +} + +func TestGetWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) + + var networkWithExtensions struct { + networks.Network + portsecurity.PortSecurityExt + } + + err := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractInto(&networkWithExtensions) + th.AssertNoErr(t, err) + + th.AssertEquals(t, networkWithExtensions.Status, "ACTIVE") + th.AssertEquals(t, networkWithExtensions.PortSecurityEnabled, true) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateRequest) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateResponse) + }) + + iTrue := true + options := networks.CreateOpts{Name: "private", AdminStateUp: &iTrue} + n, err := networks.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "ACTIVE") + th.AssertDeepEquals(t, &Network2, n) +} + +func TestCreateWithOptionalFields(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateOptionalFieldsRequest) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{}`) + }) + + iTrue := true + options := networks.CreateOpts{ + Name: "public", + AdminStateUp: &iTrue, + Shared: &iTrue, + TenantID: "12345", + AvailabilityZoneHints: []string{"zone1", "zone2"}, + } + _, err := networks.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateResponse) + }) + + iTrue, iFalse := true, false + options := networks.UpdateOpts{Name: "new_network_name", AdminStateUp: &iFalse, Shared: &iTrue} + n, err := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Name, "new_network_name") + th.AssertEquals(t, n.AdminStateUp, false) + th.AssertEquals(t, n.Shared, true) + th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := networks.Delete(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c") + th.AssertNoErr(t, res.Err) +} + +func TestCreatePortSecurity(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreatePortSecurityRequest) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreatePortSecurityResponse) + }) + + var networkWithExtensions struct { + networks.Network + portsecurity.PortSecurityExt + } + + iTrue := true + iFalse := false + networkCreateOpts := networks.CreateOpts{Name: "private", AdminStateUp: &iTrue} + createOpts := portsecurity.NetworkCreateOptsExt{ + CreateOptsBuilder: networkCreateOpts, + PortSecurityEnabled: &iFalse, + } + + err := networks.Create(fake.ServiceClient(), createOpts).ExtractInto(&networkWithExtensions) + th.AssertNoErr(t, err) + + th.AssertEquals(t, networkWithExtensions.Status, "ACTIVE") + th.AssertEquals(t, networkWithExtensions.PortSecurityEnabled, false) +} + +func TestUpdatePortSecurity(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdatePortSecurityRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdatePortSecurityResponse) + }) + + var networkWithExtensions struct { + networks.Network + portsecurity.PortSecurityExt + } + + iFalse := false + networkUpdateOpts := networks.UpdateOpts{} + updateOpts := portsecurity.NetworkUpdateOptsExt{ + UpdateOptsBuilder: networkUpdateOpts, + PortSecurityEnabled: &iFalse, + } + + err := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", updateOpts).ExtractInto(&networkWithExtensions) + th.AssertNoErr(t, err) + + th.AssertEquals(t, networkWithExtensions.Name, "private") + th.AssertEquals(t, networkWithExtensions.AdminStateUp, true) + th.AssertEquals(t, networkWithExtensions.Shared, false) + th.AssertEquals(t, networkWithExtensions.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c") + th.AssertEquals(t, networkWithExtensions.PortSecurityEnabled, false) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/requests.go index fd1e9725..2a5902d7 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/requests.go @@ -22,6 +22,7 @@ type ListOpts struct { AdminStateUp *bool `q:"admin_state_up"` NetworkID string `q:"network_id"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` DeviceOwner string `q:"device_owner"` MACAddress string `q:"mac_address"` ID string `q:"id"` @@ -81,6 +82,7 @@ type CreateOpts struct { DeviceID string `json:"device_id,omitempty"` DeviceOwner string `json:"device_owner,omitempty"` TenantID string `json:"tenant_id,omitempty"` + ProjectID string `json:"project_id,omitempty"` SecurityGroups *[]string `json:"security_groups,omitempty"` AllowedAddressPairs []AddressPair `json:"allowed_address_pairs,omitempty"` } @@ -149,7 +151,12 @@ func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/results.go index ebef98d5..66937fd9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/results.go @@ -84,9 +84,12 @@ type Port struct { // the subnets where the IP addresses are picked from FixedIPs []IP `json:"fixed_ips"` - // Owner of network. + // TenantID is the project owner of the port. TenantID string `json:"tenant_id"` + // ProjectID is the project owner of the port. + ProjectID string `json:"project_id"` + // Identifies the entity (e.g.: dhcp agent) using this port. DeviceOwner string `json:"device_owner"` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/fixtures.go index dea77fe0..cfce9b09 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/fixtures.go @@ -220,6 +220,62 @@ const CreateOmitSecurityGroupsResponse = ` } ` +const CreatePortSecurityRequest = ` +{ + "port": { + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "name": "private-port", + "admin_state_up": true, + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.2" + } + ], + "security_groups": ["foo"], + "allowed_address_pairs": [ + { + "ip_address": "10.0.0.4", + "mac_address": "fa:16:3e:c9:cb:f0" + } + ], + "port_security_enabled": false + } +} +` + +const CreatePortSecurityResponse = ` +{ + "port": { + "status": "DOWN", + "name": "private-port", + "admin_state_up": true, + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", + "device_owner": "", + "mac_address": "fa:16:3e:c9:cb:f0", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.2" + } + ], + "id": "65c0ee9f-d634-4522-8954-51021b570b0d", + "security_groups": [ + "f0ac4394-7e4a-4409-9701-ba8be283dbc3" + ], + "allowed_address_pairs": [ + { + "ip_address": "10.0.0.4", + "mac_address": "fa:16:3e:c9:cb:f0" + } + ], + "device_id": "", + "port_security_enabled": false + } +} +` + const UpdateRequest = ` { "port": { @@ -325,6 +381,46 @@ const UpdateOmitSecurityGroupsResponse = ` } ` +const UpdatePortSecurityRequest = ` +{ + "port": { + "port_security_enabled": false + } +} +` + +const UpdatePortSecurityResponse = ` +{ + "port": { + "status": "DOWN", + "name": "private-port", + "admin_state_up": true, + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", + "device_owner": "", + "mac_address": "fa:16:3e:c9:cb:f0", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.2" + } + ], + "id": "65c0ee9f-d634-4522-8954-51021b570b0d", + "security_groups": [ + "f0ac4394-7e4a-4409-9701-ba8be283dbc3" + ], + "allowed_address_pairs": [ + { + "ip_address": "10.0.0.4", + "mac_address": "fa:16:3e:c9:cb:f0" + } + ], + "device_id": "", + "port_security_enabled": false + } +} +` + const RemoveSecurityGroupRequest = ` { "port": { @@ -464,3 +560,151 @@ const DontUpdateAllowedAddressPairsResponse = ` } } ` + +// GetWithExtraDHCPOptsResponse represents a raw port response with extra +// DHCP options. +const GetWithExtraDHCPOptsResponse = ` +{ + "port": { + "status": "ACTIVE", + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", + "extra_dhcp_opts": [ + { + "opt_name": "option1", + "opt_value": "value1", + "ip_version": 4 + }, + { + "opt_name": "option2", + "opt_value": "value2", + "ip_version": 4 + } + ], + "admin_state_up": true, + "name": "port-with-extra-dhcp-opts", + "device_owner": "", + "mac_address": "fa:16:3e:c9:cb:f0", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.4" + } + ], + "id": "65c0ee9f-d634-4522-8954-51021b570b0d", + "device_id": "" + } +} +` + +// CreateWithExtraDHCPOptsRequest represents a raw port creation request +// with extra DHCP options. +const CreateWithExtraDHCPOptsRequest = ` +{ + "port": { + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "name": "port-with-extra-dhcp-opts", + "admin_state_up": true, + "fixed_ips": [ + { + "ip_address": "10.0.0.2", + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2" + } + ], + "extra_dhcp_opts": [ + { + "opt_name": "option1", + "opt_value": "value1" + } + ] + } +} +` + +// CreateWithExtraDHCPOptsResponse represents a raw port creation response +// with extra DHCP options. +const CreateWithExtraDHCPOptsResponse = ` +{ + "port": { + "status": "DOWN", + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", + "extra_dhcp_opts": [ + { + "opt_name": "option1", + "opt_value": "value1", + "ip_version": 4 + } + ], + "admin_state_up": true, + "name": "port-with-extra-dhcp-opts", + "device_owner": "", + "mac_address": "fa:16:3e:c9:cb:f0", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.2" + } + ], + "id": "65c0ee9f-d634-4522-8954-51021b570b0d", + "device_id": "" + } +} +` + +// UpdateWithExtraDHCPOptsRequest represents a raw port update request with +// extra DHCP options. +const UpdateWithExtraDHCPOptsRequest = ` +{ + "port": { + "name": "updated-port-with-dhcp-opts", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.3" + } + ], + "extra_dhcp_opts": [ + { + "opt_name": "option1", + "opt_value": null + }, + { + "opt_name": "option2", + "opt_value": "value2" + } + ] + } +} +` + +// UpdateWithExtraDHCPOptsResponse represents a raw port update response with +// extra DHCP options. +const UpdateWithExtraDHCPOptsResponse = ` +{ + "port": { + "status": "DOWN", + "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", + "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", + "extra_dhcp_opts": [ + { + "opt_name": "option2", + "opt_value": "value2", + "ip_version": 4 + } + ], + "admin_state_up": true, + "name": "updated-port-with-dhcp-opts", + "device_owner": "", + "mac_address": "fa:16:3e:c9:cb:f0", + "fixed_ips": [ + { + "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", + "ip_address": "10.0.0.3" + } + ], + "id": "65c0ee9f-d634-4522-8954-51021b570b0d", + "device_id": "" + } +} +` diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/requests_test.go new file mode 100644 index 00000000..af91cf99 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing/requests_test.go @@ -0,0 +1,779 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + count := 0 + + ports.List(fake.ServiceClient(), ports.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := ports.ExtractPorts(page) + if err != nil { + t.Errorf("Failed to extract subnets: %v", err) + return false, nil + } + + expected := []ports.Port{ + { + Status: "ACTIVE", + Name: "", + AdminStateUp: true, + NetworkID: "70c1db1f-b701-45bd-96e0-a313ee3430b3", + TenantID: "", + DeviceOwner: "network:router_gateway", + MACAddress: "fa:16:3e:58:42:ed", + FixedIPs: []ports.IP{ + { + SubnetID: "008ba151-0b8c-4a67-98b5-0d2b87666062", + IPAddress: "172.24.4.2", + }, + }, + ID: "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b", + SecurityGroups: []string{}, + DeviceID: "9ae135f4-b6e0-4dad-9e91-3c223e385824", + }, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestListWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ListResponse) + }) + + type portWithExt struct { + ports.Port + portsecurity.PortSecurityExt + } + + var allPorts []portWithExt + + allPages, err := ports.List(fake.ServiceClient(), ports.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + + err = ports.ExtractPortsInto(allPages, &allPorts) + + th.AssertEquals(t, allPorts[0].Status, "ACTIVE") + th.AssertEquals(t, allPorts[0].PortSecurityEnabled, false) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) + + n, err := ports.Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "ACTIVE") + th.AssertEquals(t, n.Name, "") + th.AssertEquals(t, n.AdminStateUp, true) + th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177") + th.AssertEquals(t, n.DeviceOwner, "network:router_interface") + th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7") + th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"}, + }) + th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2") + th.AssertDeepEquals(t, n.SecurityGroups, []string{}) + th.AssertEquals(t, n.Status, "ACTIVE") + th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e") +} + +func TestGetWithExtensions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetResponse) + }) + + var portWithExtensions struct { + ports.Port + portsecurity.PortSecurityExt + } + + err := ports.Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").ExtractInto(&portWithExtensions) + th.AssertNoErr(t, err) + + th.AssertEquals(t, portWithExtensions.Status, "ACTIVE") + th.AssertEquals(t, portWithExtensions.PortSecurityEnabled, false) +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateResponse) + }) + + asu := true + options := ports.CreateOpts{ + Name: "private-port", + AdminStateUp: &asu, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + SecurityGroups: &[]string{"foo"}, + AllowedAddressPairs: []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + n, err := ports.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "DOWN") + th.AssertEquals(t, n.Name, "private-port") + th.AssertEquals(t, n.AdminStateUp, true) + th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, n.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, n.DeviceOwner, "") + th.AssertEquals(t, n.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }) + th.AssertEquals(t, n.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertDeepEquals(t, n.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) + th.AssertDeepEquals(t, n.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) +} + +func TestCreateOmitSecurityGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateOmitSecurityGroupsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateOmitSecurityGroupsResponse) + }) + + asu := true + options := ports.CreateOpts{ + Name: "private-port", + AdminStateUp: &asu, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + AllowedAddressPairs: []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + n, err := ports.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "DOWN") + th.AssertEquals(t, n.Name, "private-port") + th.AssertEquals(t, n.AdminStateUp, true) + th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, n.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, n.DeviceOwner, "") + th.AssertEquals(t, n.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }) + th.AssertEquals(t, n.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertDeepEquals(t, n.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) + th.AssertDeepEquals(t, n.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) +} + +func TestCreateWithNoSecurityGroup(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateWithNoSecurityGroupsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateWithNoSecurityGroupsResponse) + }) + + asu := true + options := ports.CreateOpts{ + Name: "private-port", + AdminStateUp: &asu, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + SecurityGroups: &[]string{}, + AllowedAddressPairs: []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + n, err := ports.Create(fake.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Status, "DOWN") + th.AssertEquals(t, n.Name, "private-port") + th.AssertEquals(t, n.AdminStateUp, true) + th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, n.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, n.DeviceOwner, "") + th.AssertEquals(t, n.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }) + th.AssertEquals(t, n.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertDeepEquals(t, n.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) +} + +func TestRequiredCreateOpts(t *testing.T) { + res := ports.Create(fake.ServiceClient(), ports.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestCreatePortSecurity(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreatePortSecurityRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreatePortSecurityResponse) + }) + + var portWithExt struct { + ports.Port + portsecurity.PortSecurityExt + } + + asu := true + iFalse := false + portCreateOpts := ports.CreateOpts{ + Name: "private-port", + AdminStateUp: &asu, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + SecurityGroups: &[]string{"foo"}, + AllowedAddressPairs: []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + createOpts := portsecurity.PortCreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + PortSecurityEnabled: &iFalse, + } + + err := ports.Create(fake.ServiceClient(), createOpts).ExtractInto(&portWithExt) + th.AssertNoErr(t, err) + + th.AssertEquals(t, portWithExt.Status, "DOWN") + th.AssertEquals(t, portWithExt.PortSecurityEnabled, false) +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateResponse) + }) + + options := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + SecurityGroups: &[]string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}, + AllowedAddressPairs: &[]ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + + s, err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) +} + +func TestUpdateOmitSecurityGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateOmitSecurityGroupsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateOmitSecurityGroupsResponse) + }) + + options := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + AllowedAddressPairs: &[]ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + + s, err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) +} + +func TestUpdatePortSecurity(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdatePortSecurityRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdatePortSecurityResponse) + }) + + var portWithExt struct { + ports.Port + portsecurity.PortSecurityExt + } + + iFalse := false + portUpdateOpts := ports.UpdateOpts{} + updateOpts := portsecurity.PortUpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + PortSecurityEnabled: &iFalse, + } + + err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&portWithExt) + th.AssertNoErr(t, err) + + th.AssertEquals(t, portWithExt.Status, "DOWN") + th.AssertEquals(t, portWithExt.Name, "private-port") + th.AssertEquals(t, portWithExt.PortSecurityEnabled, false) +} + +func TestRemoveSecurityGroups(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, RemoveSecurityGroupRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, RemoveSecurityGroupResponse) + }) + + options := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + SecurityGroups: &[]string{}, + AllowedAddressPairs: &[]ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }, + } + + s, err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) + th.AssertDeepEquals(t, s.SecurityGroups, []string(nil)) +} + +func TestRemoveAllowedAddressPairs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, RemoveAllowedAddressPairsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, RemoveAllowedAddressPairsResponse) + }) + + options := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + SecurityGroups: &[]string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}, + AllowedAddressPairs: &[]ports.AddressPair{}, + } + + s, err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.AllowedAddressPairs, []ports.AddressPair(nil)) + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) +} + +func TestDontUpdateAllowedAddressPairs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, DontUpdateAllowedAddressPairsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, DontUpdateAllowedAddressPairsResponse) + }) + + options := ports.UpdateOpts{ + Name: "new_port_name", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + SecurityGroups: &[]string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}, + } + + s, err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "new_port_name") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertDeepEquals(t, s.AllowedAddressPairs, []ports.AddressPair{ + {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, + }) + th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := ports.Delete(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertNoErr(t, res.Err) +} + +func TestGetWithExtraDHCPOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, GetWithExtraDHCPOptsResponse) + }) + + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + err := ports.Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, "ACTIVE") + th.AssertEquals(t, s.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, s.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, s.AdminStateUp, true) + th.AssertEquals(t, s.Name, "port-with-extra-dhcp-opts") + th.AssertEquals(t, s.DeviceOwner, "") + th.AssertEquals(t, s.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.4"}, + }) + th.AssertEquals(t, s.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertEquals(t, s.DeviceID, "") + + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptName, "option1") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptValue, "value1") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].IPVersion, 4) + th.AssertDeepEquals(t, s.ExtraDHCPOpts[1].OptName, "option2") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[1].OptValue, "value2") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[1].IPVersion, 4) +} + +func TestCreateWithExtraDHCPOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, CreateWithExtraDHCPOptsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, CreateWithExtraDHCPOptsResponse) + }) + + adminStateUp := true + portCreateOpts := ports.CreateOpts{ + Name: "port-with-extra-dhcp-opts", + AdminStateUp: &adminStateUp, + NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }, + } + + createOpts := extradhcpopts.CreateOptsExt{ + CreateOptsBuilder: portCreateOpts, + ExtraDHCPOpts: []extradhcpopts.CreateExtraDHCPOpt{ + { + OptName: "option1", + OptValue: "value1", + }, + }, + } + + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + err := ports.Create(fake.ServiceClient(), createOpts).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, "DOWN") + th.AssertEquals(t, s.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, s.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, s.AdminStateUp, true) + th.AssertEquals(t, s.Name, "port-with-extra-dhcp-opts") + th.AssertEquals(t, s.DeviceOwner, "") + th.AssertEquals(t, s.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, + }) + th.AssertEquals(t, s.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertEquals(t, s.DeviceID, "") + + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptName, "option1") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptValue, "value1") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].IPVersion, 4) +} + +func TestUpdateWithExtraDHCPOpts(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, UpdateWithExtraDHCPOptsRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, UpdateWithExtraDHCPOptsResponse) + }) + + portUpdateOpts := ports.UpdateOpts{ + Name: "updated-port-with-dhcp-opts", + FixedIPs: []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }, + } + + edoValue2 := "value2" + updateOpts := extradhcpopts.UpdateOptsExt{ + UpdateOptsBuilder: portUpdateOpts, + ExtraDHCPOpts: []extradhcpopts.UpdateExtraDHCPOpt{ + { + OptName: "option1", + }, + { + OptName: "option2", + OptValue: &edoValue2, + }, + }, + } + + var s struct { + ports.Port + extradhcpopts.ExtraDHCPOptsExt + } + + err := ports.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&s) + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Status, "DOWN") + th.AssertEquals(t, s.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") + th.AssertEquals(t, s.TenantID, "d6700c0c9ffa4f1cb322cd4a1f3906fa") + th.AssertEquals(t, s.AdminStateUp, true) + th.AssertEquals(t, s.Name, "updated-port-with-dhcp-opts") + th.AssertEquals(t, s.DeviceOwner, "") + th.AssertEquals(t, s.MACAddress, "fa:16:3e:c9:cb:f0") + th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ + {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, + }) + th.AssertEquals(t, s.ID, "65c0ee9f-d634-4522-8954-51021b570b0d") + th.AssertEquals(t, s.DeviceID, "") + + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptName, "option2") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].OptValue, "value2") + th.AssertDeepEquals(t, s.ExtraDHCPOpts[0].IPVersion, 4) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/requests.go index 403f6922..2597947b 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/requests.go @@ -21,12 +21,14 @@ type ListOpts struct { EnableDHCP *bool `q:"enable_dhcp"` NetworkID string `q:"network_id"` TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` IPVersion int `q:"ip_version"` GatewayIP string `q:"gateway_ip"` CIDR string `q:"cidr"` IPv6AddressMode string `q:"ipv6_address_mode"` IPv6RAMode string `q:"ipv6_ra_mode"` ID string `q:"id"` + SubnetPoolID string `q:"subnetpool_id"` Limit int `q:"limit"` Marker string `q:"marker"` SortKey string `q:"sort_key"` @@ -78,15 +80,19 @@ type CreateOpts struct { NetworkID string `json:"network_id" required:"true"` // CIDR is the address CIDR of the subnet. - CIDR string `json:"cidr" required:"true"` + CIDR string `json:"cidr,omitempty"` // Name is a human-readable name of the subnet. Name string `json:"name,omitempty"` - // The UUID of the tenant who owns the Subnet. Only administrative users - // can specify a tenant UUID other than their own. + // The UUID of the project who owns the Subnet. Only administrative users + // can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` + // The UUID of the project who owns the Subnet. Only administrative users + // can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + // AllocationPools are IP Address pools that will be available for DHCP. AllocationPools []AllocationPool `json:"allocation_pools,omitempty"` @@ -114,6 +120,9 @@ type CreateOpts struct { // The IPv6 router advertisement specifies whether the networking service // should transmit ICMPv6 packets. IPv6RAMode string `json:"ipv6_ra_mode,omitempty"` + + // SubnetPoolID is the id of the subnet pool that subnet should be associated to. + SubnetPoolID string `json:"subnetpool_id,omitempty"` } // ToSubnetCreateMap builds a request body from CreateOpts. @@ -167,7 +176,7 @@ type UpdateOpts struct { DNSNameservers []string `json:"dns_nameservers,omitempty"` // HostRoutes are any static host routes to be set via DHCP. - HostRoutes []HostRoute `json:"host_routes,omitempty"` + HostRoutes *[]HostRoute `json:"host_routes,omitempty"` // EnableDHCP will either enable to disable the DHCP service. EnableDHCP *bool `json:"enable_dhcp,omitempty"` @@ -212,7 +221,12 @@ func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { count := 0 id := "" - pages, err := List(client, nil).AllPages() + + listOpts := ListOpts{ + Name: name, + } + + pages, err := List(client, listOpts).AllPages() if err != nil { return "", err } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/results.go index 743610f0..493e5c04 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/results.go @@ -91,15 +91,21 @@ type Subnet struct { // Specifies whether DHCP is enabled for this subnet or not. EnableDHCP bool `json:"enable_dhcp"` - // Owner of network. + // TenantID is the project owner of the subnet. TenantID string `json:"tenant_id"` + // ProjectID is the project owner of the subnet. + ProjectID string `json:"project_id"` + // The IPv6 address modes specifies mechanisms for assigning IPv6 IP addresses. IPv6AddressMode string `json:"ipv6_address_mode"` // The IPv6 router advertisement specifies whether the networking service // should transmit ICMPv6 packets. IPv6RAMode string `json:"ipv6_ra_mode"` + + // SubnetPoolID is the id of the subnet pool associated with the subnet. + SubnetPoolID string `json:"subnetpool_id"` } // SubnetPage is the page returned by a pager when traversing over a collection diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/fixtures.go index 0dac0926..8cac911e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/fixtures.go @@ -60,6 +60,25 @@ const SubnetListResult = ` "gateway_ip": null, "cidr": "192.168.1.0/24", "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0c" + }, + { + "name": "my_subnet_with_subnetpool", + "enable_dhcp": false, + "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a23", + "tenant_id": "4fd44f30292945e481c7b8a0c8908869", + "dns_nameservers": [], + "allocation_pools": [ + { + "start": "10.11.12.2", + "end": "10.11.12.254" + } + ], + "host_routes": [], + "ip_version": 4, + "gateway_ip": null, + "cidr": "10.11.12.0/24", + "id": "38186a51-f373-4bbc-838b-6eaa1aa13eac", + "subnetpool_id": "b80340c7-9960-4f67-a99c-02501656284b" } ] } @@ -122,6 +141,26 @@ var Subnet3 = subnets.Subnet{ ID: "54d6f61d-db07-451c-9ab3-b9609b6b6f0c", } +var Subnet4 = subnets.Subnet{ + Name: "my_subnet_with_subnetpool", + EnableDHCP: false, + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", + TenantID: "4fd44f30292945e481c7b8a0c8908869", + DNSNameservers: []string{}, + AllocationPools: []subnets.AllocationPool{ + { + Start: "10.11.12.2", + End: "10.11.12.254", + }, + }, + HostRoutes: []subnets.HostRoute{}, + IPVersion: 4, + GatewayIP: "", + CIDR: "10.11.12.0/24", + ID: "38186a51-f373-4bbc-838b-6eaa1aa13eac", + SubnetPoolID: "b80340c7-9960-4f67-a99c-02501656284b", +} + const SubnetGetResult = ` { "subnet": { @@ -140,7 +179,8 @@ const SubnetGetResult = ` "ip_version": 4, "gateway_ip": "192.0.0.1", "cidr": "192.0.0.0/8", - "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b" + "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b", + "subnetpool_id": "b80340c7-9960-4f67-a99c-02501656284b" } } ` @@ -159,7 +199,8 @@ const SubnetCreateRequest = ` "end": "192.168.199.254" } ], - "host_routes": [{"destination":"","nexthop": "bar"}] + "host_routes": [{"destination":"","nexthop": "bar"}], + "subnetpool_id": "b80340c7-9960-4f67-a99c-02501656284b" } } ` @@ -182,7 +223,8 @@ const SubnetCreateResult = ` "ip_version": 4, "gateway_ip": "192.168.199.1", "cidr": "192.168.199.0/24", - "id": "3b80198d-4f7b-4f77-9ef5-774d54e17126" + "id": "3b80198d-4f7b-4f77-9ef5-774d54e17126", + "subnetpool_id": "b80340c7-9960-4f67-a99c-02501656284b" } } ` @@ -294,6 +336,18 @@ const SubnetCreateWithIPv6RaAddressModeResponse = ` } ` +const SubnetCreateRequestWithNoCIDR = ` +{ + "subnet": { + "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", + "ip_version": 4, + "dns_nameservers": ["foo"], + "host_routes": [{"destination":"","nexthop": "bar"}], + "subnetpool_id": "b80340c7-9960-4f67-a99c-02501656284b" + } +} +` + const SubnetUpdateRequest = ` { "subnet": { @@ -391,6 +445,79 @@ const SubnetUpdateRemoveGatewayResponse = ` } ` +const SubnetUpdateHostRoutesRequest = ` +{ + "subnet": { + "name": "my_new_subnet", + "host_routes": [ + { + "destination": "192.168.1.1/24", + "nexthop": "bar" + } + ] + } +} +` + +const SubnetUpdateHostRoutesResponse = ` +{ + "subnet": { + "name": "my_new_subnet", + "enable_dhcp": true, + "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", + "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "dns_nameservers": [], + "allocation_pools": [ + { + "start": "10.0.0.2", + "end": "10.0.0.254" + } + ], + "ip_version": 4, + "gateway_ip": "10.0.0.1", + "host_routes": [ + { + "destination": "192.168.1.1/24", + "nexthop": "bar" + } + ], + "cidr": "10.0.0.0/24", + "id": "08eae331-0402-425a-923c-34f7cfe39c1b" + } +} +` + +const SubnetUpdateRemoveHostRoutesRequest = ` +{ + "subnet": { + "host_routes": [] + } +} +` + +const SubnetUpdateRemoveHostRoutesResponse = ` +{ + "subnet": { + "name": "my_new_subnet", + "enable_dhcp": true, + "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", + "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "dns_nameservers": [], + "allocation_pools": [ + { + "start": "10.0.0.2", + "end": "10.0.0.254" + } + ], + "host_routes": [], + "ip_version": 4, + "gateway_ip": null, + "cidr": "10.0.0.0/24", + "id": "08eae331-0402-425a-923c-34f7cfe39c1b" + } +} +` + const SubnetUpdateAllocationPoolRequest = ` { "subnet": { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/requests_test.go new file mode 100644 index 00000000..bef6794b --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/requests_test.go @@ -0,0 +1,561 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" + "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SubnetListResult) + }) + + count := 0 + + subnets.List(fake.ServiceClient(), subnets.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := subnets.ExtractSubnets(page) + if err != nil { + t.Errorf("Failed to extract subnets: %v", err) + return false, nil + } + + expected := []subnets.Subnet{ + Subnet1, + Subnet2, + Subnet3, + Subnet4, + } + + th.CheckDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/54d6f61d-db07-451c-9ab3-b9609b6b6f0b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, SubnetGetResult) + }) + + s, err := subnets.Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_subnet") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertDeepEquals(t, s.DNSNameservers, []string{}) + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "192.0.0.2", + End: "192.255.255.254", + }, + }) + th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{}) + th.AssertEquals(t, s.IPVersion, 4) + th.AssertEquals(t, s.GatewayIP, "192.0.0.1") + th.AssertEquals(t, s.CIDR, "192.0.0.0/8") + th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0b") + th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b") +} + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetCreateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetCreateResult) + }) + + var gatewayIP = "192.168.199.1" + opts := subnets.CreateOpts{ + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", + IPVersion: 4, + CIDR: "192.168.199.0/24", + GatewayIP: &gatewayIP, + AllocationPools: []subnets.AllocationPool{ + { + Start: "192.168.199.2", + End: "192.168.199.254", + }, + }, + DNSNameservers: []string{"foo"}, + HostRoutes: []subnets.HostRoute{ + {NextHop: "bar"}, + }, + SubnetPoolID: "b80340c7-9960-4f67-a99c-02501656284b", + } + s, err := subnets.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertDeepEquals(t, s.DNSNameservers, []string{}) + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "192.168.199.2", + End: "192.168.199.254", + }, + }) + th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{}) + th.AssertEquals(t, s.IPVersion, 4) + th.AssertEquals(t, s.GatewayIP, "192.168.199.1") + th.AssertEquals(t, s.CIDR, "192.168.199.0/24") + th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126") + th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b") +} + +func TestCreateNoGateway(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetCreateWithNoGatewayRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetCreateWithNoGatewayResponse) + }) + + var noGateway = "" + opts := subnets.CreateOpts{ + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", + IPVersion: 4, + CIDR: "192.168.1.0/24", + GatewayIP: &noGateway, + AllocationPools: []subnets.AllocationPool{ + { + Start: "192.168.1.2", + End: "192.168.1.254", + }, + }, + DNSNameservers: []string{}, + } + s, err := subnets.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a23") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "192.168.1.2", + End: "192.168.1.254", + }, + }) + th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{}) + th.AssertEquals(t, s.IPVersion, 4) + th.AssertEquals(t, s.GatewayIP, "") + th.AssertEquals(t, s.CIDR, "192.168.1.0/24") + th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0c") +} + +func TestCreateDefaultGateway(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetCreateWithDefaultGatewayRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetCreateWithDefaultGatewayResponse) + }) + + opts := subnets.CreateOpts{ + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", + IPVersion: 4, + CIDR: "192.168.1.0/24", + AllocationPools: []subnets.AllocationPool{ + { + Start: "192.168.1.2", + End: "192.168.1.254", + }, + }, + DNSNameservers: []string{}, + } + s, err := subnets.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a23") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "192.168.1.2", + End: "192.168.1.254", + }, + }) + th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{}) + th.AssertEquals(t, s.IPVersion, 4) + th.AssertEquals(t, s.GatewayIP, "192.168.1.1") + th.AssertEquals(t, s.CIDR, "192.168.1.0/24") + th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0c") +} + +func TestCreateIPv6RaAddressMode(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetCreateWithIPv6RaAddressModeRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetCreateWithIPv6RaAddressModeResponse) + }) + + var gatewayIP = "2001:db8:0:a::1" + opts := subnets.CreateOpts{ + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", + IPVersion: 6, + CIDR: "2001:db8:0:a:0:0:0:0/64", + GatewayIP: &gatewayIP, + IPv6AddressMode: "slaac", + IPv6RAMode: "slaac", + } + s, err := subnets.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertEquals(t, s.IPVersion, 6) + th.AssertEquals(t, s.GatewayIP, "2001:db8:0:a::1") + th.AssertEquals(t, s.CIDR, "2001:db8:0:a:0:0:0:0/64") + th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126") + th.AssertEquals(t, s.IPv6AddressMode, "slaac") + th.AssertEquals(t, s.IPv6RAMode, "slaac") +} + +func TestCreateWithNoCIDR(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetCreateRequestWithNoCIDR) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetCreateResult) + }) + + opts := subnets.CreateOpts{ + NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", + IPVersion: 4, + DNSNameservers: []string{"foo"}, + HostRoutes: []subnets.HostRoute{ + {NextHop: "bar"}, + }, + SubnetPoolID: "b80340c7-9960-4f67-a99c-02501656284b", + } + s, err := subnets.Create(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "") + th.AssertEquals(t, s.EnableDHCP, true) + th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") + th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869") + th.AssertDeepEquals(t, s.DNSNameservers, []string{}) + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "192.168.199.2", + End: "192.168.199.254", + }, + }) + th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{}) + th.AssertEquals(t, s.IPVersion, 4) + th.AssertEquals(t, s.GatewayIP, "192.168.199.1") + th.AssertEquals(t, s.CIDR, "192.168.199.0/24") + th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126") + th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b") +} + +func TestRequiredCreateOpts(t *testing.T) { + res := subnets.Create(fake.ServiceClient(), subnets.CreateOpts{}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + + res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo"}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } + + res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40}) + if res.Err == nil { + t.Fatalf("Expected error, got none") + } +} + +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateResponse) + }) + + opts := subnets.UpdateOpts{ + Name: "my_new_subnet", + DNSNameservers: []string{"foo"}, + HostRoutes: &[]subnets.HostRoute{ + {NextHop: "bar"}, + }, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") +} + +func TestUpdateGateway(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateGatewayRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateGatewayResponse) + }) + + var gatewayIP = "10.0.0.1" + opts := subnets.UpdateOpts{ + Name: "my_new_subnet", + GatewayIP: &gatewayIP, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertEquals(t, s.GatewayIP, "10.0.0.1") +} + +func TestUpdateRemoveGateway(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateRemoveGatewayRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateRemoveGatewayResponse) + }) + + var noGateway = "" + opts := subnets.UpdateOpts{ + Name: "my_new_subnet", + GatewayIP: &noGateway, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertEquals(t, s.GatewayIP, "") +} + +func TestUpdateHostRoutes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateHostRoutesRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateHostRoutesResponse) + }) + + HostRoutes := []subnets.HostRoute{ + { + DestinationCIDR: "192.168.1.1/24", + NextHop: "bar", + }, + } + + opts := subnets.UpdateOpts{ + Name: "my_new_subnet", + HostRoutes: &HostRoutes, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertDeepEquals(t, s.HostRoutes, HostRoutes) +} + +func TestUpdateRemoveHostRoutes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateRemoveHostRoutesRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateRemoveHostRoutesResponse) + }) + + noHostRoutes := []subnets.HostRoute{} + opts := subnets.UpdateOpts{ + HostRoutes: &noHostRoutes, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertDeepEquals(t, s.HostRoutes, noHostRoutes) +} + +func TestUpdateAllocationPool(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PUT") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, SubnetUpdateAllocationPoolRequest) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, SubnetUpdateAllocationPoolResponse) + }) + + opts := subnets.UpdateOpts{ + Name: "my_new_subnet", + AllocationPools: []subnets.AllocationPool{ + { + Start: "10.1.0.2", + End: "10.1.0.254", + }, + }, + } + s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "my_new_subnet") + th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{ + { + Start: "10.1.0.2", + End: "10.1.0.254", + }, + }) +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "DELETE") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.WriteHeader(http.StatusNoContent) + }) + + res := subnets.Delete(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b") + th.AssertNoErr(t, res.Err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/results_test.go new file mode 100644 index 00000000..a227ccde --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/subnets/testing/results_test.go @@ -0,0 +1,59 @@ +package testing + +import ( + "encoding/json" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestHostRoute(t *testing.T) { + sejson := []byte(` + {"subnet": { + "name": "test-subnet", + "enable_dhcp": false, + "network_id": "3e66c41e-cbbd-4019-9aab-740b7e4150a0", + "tenant_id": "f86e123198cf42d19c8854c5f80c2f06", + "dns_nameservers": [], + "gateway_ip": "172.16.0.1", + "ipv6_ra_mode": null, + "allocation_pools": [ + { + "start": "172.16.0.2", + "end": "172.16.255.254" + } + ], + "host_routes": [ + { + "destination": "172.20.1.0/24", + "nexthop": "172.16.0.2" + } + ], + "ip_version": 4, + "ipv6_address_mode": null, + "cidr": "172.16.0.0/16", + "id": "6dcaa873-7115-41af-9ef5-915f73636e43", + "subnetpool_id": null + }} +`) + + var dejson interface{} + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatalf("%s", err) + } + + resp := gophercloud.Result{Body: dejson} + var subnetWrapper struct { + Subnet subnets.Subnet `json:"subnet"` + } + err = resp.ExtractInto(&subnetWrapper) + if err != nil { + t.Fatalf("%s", err) + } + route := subnetWrapper.Subnet.HostRoutes[0] + th.AssertEquals(t, route.NextHop, "172.16.0.2") + th.AssertEquals(t, route.DestinationCIDR, "172.20.1.0/24") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/requests.go index df215878..452a331c 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/requests.go @@ -35,7 +35,7 @@ func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) (r GetResult) { h[k] = v } } - resp, err := c.Request("HEAD", getURL(c), &gophercloud.RequestOpts{ + resp, err := c.Head(getURL(c), &gophercloud.RequestOpts{ MoreHeaders: h, OkCodes: []int{204}, }) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/results.go index bf5dc846..10661e67 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/results.go @@ -63,6 +63,7 @@ func (r UpdateResult) Extract() (*UpdateHeader, error) { // GetHeader represents the headers returned in the response from a Get request. type GetHeader struct { BytesUsed int64 `json:"-"` + QuotaBytes *int64 `json:"-"` ContainerCount int64 `json:"-"` ContentLength int64 `json:"-"` ObjectCount int64 `json:"-"` @@ -78,6 +79,7 @@ func (r *GetHeader) UnmarshalJSON(b []byte) error { var s struct { tmp BytesUsed string `json:"X-Account-Bytes-Used"` + QuotaBytes string `json:"X-Account-Meta-Quota-Bytes"` ContentLength string `json:"Content-Length"` ContainerCount string `json:"X-Account-Container-Count"` ObjectCount string `json:"X-Account-Object-Count"` @@ -100,6 +102,17 @@ func (r *GetHeader) UnmarshalJSON(b []byte) error { } } + switch s.QuotaBytes { + case "": + r.QuotaBytes = nil + default: + v, err := strconv.ParseInt(s.QuotaBytes, 10, 64) + if err != nil { + return err + } + r.QuotaBytes = &v + } + switch s.ContentLength { case "": r.ContentLength = 0 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/fixtures.go index fff30714..e1d21826 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/fixtures.go @@ -11,6 +11,24 @@ import ( // HandleGetAccountSuccessfully creates an HTTP handler at `/` on the test handler mux that // responds with a `Get` response. func HandleGetAccountSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "HEAD") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Set("X-Account-Container-Count", "2") + w.Header().Set("X-Account-Object-Count", "5") + w.Header().Set("X-Account-Meta-Quota-Bytes", "42") + w.Header().Set("X-Account-Bytes-Used", "14") + w.Header().Set("X-Account-Meta-Subject", "books") + w.Header().Set("Date", "Fri, 17 Jan 2014 16:09:56 GMT") + + w.WriteHeader(http.StatusNoContent) + }) +} + +// HandleGetAccountNoQuotaSuccessfully creates an HTTP handler at `/` on the +// test handler mux that responds with a `Get` response. +func HandleGetAccountNoQuotaSuccessfully(t *testing.T) { th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "HEAD") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/requests_test.go new file mode 100644 index 00000000..c396227e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts/testing/requests_test.go @@ -0,0 +1,82 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +var ( + loc, _ = time.LoadLocation("GMT") +) + +func TestUpdateAccount(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateAccountSuccessfully(t) + + options := &accounts.UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}} + res := accounts.Update(fake.ServiceClient(), options) + th.AssertNoErr(t, res.Err) + + expected := &accounts.UpdateHeader{ + Date: time.Date(2014, time.January, 17, 16, 9, 56, 0, loc), // Fri, 17 Jan 2014 16:09:56 GMT + } + actual, err := res.Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestGetAccount(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetAccountSuccessfully(t) + + expectedMetadata := map[string]string{"Subject": "books", "Quota-Bytes": "42"} + res := accounts.Get(fake.ServiceClient(), &accounts.GetOpts{}) + th.AssertNoErr(t, res.Err) + actualMetadata, _ := res.ExtractMetadata() + th.CheckDeepEquals(t, expectedMetadata, actualMetadata) + _, err := res.Extract() + th.AssertNoErr(t, err) + + var quotaBytes int64 = 42 + expected := &accounts.GetHeader{ + QuotaBytes: "aBytes, + ContainerCount: 2, + ObjectCount: 5, + BytesUsed: 14, + Date: time.Date(2014, time.January, 17, 16, 9, 56, 0, loc), // Fri, 17 Jan 2014 16:09:56 GMT + } + actual, err := res.Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestGetAccountNoQuota(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetAccountNoQuotaSuccessfully(t) + + expectedMetadata := map[string]string{"Subject": "books"} + res := accounts.Get(fake.ServiceClient(), &accounts.GetOpts{}) + th.AssertNoErr(t, res.Err) + actualMetadata, _ := res.ExtractMetadata() + th.CheckDeepEquals(t, expectedMetadata, actualMetadata) + _, err := res.Extract() + th.AssertNoErr(t, err) + + expected := &accounts.GetHeader{ + QuotaBytes: nil, + ContainerCount: 2, + ObjectCount: 5, + BytesUsed: 14, + Date: time.Date(2014, time.January, 17, 16, 9, 56, 0, loc), // Fri, 17 Jan 2014 16:09:56 GMT + } + actual, err := res.Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/doc.go index 1ac8504d..9e5f6641 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/doc.go @@ -7,6 +7,10 @@ containers represents two different objects. In addition to containing objects, you can also use the container to control access to objects by using an access control list (ACL). +Note: When referencing the Object Storage API docs, some of the API actions +are listed under "accounts" rather than "containers". This was an intentional +design in Gophercloud to make some container actions feel more natural. + Example to List Containers listOpts := containers.ListOpts{ diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/requests.go index ecb76075..4799204e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/requests.go @@ -107,6 +107,7 @@ func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsB }) if resp != nil { r.Header = resp.Header + resp.Body.Close() } r.Err = err return @@ -176,12 +177,41 @@ func Update(c *gophercloud.ServiceClient, containerName string, opts UpdateOptsB return } +// GetOptsBuilder allows extensions to add additional parameters to the Get +// request. +type GetOptsBuilder interface { + ToContainerGetMap() (map[string]string, error) +} + +// GetOpts is a structure that holds options for listing containers. +type GetOpts struct { + Newest bool `h:"X-Newest"` +} + +// ToContainerGetMap formats a GetOpts into a map of headers. +func (opts GetOpts) ToContainerGetMap() (map[string]string, error) { + return gophercloud.BuildHeaders(opts) +} + // Get is a function that retrieves the metadata of a container. To extract just // the custom metadata, pass the GetResult response to the ExtractMetadata // function. -func Get(c *gophercloud.ServiceClient, containerName string) (r GetResult) { - resp, err := c.Request("HEAD", getURL(c, containerName), &gophercloud.RequestOpts{ - OkCodes: []int{200, 204}, +func Get(c *gophercloud.ServiceClient, containerName string, opts GetOptsBuilder) (r GetResult) { + h := make(map[string]string) + if opts != nil { + headers, err := opts.ToContainerGetMap() + if err != nil { + r.Err = err + return + } + + for k, v := range headers { + h[k] = v + } + } + resp, err := c.Head(getURL(c, containerName), &gophercloud.RequestOpts{ + MoreHeaders: h, + OkCodes: []int{200, 204}, }) if resp != nil { r.Header = resp.Header diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/testing/requests_test.go new file mode 100644 index 00000000..c5eabd29 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers/testing/requests_test.go @@ -0,0 +1,148 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +var ( + metadata = map[string]string{"gophercloud-test": "containers"} + loc, _ = time.LoadLocation("GMT") +) + +func TestListContainerInfo(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainerInfoSuccessfully(t) + + count := 0 + err := containers.List(fake.ServiceClient(), &containers.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := containers.ExtractInfo(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedListInfo, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAllContainerInfo(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainerInfoSuccessfully(t) + + allPages, err := containers.List(fake.ServiceClient(), &containers.ListOpts{Full: true}).AllPages() + th.AssertNoErr(t, err) + actual, err := containers.ExtractInfo(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedListInfo, actual) +} + +func TestListContainerNames(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainerNamesSuccessfully(t) + + count := 0 + err := containers.List(fake.ServiceClient(), &containers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := containers.ExtractNames(page) + if err != nil { + t.Errorf("Failed to extract container names: %v", err) + return false, err + } + + th.CheckDeepEquals(t, ExpectedListNames, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListAllContainerNames(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListContainerNamesSuccessfully(t) + + allPages, err := containers.List(fake.ServiceClient(), &containers.ListOpts{Full: false}).AllPages() + th.AssertNoErr(t, err) + actual, err := containers.ExtractNames(allPages) + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, ExpectedListNames, actual) +} + +func TestCreateContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateContainerSuccessfully(t) + + options := containers.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}} + res := containers.Create(fake.ServiceClient(), "testContainer", options) + th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0]) + + expected := &containers.CreateHeader{ + ContentLength: 0, + ContentType: "text/html; charset=UTF-8", + Date: time.Date(2016, time.August, 17, 19, 25, 43, 0, loc), //Wed, 17 Aug 2016 19:25:43 GMT + TransID: "tx554ed59667a64c61866f1-0058b4ba37", + } + actual, err := res.Extract() + th.CheckNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} + +func TestDeleteContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteContainerSuccessfully(t) + + res := containers.Delete(fake.ServiceClient(), "testContainer") + th.CheckNoErr(t, res.Err) +} + +func TestUpdateContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateContainerSuccessfully(t) + + options := &containers.UpdateOpts{Metadata: map[string]string{"foo": "bar"}} + res := containers.Update(fake.ServiceClient(), "testContainer", options) + th.CheckNoErr(t, res.Err) +} + +func TestGetContainer(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetContainerSuccessfully(t) + + getOpts := containers.GetOpts{ + Newest: true, + } + res := containers.Get(fake.ServiceClient(), "testContainer", getOpts) + _, err := res.ExtractMetadata() + th.CheckNoErr(t, err) + + expected := &containers.GetHeader{ + AcceptRanges: "bytes", + BytesUsed: 100, + ContentType: "application/json; charset=utf-8", + Date: time.Date(2016, time.August, 17, 19, 25, 43, 0, loc), //Wed, 17 Aug 2016 19:25:43 GMT + ObjectCount: 4, + Read: []string{"test"}, + TransID: "tx554ed59667a64c61866f1-0057b4ba37", + Write: []string{"test2", "user4"}, + StoragePolicy: "test_policy", + } + actual, err := res.Extract() + th.CheckNoErr(t, err) + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/doc.go index 1e02430f..e9b4b8a9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/doc.go @@ -4,6 +4,10 @@ object resources. An object is a resource that represents and contains data - such as documents, images, and so on. You can also store custom metadata with an object. +Note: When referencing the Object Storage API docs, some of the API actions +are listed under "containers" rather than "objects". This was an intentional +design in Gophercloud to make some object actions feel more natural. + Example to List Objects containerName := "my_container" diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/requests.go index f67bfd15..7325cd7d 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/requests.go @@ -7,6 +7,7 @@ import ( "crypto/sha1" "fmt" "io" + "io/ioutil" "strings" "time" @@ -85,6 +86,7 @@ type DownloadOpts struct { IfModifiedSince time.Time `h:"If-Modified-Since"` IfNoneMatch string `h:"If-None-Match"` IfUnmodifiedSince time.Time `h:"If-Unmodified-Since"` + Newest bool `h:"X-Newest"` Range string `h:"Range"` Expires string `q:"expires"` MultipartManifest string `q:"multipart-manifest"` @@ -125,7 +127,7 @@ func Download(c *gophercloud.ServiceClient, containerName, objectName string, op resp, err := c.Get(url, nil, &gophercloud.RequestOpts{ MoreHeaders: h, - OkCodes: []int{200, 304}, + OkCodes: []int{200, 206, 304}, }) if resp != nil { r.Header = resp.Header @@ -145,6 +147,7 @@ type CreateOptsBuilder interface { type CreateOpts struct { Content io.Reader Metadata map[string]string + NoETag bool CacheControl string `h:"Cache-Control"` ContentDisposition string `h:"Content-Disposition"` ContentEncoding string `h:"Content-Encoding"` @@ -179,16 +182,37 @@ func (opts CreateOpts) ToObjectCreateParams() (io.Reader, map[string]string, str h["X-Object-Meta-"+k] = v } + if opts.NoETag { + delete(h, "etag") + return opts.Content, h, q.String(), nil + } + + if h["ETag"] != "" { + return opts.Content, h, q.String(), nil + } + + // When we're dealing with big files an io.ReadSeeker allows us to efficiently calculate + // the md5 sum. An io.Reader is only readable once which means we have to copy the entire + // file content into memory first. + readSeeker, isReadSeeker := opts.Content.(io.ReadSeeker) + if !isReadSeeker { + data, err := ioutil.ReadAll(opts.Content) + if err != nil { + return nil, nil, "", err + } + readSeeker = bytes.NewReader(data) + } + hash := md5.New() - buf := bytes.NewBuffer([]byte{}) - _, err = io.Copy(io.MultiWriter(hash, buf), opts.Content) - if err != nil { + // io.Copy into md5 is very efficient as it's done in small chunks. + if _, err := io.Copy(hash, readSeeker); err != nil { return nil, nil, "", err } - localChecksum := fmt.Sprintf("%x", hash.Sum(nil)) - h["ETag"] = localChecksum + readSeeker.Seek(0, io.SeekStart) + + h["ETag"] = fmt.Sprintf("%x", hash.Sum(nil)) - return buf, h, q.String(), nil + return readSeeker, h, q.String(), nil } // Create is a function that creates a new object or replaces an existing @@ -315,20 +339,28 @@ func Delete(c *gophercloud.ServiceClient, containerName, objectName string, opts // GetOptsBuilder allows extensions to add additional parameters to the // Get request. type GetOptsBuilder interface { - ToObjectGetQuery() (string, error) + ToObjectGetParams() (map[string]string, string, error) } // GetOpts is a structure that holds parameters for getting an object's // metadata. type GetOpts struct { + Newest bool `h:"X-Newest"` Expires string `q:"expires"` Signature string `q:"signature"` } -// ToObjectGetQuery formats a GetOpts into a query string. -func (opts GetOpts) ToObjectGetQuery() (string, error) { +// ToObjectGetParams formats a GetOpts into a query string and a map of headers. +func (opts GetOpts) ToObjectGetParams() (map[string]string, string, error) { q, err := gophercloud.BuildQueryString(opts) - return q.String(), err + if err != nil { + return nil, "", err + } + h, err := gophercloud.BuildHeaders(opts) + if err != nil { + return nil, q.String(), err + } + return h, q.String(), nil } // Get is a function that retrieves the metadata of an object. To extract just @@ -336,16 +368,22 @@ func (opts GetOpts) ToObjectGetQuery() (string, error) { // function. func Get(c *gophercloud.ServiceClient, containerName, objectName string, opts GetOptsBuilder) (r GetResult) { url := getURL(c, containerName, objectName) + h := make(map[string]string) if opts != nil { - query, err := opts.ToObjectGetQuery() + headers, query, err := opts.ToObjectGetParams() if err != nil { r.Err = err return } + for k, v := range headers { + h[k] = v + } url += query } - resp, err := c.Request("HEAD", url, &gophercloud.RequestOpts{ - OkCodes: []int{200, 204}, + + resp, err := c.Head(url, &gophercloud.RequestOpts{ + MoreHeaders: h, + OkCodes: []int{200, 204}, }) if resp != nil { r.Header = resp.Header diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/results.go index a47b3934..49a0abcd 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/results.go @@ -134,7 +134,7 @@ type DownloadHeader struct { ETag string `json:"Etag"` LastModified time.Time `json:"-"` ObjectManifest string `json:"X-Object-Manifest"` - StaticLargeObject bool `json:"X-Static-Large-Object"` + StaticLargeObject bool `json:"-"` TransID string `json:"X-Trans-Id"` } @@ -142,10 +142,11 @@ func (r *DownloadHeader) UnmarshalJSON(b []byte) error { type tmp DownloadHeader var s struct { tmp - ContentLength string `json:"Content-Length"` - Date gophercloud.JSONRFC1123 `json:"Date"` - DeleteAt gophercloud.JSONUnix `json:"X-Delete-At"` - LastModified gophercloud.JSONRFC1123 `json:"Last-Modified"` + ContentLength string `json:"Content-Length"` + Date gophercloud.JSONRFC1123 `json:"Date"` + DeleteAt gophercloud.JSONUnix `json:"X-Delete-At"` + LastModified gophercloud.JSONRFC1123 `json:"Last-Modified"` + StaticLargeObject interface{} `json:"X-Static-Large-Object"` } err := json.Unmarshal(b, &s) if err != nil { @@ -164,6 +165,15 @@ func (r *DownloadHeader) UnmarshalJSON(b []byte) error { } } + switch t := s.StaticLargeObject.(type) { + case string: + if t == "True" || t == "true" { + r.StaticLargeObject = true + } + case bool: + r.StaticLargeObject = t + } + r.Date = time.Time(s.Date) r.DeleteAt = time.Time(s.DeleteAt) r.LastModified = time.Time(s.LastModified) @@ -214,7 +224,7 @@ type GetHeader struct { ETag string `json:"Etag"` LastModified time.Time `json:"-"` ObjectManifest string `json:"X-Object-Manifest"` - StaticLargeObject bool `json:"X-Static-Large-Object"` + StaticLargeObject bool `json:"-"` TransID string `json:"X-Trans-Id"` } @@ -222,10 +232,11 @@ func (r *GetHeader) UnmarshalJSON(b []byte) error { type tmp GetHeader var s struct { tmp - ContentLength string `json:"Content-Length"` - Date gophercloud.JSONRFC1123 `json:"Date"` - DeleteAt gophercloud.JSONUnix `json:"X-Delete-At"` - LastModified gophercloud.JSONRFC1123 `json:"Last-Modified"` + ContentLength string `json:"Content-Length"` + Date gophercloud.JSONRFC1123 `json:"Date"` + DeleteAt gophercloud.JSONUnix `json:"X-Delete-At"` + LastModified gophercloud.JSONRFC1123 `json:"Last-Modified"` + StaticLargeObject interface{} `json:"X-Static-Large-Object"` } err := json.Unmarshal(b, &s) if err != nil { @@ -244,6 +255,15 @@ func (r *GetHeader) UnmarshalJSON(b []byte) error { } } + switch t := s.StaticLargeObject.(type) { + case string: + if t == "True" || t == "true" { + r.StaticLargeObject = true + } + case bool: + r.StaticLargeObject = t + } + r.Date = time.Time(s.Date) r.DeleteAt = time.Time(s.DeleteAt) r.LastModified = time.Time(s.LastModified) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/fixtures.go index a6b7e571..0ede1d62 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/fixtures.go @@ -21,6 +21,7 @@ func HandleDownloadObjectSuccessfully(t *testing.T) { th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.Header().Set("Date", "Wed, 10 Nov 2009 23:00:00 GMT") + w.Header().Set("X-Static-Large-Object", "True") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Successful download with Gophercloud") }) @@ -243,6 +244,7 @@ func HandleGetObjectSuccessfully(t *testing.T) { th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.Header().Add("X-Object-Meta-Gophercloud-Test", "objects") + w.Header().Add("X-Static-Large-Object", "true") w.WriteHeader(http.StatusNoContent) }) } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/requests_test.go new file mode 100644 index 00000000..c5b34a75 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects/testing/requests_test.go @@ -0,0 +1,312 @@ +package testing + +import ( + "bytes" + "crypto/md5" + "fmt" + "io" + "io/ioutil" + "strings" + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +var ( + loc, _ = time.LoadLocation("GMT") +) + +func TestDownloadReader(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDownloadObjectSuccessfully(t) + + response := objects.Download(fake.ServiceClient(), "testContainer", "testObject", nil) + defer response.Body.Close() + + // Check reader + buf := bytes.NewBuffer(make([]byte, 0)) + io.CopyN(buf, response.Body, 10) + th.CheckEquals(t, "Successful", string(buf.Bytes())) +} + +func TestDownloadExtraction(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDownloadObjectSuccessfully(t) + + response := objects.Download(fake.ServiceClient(), "testContainer", "testObject", nil) + + // Check []byte extraction + bytes, err := response.ExtractContent() + th.AssertNoErr(t, err) + th.CheckEquals(t, "Successful download with Gophercloud", string(bytes)) + + expected := &objects.DownloadHeader{ + ContentLength: 36, + ContentType: "text/plain; charset=utf-8", + Date: time.Date(2009, time.November, 10, 23, 0, 0, 0, loc), + StaticLargeObject: true, + } + actual, err := response.Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) +} + +func TestListObjectInfo(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListObjectsInfoSuccessfully(t) + + count := 0 + options := &objects.ListOpts{Full: true} + err := objects.List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := objects.ExtractInfo(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedListInfo, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListObjectSubdir(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSubdirSuccessfully(t) + + count := 0 + options := &objects.ListOpts{Full: true, Prefix: "", Delimiter: "/"} + err := objects.List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := objects.ExtractInfo(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ExpectedListSubdir, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListObjectNames(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListObjectNamesSuccessfully(t) + + // Check without delimiter. + count := 0 + options := &objects.ListOpts{Full: false} + err := objects.List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := objects.ExtractNames(page) + if err != nil { + t.Errorf("Failed to extract container names: %v", err) + return false, err + } + + th.CheckDeepEquals(t, ExpectedListNames, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) + + // Check with delimiter. + count = 0 + options = &objects.ListOpts{Full: false, Delimiter: "/"} + err = objects.List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := objects.ExtractNames(page) + if err != nil { + t.Errorf("Failed to extract container names: %v", err) + return false, err + } + + th.CheckDeepEquals(t, ExpectedListNames, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestCreateObject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + content := "Did gyre and gimble in the wabe" + + HandleCreateTextObjectSuccessfully(t, content) + + options := &objects.CreateOpts{ContentType: "text/plain", Content: strings.NewReader(content)} + res := objects.Create(fake.ServiceClient(), "testContainer", "testObject", options) + th.AssertNoErr(t, res.Err) +} + +func TestCreateObjectWithCacheControl(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + content := "All mimsy were the borogoves" + + HandleCreateTextWithCacheControlSuccessfully(t, content) + + options := &objects.CreateOpts{ + CacheControl: `max-age="3600", public`, + Content: strings.NewReader(content), + } + res := objects.Create(fake.ServiceClient(), "testContainer", "testObject", options) + th.AssertNoErr(t, res.Err) +} + +func TestCreateObjectWithoutContentType(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + content := "The sky was the color of television, tuned to a dead channel." + + HandleCreateTypelessObjectSuccessfully(t, content) + + res := objects.Create(fake.ServiceClient(), "testContainer", "testObject", &objects.CreateOpts{Content: strings.NewReader(content)}) + th.AssertNoErr(t, res.Err) +} + +/* +func TestErrorIsRaisedForChecksumMismatch(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("ETag", "acbd18db4cc2f85cedef654fccc4a4d8") + w.WriteHeader(http.StatusCreated) + }) + + content := strings.NewReader("The sky was the color of television, tuned to a dead channel.") + res := Create(fake.ServiceClient(), "testContainer", "testObject", &CreateOpts{Content: content}) + + err := fmt.Errorf("Local checksum does not match API ETag header") + th.AssertDeepEquals(t, err, res.Err) +} +*/ + +func TestCopyObject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCopyObjectSuccessfully(t) + + options := &objects.CopyOpts{Destination: "/newTestContainer/newTestObject"} + res := objects.Copy(fake.ServiceClient(), "testContainer", "testObject", options) + th.AssertNoErr(t, res.Err) +} + +func TestDeleteObject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteObjectSuccessfully(t) + + res := objects.Delete(fake.ServiceClient(), "testContainer", "testObject", nil) + th.AssertNoErr(t, res.Err) +} + +func TestUpateObjectMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateObjectSuccessfully(t) + + options := &objects.UpdateOpts{Metadata: map[string]string{"Gophercloud-Test": "objects"}} + res := objects.Update(fake.ServiceClient(), "testContainer", "testObject", options) + th.AssertNoErr(t, res.Err) +} + +func TestGetObject(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetObjectSuccessfully(t) + + expected := map[string]string{"Gophercloud-Test": "objects"} + actual, err := objects.Get(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractMetadata() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) + + getOpts := objects.GetOpts{ + Newest: true, + } + actualHeaders, err := objects.Get(fake.ServiceClient(), "testContainer", "testObject", getOpts).Extract() + th.AssertNoErr(t, err) + th.AssertEquals(t, actualHeaders.StaticLargeObject, true) +} + +func TestETag(t *testing.T) { + content := "some example object" + createOpts := objects.CreateOpts{ + Content: strings.NewReader(content), + NoETag: true, + } + + _, headers, _, err := createOpts.ToObjectCreateParams() + th.AssertNoErr(t, err) + _, ok := headers["ETag"] + th.AssertEquals(t, ok, false) + + hash := md5.New() + io.WriteString(hash, content) + localChecksum := fmt.Sprintf("%x", hash.Sum(nil)) + + createOpts = objects.CreateOpts{ + Content: strings.NewReader(content), + ETag: localChecksum, + } + + _, headers, _, err = createOpts.ToObjectCreateParams() + th.AssertNoErr(t, err) + th.AssertEquals(t, headers["ETag"], localChecksum) +} + +func TestObjectCreateParamsWithoutSeek(t *testing.T) { + content := "I do not implement Seek()" + buf := bytes.NewBuffer([]byte(content)) + + createOpts := objects.CreateOpts{Content: buf} + reader, headers, _, err := createOpts.ToObjectCreateParams() + + th.AssertNoErr(t, err) + + _, ok := reader.(io.ReadSeeker) + th.AssertEquals(t, ok, true) + + c, err := ioutil.ReadAll(reader) + th.AssertNoErr(t, err) + + th.AssertEquals(t, content, string(c)) + + _, ok = headers["ETag"] + th.AssertEquals(t, true, ok) +} + +func TestObjectCreateParamsWithSeek(t *testing.T) { + content := "I implement Seek()" + createOpts := objects.CreateOpts{Content: strings.NewReader(content)} + reader, headers, _, err := createOpts.ToObjectCreateParams() + + th.AssertNoErr(t, err) + + _, ok := reader.(io.ReadSeeker) + th.AssertEquals(t, ok, true) + + c, err := ioutil.ReadAll(reader) + th.AssertNoErr(t, err) + + th.AssertEquals(t, content, string(c)) + + _, ok = headers["ETag"] + th.AssertEquals(t, true, ok) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth/testing/requests_test.go new file mode 100644 index 00000000..46571f61 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth/testing/requests_test.go @@ -0,0 +1,35 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestAuth(t *testing.T) { + authOpts := swauth.AuthOpts{ + User: "test:tester", + Key: "testing", + } + + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAuthSuccessfully(t, authOpts) + + providerClient, err := openstack.NewClient(th.Endpoint()) + th.AssertNoErr(t, err) + + swiftClient, err := swauth.NewObjectStorageV1(providerClient, authOpts) + th.AssertNoErr(t, err) + th.AssertEquals(t, swiftClient.TokenID, AuthResult.Token) +} + +func TestBadAuth(t *testing.T) { + authOpts := swauth.AuthOpts{} + _, err := authOpts.ToAuthOptsMap() + if err == nil { + t.Fatalf("Expected an error due to missing auth options") + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/apiversions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/apiversions/testing/requests_test.go new file mode 100644 index 00000000..ac59b6c6 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/apiversions/testing/requests_test.go @@ -0,0 +1,90 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/apiversions" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "versions": [ + { + "status": "CURRENT", + "id": "v1.0", + "links": [ + { + "href": "http://23.253.228.211:8000/v1", + "rel": "self" + } + ] + } + ] +}`) + }) + + count := 0 + + apiversions.ListVersions(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := apiversions.ExtractAPIVersions(page) + if err != nil { + t.Errorf("Failed to extract API versions: %v", err) + return false, err + } + + expected := []apiversions.APIVersion{ + { + Status: "CURRENT", + ID: "v1.0", + Links: []gophercloud.Link{ + gophercloud.Link{ + Href: "http://23.253.228.211:8000/v1", + Rel: "self", + }, + }, + }, + } + + th.AssertDeepEquals(t, expected, actual) + + return true, nil + }) + + if count != 1 { + t.Errorf("Expected 1 page, got %d", count) + } +} + +func TestNonJSONCannotBeExtractedIntoAPIVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + apiversions.ListVersions(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + if _, err := apiversions.ExtractAPIVersions(page); err == nil { + t.Fatalf("Expected error, got nil") + } + return true, nil + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo/testing/requests_test.go new file mode 100644 index 00000000..bd2e164a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo/testing/requests_test.go @@ -0,0 +1,21 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t, GetOutput) + + actual, err := buildinfo.Get(fake.ServiceClient()).Extract() + th.AssertNoErr(t, err) + + expected := GetExpected + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents/testing/requests_test.go new file mode 100644 index 00000000..0ad3fc31 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents/testing/requests_test.go @@ -0,0 +1,72 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackevents" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestFindEvents(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleFindSuccessfully(t, FindOutput) + + actual, err := stackevents.Find(fake.ServiceClient(), "postman_stack").Extract() + th.AssertNoErr(t, err) + + expected := FindExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t, ListOutput) + + count := 0 + err := stackevents.List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := stackevents.ExtractEvents(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListExpected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestListResourceEvents(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListResourceEventsSuccessfully(t, ListResourceEventsOutput) + + count := 0 + err := stackevents.ListResourceEvents(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := stackevents.ExtractEvents(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListResourceEventsExpected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestGetEvent(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t, GetOutput) + + actual, err := stackevents.Get(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", "93940999-7d40-44ae-8de4-19624e7b8d18").Extract() + th.AssertNoErr(t, err) + + expected := GetExpected + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources/testing/requests_test.go new file mode 100644 index 00000000..c714047f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources/testing/requests_test.go @@ -0,0 +1,112 @@ +package testing + +import ( + "sort" + "testing" + + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestFindResources(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleFindSuccessfully(t, FindOutput) + + actual, err := stackresources.Find(fake.ServiceClient(), "hello_world").Extract() + th.AssertNoErr(t, err) + + expected := FindExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestListResources(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t, ListOutput) + + count := 0 + err := stackresources.List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := stackresources.ExtractResources(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListExpected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestGetResource(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t, GetOutput) + + actual, err := stackresources.Get(fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract() + th.AssertNoErr(t, err) + + expected := GetExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestResourceMetadata(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleMetadataSuccessfully(t, MetadataOutput) + + actual, err := stackresources.Metadata(fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract() + th.AssertNoErr(t, err) + + expected := MetadataExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestListResourceTypes(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListTypesSuccessfully(t, ListTypesOutput) + + count := 0 + err := stackresources.ListTypes(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := stackresources.ExtractResourceTypes(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListTypesExpected, actual) + // test if sorting works + sort.Sort(actual) + th.CheckDeepEquals(t, SortedListTypesExpected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, 1, count) +} + +func TestGetResourceSchema(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSchemaSuccessfully(t, GetSchemaOutput) + + actual, err := stackresources.Schema(fake.ServiceClient(), "OS::Heat::AResourceName").Extract() + th.AssertNoErr(t, err) + + expected := GetSchemaExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestGetResourceTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetTemplateSuccessfully(t, GetTemplateOutput) + + actual, err := stackresources.Template(fake.ServiceClient(), "OS::Heat::AResourceName").Extract() + th.AssertNoErr(t, err) + + expected := GetTemplateExpected + th.AssertDeepEquals(t, expected, string(actual)) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/doc.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/doc.go index 19231b51..f8f2a6fe 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/doc.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/doc.go @@ -1,8 +1,115 @@ -// Package stacks provides operation for working with Heat stacks. A stack is a -// group of resources (servers, load balancers, databases, and so forth) -// combined to fulfill a useful purpose. Based on a template, Heat orchestration -// engine creates an instantiated set of resources (a stack) to run the -// application framework or component specified (in the template). A stack is a -// running instance of a template. The result of creating a stack is a deployment -// of the application framework or component. +/* +Package stacks provides operation for working with Heat stacks. A stack is a +group of resources (servers, load balancers, databases, and so forth) +combined to fulfill a useful purpose. Based on a template, Heat orchestration +engine creates an instantiated set of resources (a stack) to run the +application framework or component specified (in the template). A stack is a +running instance of a template. The result of creating a stack is a deployment +of the application framework or component. + +Summary of Behavior Between Stack Update and UpdatePatch Methods : + +Function | Test Case | Result + +Update() | Template AND Parameters WITH Conflict | Parameter takes priority, parameters are set in raw_template.environment overlay +Update() | Template ONLY | Template updates, raw_template.environment overlay is removed +Update() | Parameters ONLY | No update, template is required + +UpdatePatch() | Template AND Parameters WITH Conflict | Parameter takes priority, parameters are set in raw_template.environment overlay +UpdatePatch() | Template ONLY | Template updates, but raw_template.environment overlay is not removed, existing parameter values will remain +UpdatePatch() | Parameters ONLY | Parameters (raw_template.environment) is updated, excluded values are unchanged + +The PUT Update() function will remove parameters from the raw_template.environment overlay +if they are excluded from the operation, whereas PATCH Update() will never be destructive to the +raw_template.environment overlay. It is not possible to expose the raw_template values with a +patch update once they have been added to the environment overlay with the PATCH verb, but +newly added values that do not have a corresponding key in the overlay will display the +raw_template value. + +Example to Update a Stack Using the Update (PUT) Method + + t := make(map[string]interface{}) + f, err := ioutil.ReadFile("template.yaml") + if err != nil { + panic(err) + } + err = yaml.Unmarshal(f, t) + if err != nil { + panic(err) + } + + template := stacks.Template{} + template.TE = stacks.TE{ + Bin: f, + } + + var params = make(map[string]interface{}) + params["number_of_nodes"] = 2 + + stackName := "my_stack" + stackId := "d68cc349-ccc5-4b44-a17d-07f068c01e5a" + + stackOpts := &stacks.UpdateOpts{ + Parameters: params, + TemplateOpts: &template, + } + + res := stacks.Update(orchestrationClient, stackName, stackId, stackOpts) + if res.Err != nil { + panic(res.Err) + } + +Example to Update a Stack Using the UpdatePatch (PATCH) Method + + var params = make(map[string]interface{}) + params["number_of_nodes"] = 2 + + stackName := "my_stack" + stackId := "d68cc349-ccc5-4b44-a17d-07f068c01e5a" + + stackOpts := &stacks.UpdateOpts{ + Parameters: params, + } + + res := stacks.UpdatePatch(orchestrationClient, stackName, stackId, stackOpts) + if res.Err != nil { + panic(res.Err) + } + +Example YAML Template Containing a Heat::ResourceGroup With Three Nodes + + heat_template_version: 2016-04-08 + + parameters: + number_of_nodes: + type: number + default: 3 + description: the number of nodes + node_flavor: + type: string + default: m1.small + description: node flavor + node_image: + type: string + default: centos7.5-latest + description: node os image + node_network: + type: string + default: my-node-network + description: node network name + + resources: + resource_group: + type: OS::Heat::ResourceGroup + properties: + count: { get_param: number_of_nodes } + resource_def: + type: OS::Nova::Server + properties: + name: my_nova_server_%index% + image: { get_param: node_image } + flavor: { get_param: node_flavor } + networks: + - network: {get_param: node_network} +*/ package stacks diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/environment_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/environment_test.go new file mode 100644 index 00000000..6fcc230d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/environment_test.go @@ -0,0 +1,192 @@ +package stacks + +import ( + "fmt" + "net/http" + "net/url" + "strings" + "testing" + + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestEnvironmentValidation(t *testing.T) { + + environmentJSON := new(Environment) + environmentJSON.Bin = []byte(ValidJSONEnvironment) + err := environmentJSON.Validate() + th.AssertNoErr(t, err) + + environmentYAML := new(Environment) + environmentYAML.Bin = []byte(ValidYAMLEnvironment) + err = environmentYAML.Validate() + th.AssertNoErr(t, err) + + environmentInvalid := new(Environment) + environmentInvalid.Bin = []byte(InvalidEnvironment) + if err = environmentInvalid.Validate(); err == nil { + t.Error("environment validation did not catch invalid environment") + } +} + +func TestEnvironmentParsing(t *testing.T) { + environmentJSON := new(Environment) + environmentJSON.Bin = []byte(ValidJSONEnvironment) + err := environmentJSON.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidJSONEnvironmentParsed, environmentJSON.Parsed) + + environmentYAML := new(Environment) + environmentYAML.Bin = []byte(ValidJSONEnvironment) + err = environmentYAML.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidJSONEnvironmentParsed, environmentYAML.Parsed) + + environmentInvalid := new(Environment) + environmentInvalid.Bin = []byte("Keep Austin Weird") + err = environmentInvalid.Parse() + if err == nil { + t.Error("environment parsing did not catch invalid environment") + } +} + +func TestIgnoreIfEnvironment(t *testing.T) { + var keyValueTests = []struct { + key string + value interface{} + out bool + }{ + {"base_url", "afksdf", true}, + {"not_type", "hooks", false}, + {"get_file", "::", true}, + {"hooks", "dfsdfsd", true}, + {"type", "sdfubsduf.yaml", false}, + {"type", "sdfsdufs.environment", false}, + {"type", "sdfsdf.file", false}, + {"type", map[string]string{"key": "value"}, true}, + } + var result bool + for _, kv := range keyValueTests { + result = ignoreIfEnvironment(kv.key, kv.value) + if result != kv.out { + t.Errorf("key: %v, value: %v expected: %v, actual: %v", kv.key, kv.value, kv.out, result) + } + } +} + +func TestGetRRFileContents(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + environmentContent := ` +heat_template_version: 2013-05-23 + +description: + Heat WordPress template to support F18, using only Heat OpenStack-native + resource types, and without the requirement for heat-cfntools in the image. + WordPress is web software you can use to create a beautiful website or blog. + This template installs a single-instance WordPress deployment using a local + MySQL database to store the data. + +parameters: + + key_name: + type: string + description : Name of a KeyPair to enable SSH access to the instance + +resources: + wordpress_instance: + type: OS::Nova::Server + properties: + image: { get_param: image_id } + flavor: { get_param: instance_type } + key_name: { get_param: key_name }` + + dbContent := ` +heat_template_version: 2014-10-16 + +description: + Test template for Trove resource capabilities + +parameters: + db_pass: + type: string + hidden: true + description: Database access password + default: secrete + +resources: + +service_db: + type: OS::Trove::Instance + properties: + name: trove_test_db + datastore_type: mariadb + flavor: 1GB Instance + size: 10 + databases: + - name: test_data + users: + - name: kitchen_sink + password: { get_param: db_pass } + databases: [ test_data ]` + baseurl, err := getBasePath() + th.AssertNoErr(t, err) + + fakeEnvURL := strings.Join([]string{baseurl, "my_env.yaml"}, "/") + urlparsed, err := url.Parse(fakeEnvURL) + th.AssertNoErr(t, err) + // handler for my_env.yaml + th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, environmentContent) + }) + + fakeDBURL := strings.Join([]string{baseurl, "my_db.yaml"}, "/") + urlparsed, err = url.Parse(fakeDBURL) + th.AssertNoErr(t, err) + + // handler for my_db.yaml + th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, dbContent) + }) + + client := fakeClient{BaseClient: getHTTPClient()} + env := new(Environment) + env.Bin = []byte(`{"resource_registry": {"My::WP::Server": "my_env.yaml", "resources": {"my_db_server": {"OS::DBInstance": "my_db.yaml"}}}}`) + env.client = client + + err = env.Parse() + th.AssertNoErr(t, err) + err = env.getRRFileContents(ignoreIfEnvironment) + th.AssertNoErr(t, err) + expectedEnvFilesContent := "\nheat_template_version: 2013-05-23\n\ndescription:\n Heat WordPress template to support F18, using only Heat OpenStack-native\n resource types, and without the requirement for heat-cfntools in the image.\n WordPress is web software you can use to create a beautiful website or blog.\n This template installs a single-instance WordPress deployment using a local\n MySQL database to store the data.\n\nparameters:\n\n key_name:\n type: string\n description : Name of a KeyPair to enable SSH access to the instance\n\nresources:\n wordpress_instance:\n type: OS::Nova::Server\n properties:\n image: { get_param: image_id }\n flavor: { get_param: instance_type }\n key_name: { get_param: key_name }" + expectedDBFilesContent := "\nheat_template_version: 2014-10-16\n\ndescription:\n Test template for Trove resource capabilities\n\nparameters:\n db_pass:\n type: string\n hidden: true\n description: Database access password\n default: secrete\n\nresources:\n\nservice_db:\n type: OS::Trove::Instance\n properties:\n name: trove_test_db\n datastore_type: mariadb\n flavor: 1GB Instance\n size: 10\n databases:\n - name: test_data\n users:\n - name: kitchen_sink\n password: { get_param: db_pass }\n databases: [ test_data ]" + + th.AssertEquals(t, expectedEnvFilesContent, env.Files[fakeEnvURL]) + th.AssertEquals(t, expectedDBFilesContent, env.Files[fakeDBURL]) + + // Update env's fileMaps to replace relative filenames by absolute URLs. + env.fileMaps = map[string]string{ + "my_env.yaml": fakeEnvURL, + "my_db.yaml": fakeDBURL, + } + env.fixFileRefs() + + expectedParsed := map[string]interface{}{ + "resource_registry": map[string]interface{}{ + "My::WP::Server": fakeEnvURL, + "resources": map[string]interface{}{ + "my_db_server": map[string]interface{}{ + "OS::DBInstance": fakeDBURL, + }, + }, + }, + } + env.Parse() + th.AssertDeepEquals(t, expectedParsed, env.Parsed) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/errors.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/errors.go index cd6c18f7..a6febe04 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/errors.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/errors.go @@ -31,3 +31,11 @@ type ErrInvalidTemplateFormatVersion struct { func (e ErrInvalidTemplateFormatVersion) Error() string { return fmt.Sprintf("Template format version not found.") } + +type ErrTemplateRequired struct { + gophercloud.BaseError +} + +func (e ErrTemplateRequired) Error() string { + return fmt.Sprintf("Template required for this function.") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/requests.go index 91f38ee7..5df222ff 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/requests.go @@ -265,42 +265,66 @@ type UpdateOptsBuilder interface { ToStackUpdateMap() (map[string]interface{}, error) } +// UpdatePatchOptsBuilder is the interface options structs have to satisfy in order +// to be used in the UpdatePatch operation in this package +type UpdatePatchOptsBuilder interface { + ToStackUpdatePatchMap() (map[string]interface{}, error) +} + // UpdateOpts contains the common options struct used in this package's Update -// operation. +// and UpdatePatch operations. type UpdateOpts struct { // A structure that contains either the template file or url. Call the // associated methods to extract the information relevant to send in a create request. - TemplateOpts *Template `json:"-" required:"true"` + TemplateOpts *Template `json:"-"` // A structure that contains details for the environment of the stack. EnvironmentOpts *Environment `json:"-"` // User-defined parameters to pass to the template. - Parameters map[string]string `json:"parameters,omitempty"` + Parameters map[string]interface{} `json:"parameters,omitempty"` // The timeout for stack creation in minutes. Timeout int `json:"timeout_mins,omitempty"` - // A list of tags to assosciate with the Stack + // A list of tags to associate with the Stack Tags []string `json:"-"` } -// ToStackUpdateMap casts a CreateOpts struct to a map. +// ToStackUpdateMap validates that a template was supplied and calls +// the toStackUpdateMap private function. func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) { - b, err := gophercloud.BuildRequestBody(opts, "") - if err != nil { - return nil, err + if opts.TemplateOpts == nil { + return nil, ErrTemplateRequired{} } + return toStackUpdateMap(opts) +} - if err := opts.TemplateOpts.Parse(); err != nil { - return nil, err - } +// ToStackUpdatePatchMap calls the private function toStackUpdateMap +// directly. +func (opts UpdateOpts) ToStackUpdatePatchMap() (map[string]interface{}, error) { + return toStackUpdateMap(opts) +} - if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { +// ToStackUpdateMap casts a CreateOpts struct to a map. +func toStackUpdateMap(opts UpdateOpts) (map[string]interface{}, error) { + b, err := gophercloud.BuildRequestBody(opts, "") + if err != nil { return nil, err } - opts.TemplateOpts.fixFileRefs() - b["template"] = string(opts.TemplateOpts.Bin) files := make(map[string]string) - for k, v := range opts.TemplateOpts.Files { - files[k] = v + + if opts.TemplateOpts != nil { + if err := opts.TemplateOpts.Parse(); err != nil { + return nil, err + } + + if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { + return nil, err + } + opts.TemplateOpts.fixFileRefs() + b["template"] = string(opts.TemplateOpts.Bin) + + for k, v := range opts.TemplateOpts.Files { + files[k] = v + } } if opts.EnvironmentOpts != nil { @@ -328,8 +352,8 @@ func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) { return b, nil } -// Update accepts an UpdateOpts struct and updates an existing stack using the values -// provided. +// Update accepts an UpdateOpts struct and updates an existing stack using the +// http PUT verb with the values provided. opts.TemplateOpts is required. func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts UpdateOptsBuilder) (r UpdateResult) { b, err := opts.ToStackUpdateMap() if err != nil { @@ -340,6 +364,18 @@ func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts Update return } +// Update accepts an UpdateOpts struct and updates an existing stack using the +// http PATCH verb with the values provided. opts.TemplateOpts is not required. +func UpdatePatch(c *gophercloud.ServiceClient, stackName, stackID string, opts UpdatePatchOptsBuilder) (r UpdateResult) { + b, err := opts.ToStackUpdatePatchMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Patch(updateURL(c, stackName, stackID), b, nil, nil) + return +} + // Delete deletes a stack based on the stack name and stack ID. func Delete(c *gophercloud.ServiceClient, stackName, stackID string) (r DeleteResult) { _, r.Err = c.Delete(deleteURL(c, stackName, stackID), nil) diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/template_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/template_test.go new file mode 100644 index 00000000..1ad9fc9c --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/template_test.go @@ -0,0 +1,148 @@ +package stacks + +import ( + "fmt" + "net/http" + "net/url" + "strings" + "testing" + + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTemplateValidation(t *testing.T) { + templateJSON := new(Template) + templateJSON.Bin = []byte(ValidJSONTemplate) + err := templateJSON.Validate() + th.AssertNoErr(t, err) + + templateYAML := new(Template) + templateYAML.Bin = []byte(ValidYAMLTemplate) + err = templateYAML.Validate() + th.AssertNoErr(t, err) + + templateInvalid := new(Template) + templateInvalid.Bin = []byte(InvalidTemplateNoVersion) + if err = templateInvalid.Validate(); err == nil { + t.Error("Template validation did not catch invalid template") + } +} + +func TestTemplateParsing(t *testing.T) { + templateJSON := new(Template) + templateJSON.Bin = []byte(ValidJSONTemplate) + err := templateJSON.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidJSONTemplateParsed, templateJSON.Parsed) + + templateYAML := new(Template) + templateYAML.Bin = []byte(ValidJSONTemplate) + err = templateYAML.Parse() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, ValidJSONTemplateParsed, templateYAML.Parsed) + + templateInvalid := new(Template) + templateInvalid.Bin = []byte("Keep Austin Weird") + err = templateInvalid.Parse() + if err == nil { + t.Error("Template parsing did not catch invalid template") + } +} + +func TestIgnoreIfTemplate(t *testing.T) { + var keyValueTests = []struct { + key string + value interface{} + out bool + }{ + {"not_get_file", "afksdf", true}, + {"not_type", "sdfd", true}, + {"get_file", "shdfuisd", false}, + {"type", "dfsdfsd", true}, + {"type", "sdfubsduf.yaml", false}, + {"type", "sdfsdufs.template", false}, + {"type", "sdfsdf.file", true}, + {"type", map[string]string{"key": "value"}, true}, + } + var result bool + for _, kv := range keyValueTests { + result = ignoreIfTemplate(kv.key, kv.value) + if result != kv.out { + t.Errorf("key: %v, value: %v expected: %v, actual: %v", kv.key, kv.value, result, kv.out) + } + } +} + +func TestGetFileContents(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + baseurl, err := getBasePath() + th.AssertNoErr(t, err) + fakeURL := strings.Join([]string{baseurl, "my_nova.yaml"}, "/") + urlparsed, err := url.Parse(fakeURL) + th.AssertNoErr(t, err) + myNovaContent := `heat_template_version: 2014-10-16 +parameters: + flavor: + type: string + description: Flavor for the server to be created + default: 4353 + hidden: true +resources: + test_server: + type: "OS::Nova::Server" + properties: + name: test-server + flavor: 2 GB General Purpose v1 + image: Debian 7 (Wheezy) (PVHVM) + networks: + - {uuid: 11111111-1111-1111-1111-111111111111}` + th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, myNovaContent) + }) + + client := fakeClient{BaseClient: getHTTPClient()} + te := new(Template) + te.Bin = []byte(`heat_template_version: 2015-04-30 +resources: + my_server: + type: my_nova.yaml`) + te.client = client + + err = te.Parse() + th.AssertNoErr(t, err) + err = te.getFileContents(te.Parsed, ignoreIfTemplate, true) + th.AssertNoErr(t, err) + expectedFiles := map[string]string{ + "my_nova.yaml": `heat_template_version: 2014-10-16 +parameters: + flavor: + type: string + description: Flavor for the server to be created + default: 4353 + hidden: true +resources: + test_server: + type: "OS::Nova::Server" + properties: + name: test-server + flavor: 2 GB General Purpose v1 + image: Debian 7 (Wheezy) (PVHVM) + networks: + - {uuid: 11111111-1111-1111-1111-111111111111}`} + th.AssertEquals(t, expectedFiles["my_nova.yaml"], te.Files[fakeURL]) + te.fixFileRefs() + expectedParsed := map[string]interface{}{ + "heat_template_version": "2015-04-30", + "resources": map[string]interface{}{ + "my_server": map[string]interface{}{ + "type": fakeURL, + }, + }, + } + te.Parse() + th.AssertDeepEquals(t, expectedParsed, te.Parsed) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/fixtures.go index f3e3b57d..7c8a2f32 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/fixtures.go @@ -233,6 +233,19 @@ func HandleUpdateSuccessfully(t *testing.T) { }) } +// HandleUpdatePatchSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` +// on the test handler mux that responds with an `Update` response. +func HandleUpdatePatchSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "PATCH") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusAccepted) + }) +} + // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` // on the test handler mux that responds with a `Delete` response. func HandleDeleteSuccessfully(t *testing.T) { diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/requests_test.go new file mode 100644 index 00000000..f8bd1fe2 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/testing/requests_test.go @@ -0,0 +1,224 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreateStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t, CreateOutput) + template := new(stacks.Template) + template.Bin = []byte(` + { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + } + }`) + createOpts := stacks.CreateOpts{ + Name: "stackcreated", + Timeout: 60, + TemplateOpts: template, + DisableRollback: gophercloud.Disabled, + } + actual, err := stacks.Create(fake.ServiceClient(), createOpts).Extract() + th.AssertNoErr(t, err) + + expected := CreateExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestAdoptStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleCreateSuccessfully(t, CreateOutput) + template := new(stacks.Template) + template.Bin = []byte(` +{ + "stack_name": "postman_stack", + "template": { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + }, + "resources": { + "hello_world": { + "type":"OS::Nova::Server", + "properties": { + "key_name": "heat_key", + "flavor": { + "get_param": "flavor" + }, + "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", + "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + } +}`) + adoptOpts := stacks.AdoptOpts{ + AdoptStackData: `{environment{parameters{}}}`, + Name: "stackcreated", + Timeout: 60, + TemplateOpts: template, + DisableRollback: gophercloud.Disabled, + } + actual, err := stacks.Adopt(fake.ServiceClient(), adoptOpts).Extract() + th.AssertNoErr(t, err) + + expected := CreateExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestListStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleListSuccessfully(t, FullListOutput) + + count := 0 + err := stacks.List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { + count++ + actual, err := stacks.ExtractStacks(page) + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, ListExpected, actual) + + return true, nil + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, count, 1) +} + +func TestGetStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t, GetOutput) + + actual, err := stacks.Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract() + th.AssertNoErr(t, err) + + expected := GetExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestUpdateStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + template := new(stacks.Template) + template.Bin = []byte(` + { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + } + }`) + updateOpts := &stacks.UpdateOpts{ + TemplateOpts: template, + } + err := stacks.Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestUpdateStackNoTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdateSuccessfully(t) + + parameters := make(map[string]interface{}) + parameters["flavor"] = "m1.tiny" + + updateOpts := &stacks.UpdateOpts{ + Parameters: parameters, + } + expected := stacks.ErrTemplateRequired{} + + err := stacks.Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() + th.AssertEquals(t, expected, err) +} + +func TestUpdatePatchStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleUpdatePatchSuccessfully(t) + + parameters := make(map[string]interface{}) + parameters["flavor"] = "m1.tiny" + + updateOpts := &stacks.UpdateOpts{ + Parameters: parameters, + } + err := stacks.UpdatePatch(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestDeleteStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleDeleteSuccessfully(t) + + err := stacks.Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr() + th.AssertNoErr(t, err) +} + +func TestPreviewStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandlePreviewSuccessfully(t, GetOutput) + + template := new(stacks.Template) + template.Bin = []byte(` + { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + } + }`) + previewOpts := stacks.PreviewOpts{ + Name: "stackcreated", + Timeout: 60, + TemplateOpts: template, + DisableRollback: gophercloud.Disabled, + } + actual, err := stacks.Preview(fake.ServiceClient(), previewOpts).Extract() + th.AssertNoErr(t, err) + + expected := PreviewExpected + th.AssertDeepEquals(t, expected, actual) +} + +func TestAbandonStack(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleAbandonSuccessfully(t, AbandonOutput) + + actual, err := stacks.Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract() + th.AssertNoErr(t, err) + + expected := AbandonExpected + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/utils_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/utils_test.go new file mode 100644 index 00000000..b64e4dce --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks/utils_test.go @@ -0,0 +1,94 @@ +package stacks + +import ( + "fmt" + "net/http" + "net/url" + "strings" + "testing" + + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestTEFixFileRefs(t *testing.T) { + te := TE{ + Bin: []byte(`string_to_replace: my fair lady`), + fileMaps: map[string]string{ + "string_to_replace": "london bridge is falling down", + }, + } + te.fixFileRefs() + th.AssertEquals(t, string(te.Bin), `london bridge is falling down: my fair lady`) +} + +func TestToStringKeys(t *testing.T) { + var test1 interface{} = map[interface{}]interface{}{ + "Adam": "Smith", + "Isaac": "Newton", + } + result1, err := toStringKeys(test1) + th.AssertNoErr(t, err) + + expected := map[string]interface{}{ + "Adam": "Smith", + "Isaac": "Newton", + } + th.AssertDeepEquals(t, result1, expected) +} + +func TestGetBasePath(t *testing.T) { + _, err := getBasePath() + th.AssertNoErr(t, err) +} + +// test if HTTP client can read file type URLS. Read the URL of this file +// because if this test is running, it means this file _must_ exist +func TestGetHTTPClient(t *testing.T) { + client := getHTTPClient() + baseurl, err := getBasePath() + th.AssertNoErr(t, err) + resp, err := client.Get(baseurl) + th.AssertNoErr(t, err) + th.AssertEquals(t, resp.StatusCode, 200) +} + +// Implement a fakeclient that can be used to mock out HTTP requests +type fakeClient struct { + BaseClient Client +} + +// this client's Get method first changes the URL given to point to +// testhelper's (th) endpoints. This is done because the http Mux does not seem +// to work for fqdns with the `file` scheme +func (c fakeClient) Get(url string) (*http.Response, error) { + newurl := strings.Replace(url, "file://", th.Endpoint(), 1) + return c.BaseClient.Get(newurl) +} + +// test the fetch function +func TestFetch(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + baseurl, err := getBasePath() + th.AssertNoErr(t, err) + fakeURL := strings.Join([]string{baseurl, "file.yaml"}, "/") + urlparsed, err := url.Parse(fakeURL) + th.AssertNoErr(t, err) + + th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + w.Header().Set("Content-Type", "application/jason") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, "Fee-fi-fo-fum") + }) + + client := fakeClient{BaseClient: getHTTPClient()} + te := TE{ + URL: "file.yaml", + client: client, + } + err = te.Fetch() + th.AssertNoErr(t, err) + th.AssertEquals(t, fakeURL, te.URL) + th.AssertEquals(t, "Fee-fi-fo-fum", string(te.Bin)) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates/testing/requests_test.go new file mode 100644 index 00000000..442bcb7a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates/testing/requests_test.go @@ -0,0 +1,58 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates" + th "github.com/gophercloud/gophercloud/testhelper" + fake "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestGetTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetSuccessfully(t, GetOutput) + + actual, err := stacktemplates.Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract() + th.AssertNoErr(t, err) + + expected := GetExpected + th.AssertDeepEquals(t, expected, string(actual)) +} + +func TestValidateTemplate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleValidateSuccessfully(t, ValidateOutput) + + opts := stacktemplates.ValidateOpts{ + Template: `{ + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + }, + "resources": { + "hello_world": { + "type": "OS::Nova::Server", + "properties": { + "key_name": "heat_key", + "flavor": { + "get_param": "flavor" + }, + "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", + "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }`, + } + actual, err := stacktemplates.Validate(fake.ServiceClient(), opts).Extract() + th.AssertNoErr(t, err) + + expected := ValidateExpected + th.AssertDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions/testing/requests_test.go new file mode 100644 index 00000000..8b5501fd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions/testing/requests_test.go @@ -0,0 +1,56 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestListAPIVersions(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allVersions, err := apiversions.List(client.ServiceClient()).AllPages() + th.AssertNoErr(t, err) + + actual, err := apiversions.ExtractAPIVersions(allVersions) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ManilaAllAPIVersionResults, actual) +} + +func TestGetAPIVersion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + actual, err := apiversions.Get(client.ServiceClient(), "v2").Extract() + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, ManilaAPIVersion2Result, *actual) +} + +func TestGetNoAPIVersion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetNoResponse(t) + + _, err := apiversions.Get(client.ServiceClient(), "v2").Extract() + th.AssertEquals(t, err.Error(), "Unable to find requested API version") +} + +func TestGetMultipleAPIVersion(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetMultipleResponses(t) + + _, err := apiversions.Get(client.ServiceClient(), "v2").Extract() + th.AssertEquals(t, err.Error(), "Found 2 API versions") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones/testing/requests_test.go new file mode 100644 index 00000000..76c8574f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones/testing/requests_test.go @@ -0,0 +1,34 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// Verifies that availability zones can be listed correctly +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := availabilityzones.List(client.ServiceClient()).AllPages() + th.AssertNoErr(t, err) + actual, err := availabilityzones.ExtractAvailabilityZones(allPages) + th.AssertNoErr(t, err) + var nilTime time.Time + expected := []availabilityzones.AvailabilityZone{ + { + Name: "nova", + CreatedAt: time.Date(2015, 9, 18, 9, 50, 55, 0, time.UTC), + UpdatedAt: nilTime, + ID: "388c983d-258e-4a0e-b1ba-10da37d766db", + }, + } + + th.CheckDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go new file mode 100644 index 00000000..06d9153d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go @@ -0,0 +1,208 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// Verifies that a security service can be created correctly +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &securityservices.CreateOpts{ + Name: "SecServ1", + Description: "Creating my first Security Service", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "***", + Type: "kerberos", + } + + s, err := securityservices.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, s.Name, "SecServ1") + th.AssertEquals(t, s.Description, "Creating my first Security Service") + th.AssertEquals(t, s.User, "demo") + th.AssertEquals(t, s.DNSIP, "10.0.0.0/24") + th.AssertEquals(t, s.Password, "supersecret") + th.AssertEquals(t, s.Type, "kerberos") +} + +// Verifies that a security service cannot be created without a type +func TestCreateFails(t *testing.T) { + options := &securityservices.CreateOpts{ + Name: "SecServ1", + Description: "Creating my first Security Service", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "***", + } + + _, err := securityservices.Create(client.ServiceClient(), options).Extract() + if _, ok := err.(gophercloud.ErrMissingInput); !ok { + t.Fatal("ErrMissingInput was expected to occur") + } +} + +// Verifies that security service deletion works +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := securityservices.Delete(client.ServiceClient(), "securityServiceID") + th.AssertNoErr(t, res.Err) +} + +// Verifies that security services can be listed correctly +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := securityservices.List(client.ServiceClient(), &securityservices.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := securityservices.ExtractSecurityServices(allPages) + th.AssertNoErr(t, err) + var nilTime time.Time + expected := []securityservices.SecurityService{ + { + Status: "new", + Domain: "", + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Name: "SecServ1", + CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC), + Description: "Creating my first Security Service", + UpdatedAt: nilTime, + Server: "", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "supersecret", + Type: "kerberos", + ID: "3c829734-0679-4c17-9637-801da48c0d5f", + }, + { + Status: "new", + Domain: "", + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Name: "SecServ2", + CreatedAt: time.Date(2015, 9, 7, 12, 25, 03, 0, time.UTC), + Description: "Creating my second Security Service", + UpdatedAt: nilTime, + Server: "", + DNSIP: "10.0.0.0/24", + User: "", + Password: "", + Type: "ldap", + ID: "5a1d3a12-34a7-4087-8983-50e9ed03509a", + }, + } + + th.CheckDeepEquals(t, expected, actual) +} + +// Verifies that security services list can be called with query parameters +func TestFilteredList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockFilteredListResponse(t) + + options := &securityservices.ListOpts{ + Type: "kerberos", + } + + allPages, err := securityservices.List(client.ServiceClient(), options).AllPages() + th.AssertNoErr(t, err) + actual, err := securityservices.ExtractSecurityServices(allPages) + th.AssertNoErr(t, err) + var nilTime time.Time + expected := []securityservices.SecurityService{ + { + Status: "new", + Domain: "", + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Name: "SecServ1", + CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC), + Description: "Creating my first Security Service", + UpdatedAt: nilTime, + Server: "", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "supersecret", + Type: "kerberos", + ID: "3c829734-0679-4c17-9637-801da48c0d5f", + }, + } + + th.CheckDeepEquals(t, expected, actual) +} + +// Verifies that it is possible to get a security service +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + var nilTime time.Time + expected := securityservices.SecurityService{ + ID: "3c829734-0679-4c17-9637-801da48c0d5f", + Name: "SecServ1", + CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC), + Description: "Creating my first Security Service", + Type: "kerberos", + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Status: "new", + Domain: "", + Server: "", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "supersecret", + } + + n, err := securityservices.Get(client.ServiceClient(), "3c829734-0679-4c17-9637-801da48c0d5f").Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, &expected, n) +} + +// Verifies that it is possible to update a security service +func TestUpdate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateResponse(t) + expected := securityservices.SecurityService{ + ID: "securityServiceID", + Name: "SecServ2", + CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC), + Description: "Updating my first Security Service", + Type: "kerberos", + UpdatedAt: time.Date(2015, 9, 7, 12, 20, 10, 0, time.UTC), + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Status: "new", + Domain: "", + Server: "", + DNSIP: "10.0.0.0/24", + User: "demo", + Password: "supersecret", + } + + options := securityservices.UpdateOpts{Name: "SecServ2"} + s, err := securityservices.Update(client.ServiceClient(), "securityServiceID", options).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, s) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go new file mode 100644 index 00000000..efa46918 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go @@ -0,0 +1,280 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks" + "github.com/gophercloud/gophercloud/pagination" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// Verifies that a share network can be created correctly +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &sharenetworks.CreateOpts{ + Name: "my_network", + Description: "This is my share network", + NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", + NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06", + } + + n, err := sharenetworks.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, n.Name, "my_network") + th.AssertEquals(t, n.Description, "This is my share network") + th.AssertEquals(t, n.NeutronNetID, "998b42ee-2cee-4d36-8b95-67b5ca1f2109") + th.AssertEquals(t, n.NeutronSubnetID, "53482b62-2c84-4a53-b6ab-30d9d9800d06") +} + +// Verifies that share network deletion works +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + res := sharenetworks.Delete(client.ServiceClient(), "fa158a3d-6d9f-4187-9ca5-abbb82646eb2") + th.AssertNoErr(t, res.Err) +} + +// Verifies that share networks can be listed correctly +func TestListDetail(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := sharenetworks.ListDetail(client.ServiceClient(), &sharenetworks.ListOpts{}).AllPages() + + th.AssertNoErr(t, err) + actual, err := sharenetworks.ExtractShareNetworks(allPages) + th.AssertNoErr(t, err) + + var nilTime time.Time + expected := []sharenetworks.ShareNetwork{ + { + ID: "32763294-e3d4-456a-998d-60047677c2fb", + Name: "net_my1", + CreatedAt: time.Date(2015, 9, 4, 14, 57, 13, 0, time.UTC), + Description: "descr", + NetworkType: "", + CIDR: "", + NovaNetID: "", + NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", + NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06", + IPVersion: 0, + SegmentationID: 0, + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + }, + { + ID: "713df749-aac0-4a54-af52-10f6c991e80c", + Name: "net_my", + CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC), + Description: "desecr", + NetworkType: "", + CIDR: "", + NovaNetID: "", + NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", + NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06", + IPVersion: 0, + SegmentationID: 0, + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + }, + { + ID: "fa158a3d-6d9f-4187-9ca5-abbb82646eb2", + Name: "", + CreatedAt: time.Date(2015, 9, 4, 14, 51, 41, 0, time.UTC), + Description: "", + NetworkType: "", + CIDR: "", + NovaNetID: "", + NeutronNetID: "", + NeutronSubnetID: "", + IPVersion: 0, + SegmentationID: 0, + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + }, + } + + th.CheckDeepEquals(t, expected, actual) +} + +// Verifies that share networks list can be called with query parameters +func TestPaginatedListDetail(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockFilteredListResponse(t) + + options := &sharenetworks.ListOpts{ + Offset: 0, + Limit: 1, + } + + count := 0 + + err := sharenetworks.ListDetail(client.ServiceClient(), options).EachPage(func(page pagination.Page) (bool, error) { + count++ + _, err := sharenetworks.ExtractShareNetworks(page) + if err != nil { + t.Errorf("Failed to extract share networks: %v", err) + return false, err + } + + return true, nil + }) + th.AssertNoErr(t, err) + + th.AssertEquals(t, count, 3) +} + +// Verifies that it is possible to get a share network +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + var nilTime time.Time + expected := sharenetworks.ShareNetwork{ + ID: "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd", + Name: "net_my1", + CreatedAt: time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC), + Description: "descr", + NetworkType: "", + CIDR: "", + NovaNetID: "", + NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", + NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06", + IPVersion: 0, + SegmentationID: 0, + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + } + + n, err := sharenetworks.Get(client.ServiceClient(), "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd").Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, &expected, n) +} + +// Verifies that it is possible to update a share network using neutron network +func TestUpdateNeutron(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateNeutronResponse(t) + + expected := sharenetworks.ShareNetwork{ + ID: "713df749-aac0-4a54-af52-10f6c991e80c", + Name: "net_my2", + CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC), + Description: "new description", + NetworkType: "", + CIDR: "", + NovaNetID: "", + NeutronNetID: "new-neutron-id", + NeutronSubnetID: "new-neutron-subnet-id", + IPVersion: 4, + SegmentationID: 0, + UpdatedAt: time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC), + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + } + + options := sharenetworks.UpdateOpts{ + Name: "net_my2", + Description: "new description", + NeutronNetID: "new-neutron-id", + NeutronSubnetID: "new-neutron-subnet-id", + } + + v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, v) +} + +// Verifies that it is possible to update a share network using nova network +func TestUpdateNova(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUpdateNovaResponse(t) + + expected := sharenetworks.ShareNetwork{ + ID: "713df749-aac0-4a54-af52-10f6c991e80c", + Name: "net_my2", + CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC), + Description: "new description", + NetworkType: "", + CIDR: "", + NovaNetID: "new-nova-id", + NeutronNetID: "", + NeutronSubnetID: "", + IPVersion: 4, + SegmentationID: 0, + UpdatedAt: time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC), + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + } + + options := sharenetworks.UpdateOpts{ + Name: "net_my2", + Description: "new description", + NovaNetID: "new-nova-id", + } + + v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, v) +} + +// Verifies that it is possible to add a security service to a share network +func TestAddSecurityService(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockAddSecurityServiceResponse(t) + + var nilTime time.Time + expected := sharenetworks.ShareNetwork{ + ID: "d8ae6799-2567-4a89-aafb-fa4424350d2b", + Name: "net2", + CreatedAt: time.Date(2015, 9, 7, 12, 31, 12, 0, time.UTC), + Description: "", + NetworkType: "", + CIDR: "", + NovaNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", + NeutronNetID: "", + NeutronSubnetID: "", + IPVersion: 4, + SegmentationID: 0, + UpdatedAt: nilTime, + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + } + + options := sharenetworks.AddSecurityServiceOpts{SecurityServiceID: "securityServiceID"} + s, err := sharenetworks.AddSecurityService(client.ServiceClient(), "shareNetworkID", options).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, s) +} + +// Verifies that it is possible to remove a security service from a share network +func TestRemoveSecurityService(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockRemoveSecurityServiceResponse(t) + + options := sharenetworks.RemoveSecurityServiceOpts{SecurityServiceID: "securityServiceID"} + _, err := sharenetworks.RemoveSecurityService(client.ServiceClient(), "shareNetworkID", options).Extract() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/requests.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/requests.go index 27bc43b5..b6ba572a 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/requests.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/requests.go @@ -1,6 +1,9 @@ package shares -import "github.com/gophercloud/gophercloud" +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) // CreateOptsBuilder allows extensions to add additional parameters to the // Create request. @@ -24,7 +27,7 @@ type CreateOpts struct { // DisplayName is equivalent to Name. The API supports using both // This is an inherited attribute from the block storage API DisplayName string `json:"display_name,omitempty"` - // DisplayDescription is equivalent to Description. The API supports using bot + // DisplayDescription is equivalent to Description. The API supports using both // This is an inherited attribute from the block storage API DisplayDescription string `json:"display_description,omitempty"` // ShareType defines the sharetype. If omitted, a default share type is used @@ -66,6 +69,99 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create return } +// ListOpts holds options for listing Shares. It is passed to the +// shares.List function. +type ListOpts struct { + // (Admin only). Defines whether to list the requested resources for all projects. + AllTenants bool `q:"all_tenants"` + // The share name. + Name string `q:"name"` + // Filters by a share status. + Status string `q:"status"` + // The UUID of the share server. + ShareServerID string `q:"share_server_id"` + // One or more metadata key and value pairs as a dictionary of strings. + Metadata map[string]string `q:"metadata"` + // The extra specifications for the share type. + ExtraSpecs map[string]string `q:"extra_specs"` + // The UUID of the share type. + ShareTypeID string `q:"share_type_id"` + // The maximum number of shares to return. + Limit int `q:"limit"` + // The offset to define start point of share or share group listing. + Offset int `q:"offset"` + // The key to sort a list of shares. + SortKey string `q:"sort_key"` + // The direction to sort a list of shares. + SortDir string `q:"sort_dir"` + // The UUID of the share’s base snapshot to filter the request based on. + SnapshotID string `q:"snapshot_id"` + // The share host name. + Host string `q:"host"` + // The share network ID. + ShareNetworkID string `q:"share_network_id"` + // The UUID of the project in which the share was created. Useful with all_tenants parameter. + ProjectID string `q:"project_id"` + // The level of visibility for the share. + IsPublic *bool `q:"is_public"` + // The UUID of a share group to filter resource. + ShareGroupID string `q:"share_group_id"` + // The export location UUID that can be used to filter shares or share instances. + ExportLocationID string `q:"export_location_id"` + // The export location path that can be used to filter shares or share instances. + ExportLocationPath string `q:"export_location_path"` + // The name pattern that can be used to filter shares, share snapshots, share networks or share groups. + NamePattern string `q:"name~"` + // The description pattern that can be used to filter shares, share snapshots, share networks or share groups. + DescriptionPattern string `q:"description~"` + // Whether to show count in API response or not, default is False. + WithCount bool `q:"with_count"` + // DisplayName is equivalent to Name. The API supports using both + // This is an inherited attribute from the block storage API + DisplayName string `q:"display_name"` + // Equivalent to NamePattern. + DisplayNamePattern string `q:"display_name~"` + // VolumeTypeID is deprecated but supported. Either ShareTypeID or VolumeTypeID can be used + VolumeTypeID string `q:"volume_type_id"` + // The UUID of the share group snapshot. + ShareGroupSnapshotID string `q:"share_group_snapshot_id"` + // DisplayDescription is equivalent to Description. The API supports using both + // This is an inherited attribute from the block storage API + DisplayDescription string `q:"display_description"` + // Equivalent to DescriptionPattern + DisplayDescriptionPattern string `q:"display_description~"` +} + +// ListOptsBuilder allows extensions to add additional parameters to the List +// request. +type ListOptsBuilder interface { + ToShareListQuery() (string, error) +} + +// ToShareListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToShareListQuery() (string, error) { + q, err := gophercloud.BuildQueryString(opts) + return q.String(), err +} + +// ListDetail returns []Share optionally limited by the conditions provided in ListOpts. +func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := listDetailURL(client) + if opts != nil { + query, err := opts.ToShareListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + p := SharePage{pagination.MarkerPageBase{PageResult: r}} + p.MarkerPageBase.Owner = p + return p + }) +} + // Delete will delete an existing Share with the given UUID. func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { _, r.Err = client.Delete(deleteURL(client, id), nil) @@ -123,3 +219,51 @@ func GrantAccess(client *gophercloud.ServiceClient, id string, opts GrantAccessO }) return } + +// RevokeAccessOptsBuilder allows extensions to add additional parameters to the +// RevokeAccess request. +type RevokeAccessOptsBuilder interface { + ToRevokeAccessMap() (map[string]interface{}, error) +} + +// RevokeAccessOpts contains the options for creation of a RevokeAccess request. +// For more information about these parameters, please, refer to the shared file systems API v2, +// Share Actions, Revoke Access documentation +type RevokeAccessOpts struct { + AccessID string `json:"access_id"` +} + +// ToRevokeAccessMap assembles a request body based on the contents of a +// RevokeAccessOpts. +func (opts RevokeAccessOpts) ToRevokeAccessMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "deny_access") +} + +// RevokeAccess will revoke an existing access to a Share based on the values in RevokeAccessOpts. +// RevokeAccessResult contains only the error. To extract it, call the ExtractErr method on +// the RevokeAccessResult. Client must have Microversion set; minimum supported microversion +// for RevokeAccess is 2.7. +func RevokeAccess(client *gophercloud.ServiceClient, id string, opts RevokeAccessOptsBuilder) (r RevokeAccessResult) { + b, err := opts.ToRevokeAccessMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(revokeAccessURL(client, id), b, nil, &gophercloud.RequestOpts{ + OkCodes: []int{200, 202}, + }) + + return +} + +// ListAccessRights lists all access rules assigned to a Share based on its id. To extract +// the AccessRight slice from the response, call the Extract method on the ListAccessRightsResult. +// Client must have Microversion set; minimum supported microversion for ListAccessRights is 2.7. +func ListAccessRights(client *gophercloud.ServiceClient, id string) (r ListAccessRightsResult) { + requestBody := map[string]interface{}{"access_list": nil} + _, r.Err = client.Post(listAccessRightsURL(client, id), requestBody, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/results.go index b76f86af..393f3bbc 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/results.go @@ -2,9 +2,16 @@ package shares import ( "encoding/json" + "net/url" + "strconv" "time" "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +const ( + invalidMarker = "-1" ) // Share contains all information associated with an OpenStack Share @@ -101,6 +108,86 @@ type CreateResult struct { commonResult } +// SharePage is a pagination.pager that is returned from a call to the List function. +type SharePage struct { + pagination.MarkerPageBase +} + +// NextPageURL generates the URL for the page of results after this one. +func (r SharePage) NextPageURL() (string, error) { + currentURL := r.URL + mark, err := r.Owner.LastMarker() + if err != nil { + return "", err + } + if mark == invalidMarker { + return "", nil + } + + q := currentURL.Query() + q.Set("offset", mark) + currentURL.RawQuery = q.Encode() + return currentURL.String(), nil +} + +// LastMarker returns the last offset in a ListResult. +func (r SharePage) LastMarker() (string, error) { + shares, err := ExtractShares(r) + if err != nil { + return invalidMarker, err + } + if len(shares) == 0 { + return invalidMarker, nil + } + + u, err := url.Parse(r.URL.String()) + if err != nil { + return invalidMarker, err + } + queryParams := u.Query() + offset := queryParams.Get("offset") + limit := queryParams.Get("limit") + + // Limit is not present, only one page required + if limit == "" { + return invalidMarker, nil + } + + iOffset := 0 + if offset != "" { + iOffset, err = strconv.Atoi(offset) + if err != nil { + return invalidMarker, err + } + } + iLimit, err := strconv.Atoi(limit) + if err != nil { + return invalidMarker, err + } + iOffset = iOffset + iLimit + offset = strconv.Itoa(iOffset) + + return offset, nil +} + +// IsEmpty satisifies the IsEmpty method of the Page interface +func (r SharePage) IsEmpty() (bool, error) { + shares, err := ExtractShares(r) + return len(shares) == 0, err +} + +// ExtractShares extracts and returns a Share slice. It is used while +// iterating over a shares.List call. +func ExtractShares(r pagination.Page) ([]Share, error) { + var s struct { + Shares []Share `json:"shares"` + } + + err := (r.(SharePage)).ExtractInto(&s) + + return s.Shares, err +} + // DeleteResult contains the response body and error from a Delete request. type DeleteResult struct { gophercloud.ErrResult @@ -111,6 +198,28 @@ type GetResult struct { commonResult } +// IDFromName is a convenience function that returns a share's ID given its name. +func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) { + r, err := ListDetail(client, &ListOpts{Name: name}).AllPages() + if err != nil { + return "", err + } + + ss, err := ExtractShares(r) + if err != nil { + return "", err + } + + switch len(ss) { + case 0: + return "", gophercloud.ErrResourceNotFound{Name: name, ResourceType: "share"} + case 1: + return ss[0].ID, nil + default: + return "", gophercloud.ErrMultipleResourcesFound{Name: name, Count: len(ss), ResourceType: "share"} + } +} + // GetExportLocationsResult contains the result body and error from an // GetExportLocations request. type GetExportLocationsResult struct { @@ -177,3 +286,22 @@ func (r GrantAccessResult) Extract() (*AccessRight, error) { type GrantAccessResult struct { gophercloud.Result } + +// RevokeAccessResult contains the response body and error from a Revoke access request. +type RevokeAccessResult struct { + gophercloud.ErrResult +} + +// Extract will get a slice of AccessRight objects from the commonResult +func (r ListAccessRightsResult) Extract() ([]AccessRight, error) { + var s struct { + AccessRights []AccessRight `json:"access_list"` + } + err := r.ExtractInto(&s) + return s.AccessRights, err +} + +// ListAccessRightsResult contains the result body and error from a ListAccessRights request. +type ListAccessRightsResult struct { + gophercloud.Result +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/fixtures.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/fixtures.go index 8ab2742d..b581d44e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/fixtures.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/fixtures.go @@ -142,6 +142,73 @@ func MockGetResponse(t *testing.T) { }) } +var listDetailResponse = `{ + "shares": [ + { + "links": [ + { + "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "self" + }, + { + "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "bookmark" + } + ], + "availability_zone": "nova", + "share_network_id": "713df749-aac0-4a54-af52-10f6c991e80c", + "share_server_id": "e268f4aa-d571-43dd-9ab3-f49ad06ffaef", + "snapshot_id": null, + "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264", + "size": 1, + "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7", + "share_type_name": "default", + "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4", + "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", + "metadata": { + "project": "my_app", + "aim": "doc" + }, + "status": "available", + "description": "My custom share London", + "host": "manila2@generic1#GENERIC1", + "has_replicas": false, + "replication_type": null, + "task_state": null, + "is_public": true, + "snapshot_support": true, + "name": "my_test_share", + "created_at": "2015-09-18T10:25:24.000000", + "share_proto": "NFS", + "volume_type": "default", + "source_cgsnapshot_member_id": null + } + ] + }` + +var listDetailEmptyResponse = `{"shares": []}` + +// MockDeleteResponse creates a mock detailed-list response +func MockListDetailResponse(t *testing.T) { + th.Mux.HandleFunc(shareEndpoint+"/detail", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + r.ParseForm() + marker := r.Form.Get("offset") + + switch marker { + case "": + fmt.Fprint(w, listDetailResponse) + default: + fmt.Fprint(w, listDetailEmptyResponse) + } + }) +} + var getExportLocationsResponse = `{ "export_locations": [ { @@ -159,6 +226,7 @@ func MockGetExportLocationsResponse(t *testing.T) { th.Mux.HandleFunc(shareEndpoint+"/"+shareID+"/export_locations", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, getExportLocationsResponse) }) @@ -197,3 +265,53 @@ func MockGrantAccessResponse(t *testing.T) { fmt.Fprintf(w, grantAccessResponse) }) } + +var revokeAccessRequest = `{ + "deny_access": { + "access_id": "a2f226a5-cee8-430b-8a03-78a59bd84ee8" + } +}` + +func MockRevokeAccessResponse(t *testing.T) { + th.Mux.HandleFunc(shareEndpoint+"/"+shareID+"/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, revokeAccessRequest) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusAccepted) + }) +} + +var listAccessRightsRequest = `{ + "access_list": null + }` + +var listAccessRightsResponse = `{ + "access_list": [ + { + "share_id": "011d21e2-fbc3-4e4a-9993-9ea223f73264", + "access_type": "ip", + "access_to": "0.0.0.0/0", + "access_key": "", + "access_level": "rw", + "state": "new", + "id": "a2f226a5-cee8-430b-8a03-78a59bd84ee8" + } + ] + }` + +// MockListAccessRightsResponse creates a mock list access response +func MockListAccessRightsResponse(t *testing.T) { + th.Mux.HandleFunc(shareEndpoint+"/"+shareID+"/action", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + th.TestHeader(t, r, "Content-Type", "application/json") + th.TestHeader(t, r, "Accept", "application/json") + th.TestJSONRequest(t, r, listAccessRightsRequest) + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, listAccessRightsResponse) + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/request_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/request_test.go new file mode 100644 index 00000000..cdd218dd --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/testing/request_test.go @@ -0,0 +1,235 @@ +package testing + +import ( + "testing" + "time" + + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + options := &shares.CreateOpts{Size: 1, Name: "my_test_share", ShareProto: "NFS"} + n, err := shares.Create(client.ServiceClient(), options).Extract() + + th.AssertNoErr(t, err) + th.AssertEquals(t, n.Name, "my_test_share") + th.AssertEquals(t, n.Size, 1) + th.AssertEquals(t, n.ShareProto, "NFS") +} + +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + + result := shares.Delete(client.ServiceClient(), shareID) + th.AssertNoErr(t, result.Err) +} + +func TestGet(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetResponse(t) + + s, err := shares.Get(client.ServiceClient(), shareID).Extract() + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, s, &shares.Share{ + AvailabilityZone: "nova", + ShareNetworkID: "713df749-aac0-4a54-af52-10f6c991e80c", + ShareServerID: "e268f4aa-d571-43dd-9ab3-f49ad06ffaef", + SnapshotID: "", + ID: shareID, + Size: 1, + ShareType: "25747776-08e5-494f-ab40-a64b9d20d8f7", + ShareTypeName: "default", + ConsistencyGroupID: "9397c191-8427-4661-a2e8-b23820dc01d4", + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Metadata: map[string]string{ + "project": "my_app", + "aim": "doc", + }, + Status: "available", + Description: "My custom share London", + Host: "manila2@generic1#GENERIC1", + HasReplicas: false, + ReplicationType: "", + TaskState: "", + SnapshotSupport: true, + Name: "my_test_share", + CreatedAt: time.Date(2015, time.September, 18, 10, 25, 24, 0, time.UTC), + ShareProto: "NFS", + VolumeType: "default", + SourceCgsnapshotMemberID: "", + IsPublic: true, + Links: []map[string]string{ + { + "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "self", + }, + { + "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "bookmark", + }, + }, + }) +} + +func TestListDetail(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListDetailResponse(t) + + allPages, err := shares.ListDetail(client.ServiceClient(), &shares.ListOpts{}).AllPages() + + th.AssertNoErr(t, err) + + actual, err := shares.ExtractShares(allPages) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, actual, []shares.Share{ + shares.Share{ + AvailabilityZone: "nova", + ShareNetworkID: "713df749-aac0-4a54-af52-10f6c991e80c", + ShareServerID: "e268f4aa-d571-43dd-9ab3-f49ad06ffaef", + SnapshotID: "", + ID: shareID, + Size: 1, + ShareType: "25747776-08e5-494f-ab40-a64b9d20d8f7", + ShareTypeName: "default", + ConsistencyGroupID: "9397c191-8427-4661-a2e8-b23820dc01d4", + ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", + Metadata: map[string]string{ + "project": "my_app", + "aim": "doc", + }, + Status: "available", + Description: "My custom share London", + Host: "manila2@generic1#GENERIC1", + HasReplicas: false, + ReplicationType: "", + TaskState: "", + SnapshotSupport: true, + Name: "my_test_share", + CreatedAt: time.Date(2015, time.September, 18, 10, 25, 24, 0, time.UTC), + ShareProto: "NFS", + VolumeType: "default", + SourceCgsnapshotMemberID: "", + IsPublic: true, + Links: []map[string]string{ + { + "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "self", + }, + { + "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", + "rel": "bookmark", + }, + }, + }, + }) +} + +func TestGetExportLocationsSuccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetExportLocationsResponse(t) + + c := client.ServiceClient() + // Client c must have Microversion set; minimum supported microversion for Get Export Locations is 2.14 + c.Microversion = "2.14" + + s, err := shares.GetExportLocations(c, shareID).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, s, []shares.ExportLocation{ + { + Path: "127.0.0.1:/var/lib/manila/mnt/share-9a922036-ad26-4d27-b955-7a1e285fa74d", + ShareInstanceID: "011d21e2-fbc3-4e4a-9993-9ea223f73264", + IsAdminOnly: false, + ID: "80ed63fc-83bc-4afc-b881-da4a345ac83d", + Preferred: false, + }, + }) +} + +func TestGrantAcessSuccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGrantAccessResponse(t) + + c := client.ServiceClient() + // Client c must have Microversion set; minimum supported microversion for Grant Access is 2.7 + c.Microversion = "2.7" + + var grantAccessReq shares.GrantAccessOpts + grantAccessReq.AccessType = "ip" + grantAccessReq.AccessTo = "0.0.0.0/0" + grantAccessReq.AccessLevel = "rw" + + s, err := shares.GrantAccess(c, shareID, grantAccessReq).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, s, &shares.AccessRight{ + ShareID: "011d21e2-fbc3-4e4a-9993-9ea223f73264", + AccessType: "ip", + AccessTo: "0.0.0.0/0", + AccessKey: "", + AccessLevel: "rw", + State: "new", + ID: "a2f226a5-cee8-430b-8a03-78a59bd84ee8", + }) +} + +func TestRevokeAccessSuccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockRevokeAccessResponse(t) + + c := client.ServiceClient() + // Client c must have Microversion set; minimum supported microversion for Revoke Access is 2.7 + c.Microversion = "2.7" + + options := &shares.RevokeAccessOpts{AccessID: "a2f226a5-cee8-430b-8a03-78a59bd84ee8"} + + err := shares.RevokeAccess(c, shareID, options).ExtractErr() + th.AssertNoErr(t, err) +} + +func TestListAccessRightsSuccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListAccessRightsResponse(t) + + c := client.ServiceClient() + // Client c must have Microversion set; minimum supported microversion for Grant Access is 2.7 + c.Microversion = "2.7" + + s, err := shares.ListAccessRights(c, shareID).Extract() + + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, s, []shares.AccessRight{ + { + ShareID: "011d21e2-fbc3-4e4a-9993-9ea223f73264", + AccessType: "ip", + AccessTo: "0.0.0.0/0", + AccessKey: "", + AccessLevel: "rw", + State: "new", + ID: "a2f226a5-cee8-430b-8a03-78a59bd84ee8", + }, + }) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/urls.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/urls.go index 38e1aa43..f139e5c9 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/urls.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares/urls.go @@ -6,6 +6,10 @@ func createURL(c *gophercloud.ServiceClient) string { return c.ServiceURL("shares") } +func listDetailURL(c *gophercloud.ServiceClient) string { + return c.ServiceURL("shares", "detail") +} + func deleteURL(c *gophercloud.ServiceClient, id string) string { return c.ServiceURL("shares", id) } @@ -21,3 +25,11 @@ func getExportLocationsURL(c *gophercloud.ServiceClient, id string) string { func grantAccessURL(c *gophercloud.ServiceClient, id string) string { return c.ServiceURL("shares", id, "action") } + +func revokeAccessURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL("shares", id, "action") +} + +func listAccessRightsURL(c *gophercloud.ServiceClient, id string) string { + return c.ServiceURL("shares", id, "action") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go new file mode 100644 index 00000000..85a9e5a9 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go @@ -0,0 +1,217 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +// Verifies that a share type can be created correctly +func TestCreate(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockCreateResponse(t) + + snapshotSupport := true + extraSpecs := sharetypes.ExtraSpecsOpts{ + DriverHandlesShareServers: true, + SnapshotSupport: &snapshotSupport, + } + + options := &sharetypes.CreateOpts{ + Name: "my_new_share_type", + IsPublic: true, + ExtraSpecs: extraSpecs, + } + + st, err := sharetypes.Create(client.ServiceClient(), options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, st.Name, "my_new_share_type") + th.AssertEquals(t, st.IsPublic, true) +} + +// Verifies that a share type can't be created if the required parameters are missing +func TestCreateFails(t *testing.T) { + options := &sharetypes.CreateOpts{ + Name: "my_new_share_type", + } + + _, err := sharetypes.Create(client.ServiceClient(), options).Extract() + if _, ok := err.(gophercloud.ErrMissingInput); !ok { + t.Fatal("ErrMissingInput was expected to occur") + } + + extraSpecs := sharetypes.ExtraSpecsOpts{ + DriverHandlesShareServers: true, + } + + options = &sharetypes.CreateOpts{ + ExtraSpecs: extraSpecs, + } + + _, err = sharetypes.Create(client.ServiceClient(), options).Extract() + if _, ok := err.(gophercloud.ErrMissingInput); !ok { + t.Fatal("ErrMissingInput was expected to occur") + } +} + +// Verifies that share type deletion works +func TestDelete(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockDeleteResponse(t) + res := sharetypes.Delete(client.ServiceClient(), "shareTypeID") + th.AssertNoErr(t, res.Err) +} + +// Verifies that share types can be listed correctly +func TestList(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockListResponse(t) + + allPages, err := sharetypes.List(client.ServiceClient(), &sharetypes.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + actual, err := sharetypes.ExtractShareTypes(allPages) + th.AssertNoErr(t, err) + expected := []sharetypes.ShareType{ + { + ID: "be27425c-f807-4500-a056-d00721db45cf", + Name: "default", + IsPublic: true, + ExtraSpecs: map[string]interface{}{"snapshot_support": "True", "driver_handles_share_servers": "True"}, + RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "True"}, + }, + { + ID: "f015bebe-c38b-4c49-8832-00143b10253b", + Name: "d", + IsPublic: true, + ExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "false", "snapshot_support": "True"}, + RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "false"}, + }, + } + + th.CheckDeepEquals(t, expected, actual) +} + +// Verifies that it is possible to get the default share type +func TestGetDefault(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetDefaultResponse(t) + + expected := sharetypes.ShareType{ + ID: "be27425c-f807-4500-a056-d00721db45cf", + Name: "default", + ExtraSpecs: map[string]interface{}{"snapshot_support": "True", "driver_handles_share_servers": "True"}, + RequiredExtraSpecs: map[string]interface{}(nil), + } + + actual, err := sharetypes.GetDefault(client.ServiceClient()).Extract() + th.AssertNoErr(t, err) + th.CheckDeepEquals(t, &expected, actual) +} + +// Verifies that it is possible to get the extra specifications for a share type +func TestGetExtraSpecs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockGetExtraSpecsResponse(t) + + st, err := sharetypes.GetExtraSpecs(client.ServiceClient(), "shareTypeID").Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, st["snapshot_support"], "True") + th.AssertEquals(t, st["driver_handles_share_servers"], "True") + th.AssertEquals(t, st["my_custom_extra_spec"], "False") +} + +// Verifies that an extra specs can be added to a share type +func TestSetExtraSpecs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockSetExtraSpecsResponse(t) + + options := &sharetypes.SetExtraSpecsOpts{ + ExtraSpecs: map[string]interface{}{"my_key": "my_value"}, + } + + es, err := sharetypes.SetExtraSpecs(client.ServiceClient(), "shareTypeID", options).Extract() + th.AssertNoErr(t, err) + + th.AssertEquals(t, es["my_key"], "my_value") +} + +// Verifies that an extra specification can be unset for a share type +func TestUnsetExtraSpecs(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockUnsetExtraSpecsResponse(t) + res := sharetypes.UnsetExtraSpecs(client.ServiceClient(), "shareTypeID", "my_key") + th.AssertNoErr(t, res.Err) +} + +// Verifies that it is possible to see the access for a share type +func TestShowAccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockShowAccessResponse(t) + + expected := []sharetypes.ShareTypeAccess{ + { + ShareTypeID: "1732f284-401d-41d9-a494-425451e8b4b8", + ProjectID: "818a3f48dcd644909b3fa2e45a399a27", + }, + { + ShareTypeID: "1732f284-401d-41d9-a494-425451e8b4b8", + ProjectID: "e1284adea3ee4d2482af5ed214f3ad90", + }, + } + + shareType, err := sharetypes.ShowAccess(client.ServiceClient(), "shareTypeID").Extract() + th.AssertNoErr(t, err) + + th.CheckDeepEquals(t, expected, shareType) +} + +// Verifies that an access can be added to a share type +func TestAddAccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockAddAccessResponse(t) + + options := &sharetypes.AccessOpts{ + Project: "e1284adea3ee4d2482af5ed214f3ad90", + } + + err := sharetypes.AddAccess(client.ServiceClient(), "shareTypeID", options).ExtractErr() + th.AssertNoErr(t, err) +} + +// Verifies that an access can be removed from a share type +func TestRemoveAccess(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + MockRemoveAccessResponse(t) + + options := &sharetypes.AccessOpts{ + Project: "e1284adea3ee4d2482af5ed214f3ad90", + } + + err := sharetypes.RemoveAccess(client.ServiceClient(), "shareTypeID", options).ExtractErr() + th.AssertNoErr(t, err) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/client_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/client_test.go new file mode 100644 index 00000000..6f94e44e --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/client_test.go @@ -0,0 +1,315 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack" + th "github.com/gophercloud/gophercloud/testhelper" +) + +const ID = "0123456789" + +func TestAuthenticatedClientV3(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, ` + { + "versions": { + "values": [ + { + "status": "stable", + "id": "v3.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + }, + { + "status": "stable", + "id": "v2.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + } + ] + } + } + `, th.Endpoint()+"v3/", th.Endpoint()+"v2.0/") + }) + + th.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("X-Subject-Token", ID) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, `{ "token": { "expires_at": "2013-02-02T18:30:59.000000Z" } }`) + }) + + options := gophercloud.AuthOptions{ + Username: "me", + Password: "secret", + DomainName: "default", + TenantName: "project", + IdentityEndpoint: th.Endpoint(), + } + client, err := openstack.AuthenticatedClient(options) + th.AssertNoErr(t, err) + th.CheckEquals(t, ID, client.TokenID) +} + +func TestAuthenticatedClientV2(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, ` + { + "versions": { + "values": [ + { + "status": "experimental", + "id": "v3.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + }, + { + "status": "stable", + "id": "v2.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + } + ] + } + } + `, th.Endpoint()+"v3/", th.Endpoint()+"v2.0/") + }) + + th.Mux.HandleFunc("/v2.0/tokens", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, ` + { + "access": { + "token": { + "id": "01234567890", + "expires": "2014-10-01T10:00:00.000000Z" + }, + "serviceCatalog": [ + { + "name": "Cloud Servers", + "type": "compute", + "endpoints": [ + { + "tenantId": "t1000", + "publicURL": "https://compute.north.host.com/v1/t1000", + "internalURL": "https://compute.north.internal/v1/t1000", + "region": "North", + "versionId": "1", + "versionInfo": "https://compute.north.host.com/v1/", + "versionList": "https://compute.north.host.com/" + }, + { + "tenantId": "t1000", + "publicURL": "https://compute.north.host.com/v1.1/t1000", + "internalURL": "https://compute.north.internal/v1.1/t1000", + "region": "North", + "versionId": "1.1", + "versionInfo": "https://compute.north.host.com/v1.1/", + "versionList": "https://compute.north.host.com/" + } + ], + "endpoints_links": [] + }, + { + "name": "Cloud Files", + "type": "object-store", + "endpoints": [ + { + "tenantId": "t1000", + "publicURL": "https://storage.north.host.com/v1/t1000", + "internalURL": "https://storage.north.internal/v1/t1000", + "region": "North", + "versionId": "1", + "versionInfo": "https://storage.north.host.com/v1/", + "versionList": "https://storage.north.host.com/" + }, + { + "tenantId": "t1000", + "publicURL": "https://storage.south.host.com/v1/t1000", + "internalURL": "https://storage.south.internal/v1/t1000", + "region": "South", + "versionId": "1", + "versionInfo": "https://storage.south.host.com/v1/", + "versionList": "https://storage.south.host.com/" + } + ] + } + ] + } + } + `) + }) + + options := gophercloud.AuthOptions{ + Username: "me", + Password: "secret", + IdentityEndpoint: th.Endpoint(), + } + client, err := openstack.AuthenticatedClient(options) + th.AssertNoErr(t, err) + th.CheckEquals(t, "01234567890", client.TokenID) +} + +func TestIdentityAdminV3Client(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, ` + { + "versions": { + "values": [ + { + "status": "stable", + "id": "v3.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + }, + { + "status": "stable", + "id": "v2.0", + "links": [ + { "href": "%s", "rel": "self" } + ] + } + ] + } + } + `, th.Endpoint()+"v3/", th.Endpoint()+"v2.0/") + }) + + th.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("X-Subject-Token", ID) + + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, ` + { + "token": { + "audit_ids": ["VcxU2JYqT8OzfUVvrjEITQ", "qNUTIJntTzO1-XUk5STybw"], + "catalog": [ + { + "endpoints": [ + { + "id": "39dc322ce86c4111b4f06c2eeae0841b", + "interface": "public", + "region": "RegionOne", + "url": "http://localhost:5000" + }, + { + "id": "ec642f27474842e78bf059f6c48f4e99", + "interface": "internal", + "region": "RegionOne", + "url": "http://localhost:5000" + }, + { + "id": "c609fc430175452290b62a4242e8a7e8", + "interface": "admin", + "region": "RegionOne", + "url": "http://localhost:35357" + } + ], + "id": "4363ae44bdf34a3981fde3b823cb9aa2", + "type": "identity", + "name": "keystone" + } + ], + "expires_at": "2013-02-27T18:30:59.999999Z", + "is_domain": false, + "issued_at": "2013-02-27T16:30:59.999999Z", + "methods": [ + "password" + ], + "project": { + "domain": { + "id": "1789d1", + "name": "example.com" + }, + "id": "263fd9", + "name": "project-x" + }, + "roles": [ + { + "id": "76e72a", + "name": "admin" + }, + { + "id": "f4f392", + "name": "member" + } + ], + "service_providers": [ + { + "auth_url":"https://example.com:5000/v3/OS-FEDERATION/identity_providers/acme/protocols/saml2/auth", + "id": "sp1", + "sp_url": "https://example.com:5000/Shibboleth.sso/SAML2/ECP" + }, + { + "auth_url":"https://other.example.com:5000/v3/OS-FEDERATION/identity_providers/acme/protocols/saml2/auth", + "id": "sp2", + "sp_url": "https://other.example.com:5000/Shibboleth.sso/SAML2/ECP" + } + ], + "user": { + "domain": { + "id": "1789d1", + "name": "example.com" + }, + "id": "0ca8f6", + "name": "Joe", + "password_expires_at": "2016-11-06T15:32:17.000000" + } + } +} + `) + }) + + options := gophercloud.AuthOptions{ + Username: "me", + Password: "secret", + DomainID: "12345", + IdentityEndpoint: th.Endpoint(), + } + pc, err := openstack.AuthenticatedClient(options) + th.AssertNoErr(t, err) + sc, err := openstack.NewIdentityV3(pc, gophercloud.EndpointOpts{ + Availability: gophercloud.AvailabilityAdmin, + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, "http://localhost:35357/v3/", sc.Endpoint) +} + +func testAuthenticatedClientFails(t *testing.T, endpoint string) { + options := gophercloud.AuthOptions{ + Username: "me", + Password: "secret", + DomainName: "default", + TenantName: "project", + IdentityEndpoint: endpoint, + } + _, err := openstack.AuthenticatedClient(options) + if err == nil { + t.Fatal("expected error but call succeeded") + } +} + +func TestAuthenticatedClientV3Fails(t *testing.T) { + testAuthenticatedClientFails(t, "http://bad-address.example.com/v3") +} + +func TestAuthenticatedClientV2Fails(t *testing.T) { + testAuthenticatedClientFails(t, "http://bad-address.example.com/v2.0") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/endpoint_location_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/endpoint_location_test.go new file mode 100644 index 00000000..5ac773ee --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/testing/endpoint_location_test.go @@ -0,0 +1,274 @@ +package testing + +import ( + "strings" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack" + tokens2 "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" + tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" + th "github.com/gophercloud/gophercloud/testhelper" +) + +// Service catalog fixtures take too much vertical space! +var catalog2 = tokens2.ServiceCatalog{ + Entries: []tokens2.CatalogEntry{ + tokens2.CatalogEntry{ + Type: "same", + Name: "same", + Endpoints: []tokens2.Endpoint{ + tokens2.Endpoint{ + Region: "same", + PublicURL: "https://public.correct.com/", + InternalURL: "https://internal.correct.com/", + AdminURL: "https://admin.correct.com/", + }, + tokens2.Endpoint{ + Region: "different", + PublicURL: "https://badregion.com/", + }, + }, + }, + tokens2.CatalogEntry{ + Type: "same", + Name: "different", + Endpoints: []tokens2.Endpoint{ + tokens2.Endpoint{ + Region: "same", + PublicURL: "https://badname.com/", + }, + tokens2.Endpoint{ + Region: "different", + PublicURL: "https://badname.com/+badregion", + }, + }, + }, + tokens2.CatalogEntry{ + Type: "different", + Name: "different", + Endpoints: []tokens2.Endpoint{ + tokens2.Endpoint{ + Region: "same", + PublicURL: "https://badtype.com/+badname", + }, + tokens2.Endpoint{ + Region: "different", + PublicURL: "https://badtype.com/+badregion+badname", + }, + }, + }, + }, +} + +func TestV2EndpointExact(t *testing.T) { + expectedURLs := map[gophercloud.Availability]string{ + gophercloud.AvailabilityPublic: "https://public.correct.com/", + gophercloud.AvailabilityAdmin: "https://admin.correct.com/", + gophercloud.AvailabilityInternal: "https://internal.correct.com/", + } + + for availability, expected := range expectedURLs { + actual, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ + Type: "same", + Name: "same", + Region: "same", + Availability: availability, + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, expected, actual) + } +} + +func TestV2EndpointNone(t *testing.T) { + _, actual := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ + Type: "nope", + Availability: gophercloud.AvailabilityPublic, + }) + expected := &gophercloud.ErrEndpointNotFound{} + th.CheckEquals(t, expected.Error(), actual.Error()) +} + +func TestV2EndpointMultiple(t *testing.T) { + _, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ + Type: "same", + Region: "same", + Availability: gophercloud.AvailabilityPublic, + }) + if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") { + t.Errorf("Received unexpected error: %v", err) + } +} + +func TestV2EndpointBadAvailability(t *testing.T) { + _, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{ + Type: "same", + Name: "same", + Region: "same", + Availability: "wat", + }) + th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error()) +} + +var catalog3 = tokens3.ServiceCatalog{ + Entries: []tokens3.CatalogEntry{ + tokens3.CatalogEntry{ + Type: "same", + Name: "same", + Endpoints: []tokens3.Endpoint{ + tokens3.Endpoint{ + ID: "1", + Region: "same", + Interface: "public", + URL: "https://public.correct.com/", + }, + tokens3.Endpoint{ + ID: "2", + Region: "same", + Interface: "admin", + URL: "https://admin.correct.com/", + }, + tokens3.Endpoint{ + ID: "3", + Region: "same", + Interface: "internal", + URL: "https://internal.correct.com/", + }, + tokens3.Endpoint{ + ID: "4", + Region: "different", + Interface: "public", + URL: "https://badregion.com/", + }, + }, + }, + tokens3.CatalogEntry{ + Type: "same", + Name: "different", + Endpoints: []tokens3.Endpoint{ + tokens3.Endpoint{ + ID: "5", + Region: "same", + Interface: "public", + URL: "https://badname.com/", + }, + tokens3.Endpoint{ + ID: "6", + Region: "different", + Interface: "public", + URL: "https://badname.com/+badregion", + }, + }, + }, + tokens3.CatalogEntry{ + Type: "different", + Name: "different", + Endpoints: []tokens3.Endpoint{ + tokens3.Endpoint{ + ID: "7", + Region: "same", + Interface: "public", + URL: "https://badtype.com/+badname", + }, + tokens3.Endpoint{ + ID: "8", + Region: "different", + Interface: "public", + URL: "https://badtype.com/+badregion+badname", + }, + }, + }, + tokens3.CatalogEntry{ + Type: "someother", + Name: "someother", + Endpoints: []tokens3.Endpoint{ + tokens3.Endpoint{ + ID: "1", + Region: "someother", + Interface: "public", + URL: "https://public.correct.com/", + }, + tokens3.Endpoint{ + ID: "2", + RegionID: "someother", + Interface: "admin", + URL: "https://admin.correct.com/", + }, + tokens3.Endpoint{ + ID: "3", + RegionID: "someother", + Interface: "internal", + URL: "https://internal.correct.com/", + }, + }, + }, + }, +} + +func TestV3EndpointExact(t *testing.T) { + expectedURLs := map[gophercloud.Availability]string{ + gophercloud.AvailabilityPublic: "https://public.correct.com/", + gophercloud.AvailabilityAdmin: "https://admin.correct.com/", + gophercloud.AvailabilityInternal: "https://internal.correct.com/", + } + + for availability, expected := range expectedURLs { + actual, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{ + Type: "same", + Name: "same", + Region: "same", + Availability: availability, + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, expected, actual) + } +} + +func TestV3EndpointNone(t *testing.T) { + _, actual := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{ + Type: "nope", + Availability: gophercloud.AvailabilityPublic, + }) + expected := &gophercloud.ErrEndpointNotFound{} + th.CheckEquals(t, expected.Error(), actual.Error()) +} + +func TestV3EndpointMultiple(t *testing.T) { + _, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{ + Type: "same", + Region: "same", + Availability: gophercloud.AvailabilityPublic, + }) + if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") { + t.Errorf("Received unexpected error: %v", err) + } +} + +func TestV3EndpointBadAvailability(t *testing.T) { + _, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{ + Type: "same", + Name: "same", + Region: "same", + Availability: "wat", + }) + th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error()) +} + +func TestV3EndpointWithRegionID(t *testing.T) { + expectedURLs := map[gophercloud.Availability]string{ + gophercloud.AvailabilityPublic: "https://public.correct.com/", + gophercloud.AvailabilityAdmin: "https://admin.correct.com/", + gophercloud.AvailabilityInternal: "https://internal.correct.com/", + } + + for availability, expected := range expectedURLs { + actual, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{ + Type: "someother", + Name: "someother", + Region: "someother", + Availability: availability, + }) + th.AssertNoErr(t, err) + th.CheckEquals(t, expected, actual) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/base_endpoint.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/base_endpoint.go new file mode 100644 index 00000000..40080f7a --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/base_endpoint.go @@ -0,0 +1,28 @@ +package utils + +import ( + "net/url" + "regexp" + "strings" +) + +// BaseEndpoint will return a URL without the /vX.Y +// portion of the URL. +func BaseEndpoint(endpoint string) (string, error) { + u, err := url.Parse(endpoint) + if err != nil { + return "", err + } + + u.RawQuery, u.Fragment = "", "" + + path := u.Path + versionRe := regexp.MustCompile("v[0-9.]+/?") + + if version := versionRe.FindString(path); version != "" { + versionIndex := strings.Index(path, version) + u.Path = path[:versionIndex] + } + + return u.String(), nil +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/base_endpoint_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/base_endpoint_test.go new file mode 100644 index 00000000..944536b8 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/base_endpoint_test.go @@ -0,0 +1,88 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud/openstack/utils" + th "github.com/gophercloud/gophercloud/testhelper" +) + +type endpointTestCases struct { + Endpoint string + BaseEndpoint string +} + +func TestBaseEndpoint(t *testing.T) { + tests := []endpointTestCases{ + { + Endpoint: "http://example.com:5000/v3", + BaseEndpoint: "http://example.com:5000/", + }, + { + Endpoint: "http://example.com:5000/v3.6", + BaseEndpoint: "http://example.com:5000/", + }, + { + Endpoint: "http://example.com:5000/v2.0", + BaseEndpoint: "http://example.com:5000/", + }, + { + Endpoint: "http://example.com:5000/", + BaseEndpoint: "http://example.com:5000/", + }, + { + Endpoint: "http://example.com:5000", + BaseEndpoint: "http://example.com:5000", + }, + { + Endpoint: "http://example.com/identity/v3", + BaseEndpoint: "http://example.com/identity/", + }, + { + Endpoint: "http://example.com/identity/v3.6", + BaseEndpoint: "http://example.com/identity/", + }, + { + Endpoint: "http://example.com/identity/v2.0", + BaseEndpoint: "http://example.com/identity/", + }, + { + Endpoint: "http://example.com/identity/v2.0/projects", + BaseEndpoint: "http://example.com/identity/", + }, + { + Endpoint: "http://example.com/v2.0/projects", + BaseEndpoint: "http://example.com/", + }, + { + Endpoint: "http://example.com/identity/", + BaseEndpoint: "http://example.com/identity/", + }, + { + Endpoint: "http://dev.example.com:5000/v3", + BaseEndpoint: "http://dev.example.com:5000/", + }, + { + Endpoint: "http://dev.example.com:5000/v3.6", + BaseEndpoint: "http://dev.example.com:5000/", + }, + { + Endpoint: "http://dev.example.com/identity/", + BaseEndpoint: "http://dev.example.com/identity/", + }, + { + Endpoint: "http://dev.example.com/identity/v2.0/projects", + BaseEndpoint: "http://dev.example.com/identity/", + }, + { + Endpoint: "http://dev.example.com/identity/v3.6", + BaseEndpoint: "http://dev.example.com/identity/", + }, + } + + for _, test := range tests { + actual, err := utils.BaseEndpoint(test.Endpoint) + th.AssertNoErr(t, err) + th.AssertEquals(t, test.BaseEndpoint, actual) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/choose_version_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/choose_version_test.go new file mode 100644 index 00000000..9c0119cb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/openstack/utils/testing/choose_version_test.go @@ -0,0 +1,119 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/utils" + "github.com/gophercloud/gophercloud/testhelper" +) + +func setupVersionHandler() { + testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, ` + { + "versions": { + "values": [ + { + "status": "stable", + "id": "v3.0", + "links": [ + { "href": "%s/v3.0", "rel": "self" } + ] + }, + { + "status": "stable", + "id": "v2.0", + "links": [ + { "href": "%s/v2.0", "rel": "self" } + ] + } + ] + } + } + `, testhelper.Server.URL, testhelper.Server.URL) + }) +} + +func TestChooseVersion(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + setupVersionHandler() + + v2 := &utils.Version{ID: "v2.0", Priority: 2, Suffix: "blarg"} + v3 := &utils.Version{ID: "v3.0", Priority: 3, Suffix: "hargl"} + + c := &gophercloud.ProviderClient{ + IdentityBase: testhelper.Endpoint(), + IdentityEndpoint: "", + } + v, endpoint, err := utils.ChooseVersion(c, []*utils.Version{v2, v3}) + + if err != nil { + t.Fatalf("Unexpected error from ChooseVersion: %v", err) + } + + if v != v3 { + t.Errorf("Expected %#v to win, but %#v did instead", v3, v) + } + + expected := testhelper.Endpoint() + "v3.0/" + if endpoint != expected { + t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint) + } +} + +func TestChooseVersionOpinionatedLink(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + setupVersionHandler() + + v2 := &utils.Version{ID: "v2.0", Priority: 2, Suffix: "nope"} + v3 := &utils.Version{ID: "v3.0", Priority: 3, Suffix: "northis"} + + c := &gophercloud.ProviderClient{ + IdentityBase: testhelper.Endpoint(), + IdentityEndpoint: testhelper.Endpoint() + "v2.0/", + } + v, endpoint, err := utils.ChooseVersion(c, []*utils.Version{v2, v3}) + if err != nil { + t.Fatalf("Unexpected error from ChooseVersion: %v", err) + } + + if v != v2 { + t.Errorf("Expected %#v to win, but %#v did instead", v2, v) + } + + expected := testhelper.Endpoint() + "v2.0/" + if endpoint != expected { + t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint) + } +} + +func TestChooseVersionFromSuffix(t *testing.T) { + testhelper.SetupHTTP() + defer testhelper.TeardownHTTP() + + v2 := &utils.Version{ID: "v2.0", Priority: 2, Suffix: "/v2.0/"} + v3 := &utils.Version{ID: "v3.0", Priority: 3, Suffix: "/v3.0/"} + + c := &gophercloud.ProviderClient{ + IdentityBase: testhelper.Endpoint(), + IdentityEndpoint: testhelper.Endpoint() + "v2.0/", + } + v, endpoint, err := utils.ChooseVersion(c, []*utils.Version{v2, v3}) + if err != nil { + t.Fatalf("Unexpected error from ChooseVersion: %v", err) + } + + if v != v2 { + t.Errorf("Expected %#v to win, but %#v did instead", v2, v) + } + + expected := testhelper.Endpoint() + "v2.0/" + if endpoint != expected { + t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint) + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/pager.go b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/pager.go index 7c65926b..42c0b2db 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/pager.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/pager.go @@ -41,6 +41,8 @@ type Pager struct { createPage func(r PageResult) Page + firstPage Page + Err error // Headers supplies additional HTTP headers to populate on each paged request. @@ -89,9 +91,18 @@ func (p Pager) EachPage(handler func(Page) (bool, error)) error { } currentURL := p.initialURL for { - currentPage, err := p.fetchNextPage(currentURL) - if err != nil { - return err + var currentPage Page + + // if first page has already been fetched, no need to fetch it again + if p.firstPage != nil { + currentPage = p.firstPage + p.firstPage = nil + } else { + var err error + currentPage, err = p.fetchNextPage(currentURL) + if err != nil { + return err + } } empty, err := currentPage.IsEmpty() @@ -128,23 +139,26 @@ func (p Pager) AllPages() (Page, error) { // body will contain the final concatenated Page body. var body reflect.Value - // Grab a test page to ascertain the page body type. - testPage, err := p.fetchNextPage(p.initialURL) + // Grab a first page to ascertain the page body type. + firstPage, err := p.fetchNextPage(p.initialURL) if err != nil { return nil, err } // Store the page type so we can use reflection to create a new mega-page of // that type. - pageType := reflect.TypeOf(testPage) + pageType := reflect.TypeOf(firstPage) - // if it's a single page, just return the testPage (first page) + // if it's a single page, just return the firstPage (first page) if _, found := pageType.FieldByName("SinglePageBase"); found { - return testPage, nil + return firstPage, nil } + // store the first page to avoid getting it twice + p.firstPage = firstPage + // Switch on the page body type. Recognized types are `map[string]interface{}`, // `[]byte`, and `[]interface{}`. - switch pb := testPage.GetBody().(type) { + switch pb := firstPage.GetBody().(type) { case map[string]interface{}: // key is the map key for the page body if the body type is `map[string]interface{}`. var key string diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/linked_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/linked_test.go new file mode 100644 index 00000000..3533e445 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/linked_test.go @@ -0,0 +1,112 @@ +package testing + +import ( + "fmt" + "net/http" + "reflect" + "testing" + + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" +) + +// LinkedPager sample and test cases. + +type LinkedPageResult struct { + pagination.LinkedPageBase +} + +func (r LinkedPageResult) IsEmpty() (bool, error) { + is, err := ExtractLinkedInts(r) + return len(is) == 0, err +} + +func ExtractLinkedInts(r pagination.Page) ([]int, error) { + var s struct { + Ints []int `json:"ints"` + } + err := (r.(LinkedPageResult)).ExtractInto(&s) + return s.Ints, err +} + +func createLinked(t *testing.T) pagination.Pager { + testhelper.SetupHTTP() + + testhelper.Mux.HandleFunc("/page1", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, `{ "ints": [1, 2, 3], "links": { "next": "%s/page2" } }`, testhelper.Server.URL) + }) + + testhelper.Mux.HandleFunc("/page2", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, `{ "ints": [4, 5, 6], "links": { "next": "%s/page3" } }`, testhelper.Server.URL) + }) + + testhelper.Mux.HandleFunc("/page3", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, `{ "ints": [7, 8, 9], "links": { "next": null } }`) + }) + + client := createClient() + + createPage := func(r pagination.PageResult) pagination.Page { + return LinkedPageResult{pagination.LinkedPageBase{PageResult: r}} + } + + return pagination.NewPager(client, testhelper.Server.URL+"/page1", createPage) +} + +func TestEnumerateLinked(t *testing.T) { + pager := createLinked(t) + defer testhelper.TeardownHTTP() + + callCount := 0 + err := pager.EachPage(func(page pagination.Page) (bool, error) { + actual, err := ExtractLinkedInts(page) + if err != nil { + return false, err + } + + t.Logf("Handler invoked with %v", actual) + + var expected []int + switch callCount { + case 0: + expected = []int{1, 2, 3} + case 1: + expected = []int{4, 5, 6} + case 2: + expected = []int{7, 8, 9} + default: + t.Fatalf("Unexpected call count: %d", callCount) + return false, nil + } + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Call %d: Expected %#v, but was %#v", callCount, expected, actual) + } + + callCount++ + return true, nil + }) + if err != nil { + t.Errorf("Unexpected error for page iteration: %v", err) + } + + if callCount != 3 { + t.Errorf("Expected 3 calls, but was %d", callCount) + } +} + +func TestAllPagesLinked(t *testing.T) { + pager := createLinked(t) + defer testhelper.TeardownHTTP() + + page, err := pager.AllPages() + testhelper.AssertNoErr(t, err) + + expected := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} + actual, err := ExtractLinkedInts(page) + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/marker_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/marker_test.go new file mode 100644 index 00000000..7b1a6daf --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/marker_test.go @@ -0,0 +1,127 @@ +package testing + +import ( + "fmt" + "net/http" + "strings" + "testing" + + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" +) + +// MarkerPager sample and test cases. + +type MarkerPageResult struct { + pagination.MarkerPageBase +} + +func (r MarkerPageResult) IsEmpty() (bool, error) { + results, err := ExtractMarkerStrings(r) + if err != nil { + return true, err + } + return len(results) == 0, err +} + +func (r MarkerPageResult) LastMarker() (string, error) { + results, err := ExtractMarkerStrings(r) + if err != nil { + return "", err + } + if len(results) == 0 { + return "", nil + } + return results[len(results)-1], nil +} + +func createMarkerPaged(t *testing.T) pagination.Pager { + testhelper.SetupHTTP() + + testhelper.Mux.HandleFunc("/page", func(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + ms := r.Form["marker"] + switch { + case len(ms) == 0: + fmt.Fprintf(w, "aaa\nbbb\nccc") + case len(ms) == 1 && ms[0] == "ccc": + fmt.Fprintf(w, "ddd\neee\nfff") + case len(ms) == 1 && ms[0] == "fff": + fmt.Fprintf(w, "ggg\nhhh\niii") + case len(ms) == 1 && ms[0] == "iii": + w.WriteHeader(http.StatusNoContent) + default: + t.Errorf("Request with unexpected marker: [%v]", ms) + } + }) + + client := createClient() + + createPage := func(r pagination.PageResult) pagination.Page { + p := MarkerPageResult{pagination.MarkerPageBase{PageResult: r}} + p.MarkerPageBase.Owner = p + return p + } + + return pagination.NewPager(client, testhelper.Server.URL+"/page", createPage) +} + +func ExtractMarkerStrings(page pagination.Page) ([]string, error) { + content := page.(MarkerPageResult).Body.([]uint8) + parts := strings.Split(string(content), "\n") + results := make([]string, 0, len(parts)) + for _, part := range parts { + if len(part) > 0 { + results = append(results, part) + } + } + return results, nil +} + +func TestEnumerateMarker(t *testing.T) { + pager := createMarkerPaged(t) + defer testhelper.TeardownHTTP() + + callCount := 0 + err := pager.EachPage(func(page pagination.Page) (bool, error) { + actual, err := ExtractMarkerStrings(page) + if err != nil { + return false, err + } + + t.Logf("Handler invoked with %v", actual) + + var expected []string + switch callCount { + case 0: + expected = []string{"aaa", "bbb", "ccc"} + case 1: + expected = []string{"ddd", "eee", "fff"} + case 2: + expected = []string{"ggg", "hhh", "iii"} + default: + t.Fatalf("Unexpected call count: %d", callCount) + return false, nil + } + + testhelper.CheckDeepEquals(t, expected, actual) + + callCount++ + return true, nil + }) + testhelper.AssertNoErr(t, err) + testhelper.AssertEquals(t, callCount, 3) +} + +func TestAllPagesMarker(t *testing.T) { + pager := createMarkerPaged(t) + defer testhelper.TeardownHTTP() + + page, err := pager.AllPages() + testhelper.AssertNoErr(t, err) + + expected := []string{"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"} + actual, err := ExtractMarkerStrings(page) + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/pagination_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/pagination_test.go new file mode 100644 index 00000000..170dca45 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/pagination_test.go @@ -0,0 +1,13 @@ +package testing + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/testhelper" +) + +func createClient() *gophercloud.ServiceClient { + return &gophercloud.ServiceClient{ + ProviderClient: &gophercloud.ProviderClient{TokenID: "abc123"}, + Endpoint: testhelper.Endpoint(), + } +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/single_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/single_test.go new file mode 100644 index 00000000..8d95e948 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/pagination/testing/single_test.go @@ -0,0 +1,79 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/testhelper" +) + +// SinglePage sample and test cases. + +type SinglePageResult struct { + pagination.SinglePageBase +} + +func (r SinglePageResult) IsEmpty() (bool, error) { + is, err := ExtractSingleInts(r) + if err != nil { + return true, err + } + return len(is) == 0, nil +} + +func ExtractSingleInts(r pagination.Page) ([]int, error) { + var s struct { + Ints []int `json:"ints"` + } + err := (r.(SinglePageResult)).ExtractInto(&s) + return s.Ints, err +} + +func setupSinglePaged() pagination.Pager { + testhelper.SetupHTTP() + client := createClient() + + testhelper.Mux.HandleFunc("/only", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, `{ "ints": [1, 2, 3] }`) + }) + + createPage := func(r pagination.PageResult) pagination.Page { + return SinglePageResult{pagination.SinglePageBase(r)} + } + + return pagination.NewPager(client, testhelper.Server.URL+"/only", createPage) +} + +func TestEnumerateSinglePaged(t *testing.T) { + callCount := 0 + pager := setupSinglePaged() + defer testhelper.TeardownHTTP() + + err := pager.EachPage(func(page pagination.Page) (bool, error) { + callCount++ + + expected := []int{1, 2, 3} + actual, err := ExtractSingleInts(page) + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, expected, actual) + return true, nil + }) + testhelper.CheckNoErr(t, err) + testhelper.CheckEquals(t, 1, callCount) +} + +func TestAllPagesSingle(t *testing.T) { + pager := setupSinglePaged() + defer testhelper.TeardownHTTP() + + page, err := pager.AllPages() + testhelper.AssertNoErr(t, err) + + expected := []int{1, 2, 3} + actual, err := ExtractSingleInts(page) + testhelper.AssertNoErr(t, err) + testhelper.CheckDeepEquals(t, expected, actual) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/params.go b/discovery/vendor/github.com/gophercloud/gophercloud/params.go index 28ad9068..19b8cf7b 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/params.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/params.go @@ -363,9 +363,8 @@ func BuildQueryString(opts interface{}) (*url.URL, error) { } } } else { - // Otherwise, the field is not set. - if len(tags) == 2 && tags[1] == "required" { - // And the field is required. Return an error. + // if the field has a 'required' tag, it can't have a zero-value + if requiredTag := f.Tag.Get("required"); requiredTag == "true" { return &url.URL{}, fmt.Errorf("Required query parameter [%s] not set.", f.Name) } } @@ -439,10 +438,9 @@ func BuildHeaders(opts interface{}) (map[string]string, error) { optsMap[tags[0]] = strconv.FormatBool(v.Bool()) } } else { - // Otherwise, the field is not set. - if len(tags) == 2 && tags[1] == "required" { - // And the field is required. Return an error. - return optsMap, fmt.Errorf("Required header not set.") + // if the field has a 'required' tag, it can't have a zero-value + if requiredTag := f.Tag.Get("required"); requiredTag == "true" { + return optsMap, fmt.Errorf("Required header [%s] not set.", f.Name) } } } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/provider_client.go b/discovery/vendor/github.com/gophercloud/gophercloud/provider_client.go index 72daeb0a..77368f01 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/provider_client.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/provider_client.go @@ -126,6 +126,36 @@ func (client *ProviderClient) SetToken(t string) { client.TokenID = t } +//Reauthenticate calls client.ReauthFunc in a thread-safe way. If this is +//called because of a 401 response, the caller may pass the previous token. In +//this case, the reauthentication can be skipped if another thread has already +//reauthenticated in the meantime. If no previous token is known, an empty +//string should be passed instead to force unconditional reauthentication. +func (client *ProviderClient) Reauthenticate(previousToken string) (err error) { + if client.ReauthFunc == nil { + return nil + } + + if client.mut == nil { + return client.ReauthFunc() + } + client.mut.Lock() + defer client.mut.Unlock() + + client.reauthmut.Lock() + client.reauthmut.reauthing = true + client.reauthmut.Unlock() + + if previousToken == "" || client.TokenID == previousToken { + err = client.ReauthFunc() + } + + client.reauthmut.Lock() + client.reauthmut.reauthing = false + client.reauthmut.Unlock() + return +} + // RequestOpts customizes the behavior of the provider.Request() method. type RequestOpts struct { // JSONBody, if provided, will be encoded as JSON and used as the body of the HTTP request. The @@ -254,21 +284,7 @@ func (client *ProviderClient) Request(method, url string, options *RequestOpts) } case http.StatusUnauthorized: if client.ReauthFunc != nil { - if client.mut != nil { - client.mut.Lock() - client.reauthmut.Lock() - client.reauthmut.reauthing = true - client.reauthmut.Unlock() - if curtok := client.TokenID; curtok == prereqtok { - err = client.ReauthFunc() - } - client.reauthmut.Lock() - client.reauthmut.reauthing = false - client.reauthmut.Unlock() - client.mut.Unlock() - } else { - err = client.ReauthFunc() - } + err = client.Reauthenticate(prereqtok) if err != nil { e := &ErrUnableToReauthenticate{} e.ErrOriginal = respErr @@ -298,6 +314,11 @@ func (client *ProviderClient) Request(method, url string, options *RequestOpts) if error401er, ok := errType.(Err401er); ok { err = error401er.Error401(respErr) } + case http.StatusForbidden: + err = ErrDefault403{respErr} + if error403er, ok := errType.(Err403er); ok { + err = error403er.Error403(respErr) + } case http.StatusNotFound: err = ErrDefault404{respErr} if error404er, ok := errType.(Err404er); ok { @@ -357,7 +378,7 @@ func defaultOkCodes(method string) []int { case method == "PUT": return []int{201, 202} case method == "PATCH": - return []int{200, 204} + return []int{200, 202, 204} case method == "DELETE": return []int{202, 204} } diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/results.go b/discovery/vendor/github.com/gophercloud/gophercloud/results.go index e64feee1..30d3b155 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/results.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/results.go @@ -89,23 +89,45 @@ func (r Result) extractIntoPtr(to interface{}, label string) error { if typeOfV.Kind() == reflect.Struct { if typeOfV.NumField() > 0 && typeOfV.Field(0).Anonymous { newSlice := reflect.MakeSlice(reflect.SliceOf(typeOfV), 0, 0) - newType := reflect.New(typeOfV).Elem() for _, v := range m[label].([]interface{}) { + // For each iteration of the slice, we create a new struct. + // This is to work around a bug where elements of a slice + // are reused and not overwritten when the same copy of the + // struct is used: + // + // https://github.com/golang/go/issues/21092 + // https://github.com/golang/go/issues/24155 + // https://play.golang.org/p/NHo3ywlPZli + newType := reflect.New(typeOfV).Elem() + b, err := json.Marshal(v) if err != nil { return err } + // This is needed for structs with an UnmarshalJSON method. + // Technically this is just unmarshalling the response into + // a struct that is never used, but it's good enough to + // trigger the UnmarshalJSON method. for i := 0; i < newType.NumField(); i++ { s := newType.Field(i).Addr().Interface() - err = json.NewDecoder(bytes.NewReader(b)).Decode(s) + + // Unmarshal is used rather than NewDecoder to also work + // around the above-mentioned bug. + err = json.Unmarshal(b, s) if err != nil { return err } } + newSlice = reflect.Append(newSlice, newType) } + + // "to" should now be properly modeled to receive the + // JSON response body and unmarshal into all the correct + // fields of the struct or composed extension struct + // at the end of this method. toValue.Set(newSlice) } } @@ -345,6 +367,48 @@ func (jt *JSONRFC3339NoZ) UnmarshalJSON(data []byte) error { return nil } +// RFC3339ZNoT is the time format used in Zun (Containers Service). +const RFC3339ZNoT = "2006-01-02 15:04:05-07:00" + +type JSONRFC3339ZNoT time.Time + +func (jt *JSONRFC3339ZNoT) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + if s == "" { + return nil + } + t, err := time.Parse(RFC3339ZNoT, s) + if err != nil { + return err + } + *jt = JSONRFC3339ZNoT(t) + return nil +} + +// RFC3339ZNoTNoZ is another time format used in Zun (Containers Service). +const RFC3339ZNoTNoZ = "2006-01-02 15:04:05" + +type JSONRFC3339ZNoTNoZ time.Time + +func (jt *JSONRFC3339ZNoTNoZ) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + if s == "" { + return nil + } + t, err := time.Parse(RFC3339ZNoTNoZ, s) + if err != nil { + return err + } + *jt = JSONRFC3339ZNoTNoZ(t) + return nil +} + /* Link is an internal type to be used in packages of collection resources that are paginated in a certain way. diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/script/acceptancetest b/discovery/vendor/github.com/gophercloud/gophercloud/script/acceptancetest index 9debd48b..0541c8f4 100755 --- a/discovery/vendor/github.com/gophercloud/gophercloud/script/acceptancetest +++ b/discovery/vendor/github.com/gophercloud/gophercloud/script/acceptancetest @@ -1,5 +1,60 @@ #!/bin/bash # +set -x + +source `dirname $0`/stackenv + +timeout="60m" +failed= + # Run the acceptance tests. +# Check the error code after each suite, but do not exit early if a suite failed. + +# Identity v3 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/identity/v3/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Networking v2 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/networking/v2/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Block Storage v2 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/blockstorage/v2/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Block Storage v3 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/blockstorage/v3/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Compute v2 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/compute/v2/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Container v1 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/container/v1/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# Image Service v2 +go test -v -timeout $timeout -tags "fixtures acceptance" ./acceptance/openstack/imageservice/v2/ +if [[ $? != 0 ]]; then + failed=1 +fi + +# If any of the test suites failed, exit 1 +if [[ -n $failed ]]; then + exit 1 +fi -exec go test -p=1 github.com/gophercloud/gophercloud/acceptance/... $@ +exit 0 diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/script/format b/discovery/vendor/github.com/gophercloud/gophercloud/script/format index 8ed602fd..05645a82 100755 --- a/discovery/vendor/github.com/gophercloud/gophercloud/script/format +++ b/discovery/vendor/github.com/gophercloud/gophercloud/script/format @@ -16,8 +16,26 @@ find_files() { \) -name '*.go' } -diff=$(find_files | xargs ${goimports} -d -e 2>&1) -if [[ -n "${diff}" ]]; then - echo "${diff}" - exit 1 +ignore_files=( + "./openstack/compute/v2/extensions/quotasets/testing/fixtures.go" + "./openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go" +) + +bad_files=$(find_files | xargs ${goimports} -l) + +final_files=() +for bad_file in $bad_files; do + found= + for ignore_file in "${ignore_files[@]}"; do + [[ "${bad_file}" == "${ignore_file}" ]] && { found=1; break; } + done + [[ -n $found ]] || final_files+=("$bad_file") +done + +if [[ "${#final_files[@]}" -gt 0 ]]; then + diff=$(echo "${final_files[@]}" | xargs ${goimports} -d -e 2>&1) + if [[ -n "${diff}" ]]; then + echo "${diff}" + exit 1 + fi fi diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/script/stackenv b/discovery/vendor/github.com/gophercloud/gophercloud/script/stackenv new file mode 100644 index 00000000..6a742a32 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/script/stackenv @@ -0,0 +1,25 @@ +# Prep the testing environment by creating the required testing resources and +# environment variables. This env is for theopenlab CI jobs, you might need +# to modify this according to your setup + +pushd /opt/stack/new/devstack +source openrc admin admin +openstack flavor create m1.acctest --id 99 --ram 512 --disk 5 --vcpu 1 --ephemeral 10 +openstack flavor create m1.resize --id 98 --ram 512 --disk 6 --vcpu 1 --ephemeral 10 +_NETWORK_ID=$(openstack network show private -c id -f value) +_EXTGW_ID=$(openstack network show public -c id -f value) +_IMAGE=$(openstack image list | grep -i cirros | head -n 1) +_IMAGE_ID=$(echo $_IMAGE | awk -F\| '{print $2}' | tr -d ' ') +_IMAGE_NAME=$(echo $_IMAGE | awk -F\| '{print $3}' | tr -d ' ') +echo export OS_IMAGE_NAME="$_IMAGE_NAME" >> openrc +echo export OS_IMAGE_ID="$_IMAGE_ID" >> openrc +echo export OS_NETWORK_ID=$_NETWORK_ID >> openrc +echo export OS_EXTGW_ID=$_EXTGW_ID >> openrc +echo export OS_POOL_NAME="public" >> openrc +echo export OS_FLAVOR_ID=99 >> openrc +echo export OS_FLAVOR_ID_RESIZE=98 >> openrc +echo export OS_SHARE_NETWORK_ID=foobar >> openrc +echo export OS_DOMAIN_ID=default >> openrc +source openrc admin admin +popd + diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/service_client.go b/discovery/vendor/github.com/gophercloud/gophercloud/service_client.go index d1a48fea..2734510e 100644 --- a/discovery/vendor/github.com/gophercloud/gophercloud/service_client.go +++ b/discovery/vendor/github.com/gophercloud/gophercloud/service_client.go @@ -28,6 +28,10 @@ type ServiceClient struct { // The microversion of the service to use. Set this to use a particular microversion. Microversion string + + // MoreHeaders allows users (or Gophercloud) to set service-wide headers on requests. Put another way, + // values set in this field will be set on all the HTTP requests the service client sends. + MoreHeaders map[string]string } // ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /. @@ -108,6 +112,15 @@ func (client *ServiceClient) Delete(url string, opts *RequestOpts) (*http.Respon return client.Request("DELETE", url, opts) } +// Head calls `Request` with the "HEAD" HTTP verb. +func (client *ServiceClient) Head(url string, opts *RequestOpts) (*http.Response, error) { + if opts == nil { + opts = new(RequestOpts) + } + client.initReqOpts(url, nil, nil, opts) + return client.Request("HEAD", url, opts) +} + func (client *ServiceClient) setMicroversionHeader(opts *RequestOpts) { switch client.Type { case "compute": @@ -122,3 +135,16 @@ func (client *ServiceClient) setMicroversionHeader(opts *RequestOpts) { opts.MoreHeaders["OpenStack-API-Version"] = client.Type + " " + client.Microversion } } + +// Request carries out the HTTP operation for the service client +func (client *ServiceClient) Request(method, url string, options *RequestOpts) (*http.Response, error) { + if len(client.MoreHeaders) > 0 { + if options == nil { + options = new(RequestOpts) + } + for k, v := range client.MoreHeaders { + options.MoreHeaders[k] = v + } + } + return client.ProviderClient.Request(method, url, options) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/endpoint_search_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/endpoint_search_test.go new file mode 100644 index 00000000..22476cbb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/endpoint_search_test.go @@ -0,0 +1,20 @@ +package testing + +import ( + "testing" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestApplyDefaultsToEndpointOpts(t *testing.T) { + eo := gophercloud.EndpointOpts{Availability: gophercloud.AvailabilityPublic} + eo.ApplyDefaults("compute") + expected := gophercloud.EndpointOpts{Availability: gophercloud.AvailabilityPublic, Type: "compute"} + th.CheckDeepEquals(t, expected, eo) + + eo = gophercloud.EndpointOpts{Type: "compute"} + eo.ApplyDefaults("object-store") + expected = gophercloud.EndpointOpts{Availability: gophercloud.AvailabilityPublic, Type: "compute"} + th.CheckDeepEquals(t, expected, eo) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/params_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/params_test.go new file mode 100644 index 00000000..60253664 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/params_test.go @@ -0,0 +1,276 @@ +package testing + +import ( + "net/url" + "reflect" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestMaybeString(t *testing.T) { + testString := "" + var expected *string + actual := gophercloud.MaybeString(testString) + th.CheckDeepEquals(t, expected, actual) + + testString = "carol" + expected = &testString + actual = gophercloud.MaybeString(testString) + th.CheckDeepEquals(t, expected, actual) +} + +func TestMaybeInt(t *testing.T) { + testInt := 0 + var expected *int + actual := gophercloud.MaybeInt(testInt) + th.CheckDeepEquals(t, expected, actual) + + testInt = 4 + expected = &testInt + actual = gophercloud.MaybeInt(testInt) + th.CheckDeepEquals(t, expected, actual) +} + +func TestBuildQueryString(t *testing.T) { + type testVar string + iFalse := false + opts := struct { + J int `q:"j"` + R string `q:"r" required:"true"` + C bool `q:"c"` + S []string `q:"s"` + TS []testVar `q:"ts"` + TI []int `q:"ti"` + F *bool `q:"f"` + M map[string]string `q:"m"` + }{ + J: 2, + R: "red", + C: true, + S: []string{"one", "two", "three"}, + TS: []testVar{"a", "b"}, + TI: []int{1, 2}, + F: &iFalse, + M: map[string]string{"k1": "success1"}, + } + expected := &url.URL{RawQuery: "c=true&f=false&j=2&m=%7B%27k1%27%3A%27success1%27%7D&r=red&s=one&s=two&s=three&ti=1&ti=2&ts=a&ts=b"} + actual, err := gophercloud.BuildQueryString(&opts) + if err != nil { + t.Errorf("Error building query string: %v", err) + } + th.CheckDeepEquals(t, expected, actual) + + opts = struct { + J int `q:"j"` + R string `q:"r" required:"true"` + C bool `q:"c"` + S []string `q:"s"` + TS []testVar `q:"ts"` + TI []int `q:"ti"` + F *bool `q:"f"` + M map[string]string `q:"m"` + }{ + J: 2, + C: true, + } + _, err = gophercloud.BuildQueryString(&opts) + if err == nil { + t.Errorf("Expected error: 'Required field not set'") + } + th.CheckDeepEquals(t, expected, actual) + + _, err = gophercloud.BuildQueryString(map[string]interface{}{"Number": 4}) + if err == nil { + t.Errorf("Expected error: 'Options type is not a struct'") + } +} + +func TestBuildHeaders(t *testing.T) { + testStruct := struct { + Accept string `h:"Accept"` + Num int `h:"Number" required:"true"` + Style bool `h:"Style"` + }{ + Accept: "application/json", + Num: 4, + Style: true, + } + expected := map[string]string{"Accept": "application/json", "Number": "4", "Style": "true"} + actual, err := gophercloud.BuildHeaders(&testStruct) + th.CheckNoErr(t, err) + th.CheckDeepEquals(t, expected, actual) + + testStruct.Num = 0 + _, err = gophercloud.BuildHeaders(&testStruct) + if err == nil { + t.Errorf("Expected error: 'Required header not set'") + } + + _, err = gophercloud.BuildHeaders(map[string]interface{}{"Number": 4}) + if err == nil { + t.Errorf("Expected error: 'Options type is not a struct'") + } +} + +func TestQueriesAreEscaped(t *testing.T) { + type foo struct { + Name string `q:"something"` + Shape string `q:"else"` + } + + expected := &url.URL{RawQuery: "else=Triangl+e&something=blah%2B%3F%21%21foo"} + + actual, err := gophercloud.BuildQueryString(foo{Name: "blah+?!!foo", Shape: "Triangl e"}) + th.AssertNoErr(t, err) + + th.AssertDeepEquals(t, expected, actual) +} + +func TestBuildRequestBody(t *testing.T) { + type PasswordCredentials struct { + Username string `json:"username" required:"true"` + Password string `json:"password" required:"true"` + } + + type TokenCredentials struct { + ID string `json:"id,omitempty" required:"true"` + } + + type orFields struct { + Filler int `json:"filler,omitempty"` + F1 int `json:"f1,omitempty" or:"F2"` + F2 int `json:"f2,omitempty" or:"F1"` + } + + // AuthOptions wraps a gophercloud AuthOptions in order to adhere to the AuthOptionsBuilder + // interface. + type AuthOptions struct { + PasswordCredentials *PasswordCredentials `json:"passwordCredentials,omitempty" xor:"TokenCredentials"` + + // The TenantID and TenantName fields are optional for the Identity V2 API. + // Some providers allow you to specify a TenantName instead of the TenantId. + // Some require both. Your provider's authentication policies will determine + // how these fields influence authentication. + TenantID string `json:"tenantId,omitempty"` + TenantName string `json:"tenantName,omitempty"` + + // TokenCredentials allows users to authenticate (possibly as another user) with an + // authentication token ID. + TokenCredentials *TokenCredentials `json:"token,omitempty" xor:"PasswordCredentials"` + + OrFields *orFields `json:"or_fields,omitempty"` + } + + var successCases = []struct { + opts AuthOptions + expected map[string]interface{} + }{ + { + AuthOptions{ + PasswordCredentials: &PasswordCredentials{ + Username: "me", + Password: "swordfish", + }, + }, + map[string]interface{}{ + "auth": map[string]interface{}{ + "passwordCredentials": map[string]interface{}{ + "password": "swordfish", + "username": "me", + }, + }, + }, + }, + { + AuthOptions{ + TokenCredentials: &TokenCredentials{ + ID: "1234567", + }, + }, + map[string]interface{}{ + "auth": map[string]interface{}{ + "token": map[string]interface{}{ + "id": "1234567", + }, + }, + }, + }, + } + + for _, successCase := range successCases { + actual, err := gophercloud.BuildRequestBody(successCase.opts, "auth") + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, successCase.expected, actual) + } + + var failCases = []struct { + opts AuthOptions + expected error + }{ + { + AuthOptions{ + TenantID: "987654321", + TenantName: "me", + }, + gophercloud.ErrMissingInput{}, + }, + { + AuthOptions{ + TokenCredentials: &TokenCredentials{ + ID: "1234567", + }, + PasswordCredentials: &PasswordCredentials{ + Username: "me", + Password: "swordfish", + }, + }, + gophercloud.ErrMissingInput{}, + }, + { + AuthOptions{ + PasswordCredentials: &PasswordCredentials{ + Password: "swordfish", + }, + }, + gophercloud.ErrMissingInput{}, + }, + { + AuthOptions{ + PasswordCredentials: &PasswordCredentials{ + Username: "me", + Password: "swordfish", + }, + OrFields: &orFields{ + Filler: 2, + }, + }, + gophercloud.ErrMissingInput{}, + }, + } + + for _, failCase := range failCases { + _, err := gophercloud.BuildRequestBody(failCase.opts, "auth") + th.AssertDeepEquals(t, reflect.TypeOf(failCase.expected), reflect.TypeOf(err)) + } + + createdAt := time.Date(2018, 1, 4, 10, 00, 12, 0, time.UTC) + var complexFields = struct { + Username string `json:"username" required:"true"` + CreatedAt *time.Time `json:"-"` + }{ + Username: "jdoe", + CreatedAt: &createdAt, + } + + expectedComplexFields := map[string]interface{}{ + "username": "jdoe", + } + + actual, err := gophercloud.BuildRequestBody(complexFields, "") + th.AssertNoErr(t, err) + th.AssertDeepEquals(t, expectedComplexFields, actual) + +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/provider_client_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/provider_client_test.go new file mode 100644 index 00000000..15385beb --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/provider_client_test.go @@ -0,0 +1,124 @@ +package testing + +import ( + "fmt" + "io/ioutil" + "net/http" + "sync" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/testhelper/client" +) + +func TestAuthenticatedHeaders(t *testing.T) { + p := &gophercloud.ProviderClient{ + TokenID: "1234", + } + expected := map[string]string{"X-Auth-Token": "1234"} + actual := p.AuthenticatedHeaders() + th.CheckDeepEquals(t, expected, actual) +} + +func TestUserAgent(t *testing.T) { + p := &gophercloud.ProviderClient{} + + p.UserAgent.Prepend("custom-user-agent/2.4.0") + expected := "custom-user-agent/2.4.0 gophercloud/2.0.0" + actual := p.UserAgent.Join() + th.CheckEquals(t, expected, actual) + + p.UserAgent.Prepend("another-custom-user-agent/0.3.0", "a-third-ua/5.9.0") + expected = "another-custom-user-agent/0.3.0 a-third-ua/5.9.0 custom-user-agent/2.4.0 gophercloud/2.0.0" + actual = p.UserAgent.Join() + th.CheckEquals(t, expected, actual) + + p.UserAgent = gophercloud.UserAgent{} + expected = "gophercloud/2.0.0" + actual = p.UserAgent.Join() + th.CheckEquals(t, expected, actual) +} + +func TestConcurrentReauth(t *testing.T) { + var info = struct { + numreauths int + mut *sync.RWMutex + }{ + 0, + new(sync.RWMutex), + } + + numconc := 20 + + prereauthTok := client.TokenID + postreauthTok := "12345678" + + p := new(gophercloud.ProviderClient) + p.UseTokenLock() + p.SetToken(prereauthTok) + p.ReauthFunc = func() error { + time.Sleep(1 * time.Second) + p.AuthenticatedHeaders() + info.mut.Lock() + info.numreauths++ + info.mut.Unlock() + p.TokenID = postreauthTok + return nil + } + + th.SetupHTTP() + defer th.TeardownHTTP() + + th.Mux.HandleFunc("/route", func(w http.ResponseWriter, r *http.Request) { + if r.Header.Get("X-Auth-Token") != postreauthTok { + w.WriteHeader(http.StatusUnauthorized) + return + } + info.mut.RLock() + hasReauthed := info.numreauths != 0 + info.mut.RUnlock() + + if hasReauthed { + th.CheckEquals(t, p.Token(), postreauthTok) + } + + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, `{}`) + }) + + wg := new(sync.WaitGroup) + reqopts := new(gophercloud.RequestOpts) + reqopts.MoreHeaders = map[string]string{ + "X-Auth-Token": prereauthTok, + } + + for i := 0; i < numconc; i++ { + wg.Add(1) + go func() { + defer wg.Done() + resp, err := p.Request("GET", fmt.Sprintf("%s/route", th.Endpoint()), reqopts) + th.CheckNoErr(t, err) + if resp == nil { + t.Errorf("got a nil response") + return + } + if resp.Body == nil { + t.Errorf("response body was nil") + return + } + defer resp.Body.Close() + actual, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("error reading response body: %s", err) + return + } + th.CheckByteArrayEquals(t, []byte(`{}`), actual) + }() + } + + wg.Wait() + + th.AssertEquals(t, 1, info.numreauths) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/results_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/results_test.go new file mode 100644 index 00000000..ddcb1322 --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/results_test.go @@ -0,0 +1,208 @@ +package testing + +import ( + "encoding/json" + "testing" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" +) + +var singleResponse = ` +{ + "person": { + "name": "Bill", + "email": "bill@example.com", + "location": "Canada" + } +} +` + +var multiResponse = ` +{ + "people": [ + { + "name": "Bill", + "email": "bill@example.com", + "location": "Canada" + }, + { + "name": "Ted", + "email": "ted@example.com", + "location": "Mexico" + } + ] +} +` + +type TestPerson struct { + Name string `json:"-"` + Email string `json:"email"` +} + +func (r *TestPerson) UnmarshalJSON(b []byte) error { + type tmp TestPerson + var s struct { + tmp + Name string `json:"name"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + *r = TestPerson(s.tmp) + r.Name = s.Name + " unmarshalled" + + return nil +} + +type TestPersonExt struct { + Location string `json:"-"` +} + +func (r *TestPersonExt) UnmarshalJSON(b []byte) error { + type tmp TestPersonExt + var s struct { + tmp + Location string `json:"location"` + } + + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + *r = TestPersonExt(s.tmp) + r.Location = s.Location + " unmarshalled" + + return nil +} + +type TestPersonWithExtensions struct { + TestPerson + TestPersonExt +} + +type TestPersonWithExtensionsNamed struct { + TestPerson TestPerson + TestPersonExt TestPersonExt +} + +// TestUnmarshalAnonymousStruct tests if UnmarshalJSON is called on each +// of the anonymous structs contained in an overarching struct. +func TestUnmarshalAnonymousStructs(t *testing.T) { + var actual TestPersonWithExtensions + + var dejson interface{} + sejson := []byte(singleResponse) + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatal(err) + } + + var singleResult = gophercloud.Result{ + Body: dejson, + } + + err = singleResult.ExtractIntoStructPtr(&actual, "person") + th.AssertNoErr(t, err) + + th.AssertEquals(t, "Bill unmarshalled", actual.Name) + th.AssertEquals(t, "Canada unmarshalled", actual.Location) +} + +// TestUnmarshalSliceofAnonymousStructs tests if UnmarshalJSON is called on each +// of the anonymous structs contained in an overarching struct slice. +func TestUnmarshalSliceOfAnonymousStructs(t *testing.T) { + var actual []TestPersonWithExtensions + + var dejson interface{} + sejson := []byte(multiResponse) + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatal(err) + } + + var multiResult = gophercloud.Result{ + Body: dejson, + } + + err = multiResult.ExtractIntoSlicePtr(&actual, "people") + th.AssertNoErr(t, err) + + th.AssertEquals(t, "Bill unmarshalled", actual[0].Name) + th.AssertEquals(t, "Canada unmarshalled", actual[0].Location) + th.AssertEquals(t, "Ted unmarshalled", actual[1].Name) + th.AssertEquals(t, "Mexico unmarshalled", actual[1].Location) +} + +// TestUnmarshalSliceOfStruct tests if extracting results from a "normal" +// struct still works correctly. +func TestUnmarshalSliceofStruct(t *testing.T) { + var actual []TestPerson + + var dejson interface{} + sejson := []byte(multiResponse) + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatal(err) + } + + var multiResult = gophercloud.Result{ + Body: dejson, + } + + err = multiResult.ExtractIntoSlicePtr(&actual, "people") + th.AssertNoErr(t, err) + + th.AssertEquals(t, "Bill unmarshalled", actual[0].Name) + th.AssertEquals(t, "Ted unmarshalled", actual[1].Name) +} + +// TestUnmarshalNamedStruct tests if the result is empty. +func TestUnmarshalNamedStructs(t *testing.T) { + var actual TestPersonWithExtensionsNamed + + var dejson interface{} + sejson := []byte(singleResponse) + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatal(err) + } + + var singleResult = gophercloud.Result{ + Body: dejson, + } + + err = singleResult.ExtractIntoStructPtr(&actual, "person") + th.AssertNoErr(t, err) + + th.AssertEquals(t, "", actual.TestPerson.Name) + th.AssertEquals(t, "", actual.TestPersonExt.Location) +} + +// TestUnmarshalSliceofNamedStructs tests if the result is empty. +func TestUnmarshalSliceOfNamedStructs(t *testing.T) { + var actual []TestPersonWithExtensionsNamed + + var dejson interface{} + sejson := []byte(multiResponse) + err := json.Unmarshal(sejson, &dejson) + if err != nil { + t.Fatal(err) + } + + var multiResult = gophercloud.Result{ + Body: dejson, + } + + err = multiResult.ExtractIntoSlicePtr(&actual, "people") + th.AssertNoErr(t, err) + + th.AssertEquals(t, "", actual[0].TestPerson.Name) + th.AssertEquals(t, "", actual[0].TestPersonExt.Location) + th.AssertEquals(t, "", actual[1].TestPerson.Name) + th.AssertEquals(t, "", actual[1].TestPersonExt.Location) +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/service_client_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/service_client_test.go new file mode 100644 index 00000000..034fdc1d --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/service_client_test.go @@ -0,0 +1,34 @@ +package testing + +import ( + "fmt" + "net/http" + "testing" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestServiceURL(t *testing.T) { + c := &gophercloud.ServiceClient{Endpoint: "http://123.45.67.8/"} + expected := "http://123.45.67.8/more/parts/here" + actual := c.ServiceURL("more", "parts", "here") + th.CheckEquals(t, expected, actual) +} + +func TestMoreHeaders(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + th.Mux.HandleFunc("/route", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + c := new(gophercloud.ServiceClient) + c.MoreHeaders = map[string]string{ + "custom": "header", + } + c.ProviderClient = new(gophercloud.ProviderClient) + resp, err := c.Get(fmt.Sprintf("%s/route", th.Endpoint()), nil, nil) + th.AssertNoErr(t, err) + th.AssertEquals(t, resp.Request.Header.Get("custom"), "header") +} diff --git a/discovery/vendor/github.com/gophercloud/gophercloud/testing/util_test.go b/discovery/vendor/github.com/gophercloud/gophercloud/testing/util_test.go new file mode 100644 index 00000000..ae3e448f --- /dev/null +++ b/discovery/vendor/github.com/gophercloud/gophercloud/testing/util_test.go @@ -0,0 +1,122 @@ +package testing + +import ( + "errors" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/gophercloud/gophercloud" + th "github.com/gophercloud/gophercloud/testhelper" +) + +func TestWaitFor(t *testing.T) { + err := gophercloud.WaitFor(2, func() (bool, error) { + return true, nil + }) + th.CheckNoErr(t, err) +} + +func TestWaitForTimeout(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + err := gophercloud.WaitFor(1, func() (bool, error) { + return false, nil + }) + th.AssertEquals(t, "A timeout occurred", err.Error()) +} + +func TestWaitForError(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + err := gophercloud.WaitFor(2, func() (bool, error) { + return false, errors.New("Error has occurred") + }) + th.AssertEquals(t, "Error has occurred", err.Error()) +} + +func TestWaitForPredicateExceed(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + err := gophercloud.WaitFor(1, func() (bool, error) { + time.Sleep(4 * time.Second) + return false, errors.New("Just wasting time") + }) + th.AssertEquals(t, "A timeout occurred", err.Error()) +} + +func TestNormalizeURL(t *testing.T) { + urls := []string{ + "NoSlashAtEnd", + "SlashAtEnd/", + } + expected := []string{ + "NoSlashAtEnd/", + "SlashAtEnd/", + } + for i := 0; i < len(expected); i++ { + th.CheckEquals(t, expected[i], gophercloud.NormalizeURL(urls[i])) + } + +} + +func TestNormalizePathURL(t *testing.T) { + baseDir, _ := os.Getwd() + + rawPath := "template.yaml" + basePath, _ := filepath.Abs(".") + result, _ := gophercloud.NormalizePathURL(basePath, rawPath) + expected := strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "template.yaml"}, "/") + th.CheckEquals(t, expected, result) + + rawPath = "http://www.google.com" + basePath, _ = filepath.Abs(".") + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = "http://www.google.com" + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml" + basePath, _ = filepath.Abs(".") + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "very/nested/file.yaml"}, "/") + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml" + basePath = "http://www.google.com" + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = "http://www.google.com/very/nested/file.yaml" + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml/" + basePath = "http://www.google.com/" + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = "http://www.google.com/very/nested/file.yaml" + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml" + basePath = "http://www.google.com/even/more" + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = "http://www.google.com/even/more/very/nested/file.yaml" + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml" + basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/") + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/") + th.CheckEquals(t, expected, result) + + rawPath = "very/nested/file.yaml/" + basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/") + result, _ = gophercloud.NormalizePathURL(basePath, rawPath) + expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/") + th.CheckEquals(t, expected, result) + +} diff --git a/discovery/vendor/github.com/gregjones/httpcache/LICENSE.txt b/discovery/vendor/github.com/gregjones/httpcache/LICENSE.txt deleted file mode 100644 index 81316beb..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/LICENSE.txt +++ /dev/null @@ -1,7 +0,0 @@ -Copyright © 2012 Greg Jones (greg.jones@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/discovery/vendor/github.com/gregjones/httpcache/README.md b/discovery/vendor/github.com/gregjones/httpcache/README.md deleted file mode 100644 index eb2eae8e..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/README.md +++ /dev/null @@ -1,25 +0,0 @@ -httpcache -========= - -[![Build Status](https://travis-ci.org/gregjones/httpcache.svg?branch=master)](https://travis-ci.org/gregjones/httpcache) [![GoDoc](https://godoc.org/github.com/gregjones/httpcache?status.svg)](https://godoc.org/github.com/gregjones/httpcache) - -Package httpcache provides a http.RoundTripper implementation that works as a mostly RFC-compliant cache for http responses. - -It is only suitable for use as a 'private' cache (i.e. for a web-browser or an API-client and not for a shared proxy). - -Cache Backends --------------- - -- The built-in 'memory' cache stores responses in an in-memory map. -- [`github.com/gregjones/httpcache/diskcache`](https://github.com/gregjones/httpcache/tree/master/diskcache) provides a filesystem-backed cache using the [diskv](https://github.com/peterbourgon/diskv) library. -- [`github.com/gregjones/httpcache/memcache`](https://github.com/gregjones/httpcache/tree/master/memcache) provides memcache implementations, for both App Engine and 'normal' memcache servers. -- [`sourcegraph.com/sourcegraph/s3cache`](https://sourcegraph.com/github.com/sourcegraph/s3cache) uses Amazon S3 for storage. -- [`github.com/gregjones/httpcache/leveldbcache`](https://github.com/gregjones/httpcache/tree/master/leveldbcache) provides a filesystem-backed cache using [leveldb](https://github.com/syndtr/goleveldb/leveldb). -- [`github.com/die-net/lrucache`](https://github.com/die-net/lrucache) provides an in-memory cache that will evict least-recently used entries. -- [`github.com/die-net/lrucache/twotier`](https://github.com/die-net/lrucache/tree/master/twotier) allows caches to be combined, for example to use lrucache above with a persistent disk-cache. -- [`github.com/birkelund/boltdbcache`](https://github.com/birkelund/boltdbcache) provides a BoltDB implementation (based on the [bbolt](https://github.com/coreos/bbolt) fork). - -License -------- - -- [MIT License](LICENSE.txt) diff --git a/discovery/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go b/discovery/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go deleted file mode 100644 index 42e3129d..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go +++ /dev/null @@ -1,61 +0,0 @@ -// Package diskcache provides an implementation of httpcache.Cache that uses the diskv package -// to supplement an in-memory map with persistent storage -// -package diskcache - -import ( - "bytes" - "crypto/md5" - "encoding/hex" - "github.com/peterbourgon/diskv" - "io" -) - -// Cache is an implementation of httpcache.Cache that supplements the in-memory map with persistent storage -type Cache struct { - d *diskv.Diskv -} - -// Get returns the response corresponding to key if present -func (c *Cache) Get(key string) (resp []byte, ok bool) { - key = keyToFilename(key) - resp, err := c.d.Read(key) - if err != nil { - return []byte{}, false - } - return resp, true -} - -// Set saves a response to the cache as key -func (c *Cache) Set(key string, resp []byte) { - key = keyToFilename(key) - c.d.WriteStream(key, bytes.NewReader(resp), true) -} - -// Delete removes the response with key from the cache -func (c *Cache) Delete(key string) { - key = keyToFilename(key) - c.d.Erase(key) -} - -func keyToFilename(key string) string { - h := md5.New() - io.WriteString(h, key) - return hex.EncodeToString(h.Sum(nil)) -} - -// New returns a new Cache that will store files in basePath -func New(basePath string) *Cache { - return &Cache{ - d: diskv.New(diskv.Options{ - BasePath: basePath, - CacheSizeMax: 100 * 1024 * 1024, // 100MB - }), - } -} - -// NewWithDiskv returns a new Cache using the provided Diskv as underlying -// storage. -func NewWithDiskv(d *diskv.Diskv) *Cache { - return &Cache{d} -} diff --git a/discovery/vendor/github.com/gregjones/httpcache/httpcache.go b/discovery/vendor/github.com/gregjones/httpcache/httpcache.go deleted file mode 100644 index f6a2ec4a..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/httpcache.go +++ /dev/null @@ -1,551 +0,0 @@ -// Package httpcache provides a http.RoundTripper implementation that works as a -// mostly RFC-compliant cache for http responses. -// -// It is only suitable for use as a 'private' cache (i.e. for a web-browser or an API-client -// and not for a shared proxy). -// -package httpcache - -import ( - "bufio" - "bytes" - "errors" - "io" - "io/ioutil" - "net/http" - "net/http/httputil" - "strings" - "sync" - "time" -) - -const ( - stale = iota - fresh - transparent - // XFromCache is the header added to responses that are returned from the cache - XFromCache = "X-From-Cache" -) - -// A Cache interface is used by the Transport to store and retrieve responses. -type Cache interface { - // Get returns the []byte representation of a cached response and a bool - // set to true if the value isn't empty - Get(key string) (responseBytes []byte, ok bool) - // Set stores the []byte representation of a response against a key - Set(key string, responseBytes []byte) - // Delete removes the value associated with the key - Delete(key string) -} - -// cacheKey returns the cache key for req. -func cacheKey(req *http.Request) string { - if req.Method == http.MethodGet { - return req.URL.String() - } else { - return req.Method + " " + req.URL.String() - } -} - -// CachedResponse returns the cached http.Response for req if present, and nil -// otherwise. -func CachedResponse(c Cache, req *http.Request) (resp *http.Response, err error) { - cachedVal, ok := c.Get(cacheKey(req)) - if !ok { - return - } - - b := bytes.NewBuffer(cachedVal) - return http.ReadResponse(bufio.NewReader(b), req) -} - -// MemoryCache is an implemtation of Cache that stores responses in an in-memory map. -type MemoryCache struct { - mu sync.RWMutex - items map[string][]byte -} - -// Get returns the []byte representation of the response and true if present, false if not -func (c *MemoryCache) Get(key string) (resp []byte, ok bool) { - c.mu.RLock() - resp, ok = c.items[key] - c.mu.RUnlock() - return resp, ok -} - -// Set saves response resp to the cache with key -func (c *MemoryCache) Set(key string, resp []byte) { - c.mu.Lock() - c.items[key] = resp - c.mu.Unlock() -} - -// Delete removes key from the cache -func (c *MemoryCache) Delete(key string) { - c.mu.Lock() - delete(c.items, key) - c.mu.Unlock() -} - -// NewMemoryCache returns a new Cache that will store items in an in-memory map -func NewMemoryCache() *MemoryCache { - c := &MemoryCache{items: map[string][]byte{}} - return c -} - -// Transport is an implementation of http.RoundTripper that will return values from a cache -// where possible (avoiding a network request) and will additionally add validators (etag/if-modified-since) -// to repeated requests allowing servers to return 304 / Not Modified -type Transport struct { - // The RoundTripper interface actually used to make requests - // If nil, http.DefaultTransport is used - Transport http.RoundTripper - Cache Cache - // If true, responses returned from the cache will be given an extra header, X-From-Cache - MarkCachedResponses bool -} - -// NewTransport returns a new Transport with the -// provided Cache implementation and MarkCachedResponses set to true -func NewTransport(c Cache) *Transport { - return &Transport{Cache: c, MarkCachedResponses: true} -} - -// Client returns an *http.Client that caches responses. -func (t *Transport) Client() *http.Client { - return &http.Client{Transport: t} -} - -// varyMatches will return false unless all of the cached values for the headers listed in Vary -// match the new request -func varyMatches(cachedResp *http.Response, req *http.Request) bool { - for _, header := range headerAllCommaSepValues(cachedResp.Header, "vary") { - header = http.CanonicalHeaderKey(header) - if header != "" && req.Header.Get(header) != cachedResp.Header.Get("X-Varied-"+header) { - return false - } - } - return true -} - -// RoundTrip takes a Request and returns a Response -// -// If there is a fresh Response already in cache, then it will be returned without connecting to -// the server. -// -// If there is a stale Response, then any validators it contains will be set on the new request -// to give the server a chance to respond with NotModified. If this happens, then the cached Response -// will be returned. -func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) { - cacheKey := cacheKey(req) - cacheable := (req.Method == "GET" || req.Method == "HEAD") && req.Header.Get("range") == "" - var cachedResp *http.Response - if cacheable { - cachedResp, err = CachedResponse(t.Cache, req) - } else { - // Need to invalidate an existing value - t.Cache.Delete(cacheKey) - } - - transport := t.Transport - if transport == nil { - transport = http.DefaultTransport - } - - if cacheable && cachedResp != nil && err == nil { - if t.MarkCachedResponses { - cachedResp.Header.Set(XFromCache, "1") - } - - if varyMatches(cachedResp, req) { - // Can only use cached value if the new request doesn't Vary significantly - freshness := getFreshness(cachedResp.Header, req.Header) - if freshness == fresh { - return cachedResp, nil - } - - if freshness == stale { - var req2 *http.Request - // Add validators if caller hasn't already done so - etag := cachedResp.Header.Get("etag") - if etag != "" && req.Header.Get("etag") == "" { - req2 = cloneRequest(req) - req2.Header.Set("if-none-match", etag) - } - lastModified := cachedResp.Header.Get("last-modified") - if lastModified != "" && req.Header.Get("last-modified") == "" { - if req2 == nil { - req2 = cloneRequest(req) - } - req2.Header.Set("if-modified-since", lastModified) - } - if req2 != nil { - req = req2 - } - } - } - - resp, err = transport.RoundTrip(req) - if err == nil && req.Method == "GET" && resp.StatusCode == http.StatusNotModified { - // Replace the 304 response with the one from cache, but update with some new headers - endToEndHeaders := getEndToEndHeaders(resp.Header) - for _, header := range endToEndHeaders { - cachedResp.Header[header] = resp.Header[header] - } - resp = cachedResp - } else if (err != nil || (cachedResp != nil && resp.StatusCode >= 500)) && - req.Method == "GET" && canStaleOnError(cachedResp.Header, req.Header) { - // In case of transport failure and stale-if-error activated, returns cached content - // when available - return cachedResp, nil - } else { - if err != nil || resp.StatusCode != http.StatusOK { - t.Cache.Delete(cacheKey) - } - if err != nil { - return nil, err - } - } - } else { - reqCacheControl := parseCacheControl(req.Header) - if _, ok := reqCacheControl["only-if-cached"]; ok { - resp = newGatewayTimeoutResponse(req) - } else { - resp, err = transport.RoundTrip(req) - if err != nil { - return nil, err - } - } - } - - if cacheable && canStore(parseCacheControl(req.Header), parseCacheControl(resp.Header)) { - for _, varyKey := range headerAllCommaSepValues(resp.Header, "vary") { - varyKey = http.CanonicalHeaderKey(varyKey) - fakeHeader := "X-Varied-" + varyKey - reqValue := req.Header.Get(varyKey) - if reqValue != "" { - resp.Header.Set(fakeHeader, reqValue) - } - } - switch req.Method { - case "GET": - // Delay caching until EOF is reached. - resp.Body = &cachingReadCloser{ - R: resp.Body, - OnEOF: func(r io.Reader) { - resp := *resp - resp.Body = ioutil.NopCloser(r) - respBytes, err := httputil.DumpResponse(&resp, true) - if err == nil { - t.Cache.Set(cacheKey, respBytes) - } - }, - } - default: - respBytes, err := httputil.DumpResponse(resp, true) - if err == nil { - t.Cache.Set(cacheKey, respBytes) - } - } - } else { - t.Cache.Delete(cacheKey) - } - return resp, nil -} - -// ErrNoDateHeader indicates that the HTTP headers contained no Date header. -var ErrNoDateHeader = errors.New("no Date header") - -// Date parses and returns the value of the Date header. -func Date(respHeaders http.Header) (date time.Time, err error) { - dateHeader := respHeaders.Get("date") - if dateHeader == "" { - err = ErrNoDateHeader - return - } - - return time.Parse(time.RFC1123, dateHeader) -} - -type realClock struct{} - -func (c *realClock) since(d time.Time) time.Duration { - return time.Since(d) -} - -type timer interface { - since(d time.Time) time.Duration -} - -var clock timer = &realClock{} - -// getFreshness will return one of fresh/stale/transparent based on the cache-control -// values of the request and the response -// -// fresh indicates the response can be returned -// stale indicates that the response needs validating before it is returned -// transparent indicates the response should not be used to fulfil the request -// -// Because this is only a private cache, 'public' and 'private' in cache-control aren't -// signficant. Similarly, smax-age isn't used. -func getFreshness(respHeaders, reqHeaders http.Header) (freshness int) { - respCacheControl := parseCacheControl(respHeaders) - reqCacheControl := parseCacheControl(reqHeaders) - if _, ok := reqCacheControl["no-cache"]; ok { - return transparent - } - if _, ok := respCacheControl["no-cache"]; ok { - return stale - } - if _, ok := reqCacheControl["only-if-cached"]; ok { - return fresh - } - - date, err := Date(respHeaders) - if err != nil { - return stale - } - currentAge := clock.since(date) - - var lifetime time.Duration - var zeroDuration time.Duration - - // If a response includes both an Expires header and a max-age directive, - // the max-age directive overrides the Expires header, even if the Expires header is more restrictive. - if maxAge, ok := respCacheControl["max-age"]; ok { - lifetime, err = time.ParseDuration(maxAge + "s") - if err != nil { - lifetime = zeroDuration - } - } else { - expiresHeader := respHeaders.Get("Expires") - if expiresHeader != "" { - expires, err := time.Parse(time.RFC1123, expiresHeader) - if err != nil { - lifetime = zeroDuration - } else { - lifetime = expires.Sub(date) - } - } - } - - if maxAge, ok := reqCacheControl["max-age"]; ok { - // the client is willing to accept a response whose age is no greater than the specified time in seconds - lifetime, err = time.ParseDuration(maxAge + "s") - if err != nil { - lifetime = zeroDuration - } - } - if minfresh, ok := reqCacheControl["min-fresh"]; ok { - // the client wants a response that will still be fresh for at least the specified number of seconds. - minfreshDuration, err := time.ParseDuration(minfresh + "s") - if err == nil { - currentAge = time.Duration(currentAge + minfreshDuration) - } - } - - if maxstale, ok := reqCacheControl["max-stale"]; ok { - // Indicates that the client is willing to accept a response that has exceeded its expiration time. - // If max-stale is assigned a value, then the client is willing to accept a response that has exceeded - // its expiration time by no more than the specified number of seconds. - // If no value is assigned to max-stale, then the client is willing to accept a stale response of any age. - // - // Responses served only because of a max-stale value are supposed to have a Warning header added to them, - // but that seems like a hassle, and is it actually useful? If so, then there needs to be a different - // return-value available here. - if maxstale == "" { - return fresh - } - maxstaleDuration, err := time.ParseDuration(maxstale + "s") - if err == nil { - currentAge = time.Duration(currentAge - maxstaleDuration) - } - } - - if lifetime > currentAge { - return fresh - } - - return stale -} - -// Returns true if either the request or the response includes the stale-if-error -// cache control extension: https://tools.ietf.org/html/rfc5861 -func canStaleOnError(respHeaders, reqHeaders http.Header) bool { - respCacheControl := parseCacheControl(respHeaders) - reqCacheControl := parseCacheControl(reqHeaders) - - var err error - lifetime := time.Duration(-1) - - if staleMaxAge, ok := respCacheControl["stale-if-error"]; ok { - if staleMaxAge != "" { - lifetime, err = time.ParseDuration(staleMaxAge + "s") - if err != nil { - return false - } - } else { - return true - } - } - if staleMaxAge, ok := reqCacheControl["stale-if-error"]; ok { - if staleMaxAge != "" { - lifetime, err = time.ParseDuration(staleMaxAge + "s") - if err != nil { - return false - } - } else { - return true - } - } - - if lifetime >= 0 { - date, err := Date(respHeaders) - if err != nil { - return false - } - currentAge := clock.since(date) - if lifetime > currentAge { - return true - } - } - - return false -} - -func getEndToEndHeaders(respHeaders http.Header) []string { - // These headers are always hop-by-hop - hopByHopHeaders := map[string]struct{}{ - "Connection": struct{}{}, - "Keep-Alive": struct{}{}, - "Proxy-Authenticate": struct{}{}, - "Proxy-Authorization": struct{}{}, - "Te": struct{}{}, - "Trailers": struct{}{}, - "Transfer-Encoding": struct{}{}, - "Upgrade": struct{}{}, - } - - for _, extra := range strings.Split(respHeaders.Get("connection"), ",") { - // any header listed in connection, if present, is also considered hop-by-hop - if strings.Trim(extra, " ") != "" { - hopByHopHeaders[http.CanonicalHeaderKey(extra)] = struct{}{} - } - } - endToEndHeaders := []string{} - for respHeader, _ := range respHeaders { - if _, ok := hopByHopHeaders[respHeader]; !ok { - endToEndHeaders = append(endToEndHeaders, respHeader) - } - } - return endToEndHeaders -} - -func canStore(reqCacheControl, respCacheControl cacheControl) (canStore bool) { - if _, ok := respCacheControl["no-store"]; ok { - return false - } - if _, ok := reqCacheControl["no-store"]; ok { - return false - } - return true -} - -func newGatewayTimeoutResponse(req *http.Request) *http.Response { - var braw bytes.Buffer - braw.WriteString("HTTP/1.1 504 Gateway Timeout\r\n\r\n") - resp, err := http.ReadResponse(bufio.NewReader(&braw), req) - if err != nil { - panic(err) - } - return resp -} - -// cloneRequest returns a clone of the provided *http.Request. -// The clone is a shallow copy of the struct and its Header map. -// (This function copyright goauth2 authors: https://code.google.com/p/goauth2) -func cloneRequest(r *http.Request) *http.Request { - // shallow copy of the struct - r2 := new(http.Request) - *r2 = *r - // deep copy of the Header - r2.Header = make(http.Header) - for k, s := range r.Header { - r2.Header[k] = s - } - return r2 -} - -type cacheControl map[string]string - -func parseCacheControl(headers http.Header) cacheControl { - cc := cacheControl{} - ccHeader := headers.Get("Cache-Control") - for _, part := range strings.Split(ccHeader, ",") { - part = strings.Trim(part, " ") - if part == "" { - continue - } - if strings.ContainsRune(part, '=') { - keyval := strings.Split(part, "=") - cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") - } else { - cc[part] = "" - } - } - return cc -} - -// headerAllCommaSepValues returns all comma-separated values (each -// with whitespace trimmed) for header name in headers. According to -// Section 4.2 of the HTTP/1.1 spec -// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2), -// values from multiple occurrences of a header should be concatenated, if -// the header's value is a comma-separated list. -func headerAllCommaSepValues(headers http.Header, name string) []string { - var vals []string - for _, val := range headers[http.CanonicalHeaderKey(name)] { - fields := strings.Split(val, ",") - for i, f := range fields { - fields[i] = strings.TrimSpace(f) - } - vals = append(vals, fields...) - } - return vals -} - -// cachingReadCloser is a wrapper around ReadCloser R that calls OnEOF -// handler with a full copy of the content read from R when EOF is -// reached. -type cachingReadCloser struct { - // Underlying ReadCloser. - R io.ReadCloser - // OnEOF is called with a copy of the content of R when EOF is reached. - OnEOF func(io.Reader) - - buf bytes.Buffer // buf stores a copy of the content of R. -} - -// Read reads the next len(p) bytes from R or until R is drained. The -// return value n is the number of bytes read. If R has no data to -// return, err is io.EOF and OnEOF is called with a full copy of what -// has been read so far. -func (r *cachingReadCloser) Read(p []byte) (n int, err error) { - n, err = r.R.Read(p) - r.buf.Write(p[:n]) - if err == io.EOF { - r.OnEOF(bytes.NewReader(r.buf.Bytes())) - } - return n, err -} - -func (r *cachingReadCloser) Close() error { - return r.R.Close() -} - -// NewMemoryCacheTransport returns a new Transport using the in-memory cache implementation -func NewMemoryCacheTransport() *Transport { - c := NewMemoryCache() - t := NewTransport(c) - return t -} diff --git a/discovery/vendor/github.com/gregjones/httpcache/leveldbcache/leveldbcache.go b/discovery/vendor/github.com/gregjones/httpcache/leveldbcache/leveldbcache.go deleted file mode 100644 index 9bcb7e27..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/leveldbcache/leveldbcache.go +++ /dev/null @@ -1,51 +0,0 @@ -// Package leveldbcache provides an implementation of httpcache.Cache that -// uses github.com/syndtr/goleveldb/leveldb -package leveldbcache - -import ( - "github.com/syndtr/goleveldb/leveldb" -) - -// Cache is an implementation of httpcache.Cache with leveldb storage -type Cache struct { - db *leveldb.DB -} - -// Get returns the response corresponding to key if present -func (c *Cache) Get(key string) (resp []byte, ok bool) { - var err error - resp, err = c.db.Get([]byte(key), nil) - if err != nil { - return []byte{}, false - } - return resp, true -} - -// Set saves a response to the cache as key -func (c *Cache) Set(key string, resp []byte) { - c.db.Put([]byte(key), resp, nil) -} - -// Delete removes the response with key from the cache -func (c *Cache) Delete(key string) { - c.db.Delete([]byte(key), nil) -} - -// New returns a new Cache that will store leveldb in path -func New(path string) (*Cache, error) { - cache := &Cache{} - - var err error - cache.db, err = leveldb.OpenFile(path, nil) - - if err != nil { - return nil, err - } - return cache, nil -} - -// NewWithDB returns a new Cache using the provided leveldb as underlying -// storage. -func NewWithDB(db *leveldb.DB) *Cache { - return &Cache{db} -} diff --git a/discovery/vendor/github.com/gregjones/httpcache/memcache/appengine.go b/discovery/vendor/github.com/gregjones/httpcache/memcache/appengine.go deleted file mode 100644 index e68d9bc0..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/memcache/appengine.go +++ /dev/null @@ -1,61 +0,0 @@ -// +build appengine - -// Package memcache provides an implementation of httpcache.Cache that uses App -// Engine's memcache package to store cached responses. -// -// When not built for Google App Engine, this package will provide an -// implementation that connects to a specified memcached server. See the -// memcache.go file in this package for details. -package memcache - -import ( - "appengine" - "appengine/memcache" -) - -// Cache is an implementation of httpcache.Cache that caches responses in App -// Engine's memcache. -type Cache struct { - appengine.Context -} - -// cacheKey modifies an httpcache key for use in memcache. Specifically, it -// prefixes keys to avoid collision with other data stored in memcache. -func cacheKey(key string) string { - return "httpcache:" + key -} - -// Get returns the response corresponding to key if present. -func (c *Cache) Get(key string) (resp []byte, ok bool) { - item, err := memcache.Get(c.Context, cacheKey(key)) - if err != nil { - if err != memcache.ErrCacheMiss { - c.Context.Errorf("error getting cached response: %v", err) - } - return nil, false - } - return item.Value, true -} - -// Set saves a response to the cache as key. -func (c *Cache) Set(key string, resp []byte) { - item := &memcache.Item{ - Key: cacheKey(key), - Value: resp, - } - if err := memcache.Set(c.Context, item); err != nil { - c.Context.Errorf("error caching response: %v", err) - } -} - -// Delete removes the response with key from the cache. -func (c *Cache) Delete(key string) { - if err := memcache.Delete(c.Context, cacheKey(key)); err != nil { - c.Context.Errorf("error deleting cached response: %v", err) - } -} - -// New returns a new Cache for the given context. -func New(ctx appengine.Context) *Cache { - return &Cache{ctx} -} diff --git a/discovery/vendor/github.com/gregjones/httpcache/memcache/memcache.go b/discovery/vendor/github.com/gregjones/httpcache/memcache/memcache.go deleted file mode 100644 index 462f0e54..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/memcache/memcache.go +++ /dev/null @@ -1,60 +0,0 @@ -// +build !appengine - -// Package memcache provides an implementation of httpcache.Cache that uses -// gomemcache to store cached responses. -// -// When built for Google App Engine, this package will provide an -// implementation that uses App Engine's memcache service. See the -// appengine.go file in this package for details. -package memcache - -import ( - "github.com/bradfitz/gomemcache/memcache" -) - -// Cache is an implementation of httpcache.Cache that caches responses in a -// memcache server. -type Cache struct { - *memcache.Client -} - -// cacheKey modifies an httpcache key for use in memcache. Specifically, it -// prefixes keys to avoid collision with other data stored in memcache. -func cacheKey(key string) string { - return "httpcache:" + key -} - -// Get returns the response corresponding to key if present. -func (c *Cache) Get(key string) (resp []byte, ok bool) { - item, err := c.Client.Get(cacheKey(key)) - if err != nil { - return nil, false - } - return item.Value, true -} - -// Set saves a response to the cache as key. -func (c *Cache) Set(key string, resp []byte) { - item := &memcache.Item{ - Key: cacheKey(key), - Value: resp, - } - c.Client.Set(item) -} - -// Delete removes the response with key from the cache. -func (c *Cache) Delete(key string) { - c.Client.Delete(cacheKey(key)) -} - -// New returns a new Cache using the provided memcache server(s) with equal -// weight. If a server is listed multiple times, it gets a proportional amount -// of weight. -func New(server ...string) *Cache { - return NewWithClient(memcache.New(server...)) -} - -// NewWithClient returns a new Cache with the given memcache client. -func NewWithClient(client *memcache.Client) *Cache { - return &Cache{client} -} diff --git a/discovery/vendor/github.com/gregjones/httpcache/redis/redis.go b/discovery/vendor/github.com/gregjones/httpcache/redis/redis.go deleted file mode 100644 index 3143d443..00000000 --- a/discovery/vendor/github.com/gregjones/httpcache/redis/redis.go +++ /dev/null @@ -1,43 +0,0 @@ -// Package redis provides a redis interface for http caching. -package redis - -import ( - "github.com/garyburd/redigo/redis" - "github.com/gregjones/httpcache" -) - -// cache is an implementation of httpcache.Cache that caches responses in a -// redis server. -type cache struct { - redis.Conn -} - -// cacheKey modifies an httpcache key for use in redis. Specifically, it -// prefixes keys to avoid collision with other data stored in redis. -func cacheKey(key string) string { - return "rediscache:" + key -} - -// Get returns the response corresponding to key if present. -func (c cache) Get(key string) (resp []byte, ok bool) { - item, err := redis.Bytes(c.Do("GET", cacheKey(key))) - if err != nil { - return nil, false - } - return item, true -} - -// Set saves a response to the cache as key. -func (c cache) Set(key string, resp []byte) { - c.Do("SET", cacheKey(key), resp) -} - -// Delete removes the response with key from the cache. -func (c cache) Delete(key string) { - c.Do("DEL", cacheKey(key)) -} - -// NewWithClient returns a new Cache with the given redis connection. -func NewWithClient(client redis.Conn) httpcache.Cache { - return cache{client} -} diff --git a/discovery/vendor/github.com/hashicorp/golang-lru/2q_test.go b/discovery/vendor/github.com/hashicorp/golang-lru/2q_test.go new file mode 100644 index 00000000..1b0f3518 --- /dev/null +++ b/discovery/vendor/github.com/hashicorp/golang-lru/2q_test.go @@ -0,0 +1,306 @@ +package lru + +import ( + "math/rand" + "testing" +) + +func Benchmark2Q_Rand(b *testing.B) { + l, err := New2Q(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + trace[i] = rand.Int63() % 32768 + } + + b.ResetTimer() + + var hit, miss int + for i := 0; i < 2*b.N; i++ { + if i%2 == 0 { + l.Add(trace[i], trace[i]) + } else { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func Benchmark2Q_Freq(b *testing.B) { + l, err := New2Q(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + if i%2 == 0 { + trace[i] = rand.Int63() % 16384 + } else { + trace[i] = rand.Int63() % 32768 + } + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + l.Add(trace[i], trace[i]) + } + var hit, miss int + for i := 0; i < b.N; i++ { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func Test2Q_RandomOps(t *testing.T) { + size := 128 + l, err := New2Q(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + n := 200000 + for i := 0; i < n; i++ { + key := rand.Int63() % 512 + r := rand.Int63() + switch r % 3 { + case 0: + l.Add(key, key) + case 1: + l.Get(key) + case 2: + l.Remove(key) + } + + if l.recent.Len()+l.frequent.Len() > size { + t.Fatalf("bad: recent: %d freq: %d", + l.recent.Len(), l.frequent.Len()) + } + } +} + +func Test2Q_Get_RecentToFrequent(t *testing.T) { + l, err := New2Q(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Touch all the entries, should be in t1 + for i := 0; i < 128; i++ { + l.Add(i, i) + } + if n := l.recent.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + + // Get should upgrade to t2 + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("missing: %d", i) + } + } + if n := l.recent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } + + // Get be from t2 + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("missing: %d", i) + } + } + if n := l.recent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } +} + +func Test2Q_Add_RecentToFrequent(t *testing.T) { + l, err := New2Q(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Add initially to recent + l.Add(1, 1) + if n := l.recent.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + + // Add should upgrade to frequent + l.Add(1, 1) + if n := l.recent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + + // Add should remain in frequent + l.Add(1, 1) + if n := l.recent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } +} + +func Test2Q_Add_RecentEvict(t *testing.T) { + l, err := New2Q(4) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Add 1,2,3,4,5 -> Evict 1 + l.Add(1, 1) + l.Add(2, 2) + l.Add(3, 3) + l.Add(4, 4) + l.Add(5, 5) + if n := l.recent.Len(); n != 4 { + t.Fatalf("bad: %d", n) + } + if n := l.recentEvict.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + + // Pull in the recently evicted + l.Add(1, 1) + if n := l.recent.Len(); n != 3 { + t.Fatalf("bad: %d", n) + } + if n := l.recentEvict.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + + // Add 6, should cause another recent evict + l.Add(6, 6) + if n := l.recent.Len(); n != 3 { + t.Fatalf("bad: %d", n) + } + if n := l.recentEvict.Len(); n != 2 { + t.Fatalf("bad: %d", n) + } + if n := l.frequent.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } +} + +func Test2Q(t *testing.T) { + l, err := New2Q(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + for i := 0; i < 256; i++ { + l.Add(i, i) + } + if l.Len() != 128 { + t.Fatalf("bad len: %v", l.Len()) + } + + for i, k := range l.Keys() { + if v, ok := l.Get(k); !ok || v != k || v != i+128 { + t.Fatalf("bad key: %v", k) + } + } + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if ok { + t.Fatalf("should be evicted") + } + } + for i := 128; i < 256; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("should not be evicted") + } + } + for i := 128; i < 192; i++ { + l.Remove(i) + _, ok := l.Get(i) + if ok { + t.Fatalf("should be deleted") + } + } + + l.Purge() + if l.Len() != 0 { + t.Fatalf("bad len: %v", l.Len()) + } + if _, ok := l.Get(200); ok { + t.Fatalf("should contain nothing") + } +} + +// Test that Contains doesn't update recent-ness +func Test2Q_Contains(t *testing.T) { + l, err := New2Q(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if !l.Contains(1) { + t.Errorf("1 should be contained") + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("Contains should not have updated recent-ness of 1") + } +} + +// Test that Peek doesn't update recent-ness +func Test2Q_Peek(t *testing.T) { + l, err := New2Q(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if v, ok := l.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1: %v, %v", v, ok) + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} diff --git a/discovery/vendor/github.com/hashicorp/golang-lru/arc_test.go b/discovery/vendor/github.com/hashicorp/golang-lru/arc_test.go new file mode 100644 index 00000000..e2d9b68c --- /dev/null +++ b/discovery/vendor/github.com/hashicorp/golang-lru/arc_test.go @@ -0,0 +1,377 @@ +package lru + +import ( + "math/rand" + "testing" + "time" +) + +func init() { + rand.Seed(time.Now().Unix()) +} + +func BenchmarkARC_Rand(b *testing.B) { + l, err := NewARC(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + trace[i] = rand.Int63() % 32768 + } + + b.ResetTimer() + + var hit, miss int + for i := 0; i < 2*b.N; i++ { + if i%2 == 0 { + l.Add(trace[i], trace[i]) + } else { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func BenchmarkARC_Freq(b *testing.B) { + l, err := NewARC(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + if i%2 == 0 { + trace[i] = rand.Int63() % 16384 + } else { + trace[i] = rand.Int63() % 32768 + } + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + l.Add(trace[i], trace[i]) + } + var hit, miss int + for i := 0; i < b.N; i++ { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func TestARC_RandomOps(t *testing.T) { + size := 128 + l, err := NewARC(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + n := 200000 + for i := 0; i < n; i++ { + key := rand.Int63() % 512 + r := rand.Int63() + switch r % 3 { + case 0: + l.Add(key, key) + case 1: + l.Get(key) + case 2: + l.Remove(key) + } + + if l.t1.Len()+l.t2.Len() > size { + t.Fatalf("bad: t1: %d t2: %d b1: %d b2: %d p: %d", + l.t1.Len(), l.t2.Len(), l.b1.Len(), l.b2.Len(), l.p) + } + if l.b1.Len()+l.b2.Len() > size { + t.Fatalf("bad: t1: %d t2: %d b1: %d b2: %d p: %d", + l.t1.Len(), l.t2.Len(), l.b1.Len(), l.b2.Len(), l.p) + } + } +} + +func TestARC_Get_RecentToFrequent(t *testing.T) { + l, err := NewARC(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Touch all the entries, should be in t1 + for i := 0; i < 128; i++ { + l.Add(i, i) + } + if n := l.t1.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + + // Get should upgrade to t2 + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("missing: %d", i) + } + } + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } + + // Get be from t2 + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("missing: %d", i) + } + } + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 128 { + t.Fatalf("bad: %d", n) + } +} + +func TestARC_Add_RecentToFrequent(t *testing.T) { + l, err := NewARC(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Add initially to t1 + l.Add(1, 1) + if n := l.t1.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + + // Add should upgrade to t2 + l.Add(1, 1) + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + + // Add should remain in t2 + l.Add(1, 1) + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } +} + +func TestARC_Adaptive(t *testing.T) { + l, err := NewARC(4) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Fill t1 + for i := 0; i < 4; i++ { + l.Add(i, i) + } + if n := l.t1.Len(); n != 4 { + t.Fatalf("bad: %d", n) + } + + // Move to t2 + l.Get(0) + l.Get(1) + if n := l.t2.Len(); n != 2 { + t.Fatalf("bad: %d", n) + } + + // Evict from t1 + l.Add(4, 4) + if n := l.b1.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + + // Current state + // t1 : (MRU) [4, 3] (LRU) + // t2 : (MRU) [1, 0] (LRU) + // b1 : (MRU) [2] (LRU) + // b2 : (MRU) [] (LRU) + + // Add 2, should cause hit on b1 + l.Add(2, 2) + if n := l.b1.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if l.p != 1 { + t.Fatalf("bad: %d", l.p) + } + if n := l.t2.Len(); n != 3 { + t.Fatalf("bad: %d", n) + } + + // Current state + // t1 : (MRU) [4] (LRU) + // t2 : (MRU) [2, 1, 0] (LRU) + // b1 : (MRU) [3] (LRU) + // b2 : (MRU) [] (LRU) + + // Add 4, should migrate to t2 + l.Add(4, 4) + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 4 { + t.Fatalf("bad: %d", n) + } + + // Current state + // t1 : (MRU) [] (LRU) + // t2 : (MRU) [4, 2, 1, 0] (LRU) + // b1 : (MRU) [3] (LRU) + // b2 : (MRU) [] (LRU) + + // Add 4, should evict to b2 + l.Add(5, 5) + if n := l.t1.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 3 { + t.Fatalf("bad: %d", n) + } + if n := l.b2.Len(); n != 1 { + t.Fatalf("bad: %d", n) + } + + // Current state + // t1 : (MRU) [5] (LRU) + // t2 : (MRU) [4, 2, 1] (LRU) + // b1 : (MRU) [3] (LRU) + // b2 : (MRU) [0] (LRU) + + // Add 0, should decrease p + l.Add(0, 0) + if n := l.t1.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if n := l.t2.Len(); n != 4 { + t.Fatalf("bad: %d", n) + } + if n := l.b1.Len(); n != 2 { + t.Fatalf("bad: %d", n) + } + if n := l.b2.Len(); n != 0 { + t.Fatalf("bad: %d", n) + } + if l.p != 0 { + t.Fatalf("bad: %d", l.p) + } + + // Current state + // t1 : (MRU) [] (LRU) + // t2 : (MRU) [0, 4, 2, 1] (LRU) + // b1 : (MRU) [5, 3] (LRU) + // b2 : (MRU) [0] (LRU) +} + +func TestARC(t *testing.T) { + l, err := NewARC(128) + if err != nil { + t.Fatalf("err: %v", err) + } + + for i := 0; i < 256; i++ { + l.Add(i, i) + } + if l.Len() != 128 { + t.Fatalf("bad len: %v", l.Len()) + } + + for i, k := range l.Keys() { + if v, ok := l.Get(k); !ok || v != k || v != i+128 { + t.Fatalf("bad key: %v", k) + } + } + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if ok { + t.Fatalf("should be evicted") + } + } + for i := 128; i < 256; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("should not be evicted") + } + } + for i := 128; i < 192; i++ { + l.Remove(i) + _, ok := l.Get(i) + if ok { + t.Fatalf("should be deleted") + } + } + + l.Purge() + if l.Len() != 0 { + t.Fatalf("bad len: %v", l.Len()) + } + if _, ok := l.Get(200); ok { + t.Fatalf("should contain nothing") + } +} + +// Test that Contains doesn't update recent-ness +func TestARC_Contains(t *testing.T) { + l, err := NewARC(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if !l.Contains(1) { + t.Errorf("1 should be contained") + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("Contains should not have updated recent-ness of 1") + } +} + +// Test that Peek doesn't update recent-ness +func TestARC_Peek(t *testing.T) { + l, err := NewARC(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if v, ok := l.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1: %v, %v", v, ok) + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} diff --git a/discovery/vendor/github.com/hashicorp/golang-lru/lru_test.go b/discovery/vendor/github.com/hashicorp/golang-lru/lru_test.go new file mode 100644 index 00000000..2b31218b --- /dev/null +++ b/discovery/vendor/github.com/hashicorp/golang-lru/lru_test.go @@ -0,0 +1,221 @@ +package lru + +import ( + "math/rand" + "testing" +) + +func BenchmarkLRU_Rand(b *testing.B) { + l, err := New(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + trace[i] = rand.Int63() % 32768 + } + + b.ResetTimer() + + var hit, miss int + for i := 0; i < 2*b.N; i++ { + if i%2 == 0 { + l.Add(trace[i], trace[i]) + } else { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func BenchmarkLRU_Freq(b *testing.B) { + l, err := New(8192) + if err != nil { + b.Fatalf("err: %v", err) + } + + trace := make([]int64, b.N*2) + for i := 0; i < b.N*2; i++ { + if i%2 == 0 { + trace[i] = rand.Int63() % 16384 + } else { + trace[i] = rand.Int63() % 32768 + } + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + l.Add(trace[i], trace[i]) + } + var hit, miss int + for i := 0; i < b.N; i++ { + _, ok := l.Get(trace[i]) + if ok { + hit++ + } else { + miss++ + } + } + b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss)) +} + +func TestLRU(t *testing.T) { + evictCounter := 0 + onEvicted := func(k interface{}, v interface{}) { + if k != v { + t.Fatalf("Evict values not equal (%v!=%v)", k, v) + } + evictCounter += 1 + } + l, err := NewWithEvict(128, onEvicted) + if err != nil { + t.Fatalf("err: %v", err) + } + + for i := 0; i < 256; i++ { + l.Add(i, i) + } + if l.Len() != 128 { + t.Fatalf("bad len: %v", l.Len()) + } + + if evictCounter != 128 { + t.Fatalf("bad evict count: %v", evictCounter) + } + + for i, k := range l.Keys() { + if v, ok := l.Get(k); !ok || v != k || v != i+128 { + t.Fatalf("bad key: %v", k) + } + } + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if ok { + t.Fatalf("should be evicted") + } + } + for i := 128; i < 256; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("should not be evicted") + } + } + for i := 128; i < 192; i++ { + l.Remove(i) + _, ok := l.Get(i) + if ok { + t.Fatalf("should be deleted") + } + } + + l.Get(192) // expect 192 to be last key in l.Keys() + + for i, k := range l.Keys() { + if (i < 63 && k != i+193) || (i == 63 && k != 192) { + t.Fatalf("out of order key: %v", k) + } + } + + l.Purge() + if l.Len() != 0 { + t.Fatalf("bad len: %v", l.Len()) + } + if _, ok := l.Get(200); ok { + t.Fatalf("should contain nothing") + } +} + +// test that Add returns true/false if an eviction occurred +func TestLRUAdd(t *testing.T) { + evictCounter := 0 + onEvicted := func(k interface{}, v interface{}) { + evictCounter += 1 + } + + l, err := NewWithEvict(1, onEvicted) + if err != nil { + t.Fatalf("err: %v", err) + } + + if l.Add(1, 1) == true || evictCounter != 0 { + t.Errorf("should not have an eviction") + } + if l.Add(2, 2) == false || evictCounter != 1 { + t.Errorf("should have an eviction") + } +} + +// test that Contains doesn't update recent-ness +func TestLRUContains(t *testing.T) { + l, err := New(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if !l.Contains(1) { + t.Errorf("1 should be contained") + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("Contains should not have updated recent-ness of 1") + } +} + +// test that Contains doesn't update recent-ness +func TestLRUContainsOrAdd(t *testing.T) { + l, err := New(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + contains, evict := l.ContainsOrAdd(1, 1) + if !contains { + t.Errorf("1 should be contained") + } + if evict { + t.Errorf("nothing should be evicted here") + } + + l.Add(3, 3) + contains, evict = l.ContainsOrAdd(1, 1) + if contains { + t.Errorf("1 should not have been contained") + } + if !evict { + t.Errorf("an eviction should have occurred") + } + if !l.Contains(1) { + t.Errorf("now 1 should be contained") + } +} + +// test that Peek doesn't update recent-ness +func TestLRUPeek(t *testing.T) { + l, err := New(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if v, ok := l.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1: %v, %v", v, ok) + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} diff --git a/discovery/vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go b/discovery/vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go new file mode 100644 index 00000000..a958934f --- /dev/null +++ b/discovery/vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go @@ -0,0 +1,167 @@ +package simplelru + +import "testing" + +func TestLRU(t *testing.T) { + evictCounter := 0 + onEvicted := func(k interface{}, v interface{}) { + if k != v { + t.Fatalf("Evict values not equal (%v!=%v)", k, v) + } + evictCounter += 1 + } + l, err := NewLRU(128, onEvicted) + if err != nil { + t.Fatalf("err: %v", err) + } + + for i := 0; i < 256; i++ { + l.Add(i, i) + } + if l.Len() != 128 { + t.Fatalf("bad len: %v", l.Len()) + } + + if evictCounter != 128 { + t.Fatalf("bad evict count: %v", evictCounter) + } + + for i, k := range l.Keys() { + if v, ok := l.Get(k); !ok || v != k || v != i+128 { + t.Fatalf("bad key: %v", k) + } + } + for i := 0; i < 128; i++ { + _, ok := l.Get(i) + if ok { + t.Fatalf("should be evicted") + } + } + for i := 128; i < 256; i++ { + _, ok := l.Get(i) + if !ok { + t.Fatalf("should not be evicted") + } + } + for i := 128; i < 192; i++ { + ok := l.Remove(i) + if !ok { + t.Fatalf("should be contained") + } + ok = l.Remove(i) + if ok { + t.Fatalf("should not be contained") + } + _, ok = l.Get(i) + if ok { + t.Fatalf("should be deleted") + } + } + + l.Get(192) // expect 192 to be last key in l.Keys() + + for i, k := range l.Keys() { + if (i < 63 && k != i+193) || (i == 63 && k != 192) { + t.Fatalf("out of order key: %v", k) + } + } + + l.Purge() + if l.Len() != 0 { + t.Fatalf("bad len: %v", l.Len()) + } + if _, ok := l.Get(200); ok { + t.Fatalf("should contain nothing") + } +} + +func TestLRU_GetOldest_RemoveOldest(t *testing.T) { + l, err := NewLRU(128, nil) + if err != nil { + t.Fatalf("err: %v", err) + } + for i := 0; i < 256; i++ { + l.Add(i, i) + } + k, _, ok := l.GetOldest() + if !ok { + t.Fatalf("missing") + } + if k.(int) != 128 { + t.Fatalf("bad: %v", k) + } + + k, _, ok = l.RemoveOldest() + if !ok { + t.Fatalf("missing") + } + if k.(int) != 128 { + t.Fatalf("bad: %v", k) + } + + k, _, ok = l.RemoveOldest() + if !ok { + t.Fatalf("missing") + } + if k.(int) != 129 { + t.Fatalf("bad: %v", k) + } +} + +// Test that Add returns true/false if an eviction occurred +func TestLRU_Add(t *testing.T) { + evictCounter := 0 + onEvicted := func(k interface{}, v interface{}) { + evictCounter += 1 + } + + l, err := NewLRU(1, onEvicted) + if err != nil { + t.Fatalf("err: %v", err) + } + + if l.Add(1, 1) == true || evictCounter != 0 { + t.Errorf("should not have an eviction") + } + if l.Add(2, 2) == false || evictCounter != 1 { + t.Errorf("should have an eviction") + } +} + +// Test that Contains doesn't update recent-ness +func TestLRU_Contains(t *testing.T) { + l, err := NewLRU(2, nil) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if !l.Contains(1) { + t.Errorf("1 should be contained") + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("Contains should not have updated recent-ness of 1") + } +} + +// Test that Peek doesn't update recent-ness +func TestLRU_Peek(t *testing.T) { + l, err := NewLRU(2, nil) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if v, ok := l.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1: %v, %v", v, ok) + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} diff --git a/discovery/vendor/github.com/howeyc/gopass/.travis.yml b/discovery/vendor/github.com/howeyc/gopass/.travis.yml new file mode 100644 index 00000000..cc5d509f --- /dev/null +++ b/discovery/vendor/github.com/howeyc/gopass/.travis.yml @@ -0,0 +1,11 @@ +language: go + +os: + - linux + - osx + +go: + - 1.3 + - 1.4 + - 1.5 + - tip diff --git a/discovery/vendor/github.com/howeyc/gopass/pass_test.go b/discovery/vendor/github.com/howeyc/gopass/pass_test.go new file mode 100644 index 00000000..7ac31513 --- /dev/null +++ b/discovery/vendor/github.com/howeyc/gopass/pass_test.go @@ -0,0 +1,225 @@ +package gopass + +import ( + "bufio" + "bytes" + "fmt" + "io" + "io/ioutil" + "os" + "testing" + "time" +) + +// TestGetPasswd tests the password creation and output based on a byte buffer +// as input to mock the underlying getch() methods. +func TestGetPasswd(t *testing.T) { + type testData struct { + input []byte + + // Due to how backspaces are written, it is easier to manually write + // each expected output for the masked cases. + masked string + password string + byesLeft int + reason string + } + + ds := []testData{ + testData{[]byte("abc\n"), "***", "abc", 0, "Password parsing should stop at \\n"}, + testData{[]byte("abc\r"), "***", "abc", 0, "Password parsing should stop at \\r"}, + testData{[]byte("a\nbc\n"), "*", "a", 3, "Password parsing should stop at \\n"}, + testData{[]byte("*!]|\n"), "****", "*!]|", 0, "Special characters shouldn't affect the password."}, + + testData{[]byte("abc\r\n"), "***", "abc", 1, + "Password parsing should stop at \\r; Windows LINE_MODE should be unset so \\r is not converted to \\r\\n."}, + + testData{[]byte{'a', 'b', 'c', 8, '\n'}, "***\b \b", "ab", 0, "Backspace byte should remove the last read byte."}, + testData{[]byte{'a', 'b', 127, 'c', '\n'}, "**\b \b*", "ac", 0, "Delete byte should remove the last read byte."}, + testData{[]byte{'a', 'b', 127, 'c', 8, 127, '\n'}, "**\b \b*\b \b\b \b", "", 0, "Successive deletes continue to delete."}, + testData{[]byte{8, 8, 8, '\n'}, "", "", 0, "Deletes before characters are noops."}, + testData{[]byte{8, 8, 8, 'a', 'b', 'c', '\n'}, "***", "abc", 0, "Deletes before characters are noops."}, + + testData{[]byte{'a', 'b', 0, 'c', '\n'}, "***", "abc", 0, + "Nil byte should be ignored due; may get unintended nil bytes from syscalls on Windows."}, + } + + // Redirecting output for tests as they print to os.Stdout but we want to + // capture and test the output. + for _, masked := range []bool{true, false} { + for _, d := range ds { + pipeBytesToStdin(d.input) + + r, w, err := os.Pipe() + if err != nil { + t.Fatal(err.Error()) + } + + result, err := getPasswd("", masked, os.Stdin, w) + if err != nil { + t.Errorf("Error getting password: %s", err.Error()) + } + leftOnBuffer := flushStdin() + + // Test output (masked and unmasked). Delete/backspace actually + // deletes, overwrites and deletes again. As a result, we need to + // remove those from the pipe afterwards to mimic the console's + // interpretation of those bytes. + w.Close() + output, err := ioutil.ReadAll(r) + if err != nil { + t.Fatal(err.Error()) + } + var expectedOutput []byte + if masked { + expectedOutput = []byte(d.masked) + } else { + expectedOutput = []byte("") + } + if bytes.Compare(expectedOutput, output) != 0 { + t.Errorf("Expected output to equal %v (%q) but got %v (%q) instead when masked=%v. %s", expectedOutput, string(expectedOutput), output, string(output), masked, d.reason) + } + + if string(result) != d.password { + t.Errorf("Expected %q but got %q instead when masked=%v. %s", d.password, result, masked, d.reason) + } + + if leftOnBuffer != d.byesLeft { + t.Errorf("Expected %v bytes left on buffer but instead got %v when masked=%v. %s", d.byesLeft, leftOnBuffer, masked, d.reason) + } + } + } +} + +// TestPipe ensures we get our expected pipe behavior. +func TestPipe(t *testing.T) { + type testData struct { + input string + password string + expError error + } + ds := []testData{ + testData{"abc", "abc", io.EOF}, + testData{"abc\n", "abc", nil}, + testData{"abc\r", "abc", nil}, + testData{"abc\r\n", "abc", nil}, + } + + for _, d := range ds { + _, err := pipeToStdin(d.input) + if err != nil { + t.Log("Error writing input to stdin:", err) + t.FailNow() + } + pass, err := GetPasswd() + if string(pass) != d.password { + t.Errorf("Expected %q but got %q instead.", d.password, string(pass)) + } + if err != d.expError { + t.Errorf("Expected %v but got %q instead.", d.expError, err) + } + } +} + +// flushStdin reads from stdin for .5 seconds to ensure no bytes are left on +// the buffer. Returns the number of bytes read. +func flushStdin() int { + ch := make(chan byte) + go func(ch chan byte) { + reader := bufio.NewReader(os.Stdin) + for { + b, err := reader.ReadByte() + if err != nil { // Maybe log non io.EOF errors, if you want + close(ch) + return + } + ch <- b + } + close(ch) + }(ch) + + numBytes := 0 + for { + select { + case _, ok := <-ch: + if !ok { + return numBytes + } + numBytes++ + case <-time.After(500 * time.Millisecond): + return numBytes + } + } + return numBytes +} + +// pipeToStdin pipes the given string onto os.Stdin by replacing it with an +// os.Pipe. The write end of the pipe is closed so that EOF is read after the +// final byte. +func pipeToStdin(s string) (int, error) { + pipeReader, pipeWriter, err := os.Pipe() + if err != nil { + fmt.Println("Error getting os pipes:", err) + os.Exit(1) + } + os.Stdin = pipeReader + w, err := pipeWriter.WriteString(s) + pipeWriter.Close() + return w, err +} + +func pipeBytesToStdin(b []byte) (int, error) { + return pipeToStdin(string(b)) +} + +// TestGetPasswd_Err tests errors are properly handled from getch() +func TestGetPasswd_Err(t *testing.T) { + var inBuffer *bytes.Buffer + getch = func(io.Reader) (byte, error) { + b, err := inBuffer.ReadByte() + if err != nil { + return 13, err + } + if b == 'z' { + return 'z', fmt.Errorf("Forced error; byte returned should not be considered accurate.") + } + return b, nil + } + defer func() { getch = defaultGetCh }() + + for input, expectedPassword := range map[string]string{"abc": "abc", "abzc": "ab"} { + inBuffer = bytes.NewBufferString(input) + p, err := GetPasswdMasked() + if string(p) != expectedPassword { + t.Errorf("Expected %q but got %q instead.", expectedPassword, p) + } + if err == nil { + t.Errorf("Expected error to be returned.") + } + } +} + +func TestMaxPasswordLength(t *testing.T) { + type testData struct { + input []byte + expectedErr error + + // Helper field to output in case of failure; rather than hundreds of + // bytes. + inputDesc string + } + + ds := []testData{ + testData{append(bytes.Repeat([]byte{'a'}, maxLength), '\n'), nil, fmt.Sprintf("%v 'a' bytes followed by a newline", maxLength)}, + testData{append(bytes.Repeat([]byte{'a'}, maxLength+1), '\n'), ErrMaxLengthExceeded, fmt.Sprintf("%v 'a' bytes followed by a newline", maxLength+1)}, + testData{append(bytes.Repeat([]byte{0x00}, maxLength+1), '\n'), ErrMaxLengthExceeded, fmt.Sprintf("%v 0x00 bytes followed by a newline", maxLength+1)}, + } + + for _, d := range ds { + pipeBytesToStdin(d.input) + _, err := GetPasswd() + if err != d.expectedErr { + t.Errorf("Expected error to be %v; isntead got %v from %v", d.expectedErr, err, d.inputDesc) + } + } +} diff --git a/discovery/vendor/github.com/imdario/mergo/.travis.yml b/discovery/vendor/github.com/imdario/mergo/.travis.yml new file mode 100644 index 00000000..9d91c633 --- /dev/null +++ b/discovery/vendor/github.com/imdario/mergo/.travis.yml @@ -0,0 +1,2 @@ +language: go +install: go get -t diff --git a/discovery/vendor/github.com/imdario/mergo/issue17_test.go b/discovery/vendor/github.com/imdario/mergo/issue17_test.go new file mode 100644 index 00000000..0ee96f37 --- /dev/null +++ b/discovery/vendor/github.com/imdario/mergo/issue17_test.go @@ -0,0 +1,25 @@ +package mergo + +import ( + "encoding/json" + "testing" +) + +var ( + request = `{"timestamp":null, "name": "foo"}` + maprequest = map[string]interface{}{ + "timestamp": nil, + "name": "foo", + "newStuff": "foo", + } +) + +func TestIssue17MergeWithOverwrite(t *testing.T) { + var something map[string]interface{} + if err := json.Unmarshal([]byte(request), &something); err != nil { + t.Errorf("Error while Unmarshalling maprequest %s", err) + } + if err := MergeWithOverwrite(&something, maprequest); err != nil { + t.Errorf("Error while merging %s", err) + } +} diff --git a/discovery/vendor/github.com/imdario/mergo/issue23_test.go b/discovery/vendor/github.com/imdario/mergo/issue23_test.go new file mode 100644 index 00000000..9c325841 --- /dev/null +++ b/discovery/vendor/github.com/imdario/mergo/issue23_test.go @@ -0,0 +1,27 @@ +package mergo + +import ( + "testing" + "time" +) + +type document struct { + Created *time.Time +} + +func TestIssue23MergeWithOverwrite(t *testing.T) { + now := time.Now() + dst := document{ + &now, + } + expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + src := document{ + &expected, + } + if err := MergeWithOverwrite(&dst, src); err != nil { + t.Errorf("Error while merging %s", err) + } + if dst.Created != src.Created { + t.Fatalf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created) + } +} diff --git a/discovery/vendor/github.com/imdario/mergo/issue38_test.go b/discovery/vendor/github.com/imdario/mergo/issue38_test.go new file mode 100644 index 00000000..286b68cb --- /dev/null +++ b/discovery/vendor/github.com/imdario/mergo/issue38_test.go @@ -0,0 +1,59 @@ +package mergo + +import ( + "testing" + "time" +) + +type structWithoutTimePointer struct { + Created time.Time +} + +func TestIssue38Merge(t *testing.T) { + dst := structWithoutTimePointer{ + time.Now(), + } + + expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + src := structWithoutTimePointer{ + expected, + } + if err := Merge(&dst, src); err != nil { + t.Errorf("Error while merging %s", err) + } + if dst.Created == src.Created { + t.Fatalf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created) + } +} + +func TestIssue38MergeEmptyStruct(t *testing.T) { + dst := structWithoutTimePointer{} + + expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + src := structWithoutTimePointer{ + expected, + } + if err := Merge(&dst, src); err != nil { + t.Errorf("Error while merging %s", err) + } + if dst.Created == src.Created { + t.Fatalf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created) + } +} + +func TestIssue38MergeWithOverwrite(t *testing.T) { + dst := structWithoutTimePointer{ + time.Now(), + } + + expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + src := structWithoutTimePointer{ + expected, + } + if err := MergeWithOverwrite(&dst, src); err != nil { + t.Errorf("Error while merging %s", err) + } + if dst.Created != src.Created { + t.Fatalf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created) + } +} diff --git a/discovery/vendor/github.com/imdario/mergo/mergo_test.go b/discovery/vendor/github.com/imdario/mergo/mergo_test.go new file mode 100644 index 00000000..e167c332 --- /dev/null +++ b/discovery/vendor/github.com/imdario/mergo/mergo_test.go @@ -0,0 +1,662 @@ +// Copyright 2013 Dario Castañé. All rights reserved. +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mergo + +import ( + "gopkg.in/yaml.v2" + "io/ioutil" + "reflect" + "testing" + "time" +) + +type simpleTest struct { + Value int +} + +type complexTest struct { + St simpleTest + sz int + ID string +} + +type mapTest struct { + M map[int]int +} + +type ifcTest struct { + I interface{} +} + +type moreComplextText struct { + Ct complexTest + St simpleTest + Nt simpleTest +} + +type pointerTest struct { + C *simpleTest +} + +type sliceTest struct { + S []int +} + +func TestKb(t *testing.T) { + type testStruct struct { + Name string + KeyValue map[string]interface{} + } + + akv := make(map[string]interface{}) + akv["Key1"] = "not value 1" + akv["Key2"] = "value2" + a := testStruct{} + a.Name = "A" + a.KeyValue = akv + + bkv := make(map[string]interface{}) + bkv["Key1"] = "value1" + bkv["Key3"] = "value3" + b := testStruct{} + b.Name = "B" + b.KeyValue = bkv + + ekv := make(map[string]interface{}) + ekv["Key1"] = "value1" + ekv["Key2"] = "value2" + ekv["Key3"] = "value3" + expected := testStruct{} + expected.Name = "B" + expected.KeyValue = ekv + + Merge(&b, a) + + if !reflect.DeepEqual(b, expected) { + t.Errorf("Actual: %#v did not match \nExpected: %#v", b, expected) + } +} + +func TestNil(t *testing.T) { + if err := Merge(nil, nil); err != ErrNilArguments { + t.Fail() + } +} + +func TestDifferentTypes(t *testing.T) { + a := simpleTest{42} + b := 42 + if err := Merge(&a, b); err != ErrDifferentArgumentsTypes { + t.Fail() + } +} + +func TestSimpleStruct(t *testing.T) { + a := simpleTest{} + b := simpleTest{42} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if a.Value != 42 { + t.Fatalf("b not merged in properly: a.Value(%d) != b.Value(%d)", a.Value, b.Value) + } + if !reflect.DeepEqual(a, b) { + t.FailNow() + } +} + +func TestComplexStruct(t *testing.T) { + a := complexTest{} + a.ID = "athing" + b := complexTest{simpleTest{42}, 1, "bthing"} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if a.St.Value != 42 { + t.Fatalf("b not merged in properly: a.St.Value(%d) != b.St.Value(%d)", a.St.Value, b.St.Value) + } + if a.sz == 1 { + t.Fatalf("a's private field sz not preserved from merge: a.sz(%d) == b.sz(%d)", a.sz, b.sz) + } + if a.ID == b.ID { + t.Fatalf("a's field ID merged unexpectedly: a.ID(%s) == b.ID(%s)", a.ID, b.ID) + } +} + +func TestComplexStructWithOverwrite(t *testing.T) { + a := complexTest{simpleTest{1}, 1, "do-not-overwrite-with-empty-value"} + b := complexTest{simpleTest{42}, 2, ""} + + expect := complexTest{simpleTest{42}, 1, "do-not-overwrite-with-empty-value"} + if err := MergeWithOverwrite(&a, b); err != nil { + t.FailNow() + } + + if !reflect.DeepEqual(a, expect) { + t.Fatalf("Test failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", a, expect) + } +} + +func TestPointerStruct(t *testing.T) { + s1 := simpleTest{} + s2 := simpleTest{19} + a := pointerTest{&s1} + b := pointerTest{&s2} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if a.C.Value != b.C.Value { + t.Fatalf("b not merged in properly: a.C.Value(%d) != b.C.Value(%d)", a.C.Value, b.C.Value) + } +} + +type embeddingStruct struct { + embeddedStruct +} + +type embeddedStruct struct { + A string +} + +func TestEmbeddedStruct(t *testing.T) { + tests := []struct { + src embeddingStruct + dst embeddingStruct + expected embeddingStruct + }{ + { + src: embeddingStruct{ + embeddedStruct{"foo"}, + }, + dst: embeddingStruct{ + embeddedStruct{""}, + }, + expected: embeddingStruct{ + embeddedStruct{"foo"}, + }, + }, + { + src: embeddingStruct{ + embeddedStruct{""}, + }, + dst: embeddingStruct{ + embeddedStruct{"bar"}, + }, + expected: embeddingStruct{ + embeddedStruct{"bar"}, + }, + }, + { + src: embeddingStruct{ + embeddedStruct{"foo"}, + }, + dst: embeddingStruct{ + embeddedStruct{"bar"}, + }, + expected: embeddingStruct{ + embeddedStruct{"bar"}, + }, + }, + } + + for _, test := range tests { + err := Merge(&test.dst, test.src) + if err != nil { + t.Errorf("unexpected error: %v", err) + continue + } + if !reflect.DeepEqual(test.dst, test.expected) { + t.Errorf("unexpected output\nexpected:\n%+v\nsaw:\n%+v\n", test.expected, test.dst) + } + } +} + +func TestPointerStructNil(t *testing.T) { + a := pointerTest{nil} + b := pointerTest{&simpleTest{19}} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if a.C.Value != b.C.Value { + t.Fatalf("b not merged in a properly: a.C.Value(%d) != b.C.Value(%d)", a.C.Value, b.C.Value) + } +} + +func TestSliceStruct(t *testing.T) { + a := sliceTest{} + b := sliceTest{[]int{1, 2, 3}} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if len(b.S) != 3 { + t.FailNow() + } + if len(a.S) != len(b.S) { + t.Fatalf("b not merged in a proper way %d != %d", len(a.S), len(b.S)) + } + + a = sliceTest{[]int{1}} + b = sliceTest{[]int{1, 2, 3}} + if err := Merge(&a, b); err != nil { + t.FailNow() + } + if len(a.S) != 1 { + t.FailNow() + } + if len(a.S) == len(b.S) { + t.Fatalf("b merged unexpectedly %d != %d", len(a.S), len(b.S)) + } +} + +func TestEmptyMaps(t *testing.T) { + a := mapTest{} + b := mapTest{ + map[int]int{}, + } + if err := Merge(&a, b); err != nil { + t.Fail() + } + if !reflect.DeepEqual(a, b) { + t.FailNow() + } +} + +func TestEmptyToEmptyMaps(t *testing.T) { + a := mapTest{} + b := mapTest{} + if err := Merge(&a, b); err != nil { + t.Fail() + } + if !reflect.DeepEqual(a, b) { + t.FailNow() + } +} + +func TestEmptyToNotEmptyMaps(t *testing.T) { + a := mapTest{map[int]int{ + 1: 2, + 3: 4, + }} + aa := mapTest{map[int]int{ + 1: 2, + 3: 4, + }} + b := mapTest{ + map[int]int{}, + } + if err := Merge(&a, b); err != nil { + t.Fail() + } + if !reflect.DeepEqual(a, aa) { + t.FailNow() + } +} + +func TestMapsWithOverwrite(t *testing.T) { + m := map[string]simpleTest{ + "a": {}, // overwritten by 16 + "b": {42}, // not overwritten by empty value + "c": {13}, // overwritten by 12 + "d": {61}, + } + n := map[string]simpleTest{ + "a": {16}, + "b": {}, + "c": {12}, + "e": {14}, + } + expect := map[string]simpleTest{ + "a": {16}, + "b": {}, + "c": {12}, + "d": {61}, + "e": {14}, + } + + if err := MergeWithOverwrite(&m, n); err != nil { + t.Fatalf(err.Error()) + } + + if !reflect.DeepEqual(m, expect) { + t.Fatalf("Test failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", m, expect) + } +} + +func TestMaps(t *testing.T) { + m := map[string]simpleTest{ + "a": {}, + "b": {42}, + "c": {13}, + "d": {61}, + } + n := map[string]simpleTest{ + "a": {16}, + "b": {}, + "c": {12}, + "e": {14}, + } + expect := map[string]simpleTest{ + "a": {0}, + "b": {42}, + "c": {13}, + "d": {61}, + "e": {14}, + } + + if err := Merge(&m, n); err != nil { + t.Fatalf(err.Error()) + } + + if !reflect.DeepEqual(m, expect) { + t.Fatalf("Test failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", m, expect) + } + if m["a"].Value != 0 { + t.Fatalf(`n merged in m because I solved non-addressable map values TODO: m["a"].Value(%d) != n["a"].Value(%d)`, m["a"].Value, n["a"].Value) + } + if m["b"].Value != 42 { + t.Fatalf(`n wrongly merged in m: m["b"].Value(%d) != n["b"].Value(%d)`, m["b"].Value, n["b"].Value) + } + if m["c"].Value != 13 { + t.Fatalf(`n overwritten in m: m["c"].Value(%d) != n["c"].Value(%d)`, m["c"].Value, n["c"].Value) + } +} + +func TestYAMLMaps(t *testing.T) { + thing := loadYAML("testdata/thing.yml") + license := loadYAML("testdata/license.yml") + ft := thing["fields"].(map[interface{}]interface{}) + fl := license["fields"].(map[interface{}]interface{}) + // license has one extra field (site) and another already existing in thing (author) that Mergo won't override. + expectedLength := len(ft) + len(fl) - 1 + if err := Merge(&license, thing); err != nil { + t.Fatal(err.Error()) + } + currentLength := len(license["fields"].(map[interface{}]interface{})) + if currentLength != expectedLength { + t.Fatalf(`thing not merged in license properly, license must have %d elements instead of %d`, expectedLength, currentLength) + } + fields := license["fields"].(map[interface{}]interface{}) + if _, ok := fields["id"]; !ok { + t.Fatalf(`thing not merged in license properly, license must have a new id field from thing`) + } +} + +func TestTwoPointerValues(t *testing.T) { + a := &simpleTest{} + b := &simpleTest{42} + if err := Merge(a, b); err != nil { + t.Fatalf(`Boom. You crossed the streams: %s`, err) + } +} + +func TestMap(t *testing.T) { + a := complexTest{} + a.ID = "athing" + c := moreComplextText{a, simpleTest{}, simpleTest{}} + b := map[string]interface{}{ + "ct": map[string]interface{}{ + "st": map[string]interface{}{ + "value": 42, + }, + "sz": 1, + "id": "bthing", + }, + "st": &simpleTest{144}, // Mapping a reference + "zt": simpleTest{299}, // Mapping a missing field (zt doesn't exist) + "nt": simpleTest{3}, + } + if err := Map(&c, b); err != nil { + t.FailNow() + } + m := b["ct"].(map[string]interface{}) + n := m["st"].(map[string]interface{}) + o := b["st"].(*simpleTest) + p := b["nt"].(simpleTest) + if c.Ct.St.Value != 42 { + t.Fatalf("b not merged in properly: c.Ct.St.Value(%d) != b.Ct.St.Value(%d)", c.Ct.St.Value, n["value"]) + } + if c.St.Value != 144 { + t.Fatalf("b not merged in properly: c.St.Value(%d) != b.St.Value(%d)", c.St.Value, o.Value) + } + if c.Nt.Value != 3 { + t.Fatalf("b not merged in properly: c.Nt.Value(%d) != b.Nt.Value(%d)", c.St.Value, p.Value) + } + if c.Ct.sz == 1 { + t.Fatalf("a's private field sz not preserved from merge: c.Ct.sz(%d) == b.Ct.sz(%d)", c.Ct.sz, m["sz"]) + } + if c.Ct.ID == m["id"] { + t.Fatalf("a's field ID merged unexpectedly: c.Ct.ID(%s) == b.Ct.ID(%s)", c.Ct.ID, m["id"]) + } +} + +func TestSimpleMap(t *testing.T) { + a := simpleTest{} + b := map[string]interface{}{ + "value": 42, + } + if err := Map(&a, b); err != nil { + t.FailNow() + } + if a.Value != 42 { + t.Fatalf("b not merged in properly: a.Value(%d) != b.Value(%v)", a.Value, b["value"]) + } +} + +func TestIfcMap(t *testing.T) { + a := ifcTest{} + b := ifcTest{42} + if err := Map(&a, b); err != nil { + t.FailNow() + } + if a.I != 42 { + t.Fatalf("b not merged in properly: a.I(%d) != b.I(%d)", a.I, b.I) + } + if !reflect.DeepEqual(a, b) { + t.FailNow() + } +} + +func TestIfcMapNoOverwrite(t *testing.T) { + a := ifcTest{13} + b := ifcTest{42} + if err := Map(&a, b); err != nil { + t.FailNow() + } + if a.I != 13 { + t.Fatalf("a not left alone: a.I(%d) == b.I(%d)", a.I, b.I) + } +} + +func TestIfcMapWithOverwrite(t *testing.T) { + a := ifcTest{13} + b := ifcTest{42} + if err := MapWithOverwrite(&a, b); err != nil { + t.FailNow() + } + if a.I != 42 { + t.Fatalf("b not merged in properly: a.I(%d) != b.I(%d)", a.I, b.I) + } + if !reflect.DeepEqual(a, b) { + t.FailNow() + } +} + +type pointerMapTest struct { + A int + hidden int + B *simpleTest +} + +func TestBackAndForth(t *testing.T) { + pt := pointerMapTest{42, 1, &simpleTest{66}} + m := make(map[string]interface{}) + if err := Map(&m, pt); err != nil { + t.FailNow() + } + var ( + v interface{} + ok bool + ) + if v, ok = m["a"]; v.(int) != pt.A || !ok { + t.Fatalf("pt not merged in properly: m[`a`](%d) != pt.A(%d)", v, pt.A) + } + if v, ok = m["b"]; !ok { + t.Fatalf("pt not merged in properly: B is missing in m") + } + var st *simpleTest + if st = v.(*simpleTest); st.Value != 66 { + t.Fatalf("something went wrong while mapping pt on m, B wasn't copied") + } + bpt := pointerMapTest{} + if err := Map(&bpt, m); err != nil { + t.Fatal(err) + } + if bpt.A != pt.A { + t.Fatalf("pt not merged in properly: bpt.A(%d) != pt.A(%d)", bpt.A, pt.A) + } + if bpt.hidden == pt.hidden { + t.Fatalf("pt unexpectedly merged: bpt.hidden(%d) == pt.hidden(%d)", bpt.hidden, pt.hidden) + } + if bpt.B.Value != pt.B.Value { + t.Fatalf("pt not merged in properly: bpt.B.Value(%d) != pt.B.Value(%d)", bpt.B.Value, pt.B.Value) + } +} + +func TestEmbeddedPointerUnpacking(t *testing.T) { + tests := []struct{ input pointerMapTest }{ + {pointerMapTest{42, 1, nil}}, + {pointerMapTest{42, 1, &simpleTest{66}}}, + } + newValue := 77 + m := map[string]interface{}{ + "b": map[string]interface{}{ + "value": newValue, + }, + } + for _, test := range tests { + pt := test.input + if err := MapWithOverwrite(&pt, m); err != nil { + t.FailNow() + } + if pt.B.Value != newValue { + t.Fatalf("pt not mapped properly: pt.A.Value(%d) != m[`b`][`value`](%d)", pt.B.Value, newValue) + } + + } +} + +type structWithTimePointer struct { + Birth *time.Time +} + +func TestTime(t *testing.T) { + now := time.Now() + dataStruct := structWithTimePointer{ + Birth: &now, + } + dataMap := map[string]interface{}{ + "Birth": &now, + } + b := structWithTimePointer{} + if err := Merge(&b, dataStruct); err != nil { + t.FailNow() + } + if b.Birth.IsZero() { + t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)", b.Birth, dataStruct.Birth) + } + if b.Birth != dataStruct.Birth { + t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)", b.Birth, dataStruct.Birth) + } + b = structWithTimePointer{} + if err := Map(&b, dataMap); err != nil { + t.FailNow() + } + if b.Birth.IsZero() { + t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataMap['Birth'](%v)", b.Birth, dataMap["Birth"]) + } +} + +type simpleNested struct { + A int +} + +type structWithNestedPtrValueMap struct { + NestedPtrValue map[string]*simpleNested +} + +func TestNestedPtrValueInMap(t *testing.T) { + src := &structWithNestedPtrValueMap{ + NestedPtrValue: map[string]*simpleNested{ + "x": { + A: 1, + }, + }, + } + dst := &structWithNestedPtrValueMap{ + NestedPtrValue: map[string]*simpleNested{ + "x": {}, + }, + } + if err := Map(dst, src); err != nil { + t.FailNow() + } + if dst.NestedPtrValue["x"].A == 0 { + t.Fatalf("Nested Ptr value not merged in properly: dst.NestedPtrValue[\"x\"].A(%v) != src.NestedPtrValue[\"x\"].A(%v)", dst.NestedPtrValue["x"].A, src.NestedPtrValue["x"].A) + } +} + +func loadYAML(path string) (m map[string]interface{}) { + m = make(map[string]interface{}) + raw, _ := ioutil.ReadFile(path) + _ = yaml.Unmarshal(raw, &m) + return +} + +type structWithMap struct { + m map[string]structWithUnexportedProperty +} + +type structWithUnexportedProperty struct { + s string +} + +func TestUnexportedProperty(t *testing.T) { + a := structWithMap{map[string]structWithUnexportedProperty{ + "key": structWithUnexportedProperty{"hello"}, + }} + b := structWithMap{map[string]structWithUnexportedProperty{ + "key": structWithUnexportedProperty{"hi"}, + }} + defer func() { + if r := recover(); r != nil { + t.Errorf("Should not have panicked") + } + }() + Merge(&a, b) +} + +type structWithBoolPointer struct { + C *bool +} + +func TestBooleanPointer(t *testing.T) { + bt, bf := true, false + src := structWithBoolPointer{ + &bt, + } + dst := structWithBoolPointer{ + &bf, + } + if err := Merge(&dst, src); err != nil { + t.FailNow() + } + if dst.C == src.C { + t.Fatalf("dst.C should be a different pointer than src.C") + } + if *dst.C != *src.C { + t.Fatalf("dst.C should be true") + } +} diff --git a/discovery/vendor/github.com/json-iterator/go/.gitignore b/discovery/vendor/github.com/json-iterator/go/.gitignore index ce242daf..15556530 100644 --- a/discovery/vendor/github.com/json-iterator/go/.gitignore +++ b/discovery/vendor/github.com/json-iterator/go/.gitignore @@ -1,4 +1,4 @@ -.idea -/coverage.txt -/profile.out +/vendor /bug_test.go +/coverage.txt +/.idea diff --git a/discovery/vendor/github.com/json-iterator/go/.travis.yml b/discovery/vendor/github.com/json-iterator/go/.travis.yml new file mode 100644 index 00000000..449e67cd --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/.travis.yml @@ -0,0 +1,14 @@ +language: go + +go: + - 1.8.x + - 1.x + +before_install: + - go get -t -v ./... + +script: + - ./test.sh + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/discovery/vendor/github.com/json-iterator/go/Gopkg.lock b/discovery/vendor/github.com/json-iterator/go/Gopkg.lock new file mode 100644 index 00000000..3719afe8 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/Gopkg.lock @@ -0,0 +1,27 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/json-iterator/go" + packages = ["."] + revision = "ca39e5af3ece67bbcda3d0f4f56a8e24d9f2dad4" + version = "1.1.3" + +[[projects]] + name = "github.com/modern-go/concurrent" + packages = ["."] + revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a" + version = "1.0.0" + +[[projects]] + name = "github.com/modern-go/reflect2" + packages = ["."] + revision = "1df9eeb2bb81f327b96228865c5687bc2194af3f" + version = "1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "56a0b9e9e61d2bc8af5e1b68537401b7f4d60805eda3d107058f3171aa5cf793" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/discovery/vendor/github.com/json-iterator/go/Gopkg.toml b/discovery/vendor/github.com/json-iterator/go/Gopkg.toml new file mode 100644 index 00000000..5801ffa1 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/Gopkg.toml @@ -0,0 +1,26 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + +ignored = ["github.com/davecgh/go-spew*","github.com/google/gofuzz*","github.com/stretchr/testify*"] + +[[constraint]] + name = "github.com/modern-go/reflect2" + version = "1.0.0" diff --git a/discovery/vendor/github.com/json-iterator/go/README.md b/discovery/vendor/github.com/json-iterator/go/README.md index 3a0d6809..54d5afe9 100644 --- a/discovery/vendor/github.com/json-iterator/go/README.md +++ b/discovery/vendor/github.com/json-iterator/go/README.md @@ -8,6 +8,8 @@ A high-performance 100% compatible drop-in replacement of "encoding/json" +You can also use thrift like JSON using [thrift-iterator](https://github.com/thrift-iterator/go) + ``` Go开发者们请加入我们,滴滴出行平台技术部 taowen@didichuxing.com ``` @@ -29,6 +31,9 @@ Raw Result (easyjson requires static code generation) | easyjson encode | 883 ns/op | 576 B/op | 3 allocs/op | | jsoniter encode | 837 ns/op | 384 B/op | 4 allocs/op | +Always benchmark with your own workload. +The result depends heavily on the data input. + # Usage 100% compatibility with standard lib diff --git a/discovery/vendor/github.com/json-iterator/go/adapter.go b/discovery/vendor/github.com/json-iterator/go/adapter.go new file mode 100644 index 00000000..f371bfed --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/adapter.go @@ -0,0 +1,148 @@ +package jsoniter + +import ( + "bytes" + "io" +) + +// RawMessage to make replace json with jsoniter +type RawMessage []byte + +// Unmarshal adapts to json/encoding Unmarshal API +// +// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. +// Refer to https://godoc.org/encoding/json#Unmarshal for more information +func Unmarshal(data []byte, v interface{}) error { + return ConfigDefault.Unmarshal(data, v) +} + +// UnmarshalFromString convenient method to read from string instead of []byte +func UnmarshalFromString(str string, v interface{}) error { + return ConfigDefault.UnmarshalFromString(str, v) +} + +// Get quick method to get value from deeply nested JSON structure +func Get(data []byte, path ...interface{}) Any { + return ConfigDefault.Get(data, path...) +} + +// Marshal adapts to json/encoding Marshal API +// +// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API +// Refer to https://godoc.org/encoding/json#Marshal for more information +func Marshal(v interface{}) ([]byte, error) { + return ConfigDefault.Marshal(v) +} + +// MarshalIndent same as json.MarshalIndent. Prefix is not supported. +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + return ConfigDefault.MarshalIndent(v, prefix, indent) +} + +// MarshalToString convenient method to write as string instead of []byte +func MarshalToString(v interface{}) (string, error) { + return ConfigDefault.MarshalToString(v) +} + +// NewDecoder adapts to json/stream NewDecoder API. +// +// NewDecoder returns a new decoder that reads from r. +// +// Instead of a json/encoding Decoder, an Decoder is returned +// Refer to https://godoc.org/encoding/json#NewDecoder for more information +func NewDecoder(reader io.Reader) *Decoder { + return ConfigDefault.NewDecoder(reader) +} + +// Decoder reads and decodes JSON values from an input stream. +// Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress) +type Decoder struct { + iter *Iterator +} + +// Decode decode JSON into interface{} +func (adapter *Decoder) Decode(obj interface{}) error { + if adapter.iter.head == adapter.iter.tail && adapter.iter.reader != nil { + if !adapter.iter.loadMore() { + return io.EOF + } + } + adapter.iter.ReadVal(obj) + err := adapter.iter.Error + if err == io.EOF { + return nil + } + return adapter.iter.Error +} + +// More is there more? +func (adapter *Decoder) More() bool { + iter := adapter.iter + if iter.Error != nil { + return false + } + if iter.head != iter.tail { + return true + } + return iter.loadMore() +} + +// Buffered remaining buffer +func (adapter *Decoder) Buffered() io.Reader { + remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail] + return bytes.NewReader(remaining) +} + +// UseNumber causes the Decoder to unmarshal a number into an interface{} as a +// Number instead of as a float64. +func (adapter *Decoder) UseNumber() { + cfg := adapter.iter.cfg.configBeforeFrozen + cfg.UseNumber = true + adapter.iter.cfg = cfg.frozeWithCacheReuse() +} + +// DisallowUnknownFields causes the Decoder to return an error when the destination +// is a struct and the input contains object keys which do not match any +// non-ignored, exported fields in the destination. +func (adapter *Decoder) DisallowUnknownFields() { + cfg := adapter.iter.cfg.configBeforeFrozen + cfg.DisallowUnknownFields = true + adapter.iter.cfg = cfg.frozeWithCacheReuse() +} + +// NewEncoder same as json.NewEncoder +func NewEncoder(writer io.Writer) *Encoder { + return ConfigDefault.NewEncoder(writer) +} + +// Encoder same as json.Encoder +type Encoder struct { + stream *Stream +} + +// Encode encode interface{} as JSON to io.Writer +func (adapter *Encoder) Encode(val interface{}) error { + adapter.stream.WriteVal(val) + adapter.stream.WriteRaw("\n") + adapter.stream.Flush() + return adapter.stream.Error +} + +// SetIndent set the indention. Prefix is not supported +func (adapter *Encoder) SetIndent(prefix, indent string) { + config := adapter.stream.cfg.configBeforeFrozen + config.IndentionStep = len(indent) + adapter.stream.cfg = config.frozeWithCacheReuse() +} + +// SetEscapeHTML escape html by default, set to false to disable +func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) { + config := adapter.stream.cfg.configBeforeFrozen + config.EscapeHTML = escapeHTML + adapter.stream.cfg = config.frozeWithCacheReuse() +} + +// Valid reports whether data is a valid JSON encoding. +func Valid(data []byte) bool { + return ConfigDefault.Valid(data) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any.go b/discovery/vendor/github.com/json-iterator/go/any.go new file mode 100644 index 00000000..daecfed6 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any.go @@ -0,0 +1,321 @@ +package jsoniter + +import ( + "errors" + "fmt" + "github.com/modern-go/reflect2" + "io" + "reflect" + "strconv" + "unsafe" +) + +// Any generic object representation. +// The lazy json implementation holds []byte and parse lazily. +type Any interface { + LastError() error + ValueType() ValueType + MustBeValid() Any + ToBool() bool + ToInt() int + ToInt32() int32 + ToInt64() int64 + ToUint() uint + ToUint32() uint32 + ToUint64() uint64 + ToFloat32() float32 + ToFloat64() float64 + ToString() string + ToVal(val interface{}) + Get(path ...interface{}) Any + Size() int + Keys() []string + GetInterface() interface{} + WriteTo(stream *Stream) +} + +type baseAny struct{} + +func (any *baseAny) Get(path ...interface{}) Any { + return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)} +} + +func (any *baseAny) Size() int { + return 0 +} + +func (any *baseAny) Keys() []string { + return []string{} +} + +func (any *baseAny) ToVal(obj interface{}) { + panic("not implemented") +} + +// WrapInt32 turn int32 into Any interface +func WrapInt32(val int32) Any { + return &int32Any{baseAny{}, val} +} + +// WrapInt64 turn int64 into Any interface +func WrapInt64(val int64) Any { + return &int64Any{baseAny{}, val} +} + +// WrapUint32 turn uint32 into Any interface +func WrapUint32(val uint32) Any { + return &uint32Any{baseAny{}, val} +} + +// WrapUint64 turn uint64 into Any interface +func WrapUint64(val uint64) Any { + return &uint64Any{baseAny{}, val} +} + +// WrapFloat64 turn float64 into Any interface +func WrapFloat64(val float64) Any { + return &floatAny{baseAny{}, val} +} + +// WrapString turn string into Any interface +func WrapString(val string) Any { + return &stringAny{baseAny{}, val} +} + +// Wrap turn a go object into Any interface +func Wrap(val interface{}) Any { + if val == nil { + return &nilAny{} + } + asAny, isAny := val.(Any) + if isAny { + return asAny + } + typ := reflect2.TypeOf(val) + switch typ.Kind() { + case reflect.Slice: + return wrapArray(val) + case reflect.Struct: + return wrapStruct(val) + case reflect.Map: + return wrapMap(val) + case reflect.String: + return WrapString(val.(string)) + case reflect.Int: + if strconv.IntSize == 32 { + return WrapInt32(int32(val.(int))) + } + return WrapInt64(int64(val.(int))) + case reflect.Int8: + return WrapInt32(int32(val.(int8))) + case reflect.Int16: + return WrapInt32(int32(val.(int16))) + case reflect.Int32: + return WrapInt32(val.(int32)) + case reflect.Int64: + return WrapInt64(val.(int64)) + case reflect.Uint: + if strconv.IntSize == 32 { + return WrapUint32(uint32(val.(uint))) + } + return WrapUint64(uint64(val.(uint))) + case reflect.Uintptr: + if ptrSize == 32 { + return WrapUint32(uint32(val.(uintptr))) + } + return WrapUint64(uint64(val.(uintptr))) + case reflect.Uint8: + return WrapUint32(uint32(val.(uint8))) + case reflect.Uint16: + return WrapUint32(uint32(val.(uint16))) + case reflect.Uint32: + return WrapUint32(uint32(val.(uint32))) + case reflect.Uint64: + return WrapUint64(val.(uint64)) + case reflect.Float32: + return WrapFloat64(float64(val.(float32))) + case reflect.Float64: + return WrapFloat64(val.(float64)) + case reflect.Bool: + if val.(bool) == true { + return &trueAny{} + } + return &falseAny{} + } + return &invalidAny{baseAny{}, fmt.Errorf("unsupported type: %v", typ)} +} + +// ReadAny read next JSON element as an Any object. It is a better json.RawMessage. +func (iter *Iterator) ReadAny() Any { + return iter.readAny() +} + +func (iter *Iterator) readAny() Any { + c := iter.nextToken() + switch c { + case '"': + iter.unreadByte() + return &stringAny{baseAny{}, iter.ReadString()} + case 'n': + iter.skipThreeBytes('u', 'l', 'l') // null + return &nilAny{} + case 't': + iter.skipThreeBytes('r', 'u', 'e') // true + return &trueAny{} + case 'f': + iter.skipFourBytes('a', 'l', 's', 'e') // false + return &falseAny{} + case '{': + return iter.readObjectAny() + case '[': + return iter.readArrayAny() + case '-': + return iter.readNumberAny(false) + case 0: + return &invalidAny{baseAny{}, errors.New("input is empty")} + default: + return iter.readNumberAny(true) + } +} + +func (iter *Iterator) readNumberAny(positive bool) Any { + iter.startCapture(iter.head - 1) + iter.skipNumber() + lazyBuf := iter.stopCapture() + return &numberLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} +} + +func (iter *Iterator) readObjectAny() Any { + iter.startCapture(iter.head - 1) + iter.skipObject() + lazyBuf := iter.stopCapture() + return &objectLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} +} + +func (iter *Iterator) readArrayAny() Any { + iter.startCapture(iter.head - 1) + iter.skipArray() + lazyBuf := iter.stopCapture() + return &arrayLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} +} + +func locateObjectField(iter *Iterator, target string) []byte { + var found []byte + iter.ReadObjectCB(func(iter *Iterator, field string) bool { + if field == target { + found = iter.SkipAndReturnBytes() + return false + } + iter.Skip() + return true + }) + return found +} + +func locateArrayElement(iter *Iterator, target int) []byte { + var found []byte + n := 0 + iter.ReadArrayCB(func(iter *Iterator) bool { + if n == target { + found = iter.SkipAndReturnBytes() + return false + } + iter.Skip() + n++ + return true + }) + return found +} + +func locatePath(iter *Iterator, path []interface{}) Any { + for i, pathKeyObj := range path { + switch pathKey := pathKeyObj.(type) { + case string: + valueBytes := locateObjectField(iter, pathKey) + if valueBytes == nil { + return newInvalidAny(path[i:]) + } + iter.ResetBytes(valueBytes) + case int: + valueBytes := locateArrayElement(iter, pathKey) + if valueBytes == nil { + return newInvalidAny(path[i:]) + } + iter.ResetBytes(valueBytes) + case int32: + if '*' == pathKey { + return iter.readAny().Get(path[i:]...) + } + return newInvalidAny(path[i:]) + default: + return newInvalidAny(path[i:]) + } + } + if iter.Error != nil && iter.Error != io.EOF { + return &invalidAny{baseAny{}, iter.Error} + } + return iter.readAny() +} + +var anyType = reflect2.TypeOfPtr((*Any)(nil)).Elem() + +func createDecoderOfAny(ctx *ctx, typ reflect2.Type) ValDecoder { + if typ == anyType { + return &directAnyCodec{} + } + if typ.Implements(anyType) { + return &anyCodec{ + valType: typ, + } + } + return nil +} + +func createEncoderOfAny(ctx *ctx, typ reflect2.Type) ValEncoder { + if typ == anyType { + return &directAnyCodec{} + } + if typ.Implements(anyType) { + return &anyCodec{ + valType: typ, + } + } + return nil +} + +type anyCodec struct { + valType reflect2.Type +} + +func (codec *anyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { + panic("not implemented") +} + +func (codec *anyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { + obj := codec.valType.UnsafeIndirect(ptr) + any := obj.(Any) + any.WriteTo(stream) +} + +func (codec *anyCodec) IsEmpty(ptr unsafe.Pointer) bool { + obj := codec.valType.UnsafeIndirect(ptr) + any := obj.(Any) + return any.Size() == 0 +} + +type directAnyCodec struct { +} + +func (codec *directAnyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { + *(*Any)(ptr) = iter.readAny() +} + +func (codec *directAnyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { + any := *(*Any)(ptr) + any.WriteTo(stream) +} + +func (codec *directAnyCodec) IsEmpty(ptr unsafe.Pointer) bool { + any := *(*Any)(ptr) + return any.Size() == 0 +} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_array.go b/discovery/vendor/github.com/json-iterator/go/any_array.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_array.go rename to discovery/vendor/github.com/json-iterator/go/any_array.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_bool.go b/discovery/vendor/github.com/json-iterator/go/any_bool.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_bool.go rename to discovery/vendor/github.com/json-iterator/go/any_bool.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_float.go b/discovery/vendor/github.com/json-iterator/go/any_float.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_float.go rename to discovery/vendor/github.com/json-iterator/go/any_float.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_int32.go b/discovery/vendor/github.com/json-iterator/go/any_int32.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_int32.go rename to discovery/vendor/github.com/json-iterator/go/any_int32.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_int64.go b/discovery/vendor/github.com/json-iterator/go/any_int64.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_int64.go rename to discovery/vendor/github.com/json-iterator/go/any_int64.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_invalid.go b/discovery/vendor/github.com/json-iterator/go/any_invalid.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_invalid.go rename to discovery/vendor/github.com/json-iterator/go/any_invalid.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_nil.go b/discovery/vendor/github.com/json-iterator/go/any_nil.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_nil.go rename to discovery/vendor/github.com/json-iterator/go/any_nil.go diff --git a/discovery/vendor/github.com/json-iterator/go/any_number.go b/discovery/vendor/github.com/json-iterator/go/any_number.go new file mode 100644 index 00000000..9d1e901a --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_number.go @@ -0,0 +1,123 @@ +package jsoniter + +import ( + "io" + "unsafe" +) + +type numberLazyAny struct { + baseAny + cfg *frozenConfig + buf []byte + err error +} + +func (any *numberLazyAny) ValueType() ValueType { + return NumberValue +} + +func (any *numberLazyAny) MustBeValid() Any { + return any +} + +func (any *numberLazyAny) LastError() error { + return any.err +} + +func (any *numberLazyAny) ToBool() bool { + return any.ToFloat64() != 0 +} + +func (any *numberLazyAny) ToInt() int { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadInt() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToInt32() int32 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadInt32() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToInt64() int64 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadInt64() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToUint() uint { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadUint() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToUint32() uint32 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadUint32() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToUint64() uint64 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadUint64() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToFloat32() float32 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadFloat32() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToFloat64() float64 { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + val := iter.ReadFloat64() + if iter.Error != nil && iter.Error != io.EOF { + any.err = iter.Error + } + return val +} + +func (any *numberLazyAny) ToString() string { + return *(*string)(unsafe.Pointer(&any.buf)) +} + +func (any *numberLazyAny) WriteTo(stream *Stream) { + stream.Write(any.buf) +} + +func (any *numberLazyAny) GetInterface() interface{} { + iter := any.cfg.BorrowIterator(any.buf) + defer any.cfg.ReturnIterator(iter) + return iter.Read() +} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_object.go b/discovery/vendor/github.com/json-iterator/go/any_object.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_object.go rename to discovery/vendor/github.com/json-iterator/go/any_object.go diff --git a/discovery/vendor/github.com/json-iterator/go/any_str.go b/discovery/vendor/github.com/json-iterator/go/any_str.go new file mode 100644 index 00000000..a4b93c78 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_str.go @@ -0,0 +1,166 @@ +package jsoniter + +import ( + "fmt" + "strconv" +) + +type stringAny struct { + baseAny + val string +} + +func (any *stringAny) Get(path ...interface{}) Any { + if len(path) == 0 { + return any + } + return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)} +} + +func (any *stringAny) Parse() *Iterator { + return nil +} + +func (any *stringAny) ValueType() ValueType { + return StringValue +} + +func (any *stringAny) MustBeValid() Any { + return any +} + +func (any *stringAny) LastError() error { + return nil +} + +func (any *stringAny) ToBool() bool { + str := any.ToString() + if str == "0" { + return false + } + for _, c := range str { + switch c { + case ' ', '\n', '\r', '\t': + default: + return true + } + } + return false +} + +func (any *stringAny) ToInt() int { + return int(any.ToInt64()) + +} + +func (any *stringAny) ToInt32() int32 { + return int32(any.ToInt64()) +} + +func (any *stringAny) ToInt64() int64 { + if any.val == "" { + return 0 + } + + flag := 1 + startPos := 0 + endPos := 0 + if any.val[0] == '+' || any.val[0] == '-' { + startPos = 1 + } + + if any.val[0] == '-' { + flag = -1 + } + + for i := startPos; i < len(any.val); i++ { + if any.val[i] >= '0' && any.val[i] <= '9' { + endPos = i + 1 + } else { + break + } + } + parsed, _ := strconv.ParseInt(any.val[startPos:endPos], 10, 64) + return int64(flag) * parsed +} + +func (any *stringAny) ToUint() uint { + return uint(any.ToUint64()) +} + +func (any *stringAny) ToUint32() uint32 { + return uint32(any.ToUint64()) +} + +func (any *stringAny) ToUint64() uint64 { + if any.val == "" { + return 0 + } + + startPos := 0 + endPos := 0 + + if any.val[0] == '-' { + return 0 + } + if any.val[0] == '+' { + startPos = 1 + } + + for i := startPos; i < len(any.val); i++ { + if any.val[i] >= '0' && any.val[i] <= '9' { + endPos = i + 1 + } else { + break + } + } + parsed, _ := strconv.ParseUint(any.val[startPos:endPos], 10, 64) + return parsed +} + +func (any *stringAny) ToFloat32() float32 { + return float32(any.ToFloat64()) +} + +func (any *stringAny) ToFloat64() float64 { + if len(any.val) == 0 { + return 0 + } + + // first char invalid + if any.val[0] != '+' && any.val[0] != '-' && (any.val[0] > '9' || any.val[0] < '0') { + return 0 + } + + // extract valid num expression from string + // eg 123true => 123, -12.12xxa => -12.12 + endPos := 1 + for i := 1; i < len(any.val); i++ { + if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' { + endPos = i + 1 + continue + } + + // end position is the first char which is not digit + if any.val[i] >= '0' && any.val[i] <= '9' { + endPos = i + 1 + } else { + endPos = i + break + } + } + parsed, _ := strconv.ParseFloat(any.val[:endPos], 64) + return parsed +} + +func (any *stringAny) ToString() string { + return any.val +} + +func (any *stringAny) WriteTo(stream *Stream) { + stream.WriteString(any.val) +} + +func (any *stringAny) GetInterface() interface{} { + return any.val +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_array_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_array_test.go new file mode 100644 index 00000000..a28bd8d3 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_array_test.go @@ -0,0 +1,123 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func Test_read_empty_array_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[]")) + should.Equal(jsoniter.ArrayValue, any.Get().ValueType()) + should.Equal(jsoniter.InvalidValue, any.Get(0.3).ValueType()) + should.Equal(0, any.Size()) + should.Equal(jsoniter.ArrayValue, any.ValueType()) + should.Nil(any.LastError()) + should.Equal(0, any.ToInt()) + should.Equal(int32(0), any.ToInt32()) + should.Equal(int64(0), any.ToInt64()) + should.Equal(uint(0), any.ToUint()) + should.Equal(uint32(0), any.ToUint32()) + should.Equal(uint64(0), any.ToUint64()) + should.Equal(float32(0), any.ToFloat32()) + should.Equal(float64(0), any.ToFloat64()) +} + +func Test_read_one_element_array_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[1]")) + should.Equal(1, any.Size()) +} + +func Test_read_two_element_array_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[1,2]")) + should.Equal(1, any.Get(0).ToInt()) + should.Equal(2, any.Size()) + should.True(any.ToBool()) + should.Equal(1, any.ToInt()) + should.Equal([]interface{}{float64(1), float64(2)}, any.GetInterface()) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("[1,2]", string(stream.Buffer())) + arr := []int{} + any.ToVal(&arr) + should.Equal([]int{1, 2}, arr) +} + +func Test_wrap_array_and_convert_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Wrap([]int{1, 2, 3}) + any2 := jsoniter.Wrap([]int{}) + + should.Equal("[1,2,3]", any.ToString()) + should.True(any.ToBool()) + should.False(any2.ToBool()) + + should.Equal(1, any.ToInt()) + should.Equal(0, any2.ToInt()) + should.Equal(int32(1), any.ToInt32()) + should.Equal(int32(0), any2.ToInt32()) + should.Equal(int64(1), any.ToInt64()) + should.Equal(int64(0), any2.ToInt64()) + should.Equal(uint(1), any.ToUint()) + should.Equal(uint(0), any2.ToUint()) + should.Equal(uint32(1), any.ToUint32()) + should.Equal(uint32(0), any2.ToUint32()) + should.Equal(uint64(1), any.ToUint64()) + should.Equal(uint64(0), any2.ToUint64()) + should.Equal(float32(1), any.ToFloat32()) + should.Equal(float32(0), any2.ToFloat32()) + should.Equal(float64(1), any.ToFloat64()) + should.Equal(float64(0), any2.ToFloat64()) + should.Equal(3, any.Size()) + should.Equal(0, any2.Size()) + + var i interface{} = []int{1, 2, 3} + should.Equal(i, any.GetInterface()) +} + +func Test_array_lazy_any_get(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[1,[2,3],4]")) + should.Equal(3, any.Get(1, 1).ToInt()) + should.Equal("[1,[2,3],4]", any.ToString()) +} + +func Test_array_lazy_any_get_all(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[[1],[2],[3,4]]")) + should.Equal("[1,2,3]", any.Get('*', 0).ToString()) + any = jsoniter.Get([]byte("[[[1],[2],[3,4]]]"), 0, '*', 0) + should.Equal("[1,2,3]", any.ToString()) +} + +func Test_array_wrapper_any_get_all(t *testing.T) { + should := require.New(t) + any := jsoniter.Wrap([][]int{ + {1, 2}, + {3, 4}, + {5, 6}, + }) + should.Equal("[1,3,5]", any.Get('*', 0).ToString()) + should.Equal(jsoniter.ArrayValue, any.ValueType()) + should.True(any.ToBool()) + should.Equal(1, any.Get(0, 0).ToInt()) +} + +func Test_array_lazy_any_get_invalid(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("[]")) + should.Equal(jsoniter.InvalidValue, any.Get(1, 1).ValueType()) + should.NotNil(any.Get(1, 1).LastError()) + should.Equal(jsoniter.InvalidValue, any.Get("1").ValueType()) + should.NotNil(any.Get("1").LastError()) +} + +func Test_invalid_array(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("["), 0) + should.Equal(jsoniter.InvalidValue, any.ValueType()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_bool_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_bool_test.go new file mode 100644 index 00000000..045671f2 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_bool_test.go @@ -0,0 +1,65 @@ +package any_tests + +import ( + "fmt" + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +var boolConvertMap = map[string]bool{ + "null": false, + "true": true, + "false": false, + + `"true"`: true, + `"false"`: true, + + "123": true, + `"123"`: true, + "0": false, + `"0"`: false, + "-1": true, + `"-1"`: true, + + "1.1": true, + "0.0": false, + "-1.1": true, + `""`: false, + "[1,2]": true, + "[]": false, + "{}": true, + `{"abc":1}`: true, +} + +func Test_read_bool_as_any(t *testing.T) { + should := require.New(t) + + var any jsoniter.Any + for k, v := range boolConvertMap { + any = jsoniter.Get([]byte(k)) + if v { + should.True(any.ToBool(), fmt.Sprintf("origin val is %v", k)) + } else { + should.False(any.ToBool(), fmt.Sprintf("origin val is %v", k)) + } + } + +} + +func Test_write_bool_to_stream(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("true")) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("true", string(stream.Buffer())) + should.Equal(any.ValueType(), jsoniter.BoolValue) + + any = jsoniter.Get([]byte("false")) + stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("false", string(stream.Buffer())) + + should.Equal(any.ValueType(), jsoniter.BoolValue) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_float_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_float_test.go new file mode 100644 index 00000000..4426e35a --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_float_test.go @@ -0,0 +1,103 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +var floatConvertMap = map[string]float64{ + "null": 0, + "true": 1, + "false": 0, + + `"true"`: 0, + `"false"`: 0, + + "1e1": 10, + "1e+1": 10, + "1e-1": .1, + "1E1": 10, + "1E+1": 10, + "1E-1": .1, + + "-1e1": -10, + "-1e+1": -10, + "-1e-1": -.1, + "-1E1": -10, + "-1E+1": -10, + "-1E-1": -.1, + + `"1e1"`: 10, + `"1e+1"`: 10, + `"1e-1"`: .1, + `"1E1"`: 10, + `"1E+1"`: 10, + `"1E-1"`: .1, + + `"-1e1"`: -10, + `"-1e+1"`: -10, + `"-1e-1"`: -.1, + `"-1E1"`: -10, + `"-1E+1"`: -10, + `"-1E-1"`: -.1, + + "123": 123, + `"123true"`: 123, + `"+"`: 0, + `"-"`: 0, + + `"-123true"`: -123, + `"-99.9true"`: -99.9, + "0": 0, + `"0"`: 0, + "-1": -1, + + "1.1": 1.1, + "0.0": 0, + "-1.1": -1.1, + `"+1.1"`: 1.1, + `""`: 0, + "[1,2]": 1, + "[]": 0, + "{}": 0, + `{"abc":1}`: 0, +} + +func Test_read_any_to_float(t *testing.T) { + should := require.New(t) + for k, v := range floatConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(float64(v), any.ToFloat64(), "the original val is "+k) + } + + for k, v := range floatConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(float32(v), any.ToFloat32(), "the original val is "+k) + } +} + +func Test_read_float_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.WrapFloat64(12.3) + anyFloat64 := float64(12.3) + //negaAnyFloat64 := float64(-1.1) + any2 := jsoniter.WrapFloat64(-1.1) + should.Equal(float64(12.3), any.ToFloat64()) + //should.Equal("12.3", any.ToString()) + should.True(any.ToBool()) + should.Equal(float32(anyFloat64), any.ToFloat32()) + should.Equal(int(anyFloat64), any.ToInt()) + should.Equal(int32(anyFloat64), any.ToInt32()) + should.Equal(int64(anyFloat64), any.ToInt64()) + should.Equal(uint(anyFloat64), any.ToUint()) + should.Equal(uint32(anyFloat64), any.ToUint32()) + should.Equal(uint64(anyFloat64), any.ToUint64()) + should.Equal(uint(0), any2.ToUint()) + should.Equal(uint32(0), any2.ToUint32()) + should.Equal(uint64(0), any2.ToUint64()) + should.Equal(any.ValueType(), jsoniter.NumberValue) + + should.Equal("1.23E+01", any.ToString()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_int_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_int_test.go new file mode 100644 index 00000000..c5a3d426 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_int_test.go @@ -0,0 +1,198 @@ +package any_tests + +import ( + "fmt" + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +var intConvertMap = map[string]int{ + "null": 0, + "321.1": 321, + "-321.1": -321, + `"1.1"`: 1, + `"-321.1"`: -321, + "0.0": 0, + "0": 0, + `"0"`: 0, + `"0.0"`: 0, + "-1.1": -1, + "true": 1, + "false": 0, + `"true"`: 0, + `"false"`: 0, + `"true123"`: 0, + `"123true"`: 123, + `"-123true"`: -123, + `"1.2332e6"`: 1, + `""`: 0, + "+": 0, + "-": 0, + "[]": 0, + "[1,2]": 1, + `["1","2"]`: 1, + // object in php cannot convert to int + "{}": 0, +} + +func Test_read_any_to_int(t *testing.T) { + should := require.New(t) + + // int + for k, v := range intConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(v, any.ToInt(), fmt.Sprintf("origin val %v", k)) + } + + // int32 + for k, v := range intConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(int32(v), any.ToInt32(), fmt.Sprintf("original val is %v", k)) + } + + // int64 + for k, v := range intConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(int64(v), any.ToInt64(), fmt.Sprintf("original val is %v", k)) + } + +} + +var uintConvertMap = map[string]int{ + "null": 0, + "321.1": 321, + `"1.1"`: 1, + `"-123.1"`: 0, + "0.0": 0, + "0": 0, + `"0"`: 0, + `"0.0"`: 0, + `"00.0"`: 0, + "true": 1, + "false": 0, + `"true"`: 0, + `"false"`: 0, + `"true123"`: 0, + `"+1"`: 1, + `"123true"`: 123, + `"-123true"`: 0, + `"1.2332e6"`: 1, + `""`: 0, + "+": 0, + "-": 0, + ".": 0, + "[]": 0, + "[1,2]": 1, + "{}": 0, + "{1,2}": 0, + "-1.1": 0, + "-321.1": 0, +} + +func Test_read_any_to_uint(t *testing.T) { + should := require.New(t) + + for k, v := range uintConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(uint64(v), any.ToUint64(), fmt.Sprintf("origin val %v", k)) + } + + for k, v := range uintConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(uint32(v), any.ToUint32(), fmt.Sprintf("origin val %v", k)) + } + + for k, v := range uintConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(uint(v), any.ToUint(), fmt.Sprintf("origin val %v", k)) + } + +} + +func Test_read_int64_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.WrapInt64(12345) + should.Equal(12345, any.ToInt()) + should.Equal(int32(12345), any.ToInt32()) + should.Equal(int64(12345), any.ToInt64()) + should.Equal(uint(12345), any.ToUint()) + should.Equal(uint32(12345), any.ToUint32()) + should.Equal(uint64(12345), any.ToUint64()) + should.Equal(float32(12345), any.ToFloat32()) + should.Equal(float64(12345), any.ToFloat64()) + should.Equal("12345", any.ToString()) + should.Equal(true, any.ToBool()) + should.Equal(any.ValueType(), jsoniter.NumberValue) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("12345", string(stream.Buffer())) +} +func Test_read_int32_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.WrapInt32(12345) + should.Equal(12345, any.ToInt()) + should.Equal(int32(12345), any.ToInt32()) + should.Equal(int64(12345), any.ToInt64()) + should.Equal(uint(12345), any.ToUint()) + should.Equal(uint32(12345), any.ToUint32()) + should.Equal(uint64(12345), any.ToUint64()) + should.Equal(float32(12345), any.ToFloat32()) + should.Equal(float64(12345), any.ToFloat64()) + should.Equal("12345", any.ToString()) + should.Equal(true, any.ToBool()) + should.Equal(any.ValueType(), jsoniter.NumberValue) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("12345", string(stream.Buffer())) +} + +func Test_read_uint32_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.WrapUint32(12345) + should.Equal(12345, any.ToInt()) + should.Equal(int32(12345), any.ToInt32()) + should.Equal(int64(12345), any.ToInt64()) + should.Equal(uint(12345), any.ToUint()) + should.Equal(uint32(12345), any.ToUint32()) + should.Equal(uint64(12345), any.ToUint64()) + should.Equal(float32(12345), any.ToFloat32()) + should.Equal(float64(12345), any.ToFloat64()) + should.Equal("12345", any.ToString()) + should.Equal(true, any.ToBool()) + should.Equal(any.ValueType(), jsoniter.NumberValue) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("12345", string(stream.Buffer())) +} + +func Test_read_uint64_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.WrapUint64(12345) + should.Equal(12345, any.ToInt()) + should.Equal(int32(12345), any.ToInt32()) + should.Equal(int64(12345), any.ToInt64()) + should.Equal(uint(12345), any.ToUint()) + should.Equal(uint32(12345), any.ToUint32()) + should.Equal(uint64(12345), any.ToUint64()) + should.Equal(float32(12345), any.ToFloat32()) + should.Equal(float64(12345), any.ToFloat64()) + should.Equal("12345", any.ToString()) + should.Equal(true, any.ToBool()) + should.Equal(any.ValueType(), jsoniter.NumberValue) + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("12345", string(stream.Buffer())) + stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + stream.WriteUint(uint(123)) + should.Equal("123", string(stream.Buffer())) +} + +func Test_int_lazy_any_get(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("1234")) + // panic!! + //should.Equal(any.LastError(), io.EOF) + should.Equal(jsoniter.InvalidValue, any.Get(1, "2").ValueType()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_map_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_map_test.go new file mode 100644 index 00000000..c5f2e6fe --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_map_test.go @@ -0,0 +1,28 @@ +package any_tests + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func Test_wrap_map(t *testing.T) { + should := require.New(t) + any := jsoniter.Wrap(map[string]string{"Field1": "hello"}) + should.Equal("hello", any.Get("Field1").ToString()) + any = jsoniter.Wrap(map[string]string{"Field1": "hello"}) + should.Equal(1, any.Size()) +} + +func Test_map_wrapper_any_get_all(t *testing.T) { + should := require.New(t) + any := jsoniter.Wrap(map[string][]int{"Field1": {1, 2}}) + should.Equal(`{"Field1":1}`, any.Get('*', 0).ToString()) + should.Contains(any.Keys(), "Field1") + + // map write to + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0) + any.WriteTo(stream) + // TODO cannot pass + //should.Equal(string(stream.buf), "") +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_null_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_null_test.go new file mode 100644 index 00000000..a86625e9 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_null_test.go @@ -0,0 +1,16 @@ +package any_tests + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func Test_read_null_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`null`)) + should.Equal(0, any.ToInt()) + should.Equal(float64(0), any.ToFloat64()) + should.Equal("", any.ToString()) + should.False(any.ToBool()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_object_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_object_test.go new file mode 100644 index 00000000..a36f6cae --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_object_test.go @@ -0,0 +1,123 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func Test_read_object_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`{"a":"stream","c":"d"}`)) + should.Equal(`{"a":"stream","c":"d"}`, any.ToString()) + // partial parse + should.Equal("stream", any.Get("a").ToString()) + should.Equal("d", any.Get("c").ToString()) + should.Equal(2, len(any.Keys())) + any = jsoniter.Get([]byte(`{"a":"stream","c":"d"}`)) + // full parse + should.Equal(2, len(any.Keys())) + should.Equal(2, any.Size()) + should.True(any.ToBool()) + should.Equal(0, any.ToInt()) + should.Equal(jsoniter.ObjectValue, any.ValueType()) + should.Nil(any.LastError()) + obj := struct { + A string + }{} + any.ToVal(&obj) + should.Equal("stream", obj.A) +} + +func Test_object_lazy_any_get(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`{"a":{"stream":{"c":"d"}}}`)) + should.Equal("d", any.Get("a", "stream", "c").ToString()) +} + +func Test_object_lazy_any_get_all(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`{"a":[0],"stream":[1]}`)) + should.Contains(any.Get('*', 0).ToString(), `"a":0`) +} + +func Test_object_lazy_any_get_invalid(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`{}`)) + should.Equal(jsoniter.InvalidValue, any.Get("a", "stream", "c").ValueType()) + should.Equal(jsoniter.InvalidValue, any.Get(1).ValueType()) +} + +func Test_wrap_map_and_convert_to_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Wrap(map[string]interface{}{"a": 1}) + should.True(any.ToBool()) + should.Equal(0, any.ToInt()) + should.Equal(int32(0), any.ToInt32()) + should.Equal(int64(0), any.ToInt64()) + should.Equal(float32(0), any.ToFloat32()) + should.Equal(float64(0), any.ToFloat64()) + should.Equal(uint(0), any.ToUint()) + should.Equal(uint32(0), any.ToUint32()) + should.Equal(uint64(0), any.ToUint64()) +} + +func Test_wrap_object_and_convert_to_any(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 string + field2 string + } + any := jsoniter.Wrap(TestObject{"hello", "world"}) + should.Equal("hello", any.Get("Field1").ToString()) + any = jsoniter.Wrap(TestObject{"hello", "world"}) + should.Equal(2, any.Size()) + should.Equal(`{"Field1":"hello"}`, any.Get('*').ToString()) + + should.Equal(0, any.ToInt()) + should.Equal(int32(0), any.ToInt32()) + should.Equal(int64(0), any.ToInt64()) + should.Equal(float32(0), any.ToFloat32()) + should.Equal(float64(0), any.ToFloat64()) + should.Equal(uint(0), any.ToUint()) + should.Equal(uint32(0), any.ToUint32()) + should.Equal(uint64(0), any.ToUint64()) + should.True(any.ToBool()) + should.Equal(`{"Field1":"hello"}`, any.ToString()) + + // cannot pass! + //stream := NewStream(ConfigDefault, nil, 32) + //any.WriteTo(stream) + //should.Equal(`{"Field1":"hello"}`, string(stream.Buffer())) + // cannot pass! + +} + +func Test_any_within_struct(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 jsoniter.Any + Field2 jsoniter.Any + } + obj := TestObject{} + err := jsoniter.UnmarshalFromString(`{"Field1": "hello", "Field2": [1,2,3]}`, &obj) + should.Nil(err) + should.Equal("hello", obj.Field1.ToString()) + should.Equal("[1,2,3]", obj.Field2.ToString()) +} + +func Test_object_wrapper_any_get_all(t *testing.T) { + should := require.New(t) + type TestObject struct { + Field1 []int + Field2 []int + } + any := jsoniter.Wrap(TestObject{[]int{1, 2}, []int{3, 4}}) + should.Contains(any.Get('*', 0).ToString(), `"Field2":3`) + should.Contains(any.Keys(), "Field1") + should.Contains(any.Keys(), "Field2") + should.NotContains(any.Keys(), "Field3") + + //should.Contains(any.GetObject()["Field1"].GetArray()[0], 1) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_string_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_string_test.go new file mode 100644 index 00000000..3cd32468 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_any_string_test.go @@ -0,0 +1,58 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +var stringConvertMap = map[string]string{ + "null": "", + "321.1": "321.1", + `"1.1"`: "1.1", + `"-123.1"`: "-123.1", + "0.0": "0.0", + "0": "0", + `"0"`: "0", + `"0.0"`: "0.0", + `"00.0"`: "00.0", + "true": "true", + "false": "false", + `"true"`: "true", + `"false"`: "false", + `"true123"`: "true123", + `"+1"`: "+1", + "[]": "[]", + "[1,2]": "[1,2]", + "{}": "{}", + `{"a":1, "stream":true}`: `{"a":1, "stream":true}`, +} + +func Test_read_any_to_string(t *testing.T) { + should := require.New(t) + for k, v := range stringConvertMap { + any := jsoniter.Get([]byte(k)) + should.Equal(v, any.ToString(), "original val "+k) + } +} + +func Test_read_string_as_any(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte(`"hello"`)) + should.Equal("hello", any.ToString()) + should.True(any.ToBool()) + any = jsoniter.Get([]byte(`" "`)) + should.False(any.ToBool()) + any = jsoniter.Get([]byte(`"false"`)) + should.True(any.ToBool()) + any = jsoniter.Get([]byte(`"123"`)) + should.Equal(123, any.ToInt()) +} + +func Test_wrap_string(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("-32000")).MustBeValid() + should.Equal(-32000, any.ToInt()) + should.NoError(any.LastError()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_must_be_valid_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_must_be_valid_test.go new file mode 100644 index 00000000..8974eb7f --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_must_be_valid_test.go @@ -0,0 +1,72 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +// if must be valid is useless, just drop this test +func Test_must_be_valid(t *testing.T) { + should := require.New(t) + any := jsoniter.Get([]byte("123")) + should.Equal(any.MustBeValid().ToInt(), 123) + + any = jsoniter.Wrap(int8(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(int16(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(int32(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(int64(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(uint(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(uint8(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(uint16(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(uint32(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(uint64(10)) + should.Equal(any.MustBeValid().ToInt(), 10) + + any = jsoniter.Wrap(float32(10)) + should.Equal(any.MustBeValid().ToFloat64(), float64(10)) + + any = jsoniter.Wrap(float64(10)) + should.Equal(any.MustBeValid().ToFloat64(), float64(10)) + + any = jsoniter.Wrap(true) + should.Equal(any.MustBeValid().ToFloat64(), float64(1)) + + any = jsoniter.Wrap(false) + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap(nil) + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap(struct{ age int }{age: 1}) + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap(map[string]interface{}{"abc": 1}) + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap("abc") + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap([]int{}) + should.Equal(any.MustBeValid().ToFloat64(), float64(0)) + + any = jsoniter.Wrap([]int{1, 2}) + should.Equal(any.MustBeValid().ToFloat64(), float64(1)) +} diff --git a/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_wrap_test.go b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_wrap_test.go new file mode 100644 index 00000000..480985ff --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/any_tests/jsoniter_wrap_test.go @@ -0,0 +1,119 @@ +package any_tests + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func Test_wrap_and_valuetype_everything(t *testing.T) { + should := require.New(t) + var i interface{} + any := jsoniter.Get([]byte("123")) + // default of number type is float64 + i = float64(123) + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(int8(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + // get interface is not int8 interface + // i = int8(10) + // should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(int16(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + //i = int16(10) + //should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(int32(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + i = int32(10) + should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(int64(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + i = int64(10) + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(uint(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + // not equal + //i = uint(10) + //should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(uint8(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + // not equal + // i = uint8(10) + // should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(uint16(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + any = jsoniter.Wrap(uint32(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + i = uint32(10) + should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(uint64(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + i = uint64(10) + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(float32(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + // not equal + //i = float32(10) + //should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(float64(10)) + should.Equal(any.ValueType(), jsoniter.NumberValue) + should.Equal(any.LastError(), nil) + i = float64(10) + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(true) + should.Equal(any.ValueType(), jsoniter.BoolValue) + should.Equal(any.LastError(), nil) + i = true + should.Equal(i, any.GetInterface()) + any = jsoniter.Wrap(false) + should.Equal(any.ValueType(), jsoniter.BoolValue) + should.Equal(any.LastError(), nil) + i = false + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(nil) + should.Equal(any.ValueType(), jsoniter.NilValue) + should.Equal(any.LastError(), nil) + i = nil + should.Equal(i, any.GetInterface()) + + stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32) + any.WriteTo(stream) + should.Equal("null", string(stream.Buffer())) + should.Equal(any.LastError(), nil) + + any = jsoniter.Wrap(struct{ age int }{age: 1}) + should.Equal(any.ValueType(), jsoniter.ObjectValue) + should.Equal(any.LastError(), nil) + i = struct{ age int }{age: 1} + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap(map[string]interface{}{"abc": 1}) + should.Equal(any.ValueType(), jsoniter.ObjectValue) + should.Equal(any.LastError(), nil) + i = map[string]interface{}{"abc": 1} + should.Equal(i, any.GetInterface()) + + any = jsoniter.Wrap("abc") + i = "abc" + should.Equal(i, any.GetInterface()) + should.Equal(nil, any.LastError()) + +} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_uint32.go b/discovery/vendor/github.com/json-iterator/go/any_uint32.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_uint32.go rename to discovery/vendor/github.com/json-iterator/go/any_uint32.go diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_uint64.go b/discovery/vendor/github.com/json-iterator/go/any_uint64.go similarity index 100% rename from discovery/vendor/github.com/json-iterator/go/feature_any_uint64.go rename to discovery/vendor/github.com/json-iterator/go/any_uint64.go diff --git a/discovery/vendor/github.com/json-iterator/go/api_tests/config_test.go b/discovery/vendor/github.com/json-iterator/go/api_tests/config_test.go new file mode 100644 index 00000000..7aa349be --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/api_tests/config_test.go @@ -0,0 +1,174 @@ +package test + +import ( + "encoding/json" + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func Test_use_number_for_unmarshal(t *testing.T) { + should := require.New(t) + api := jsoniter.Config{UseNumber: true}.Froze() + var obj interface{} + should.Nil(api.UnmarshalFromString("123", &obj)) + should.Equal(json.Number("123"), obj) +} + +func Test_customize_float_marshal(t *testing.T) { + should := require.New(t) + json := jsoniter.Config{MarshalFloatWith6Digits: true}.Froze() + str, err := json.MarshalToString(float32(1.23456789)) + should.Nil(err) + should.Equal("1.234568", str) +} + +func Test_customize_tag_key(t *testing.T) { + + type TestObject struct { + Field string `orm:"field"` + } + + should := require.New(t) + json := jsoniter.Config{TagKey: "orm"}.Froze() + str, err := json.MarshalToString(TestObject{"hello"}) + should.Nil(err) + should.Equal(`{"field":"hello"}`, str) +} + +func Test_read_large_number_as_interface(t *testing.T) { + should := require.New(t) + var val interface{} + err := jsoniter.Config{UseNumber: true}.Froze().UnmarshalFromString(`123456789123456789123456789`, &val) + should.Nil(err) + output, err := jsoniter.MarshalToString(val) + should.Nil(err) + should.Equal(`123456789123456789123456789`, output) +} + +type caseSensitiveStruct struct { + A string `json:"a"` + B string `json:"b,omitempty"` + C *C `json:"C,omitempty"` +} + +type C struct { + D int64 `json:"D,omitempty"` + E *E `json:"e,omitempty"` +} + +type E struct { + F string `json:"F,omitempty"` +} + +func Test_CaseSensitive(t *testing.T) { + should := require.New(t) + + testCases := []struct { + input string + expectedOutput string + caseSensitive bool + }{ + { + input: `{"A":"foo","B":"bar"}`, + expectedOutput: `{"a":"foo","b":"bar"}`, + caseSensitive: false, + }, + { + input: `{"a":"foo","b":"bar"}`, + expectedOutput: `{"a":"foo","b":"bar"}`, + caseSensitive: true, + }, + { + input: `{"a":"foo","b":"bar","C":{"D":10}}`, + expectedOutput: `{"a":"foo","b":"bar","C":{"D":10}}`, + caseSensitive: true, + }, + { + input: `{"a":"foo","B":"bar","c":{"d":10}}`, + expectedOutput: `{"a":"foo"}`, + caseSensitive: true, + }, + { + input: `{"a":"foo","C":{"d":10}}`, + expectedOutput: `{"a":"foo","C":{}}`, + caseSensitive: true, + }, + { + input: `{"a":"foo","C":{"D":10,"e":{"f":"baz"}}}`, + expectedOutput: `{"a":"foo","C":{"D":10,"e":{}}}`, + caseSensitive: true, + }, + { + input: `{"a":"foo","C":{"D":10,"e":{"F":"baz"}}}`, + expectedOutput: `{"a":"foo","C":{"D":10,"e":{"F":"baz"}}}`, + caseSensitive: true, + }, + { + input: `{"A":"foo","c":{"d":10,"E":{"f":"baz"}}}`, + expectedOutput: `{"a":"foo","C":{"D":10,"e":{"F":"baz"}}}`, + caseSensitive: false, + }, + } + + for _, tc := range testCases { + val := caseSensitiveStruct{} + err := jsoniter.Config{CaseSensitive: tc.caseSensitive}.Froze().UnmarshalFromString(tc.input, &val) + should.Nil(err) + + output, err := jsoniter.MarshalToString(val) + should.Nil(err) + should.Equal(tc.expectedOutput, output) + } +} + +type structWithElevenFields struct { + A string `json:"A,omitempty"` + B string `json:"B,omitempty"` + C string `json:"C,omitempty"` + D string `json:"d,omitempty"` + E string `json:"e,omitempty"` + F string `json:"f,omitempty"` + G string `json:"g,omitempty"` + H string `json:"h,omitempty"` + I string `json:"i,omitempty"` + J string `json:"j,omitempty"` + K string `json:"k,omitempty"` +} + +func Test_CaseSensitive_MoreThanTenFields(t *testing.T) { + should := require.New(t) + + testCases := []struct { + input string + expectedOutput string + caseSensitive bool + }{ + { + input: `{"A":"1","B":"2","C":"3","d":"4","e":"5","f":"6","g":"7","h":"8","i":"9","j":"10","k":"11"}`, + expectedOutput: `{"A":"1","B":"2","C":"3","d":"4","e":"5","f":"6","g":"7","h":"8","i":"9","j":"10","k":"11"}`, + caseSensitive: true, + }, + { + input: `{"a":"1","b":"2","c":"3","D":"4","E":"5","F":"6"}`, + expectedOutput: `{"A":"1","B":"2","C":"3","d":"4","e":"5","f":"6"}`, + caseSensitive: false, + }, + { + input: `{"A":"1","b":"2","d":"4","E":"5"}`, + expectedOutput: `{"A":"1","d":"4"}`, + caseSensitive: true, + }, + } + + for _, tc := range testCases { + val := structWithElevenFields{} + err := jsoniter.Config{CaseSensitive: tc.caseSensitive}.Froze().UnmarshalFromString(tc.input, &val) + should.Nil(err) + + output, err := jsoniter.MarshalToString(val) + should.Nil(err) + should.Equal(tc.expectedOutput, output) + } +} diff --git a/discovery/vendor/github.com/json-iterator/go/api_tests/decoder_test.go b/discovery/vendor/github.com/json-iterator/go/api_tests/decoder_test.go new file mode 100644 index 00000000..8e1c1607 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/api_tests/decoder_test.go @@ -0,0 +1,64 @@ +package test + +import ( + "bytes" + "encoding/json" + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "io/ioutil" + "testing" +) + +func Test_disallowUnknownFields(t *testing.T) { + should := require.New(t) + type TestObject struct{} + var obj TestObject + decoder := jsoniter.NewDecoder(bytes.NewBufferString(`{"field1":100}`)) + decoder.DisallowUnknownFields() + should.Error(decoder.Decode(&obj)) +} + +func Test_new_decoder(t *testing.T) { + should := require.New(t) + decoder1 := json.NewDecoder(bytes.NewBufferString(`[1][2]`)) + decoder2 := jsoniter.NewDecoder(bytes.NewBufferString(`[1][2]`)) + arr1 := []int{} + should.Nil(decoder1.Decode(&arr1)) + should.Equal([]int{1}, arr1) + arr2 := []int{} + should.True(decoder1.More()) + buffered, _ := ioutil.ReadAll(decoder1.Buffered()) + should.Equal("[2]", string(buffered)) + should.Nil(decoder2.Decode(&arr2)) + should.Equal([]int{1}, arr2) + should.True(decoder2.More()) + buffered, _ = ioutil.ReadAll(decoder2.Buffered()) + should.Equal("[2]", string(buffered)) + + should.Nil(decoder1.Decode(&arr1)) + should.Equal([]int{2}, arr1) + should.False(decoder1.More()) + should.Nil(decoder2.Decode(&arr2)) + should.Equal([]int{2}, arr2) + should.False(decoder2.More()) +} + +func Test_use_number(t *testing.T) { + should := require.New(t) + decoder1 := json.NewDecoder(bytes.NewBufferString(`123`)) + decoder1.UseNumber() + decoder2 := jsoniter.NewDecoder(bytes.NewBufferString(`123`)) + decoder2.UseNumber() + var obj1 interface{} + should.Nil(decoder1.Decode(&obj1)) + should.Equal(json.Number("123"), obj1) + var obj2 interface{} + should.Nil(decoder2.Decode(&obj2)) + should.Equal(json.Number("123"), obj2) +} + +func Test_decoder_more(t *testing.T) { + should := require.New(t) + decoder := jsoniter.NewDecoder(bytes.NewBufferString("abcde")) + should.True(decoder.More()) +} \ No newline at end of file diff --git a/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_18_test.go b/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_18_test.go new file mode 100644 index 00000000..3c159b58 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_18_test.go @@ -0,0 +1,46 @@ +//+build go1.8 + +package test + +import ( + "bytes" + "encoding/json" + "testing" + "unicode/utf8" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func Test_new_encoder(t *testing.T) { + should := require.New(t) + buf1 := &bytes.Buffer{} + encoder1 := json.NewEncoder(buf1) + encoder1.SetEscapeHTML(false) + encoder1.Encode([]int{1}) + should.Equal("[1]\n", buf1.String()) + buf2 := &bytes.Buffer{} + encoder2 := jsoniter.NewEncoder(buf2) + encoder2.SetEscapeHTML(false) + encoder2.Encode([]int{1}) + should.Equal("[1]\n", buf2.String()) +} + +func Test_string_encode_with_std_without_html_escape(t *testing.T) { + api := jsoniter.Config{EscapeHTML: false}.Froze() + should := require.New(t) + for i := 0; i < utf8.RuneSelf; i++ { + input := string([]byte{byte(i)}) + buf := &bytes.Buffer{} + encoder := json.NewEncoder(buf) + encoder.SetEscapeHTML(false) + err := encoder.Encode(input) + should.Nil(err) + stdOutput := buf.String() + stdOutput = stdOutput[:len(stdOutput)-1] + jsoniterOutputBytes, err := api.Marshal(input) + should.Nil(err) + jsoniterOutput := string(jsoniterOutputBytes) + should.Equal(stdOutput, jsoniterOutput) + } +} diff --git a/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_test.go b/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_test.go new file mode 100644 index 00000000..7b9202cf --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/api_tests/encoder_test.go @@ -0,0 +1,20 @@ +package test + +import ( + "bytes" + "encoding/json" + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +// Standard Encoder has trailing newline. +func TestEncoderHasTrailingNewline(t *testing.T) { + should := require.New(t) + var buf, stdbuf bytes.Buffer + enc := jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder(&buf) + enc.Encode(1) + stdenc := json.NewEncoder(&stdbuf) + stdenc.Encode(1) + should.Equal(stdbuf.Bytes(), buf.Bytes()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/api_tests/marshal_indent_test.go b/discovery/vendor/github.com/json-iterator/go/api_tests/marshal_indent_test.go new file mode 100644 index 00000000..926931a8 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/api_tests/marshal_indent_test.go @@ -0,0 +1,36 @@ +package test + +import ( + "encoding/json" + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func Test_marshal_indent(t *testing.T) { + should := require.New(t) + obj := struct { + F1 int + F2 []int + }{1, []int{2, 3, 4}} + output, err := json.MarshalIndent(obj, "", " ") + should.Nil(err) + should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output)) + output, err = jsoniter.MarshalIndent(obj, "", " ") + should.Nil(err) + should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output)) +} + +func Test_marshal_indent_map(t *testing.T) { + should := require.New(t) + obj := map[int]int{1: 2} + output, err := json.MarshalIndent(obj, "", " ") + should.Nil(err) + should.Equal("{\n \"1\": 2\n}", string(output)) + output, err = jsoniter.MarshalIndent(obj, "", " ") + should.Nil(err) + should.Equal("{\n \"1\": 2\n}", string(output)) + output, err = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", " ") + should.Nil(err) + should.Equal("{\n \"1\": 2\n}", string(output)) +} diff --git a/discovery/vendor/github.com/json-iterator/go/benchmarks/encode_string_test.go b/discovery/vendor/github.com/json-iterator/go/benchmarks/encode_string_test.go new file mode 100644 index 00000000..c1cb1afb --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/benchmarks/encode_string_test.go @@ -0,0 +1,25 @@ +package test + +import ( + "bytes" + "github.com/json-iterator/go" + "testing" +) + +func Benchmark_encode_string_with_SetEscapeHTML(b *testing.B) { + type V struct { + S string + B bool + I int + } + var json = jsoniter.ConfigCompatibleWithStandardLibrary + b.ReportAllocs() + for i := 0; i < b.N; i++ { + buf := &bytes.Buffer{} + enc := json.NewEncoder(buf) + enc.SetEscapeHTML(true) + if err := enc.Encode(V{S: "s", B: true, I: 233}); err != nil { + b.Fatal(err) + } + } +} diff --git a/discovery/vendor/github.com/json-iterator/go/benchmarks/jsoniter_large_file_test.go b/discovery/vendor/github.com/json-iterator/go/benchmarks/jsoniter_large_file_test.go new file mode 100644 index 00000000..465eaec9 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/benchmarks/jsoniter_large_file_test.go @@ -0,0 +1,158 @@ +package test + +import ( + "encoding/json" + "github.com/json-iterator/go" + "io/ioutil" + "os" + "testing" +) + +//func Test_large_file(t *testing.T) { +// file, err := os.Open("/tmp/large-file.json") +// if err != nil { +// t.Fatal(err) +// } +// iter := Parse(file, 4096) +// count := 0 +// for iter.ReadArray() { +// iter.Skip() +// count++ +// } +// if count != 11351 { +// t.Fatal(count) +// } +//} + +func init() { + ioutil.WriteFile("/tmp/large-file.json", []byte(`[{ + "person": { + "id": "d50887ca-a6ce-4e59-b89f-14f0b5d03b03", + "name": { + "fullName": "Leonid Bugaev", + "givenName": "Leonid", + "familyName": "Bugaev" + }, + "email": "leonsbox@gmail.com", + "gender": "male", + "location": "Saint Petersburg, Saint Petersburg, RU", + "geo": { + "city": "Saint Petersburg", + "state": "Saint Petersburg", + "country": "Russia", + "lat": 59.9342802, + "lng": 30.3350986 + }, + "bio": "Senior engineer at Granify.com", + "site": "http://flickfaver.com", + "avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/d50887ca-a6ce-4e59-b89f-14f0b5d03b03", + "employment": { + "name": "www.latera.ru", + "title": "Software Engineer", + "domain": "gmail.com" + }, + "facebook": { + "handle": "leonid.bugaev" + }, + "github": { + "handle": "buger", + "id": 14009, + "avatar": "https://avatars.githubusercontent.com/u/14009?v=3", + "company": "Granify", + "blog": "http://leonsbox.com", + "followers": 95, + "following": 10 + }, + "twitter": { + "handle": "flickfaver", + "id": 77004410, + "bio": null, + "followers": 2, + "following": 1, + "statuses": 5, + "favorites": 0, + "location": "", + "site": "http://flickfaver.com", + "avatar": null + }, + "linkedin": { + "handle": "in/leonidbugaev" + }, + "googleplus": { + "handle": null + }, + "angellist": { + "handle": "leonid-bugaev", + "id": 61541, + "bio": "Senior engineer at Granify.com", + "blog": "http://buger.github.com", + "site": "http://buger.github.com", + "followers": 41, + "avatar": "https://d1qb2nb5cznatu.cloudfront.net/users/61541-medium_jpg?1405474390" + }, + "klout": { + "handle": null, + "score": null + }, + "foursquare": { + "handle": null + }, + "aboutme": { + "handle": "leonid.bugaev", + "bio": null, + "avatar": null + }, + "gravatar": { + "handle": "buger", + "urls": [ + ], + "avatar": "http://1.gravatar.com/avatar/f7c8edd577d13b8930d5522f28123510", + "avatars": [ + { + "url": "http://1.gravatar.com/avatar/f7c8edd577d13b8930d5522f28123510", + "type": "thumbnail" + } + ] + }, + "fuzzy": false + }, + "company": "hello" +}]`), 0666) +} + +/* +200000 8886 ns/op 4336 B/op 6 allocs/op +50000 34244 ns/op 6744 B/op 14 allocs/op +*/ +func Benchmark_jsoniter_large_file(b *testing.B) { + b.ReportAllocs() + for n := 0; n < b.N; n++ { + file, _ := os.Open("/tmp/large-file.json") + iter := jsoniter.Parse(jsoniter.ConfigDefault, file, 4096) + count := 0 + iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { + // Skip() is strict by default, use --tags jsoniter-sloppy to skip without validation + iter.Skip() + count++ + return true + }) + file.Close() + if iter.Error != nil { + b.Error(iter.Error) + } + } +} + +func Benchmark_json_large_file(b *testing.B) { + b.ReportAllocs() + for n := 0; n < b.N; n++ { + file, _ := os.Open("/tmp/large-file.json") + bytes, _ := ioutil.ReadAll(file) + file.Close() + result := []struct{}{} + err := json.Unmarshal(bytes, &result) + if err != nil { + b.Error(err) + } + } +} diff --git a/discovery/vendor/github.com/json-iterator/go/build.sh b/discovery/vendor/github.com/json-iterator/go/build.sh new file mode 100755 index 00000000..b45ef688 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +set -x + +if [ ! -d /tmp/build-golang/src/github.com/json-iterator ]; then + mkdir -p /tmp/build-golang/src/github.com/json-iterator + ln -s $PWD /tmp/build-golang/src/github.com/json-iterator/go +fi +export GOPATH=/tmp/build-golang +go get -u github.com/golang/dep/cmd/dep +cd /tmp/build-golang/src/github.com/json-iterator/go +exec $GOPATH/bin/dep ensure -update diff --git a/discovery/vendor/github.com/json-iterator/go/config.go b/discovery/vendor/github.com/json-iterator/go/config.go new file mode 100644 index 00000000..83581912 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/config.go @@ -0,0 +1,372 @@ +package jsoniter + +import ( + "encoding/json" + "io" + "reflect" + "sync" + "unsafe" + + "github.com/modern-go/concurrent" + "github.com/modern-go/reflect2" +) + +// Config customize how the API should behave. +// The API is created from Config by Froze. +type Config struct { + IndentionStep int + MarshalFloatWith6Digits bool + EscapeHTML bool + SortMapKeys bool + UseNumber bool + DisallowUnknownFields bool + TagKey string + OnlyTaggedField bool + ValidateJsonRawMessage bool + ObjectFieldMustBeSimpleString bool + CaseSensitive bool +} + +// API the public interface of this package. +// Primary Marshal and Unmarshal. +type API interface { + IteratorPool + StreamPool + MarshalToString(v interface{}) (string, error) + Marshal(v interface{}) ([]byte, error) + MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) + UnmarshalFromString(str string, v interface{}) error + Unmarshal(data []byte, v interface{}) error + Get(data []byte, path ...interface{}) Any + NewEncoder(writer io.Writer) *Encoder + NewDecoder(reader io.Reader) *Decoder + Valid(data []byte) bool + RegisterExtension(extension Extension) + DecoderOf(typ reflect2.Type) ValDecoder + EncoderOf(typ reflect2.Type) ValEncoder +} + +// ConfigDefault the default API +var ConfigDefault = Config{ + EscapeHTML: true, +}.Froze() + +// ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior +var ConfigCompatibleWithStandardLibrary = Config{ + EscapeHTML: true, + SortMapKeys: true, + ValidateJsonRawMessage: true, +}.Froze() + +// ConfigFastest marshals float with only 6 digits precision +var ConfigFastest = Config{ + EscapeHTML: false, + MarshalFloatWith6Digits: true, // will lose precession + ObjectFieldMustBeSimpleString: true, // do not unescape object field +}.Froze() + +type frozenConfig struct { + configBeforeFrozen Config + sortMapKeys bool + indentionStep int + objectFieldMustBeSimpleString bool + onlyTaggedField bool + disallowUnknownFields bool + decoderCache *concurrent.Map + encoderCache *concurrent.Map + extensions []Extension + streamPool *sync.Pool + iteratorPool *sync.Pool + caseSensitive bool +} + +func (cfg *frozenConfig) initCache() { + cfg.decoderCache = concurrent.NewMap() + cfg.encoderCache = concurrent.NewMap() +} + +func (cfg *frozenConfig) addDecoderToCache(cacheKey uintptr, decoder ValDecoder) { + cfg.decoderCache.Store(cacheKey, decoder) +} + +func (cfg *frozenConfig) addEncoderToCache(cacheKey uintptr, encoder ValEncoder) { + cfg.encoderCache.Store(cacheKey, encoder) +} + +func (cfg *frozenConfig) getDecoderFromCache(cacheKey uintptr) ValDecoder { + decoder, found := cfg.decoderCache.Load(cacheKey) + if found { + return decoder.(ValDecoder) + } + return nil +} + +func (cfg *frozenConfig) getEncoderFromCache(cacheKey uintptr) ValEncoder { + encoder, found := cfg.encoderCache.Load(cacheKey) + if found { + return encoder.(ValEncoder) + } + return nil +} + +var cfgCache = concurrent.NewMap() + +func getFrozenConfigFromCache(cfg Config) *frozenConfig { + obj, found := cfgCache.Load(cfg) + if found { + return obj.(*frozenConfig) + } + return nil +} + +func addFrozenConfigToCache(cfg Config, frozenConfig *frozenConfig) { + cfgCache.Store(cfg, frozenConfig) +} + +// Froze forge API from config +func (cfg Config) Froze() API { + api := &frozenConfig{ + sortMapKeys: cfg.SortMapKeys, + indentionStep: cfg.IndentionStep, + objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString, + onlyTaggedField: cfg.OnlyTaggedField, + disallowUnknownFields: cfg.DisallowUnknownFields, + caseSensitive: cfg.CaseSensitive, + } + api.streamPool = &sync.Pool{ + New: func() interface{} { + return NewStream(api, nil, 512) + }, + } + api.iteratorPool = &sync.Pool{ + New: func() interface{} { + return NewIterator(api) + }, + } + api.initCache() + encoderExtension := EncoderExtension{} + decoderExtension := DecoderExtension{} + if cfg.MarshalFloatWith6Digits { + api.marshalFloatWith6Digits(encoderExtension) + } + if cfg.EscapeHTML { + api.escapeHTML(encoderExtension) + } + if cfg.UseNumber { + api.useNumber(decoderExtension) + } + if cfg.ValidateJsonRawMessage { + api.validateJsonRawMessage(encoderExtension) + } + if len(encoderExtension) > 0 { + api.extensions = append(api.extensions, encoderExtension) + } + if len(decoderExtension) > 0 { + api.extensions = append(api.extensions, decoderExtension) + } + api.configBeforeFrozen = cfg + return api +} + +func (cfg Config) frozeWithCacheReuse() *frozenConfig { + api := getFrozenConfigFromCache(cfg) + if api != nil { + return api + } + api = cfg.Froze().(*frozenConfig) + addFrozenConfigToCache(cfg, api) + return api +} + +func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) { + encoder := &funcEncoder{func(ptr unsafe.Pointer, stream *Stream) { + rawMessage := *(*json.RawMessage)(ptr) + iter := cfg.BorrowIterator([]byte(rawMessage)) + iter.Read() + if iter.Error != nil { + stream.WriteRaw("null") + } else { + cfg.ReturnIterator(iter) + stream.WriteRaw(string(rawMessage)) + } + }, func(ptr unsafe.Pointer) bool { + return false + }} + extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder + extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder +} + +func (cfg *frozenConfig) useNumber(extension DecoderExtension) { + extension[reflect2.TypeOfPtr((*interface{})(nil)).Elem()] = &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) { + exitingValue := *((*interface{})(ptr)) + if exitingValue != nil && reflect.TypeOf(exitingValue).Kind() == reflect.Ptr { + iter.ReadVal(exitingValue) + return + } + if iter.WhatIsNext() == NumberValue { + *((*interface{})(ptr)) = json.Number(iter.readNumberAsString()) + } else { + *((*interface{})(ptr)) = iter.Read() + } + }} +} +func (cfg *frozenConfig) getTagKey() string { + tagKey := cfg.configBeforeFrozen.TagKey + if tagKey == "" { + return "json" + } + return tagKey +} + +func (cfg *frozenConfig) RegisterExtension(extension Extension) { + cfg.extensions = append(cfg.extensions, extension) +} + +type lossyFloat32Encoder struct { +} + +func (encoder *lossyFloat32Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { + stream.WriteFloat32Lossy(*((*float32)(ptr))) +} + +func (encoder *lossyFloat32Encoder) IsEmpty(ptr unsafe.Pointer) bool { + return *((*float32)(ptr)) == 0 +} + +type lossyFloat64Encoder struct { +} + +func (encoder *lossyFloat64Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { + stream.WriteFloat64Lossy(*((*float64)(ptr))) +} + +func (encoder *lossyFloat64Encoder) IsEmpty(ptr unsafe.Pointer) bool { + return *((*float64)(ptr)) == 0 +} + +// EnableLossyFloatMarshalling keeps 10**(-6) precision +// for float variables for better performance. +func (cfg *frozenConfig) marshalFloatWith6Digits(extension EncoderExtension) { + // for better performance + extension[reflect2.TypeOfPtr((*float32)(nil)).Elem()] = &lossyFloat32Encoder{} + extension[reflect2.TypeOfPtr((*float64)(nil)).Elem()] = &lossyFloat64Encoder{} +} + +type htmlEscapedStringEncoder struct { +} + +func (encoder *htmlEscapedStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { + str := *((*string)(ptr)) + stream.WriteStringWithHTMLEscaped(str) +} + +func (encoder *htmlEscapedStringEncoder) IsEmpty(ptr unsafe.Pointer) bool { + return *((*string)(ptr)) == "" +} + +func (cfg *frozenConfig) escapeHTML(encoderExtension EncoderExtension) { + encoderExtension[reflect2.TypeOfPtr((*string)(nil)).Elem()] = &htmlEscapedStringEncoder{} +} + +func (cfg *frozenConfig) cleanDecoders() { + typeDecoders = map[string]ValDecoder{} + fieldDecoders = map[string]ValDecoder{} + *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) +} + +func (cfg *frozenConfig) cleanEncoders() { + typeEncoders = map[string]ValEncoder{} + fieldEncoders = map[string]ValEncoder{} + *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) +} + +func (cfg *frozenConfig) MarshalToString(v interface{}) (string, error) { + stream := cfg.BorrowStream(nil) + defer cfg.ReturnStream(stream) + stream.WriteVal(v) + if stream.Error != nil { + return "", stream.Error + } + return string(stream.Buffer()), nil +} + +func (cfg *frozenConfig) Marshal(v interface{}) ([]byte, error) { + stream := cfg.BorrowStream(nil) + defer cfg.ReturnStream(stream) + stream.WriteVal(v) + if stream.Error != nil { + return nil, stream.Error + } + result := stream.Buffer() + copied := make([]byte, len(result)) + copy(copied, result) + return copied, nil +} + +func (cfg *frozenConfig) MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + if prefix != "" { + panic("prefix is not supported") + } + for _, r := range indent { + if r != ' ' { + panic("indent can only be space") + } + } + newCfg := cfg.configBeforeFrozen + newCfg.IndentionStep = len(indent) + return newCfg.frozeWithCacheReuse().Marshal(v) +} + +func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error { + data := []byte(str) + iter := cfg.BorrowIterator(data) + defer cfg.ReturnIterator(iter) + iter.ReadVal(v) + c := iter.nextToken() + if c == 0 { + if iter.Error == io.EOF { + return nil + } + return iter.Error + } + iter.ReportError("Unmarshal", "there are bytes left after unmarshal") + return iter.Error +} + +func (cfg *frozenConfig) Get(data []byte, path ...interface{}) Any { + iter := cfg.BorrowIterator(data) + defer cfg.ReturnIterator(iter) + return locatePath(iter, path) +} + +func (cfg *frozenConfig) Unmarshal(data []byte, v interface{}) error { + iter := cfg.BorrowIterator(data) + defer cfg.ReturnIterator(iter) + iter.ReadVal(v) + c := iter.nextToken() + if c == 0 { + if iter.Error == io.EOF { + return nil + } + return iter.Error + } + iter.ReportError("Unmarshal", "there are bytes left after unmarshal") + return iter.Error +} + +func (cfg *frozenConfig) NewEncoder(writer io.Writer) *Encoder { + stream := NewStream(cfg, writer, 512) + return &Encoder{stream} +} + +func (cfg *frozenConfig) NewDecoder(reader io.Reader) *Decoder { + iter := Parse(cfg, reader, 512) + return &Decoder{iter} +} + +func (cfg *frozenConfig) Valid(data []byte) bool { + iter := cfg.BorrowIterator(data) + defer cfg.ReturnIterator(iter) + iter.Skip() + return iter.Error == nil +} diff --git a/discovery/vendor/github.com/json-iterator/go/example_test.go b/discovery/vendor/github.com/json-iterator/go/example_test.go new file mode 100644 index 00000000..7f521a30 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/example_test.go @@ -0,0 +1,121 @@ +package jsoniter + +import ( + "fmt" + "os" + "strings" +) + +func ExampleMarshal() { + type ColorGroup struct { + ID int + Name string + Colors []string + } + group := ColorGroup{ + ID: 1, + Name: "Reds", + Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, + } + b, err := Marshal(group) + if err != nil { + fmt.Println("error:", err) + } + os.Stdout.Write(b) + // Output: + // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} +} + +func ExampleUnmarshal() { + var jsonBlob = []byte(`[ + {"Name": "Platypus", "Order": "Monotremata"}, + {"Name": "Quoll", "Order": "Dasyuromorphia"} + ]`) + type Animal struct { + Name string + Order string + } + var animals []Animal + err := Unmarshal(jsonBlob, &animals) + if err != nil { + fmt.Println("error:", err) + } + fmt.Printf("%+v", animals) + // Output: + // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}] +} + +func ExampleConfigFastest_Marshal() { + type ColorGroup struct { + ID int + Name string + Colors []string + } + group := ColorGroup{ + ID: 1, + Name: "Reds", + Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, + } + stream := ConfigFastest.BorrowStream(nil) + defer ConfigFastest.ReturnStream(stream) + stream.WriteVal(group) + if stream.Error != nil { + fmt.Println("error:", stream.Error) + } + os.Stdout.Write(stream.Buffer()) + // Output: + // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} +} + +func ExampleConfigFastest_Unmarshal() { + var jsonBlob = []byte(`[ + {"Name": "Platypus", "Order": "Monotremata"}, + {"Name": "Quoll", "Order": "Dasyuromorphia"} + ]`) + type Animal struct { + Name string + Order string + } + var animals []Animal + iter := ConfigFastest.BorrowIterator(jsonBlob) + defer ConfigFastest.ReturnIterator(iter) + iter.ReadVal(&animals) + if iter.Error != nil { + fmt.Println("error:", iter.Error) + } + fmt.Printf("%+v", animals) + // Output: + // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}] +} + +func ExampleGet() { + val := []byte(`{"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}`) + fmt.Printf(Get(val, "Colors", 0).ToString()) + // Output: + // Crimson +} + +func ExampleMapKey() { + hello := MyKey("hello") + output, _ := Marshal(map[*MyKey]string{&hello: "world"}) + fmt.Println(string(output)) + obj := map[*MyKey]string{} + Unmarshal(output, &obj) + for k, v := range obj { + fmt.Println(*k, v) + } + // Output: + // {"Hello":"world"} + // Hel world +} + +type MyKey string + +func (m *MyKey) MarshalText() ([]byte, error) { + return []byte(strings.Replace(string(*m), "h", "H", -1)), nil +} + +func (m *MyKey) UnmarshalText(text []byte) error { + *m = MyKey(text[:3]) + return nil +} diff --git a/discovery/vendor/github.com/json-iterator/go/extension_tests/decoder_test.go b/discovery/vendor/github.com/json-iterator/go/extension_tests/decoder_test.go new file mode 100644 index 00000000..db253d88 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extension_tests/decoder_test.go @@ -0,0 +1,100 @@ +package test + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "strconv" + "testing" + "time" + "unsafe" +) + +func Test_customize_type_decoder(t *testing.T) { + t.Skip() + jsoniter.RegisterTypeDecoderFunc("time.Time", func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + t, err := time.ParseInLocation("2006-01-02 15:04:05", iter.ReadString(), time.UTC) + if err != nil { + iter.Error = err + return + } + *((*time.Time)(ptr)) = t + }) + //defer jsoniter.ConfigDefault.(*frozenConfig).cleanDecoders() + val := time.Time{} + err := jsoniter.Unmarshal([]byte(`"2016-12-05 08:43:28"`), &val) + if err != nil { + t.Fatal(err) + } + year, month, day := val.Date() + if year != 2016 || month != 12 || day != 5 { + t.Fatal(val) + } +} + +func Test_customize_byte_array_encoder(t *testing.T) { + t.Skip() + //jsoniter.ConfigDefault.(*frozenConfig).cleanEncoders() + should := require.New(t) + jsoniter.RegisterTypeEncoderFunc("[]uint8", func(ptr unsafe.Pointer, stream *jsoniter.Stream) { + t := *((*[]byte)(ptr)) + stream.WriteString(string(t)) + }, nil) + //defer jsoniter.ConfigDefault.(*frozenConfig).cleanEncoders() + val := []byte("abc") + str, err := jsoniter.MarshalToString(val) + should.Nil(err) + should.Equal(`"abc"`, str) +} + +func Test_customize_field_decoder(t *testing.T) { + type Tom struct { + field1 string + } + jsoniter.RegisterFieldDecoderFunc("jsoniter.Tom", "field1", func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + *((*string)(ptr)) = strconv.Itoa(iter.ReadInt()) + }) + //defer jsoniter.ConfigDefault.(*frozenConfig).cleanDecoders() + tom := Tom{} + err := jsoniter.Unmarshal([]byte(`{"field1": 100}`), &tom) + if err != nil { + t.Fatal(err) + } +} + +func Test_recursive_empty_interface_customization(t *testing.T) { + t.Skip() + var obj interface{} + jsoniter.RegisterTypeDecoderFunc("interface {}", func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + switch iter.WhatIsNext() { + case jsoniter.NumberValue: + *(*interface{})(ptr) = iter.ReadInt64() + default: + *(*interface{})(ptr) = iter.Read() + } + }) + should := require.New(t) + jsoniter.Unmarshal([]byte("[100]"), &obj) + should.Equal([]interface{}{int64(100)}, obj) +} + +type MyInterface interface { + Hello() string +} + +type MyString string + +func (ms MyString) Hello() string { + return string(ms) +} + +func Test_read_custom_interface(t *testing.T) { + t.Skip() + should := require.New(t) + var val MyInterface + jsoniter.RegisterTypeDecoderFunc("jsoniter.MyInterface", func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + *((*MyInterface)(ptr)) = MyString(iter.ReadString()) + }) + err := jsoniter.UnmarshalFromString(`"hello"`, &val) + should.Nil(err) + should.Equal("hello", val.Hello()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extension_tests/extension_test.go b/discovery/vendor/github.com/json-iterator/go/extension_tests/extension_test.go new file mode 100644 index 00000000..836db5bc --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extension_tests/extension_test.go @@ -0,0 +1,120 @@ +package test + +import ( + "github.com/json-iterator/go" + "github.com/modern-go/reflect2" + "github.com/stretchr/testify/require" + "reflect" + "strconv" + "testing" + "unsafe" +) + +type TestObject1 struct { + Field1 string +} + +type testExtension struct { + jsoniter.DummyExtension +} + +func (extension *testExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) { + if structDescriptor.Type.String() != "test.TestObject1" { + return + } + binding := structDescriptor.GetField("Field1") + binding.Encoder = &funcEncoder{fun: func(ptr unsafe.Pointer, stream *jsoniter.Stream) { + str := *((*string)(ptr)) + val, _ := strconv.Atoi(str) + stream.WriteInt(val) + }} + binding.Decoder = &funcDecoder{func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + *((*string)(ptr)) = strconv.Itoa(iter.ReadInt()) + }} + binding.ToNames = []string{"field-1"} + binding.FromNames = []string{"field-1"} +} + +func Test_customize_field_by_extension(t *testing.T) { + should := require.New(t) + cfg := jsoniter.Config{}.Froze() + cfg.RegisterExtension(&testExtension{}) + obj := TestObject1{} + err := cfg.UnmarshalFromString(`{"field-1": 100}`, &obj) + should.Nil(err) + should.Equal("100", obj.Field1) + str, err := cfg.MarshalToString(obj) + should.Nil(err) + should.Equal(`{"field-1":100}`, str) +} + +func Test_customize_map_key_encoder(t *testing.T) { + should := require.New(t) + cfg := jsoniter.Config{}.Froze() + cfg.RegisterExtension(&testMapKeyExtension{}) + m := map[int]int{1: 2} + output, err := cfg.MarshalToString(m) + should.NoError(err) + should.Equal(`{"2":2}`, output) + m = map[int]int{} + should.NoError(cfg.UnmarshalFromString(output, &m)) + should.Equal(map[int]int{1: 2}, m) +} + +type testMapKeyExtension struct { + jsoniter.DummyExtension +} + +func (extension *testMapKeyExtension) CreateMapKeyEncoder(typ reflect2.Type) jsoniter.ValEncoder { + if typ.Kind() == reflect.Int { + return &funcEncoder{ + fun: func(ptr unsafe.Pointer, stream *jsoniter.Stream) { + stream.WriteRaw(`"`) + stream.WriteInt(*(*int)(ptr) + 1) + stream.WriteRaw(`"`) + }, + } + } + return nil +} + +func (extension *testMapKeyExtension) CreateMapKeyDecoder(typ reflect2.Type) jsoniter.ValDecoder { + if typ.Kind() == reflect.Int { + return &funcDecoder{ + fun: func(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + i, err := strconv.Atoi(iter.ReadString()) + if err != nil { + iter.ReportError("read map key", err.Error()) + return + } + i-- + *(*int)(ptr) = i + }, + } + } + return nil +} + +type funcDecoder struct { + fun jsoniter.DecoderFunc +} + +func (decoder *funcDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + decoder.fun(ptr, iter) +} + +type funcEncoder struct { + fun jsoniter.EncoderFunc + isEmptyFunc func(ptr unsafe.Pointer) bool +} + +func (encoder *funcEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { + encoder.fun(ptr, stream) +} + +func (encoder *funcEncoder) IsEmpty(ptr unsafe.Pointer) bool { + if encoder.isEmptyFunc == nil { + return false + } + return encoder.isEmptyFunc(ptr) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec.go b/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec.go new file mode 100644 index 00000000..543895be --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec.go @@ -0,0 +1,238 @@ +package extra + +import ( + "github.com/json-iterator/go" + "github.com/modern-go/reflect2" + "unicode/utf8" + "unsafe" +) + +// safeSet holds the value true if the ASCII character with the given array +// position can be represented inside a JSON string without any further +// escaping. +// +// All values are true except for the ASCII control characters (0-31), the +// double quote ("), and the backslash character ("\"). +var safeSet = [utf8.RuneSelf]bool{ + ' ': true, + '!': true, + '"': false, + '#': true, + '$': true, + '%': true, + '&': true, + '\'': true, + '(': true, + ')': true, + '*': true, + '+': true, + ',': true, + '-': true, + '.': true, + '/': true, + '0': true, + '1': true, + '2': true, + '3': true, + '4': true, + '5': true, + '6': true, + '7': true, + '8': true, + '9': true, + ':': true, + ';': true, + '<': true, + '=': true, + '>': true, + '?': true, + '@': true, + 'A': true, + 'B': true, + 'C': true, + 'D': true, + 'E': true, + 'F': true, + 'G': true, + 'H': true, + 'I': true, + 'J': true, + 'K': true, + 'L': true, + 'M': true, + 'N': true, + 'O': true, + 'P': true, + 'Q': true, + 'R': true, + 'S': true, + 'T': true, + 'U': true, + 'V': true, + 'W': true, + 'X': true, + 'Y': true, + 'Z': true, + '[': true, + '\\': false, + ']': true, + '^': true, + '_': true, + '`': true, + 'a': true, + 'b': true, + 'c': true, + 'd': true, + 'e': true, + 'f': true, + 'g': true, + 'h': true, + 'i': true, + 'j': true, + 'k': true, + 'l': true, + 'm': true, + 'n': true, + 'o': true, + 'p': true, + 'q': true, + 'r': true, + 's': true, + 't': true, + 'u': true, + 'v': true, + 'w': true, + 'x': true, + 'y': true, + 'z': true, + '{': true, + '|': true, + '}': true, + '~': true, + '\u007f': true, +} + +var binaryType = reflect2.TypeOfPtr((*[]byte)(nil)).Elem() + +type BinaryAsStringExtension struct { + jsoniter.DummyExtension +} + +func (extension *BinaryAsStringExtension) CreateEncoder(typ reflect2.Type) jsoniter.ValEncoder { + if typ == binaryType { + return &binaryAsStringCodec{} + } + return nil +} + +func (extension *BinaryAsStringExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder { + if typ == binaryType { + return &binaryAsStringCodec{} + } + return nil +} + +type binaryAsStringCodec struct { +} + +func (codec *binaryAsStringCodec) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { + rawBytes := iter.ReadStringAsSlice() + bytes := make([]byte, 0, len(rawBytes)) + for i := 0; i < len(rawBytes); i++ { + b := rawBytes[i] + if b == '\\' { + b2 := rawBytes[i+1] + if b2 != '\\' { + iter.ReportError("decode binary as string", `\\x is only supported escape`) + return + } + b3 := rawBytes[i+2] + if b3 != 'x' { + iter.ReportError("decode binary as string", `\\x is only supported escape`) + return + } + b4 := rawBytes[i+3] + b5 := rawBytes[i+4] + i = i + 4 + b = readHex(iter, b4, b5) + } + bytes = append(bytes, b) + } + *(*[]byte)(ptr) = bytes +} +func (codec *binaryAsStringCodec) IsEmpty(ptr unsafe.Pointer) bool { + return len(*((*[]byte)(ptr))) == 0 +} +func (codec *binaryAsStringCodec) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { + newBuffer := writeBytes(stream.Buffer(), *(*[]byte)(ptr)) + stream.SetBuffer(newBuffer) +} + +func readHex(iter *jsoniter.Iterator, b1, b2 byte) byte { + var ret byte + if b1 >= '0' && b1 <= '9' { + ret = b1 - '0' + } else if b1 >= 'a' && b1 <= 'f' { + ret = b1 - 'a' + 10 + } else { + iter.ReportError("read hex", "expects 0~9 or a~f, but found "+string([]byte{b1})) + return 0 + } + ret = ret * 16 + if b2 >= '0' && b2 <= '9' { + ret = b2 - '0' + } else if b2 >= 'a' && b2 <= 'f' { + ret = b2 - 'a' + 10 + } else { + iter.ReportError("read hex", "expects 0~9 or a~f, but found "+string([]byte{b2})) + return 0 + } + return ret +} + +var hex = "0123456789abcdef" + +func writeBytes(space []byte, s []byte) []byte { + space = append(space, '"') + // write string, the fast path, without utf8 and escape support + var i int + var c byte + for i, c = range s { + if c < utf8.RuneSelf && safeSet[c] { + space = append(space, c) + } else { + break + } + } + if i == len(s)-1 { + space = append(space, '"') + return space + } + return writeBytesSlowPath(space, s[i:]) +} + +func writeBytesSlowPath(space []byte, s []byte) []byte { + start := 0 + // for the remaining parts, we process them char by char + var i int + var b byte + for i, b = range s { + if b >= utf8.RuneSelf { + space = append(space, '\\', '\\', 'x', hex[b>>4], hex[b&0xF]) + start = i + 1 + continue + } + if safeSet[b] { + continue + } + if start < i { + space = append(space, s[start:i]...) + } + space = append(space, '\\', '\\', 'x', hex[b>>4], hex[b&0xF]) + start = i + 1 + } + if start < len(s) { + space = append(space, s[start:]...) + } + return append(space, '"') +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec_test.go b/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec_test.go new file mode 100644 index 00000000..a00479e6 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/binary_as_string_codec_test.go @@ -0,0 +1,32 @@ +package extra + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func init() { + jsoniter.RegisterExtension(&BinaryAsStringExtension{}) +} + +func TestBinaryAsStringCodec(t *testing.T) { + t.Run("safe set", func(t *testing.T) { + should := require.New(t) + output, err := jsoniter.Marshal([]byte("hello")) + should.NoError(err) + should.Equal(`"hello"`, string(output)) + var val []byte + should.NoError(jsoniter.Unmarshal(output, &val)) + should.Equal(`hello`, string(val)) + }) + t.Run("non safe set", func(t *testing.T) { + should := require.New(t) + output, err := jsoniter.Marshal([]byte{1, 2, 3, 15}) + should.NoError(err) + should.Equal(`"\\x01\\x02\\x03\\x0f"`, string(output)) + var val []byte + should.NoError(jsoniter.Unmarshal(output, &val)) + should.Equal([]byte{1, 2, 3, 15}, val) + }) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder.go b/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder.go index 9b63c277..52546b11 100644 --- a/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder.go +++ b/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder.go @@ -9,6 +9,7 @@ import ( "unsafe" "github.com/json-iterator/go" + "github.com/modern-go/reflect2" ) const maxUint = ^uint(0) @@ -148,7 +149,7 @@ type tolerateEmptyArrayExtension struct { jsoniter.DummyExtension } -func (extension *tolerateEmptyArrayExtension) DecorateDecoder(typ reflect.Type, decoder jsoniter.ValDecoder) jsoniter.ValDecoder { +func (extension *tolerateEmptyArrayExtension) DecorateDecoder(typ reflect2.Type, decoder jsoniter.ValDecoder) jsoniter.ValDecoder { if typ.Kind() == reflect.Struct || typ.Kind() == reflect.Map { return &tolerateEmptyArrayDecoder{decoder} } @@ -182,6 +183,9 @@ func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Ite *((*string)(ptr)) = string(number) case jsoniter.StringValue: *((*string)(ptr)) = iter.ReadString() + case jsoniter.NilValue: + iter.Skip() + *((*string)(ptr)) = "" default: iter.ReportError("fuzzyStringDecoder", "not number or string") } @@ -207,9 +211,15 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It } else { str = "0" } + case jsoniter.NilValue: + iter.Skip() + str = "0" default: iter.ReportError("fuzzyIntegerDecoder", "not number or string") } + if len(str) == 0 { + str = "0" + } newIter := iter.Pool().BorrowIterator([]byte(str)) defer iter.Pool().ReturnIterator(newIter) isFloat := strings.IndexByte(str, '.') != -1 @@ -243,6 +253,9 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It } else { *((*float32)(ptr)) = 0 } + case jsoniter.NilValue: + iter.Skip() + *((*float32)(ptr)) = 0 default: iter.ReportError("fuzzyFloat32Decoder", "not number or string") } @@ -272,7 +285,10 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It } else { *((*float64)(ptr)) = 0 } + case jsoniter.NilValue: + iter.Skip() + *((*float64)(ptr)) = 0 default: - iter.ReportError("fuzzyFloat32Decoder", "not number or string") + iter.ReportError("fuzzyFloat64Decoder", "not number or string") } } diff --git a/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder_test.go b/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder_test.go new file mode 100644 index 00000000..69315adf --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/fuzzy_decoder_test.go @@ -0,0 +1,393 @@ +package extra + +import ( + "testing" + + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" +) + +func init() { + RegisterFuzzyDecoders() +} + +func Test_any_to_string(t *testing.T) { + should := require.New(t) + var val string + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal("100", val) + should.Nil(jsoniter.UnmarshalFromString("10", &val)) + should.Equal("10", val) + should.Nil(jsoniter.UnmarshalFromString("10.1", &val)) + should.Equal("10.1", val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal("10.1", val) + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) +} +func Test_any_to_int64(t *testing.T) { + should := require.New(t) + var val int64 + + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(int64(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(int64(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(int64(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(int64(10), val) + should.Nil(jsoniter.UnmarshalFromString(`""`, &val)) + should.Equal(int64(0), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(int64(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(int64(1), val) + + should.Nil(jsoniter.UnmarshalFromString(`-10`, &val)) + should.Equal(int64(-10), val) + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_int(t *testing.T) { + should := require.New(t) + var val int + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(100, val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(10, val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(10, val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(10, val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(0, val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(1, val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_int16(t *testing.T) { + should := require.New(t) + var val int16 + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(int16(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(int16(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(int16(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(int16(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(int16(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(int16(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_int32(t *testing.T) { + should := require.New(t) + var val int32 + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(int32(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(int32(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(int32(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(int32(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(int32(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(int32(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_int8(t *testing.T) { + should := require.New(t) + var val int8 + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(int8(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(int8(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(int8(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(int8(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(int8(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(int8(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_uint8(t *testing.T) { + should := require.New(t) + var val uint8 + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(uint8(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(uint8(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(uint8(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(uint8(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(uint8(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(uint8(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_uint64(t *testing.T) { + should := require.New(t) + var val uint64 + + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(uint64(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(uint64(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(uint64(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(uint64(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(uint64(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(uint64(1), val) + + // TODO fix? + should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val)) + should.Equal(uint64(0), val) + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} +func Test_any_to_uint32(t *testing.T) { + should := require.New(t) + var val uint32 + + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(uint32(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(uint32(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(uint32(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(uint32(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(uint32(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(uint32(1), val) + + // TODO fix? + should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val)) + should.Equal(uint32(0), val) + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} +func Test_any_to_uint16(t *testing.T) { + should := require.New(t) + var val uint16 + + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(uint16(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(uint16(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(uint16(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(uint16(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(uint16(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(uint16(1), val) + + // TODO fix? + should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val)) + should.Equal(uint16(0), val) + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} +func Test_any_to_uint(t *testing.T) { + should := require.New(t) + var val uint + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(uint(100), val) + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(uint(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(uint(10), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(uint(10), val) + + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(uint(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(uint(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) + // large float to int + should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val)) +} + +func Test_any_to_float32(t *testing.T) { + should := require.New(t) + var val float32 + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(float32(100), val) + + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(float32(10.1), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(float32(10.1), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(float32(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(float32(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(float32(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) +} + +func Test_any_to_float64(t *testing.T) { + should := require.New(t) + var val float64 + + should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val)) + should.Equal(float64(100), val) + + should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val)) + should.Equal(float64(10.1), val) + should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val)) + should.Equal(float64(10.1), val) + should.Nil(jsoniter.UnmarshalFromString(`10`, &val)) + should.Equal(float64(10), val) + + // bool part + should.Nil(jsoniter.UnmarshalFromString(`false`, &val)) + should.Equal(float64(0), val) + should.Nil(jsoniter.UnmarshalFromString(`true`, &val)) + should.Equal(float64(1), val) + + should.NotNil(jsoniter.UnmarshalFromString("{}", &val)) + should.NotNil(jsoniter.UnmarshalFromString("[]", &val)) +} + +func Test_empty_array_as_map(t *testing.T) { + should := require.New(t) + var val map[string]interface{} + should.Nil(jsoniter.UnmarshalFromString(`[]`, &val)) + should.Equal(map[string]interface{}{}, val) +} + +func Test_empty_array_as_object(t *testing.T) { + should := require.New(t) + var val struct{} + should.Nil(jsoniter.UnmarshalFromString(`[]`, &val)) + should.Equal(struct{}{}, val) +} + +func Test_bad_case(t *testing.T) { + var jsonstr = ` +{ + "extra_type": 181760, + "combo_type": 0, + "trigger_time_ms": 1498800398000, + "_create_time": "2017-06-16 11:21:39", + "_msg_type": 41000 +} +` + + type OrderEventRequestParams struct { + ExtraType uint64 `json:"extra_type"` + } + + var a OrderEventRequestParams + err := jsoniter.UnmarshalFromString(jsonstr, &a) + should := require.New(t) + should.Nil(err) +} + +func Test_null_to_string(t *testing.T) { + should := require.New(t) + body := []byte(`null`) + var message string + err := jsoniter.Unmarshal(body, &message) + should.NoError(err) +} + +func Test_null_to_int(t *testing.T) { + should := require.New(t) + body := []byte(`null`) + var message int + err := jsoniter.Unmarshal(body, &message) + should.NoError(err) +} + +func Test_null_to_float32(t *testing.T) { + should := require.New(t) + body := []byte(`null`) + var message float32 + err := jsoniter.Unmarshal(body, &message) + should.NoError(err) +} + +func Test_null_to_float64(t *testing.T) { + should := require.New(t) + body := []byte(`null`) + var message float64 + err := jsoniter.Unmarshal(body, &message) + should.NoError(err) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy.go b/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy.go index 642556fe..671e4951 100644 --- a/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy.go +++ b/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy.go @@ -17,8 +17,8 @@ type namingStrategyExtension struct { func (extension *namingStrategyExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) { for _, binding := range structDescriptor.Fields { - binding.ToNames = []string{extension.translate(binding.Field.Name)} - binding.FromNames = []string{extension.translate(binding.Field.Name)} + binding.ToNames = []string{extension.translate(binding.Field.Name())} + binding.FromNames = []string{extension.translate(binding.Field.Name())} } } diff --git a/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy_test.go b/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy_test.go new file mode 100644 index 00000000..d1560812 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/naming_strategy_test.go @@ -0,0 +1,23 @@ +package extra + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func Test_lower_case_with_underscores(t *testing.T) { + should := require.New(t) + should.Equal("hello_world", LowerCaseWithUnderscores("helloWorld")) + should.Equal("hello_world", LowerCaseWithUnderscores("HelloWorld")) + SetNamingStrategy(LowerCaseWithUnderscores) + output, err := jsoniter.Marshal(struct { + UserName string + FirstLanguage string + }{ + UserName: "taowen", + FirstLanguage: "Chinese", + }) + should.Nil(err) + should.Equal(`{"user_name":"taowen","first_language":"Chinese"}`, string(output)) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/privat_fields.go b/discovery/vendor/github.com/json-iterator/go/extra/privat_fields.go index 18643961..0cfd549e 100644 --- a/discovery/vendor/github.com/json-iterator/go/extra/privat_fields.go +++ b/discovery/vendor/github.com/json-iterator/go/extra/privat_fields.go @@ -3,6 +3,7 @@ package extra import ( "github.com/json-iterator/go" "unicode" + "strings" ) // SupportPrivateFields include private fields when encoding/decoding @@ -16,10 +17,39 @@ type privateFieldsExtension struct { func (extension *privateFieldsExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) { for _, binding := range structDescriptor.Fields { - isPrivate := unicode.IsLower(rune(binding.Field.Name[0])) + isPrivate := unicode.IsLower(rune(binding.Field.Name()[0])) if isPrivate { - binding.FromNames = []string{binding.Field.Name} - binding.ToNames = []string{binding.Field.Name} + tag, hastag := binding.Field.Tag().Lookup("json") + if !hastag { + binding.FromNames = []string{binding.Field.Name()} + binding.ToNames = []string{binding.Field.Name()} + continue + } + tagParts := strings.Split(tag, ",") + names := calcFieldNames(binding.Field.Name(), tagParts[0], tag) + binding.FromNames = names + binding.ToNames = names } } } + +func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string { + // ignore? + if wholeTag == "-" { + return []string{} + } + // rename? + var fieldNames []string + if tagProvidedFieldName == "" { + fieldNames = []string{originalFieldName} + } else { + fieldNames = []string{tagProvidedFieldName} + } + // private? + isNotExported := unicode.IsLower(rune(originalFieldName[0])) + if isNotExported { + fieldNames = []string{} + } + return fieldNames +} + diff --git a/discovery/vendor/github.com/json-iterator/go/extra/private_fields_test.go b/discovery/vendor/github.com/json-iterator/go/extra/private_fields_test.go new file mode 100644 index 00000000..d3bc40da --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/private_fields_test.go @@ -0,0 +1,18 @@ +package extra + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" +) + +func Test_private_fields(t *testing.T) { + type TestObject struct { + field1 string + } + SupportPrivateFields() + should := require.New(t) + obj := TestObject{} + should.Nil(jsoniter.UnmarshalFromString(`{"field1":"Hello"}`, &obj)) + should.Equal("Hello", obj.field1) +} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec.go b/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec.go index e270cd40..9893872a 100644 --- a/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec.go +++ b/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec.go @@ -29,6 +29,3 @@ func (codec *timeAsInt64Codec) Encode(ptr unsafe.Pointer, stream *jsoniter.Strea ts := *((*time.Time)(ptr)) stream.WriteInt64(ts.UnixNano() / codec.precision.Nanoseconds()) } -func (codec *timeAsInt64Codec) EncodeInterface(val interface{}, stream *jsoniter.Stream) { - jsoniter.WriteToStream(val, stream, codec) -} diff --git a/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec_test.go b/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec_test.go new file mode 100644 index 00000000..b27220f1 --- /dev/null +++ b/discovery/vendor/github.com/json-iterator/go/extra/time_as_int64_codec_test.go @@ -0,0 +1,31 @@ +package extra + +import ( + "github.com/json-iterator/go" + "github.com/stretchr/testify/require" + "testing" + "time" +) + +func Test_time_as_int64(t *testing.T) { + should := require.New(t) + RegisterTimeAsInt64Codec(time.Nanosecond) + output, err := jsoniter.Marshal(time.Unix(1497952257, 1002)) + should.Nil(err) + should.Equal("1497952257000001002", string(output)) + var val time.Time + should.Nil(jsoniter.Unmarshal(output, &val)) + should.Equal(int64(1497952257000001002), val.UnixNano()) +} + +func Test_time_as_int64_keep_microsecond(t *testing.T) { + t.Skip("conflict") + should := require.New(t) + RegisterTimeAsInt64Codec(time.Microsecond) + output, err := jsoniter.Marshal(time.Unix(1, 1002)) + should.Nil(err) + should.Equal("1000001", string(output)) + var val time.Time + should.Nil(jsoniter.Unmarshal(output, &val)) + should.Equal(int64(1000001000), val.UnixNano()) +} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_adapter.go b/discovery/vendor/github.com/json-iterator/go/feature_adapter.go deleted file mode 100644 index 0214b711..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_adapter.go +++ /dev/null @@ -1,133 +0,0 @@ -package jsoniter - -import ( - "bytes" - "io" -) - -// RawMessage to make replace json with jsoniter -type RawMessage []byte - -// Unmarshal adapts to json/encoding Unmarshal API -// -// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. -// Refer to https://godoc.org/encoding/json#Unmarshal for more information -func Unmarshal(data []byte, v interface{}) error { - return ConfigDefault.Unmarshal(data, v) -} - -func lastNotSpacePos(data []byte) int { - for i := len(data) - 1; i >= 0; i-- { - if data[i] != ' ' && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' { - return i + 1 - } - } - return 0 -} - -// UnmarshalFromString convenient method to read from string instead of []byte -func UnmarshalFromString(str string, v interface{}) error { - return ConfigDefault.UnmarshalFromString(str, v) -} - -// Get quick method to get value from deeply nested JSON structure -func Get(data []byte, path ...interface{}) Any { - return ConfigDefault.Get(data, path...) -} - -// Marshal adapts to json/encoding Marshal API -// -// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API -// Refer to https://godoc.org/encoding/json#Marshal for more information -func Marshal(v interface{}) ([]byte, error) { - return ConfigDefault.Marshal(v) -} - -// MarshalIndent same as json.MarshalIndent. Prefix is not supported. -func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { - return ConfigDefault.MarshalIndent(v, prefix, indent) -} - -// MarshalToString convenient method to write as string instead of []byte -func MarshalToString(v interface{}) (string, error) { - return ConfigDefault.MarshalToString(v) -} - -// NewDecoder adapts to json/stream NewDecoder API. -// -// NewDecoder returns a new decoder that reads from r. -// -// Instead of a json/encoding Decoder, an Decoder is returned -// Refer to https://godoc.org/encoding/json#NewDecoder for more information -func NewDecoder(reader io.Reader) *Decoder { - return ConfigDefault.NewDecoder(reader) -} - -// Decoder reads and decodes JSON values from an input stream. -// Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress) -type Decoder struct { - iter *Iterator -} - -// Decode decode JSON into interface{} -func (adapter *Decoder) Decode(obj interface{}) error { - adapter.iter.ReadVal(obj) - err := adapter.iter.Error - if err == io.EOF { - return nil - } - return adapter.iter.Error -} - -// More is there more? -func (adapter *Decoder) More() bool { - return adapter.iter.head != adapter.iter.tail -} - -// Buffered remaining buffer -func (adapter *Decoder) Buffered() io.Reader { - remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail] - return bytes.NewReader(remaining) -} - -// UseNumber for number JSON element, use float64 or json.NumberValue (alias of string) -func (adapter *Decoder) UseNumber() { - origCfg := adapter.iter.cfg.configBeforeFrozen - origCfg.UseNumber = true - adapter.iter.cfg = origCfg.Froze().(*frozenConfig) -} - -// NewEncoder same as json.NewEncoder -func NewEncoder(writer io.Writer) *Encoder { - return ConfigDefault.NewEncoder(writer) -} - -// Encoder same as json.Encoder -type Encoder struct { - stream *Stream -} - -// Encode encode interface{} as JSON to io.Writer -func (adapter *Encoder) Encode(val interface{}) error { - adapter.stream.WriteVal(val) - adapter.stream.WriteRaw("\n") - adapter.stream.Flush() - return adapter.stream.Error -} - -// SetIndent set the indention. Prefix is not supported -func (adapter *Encoder) SetIndent(prefix, indent string) { - adapter.stream.cfg.indentionStep = len(indent) -} - -// SetEscapeHTML escape html by default, set to false to disable -func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) { - config := adapter.stream.cfg.configBeforeFrozen - config.EscapeHTML = escapeHTML - adapter.stream.cfg = config.Froze().(*frozenConfig) -} - -// Valid reports whether data is a valid JSON encoding. -func Valid(data []byte) bool { - return ConfigDefault.Valid(data) -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any.go b/discovery/vendor/github.com/json-iterator/go/feature_any.go deleted file mode 100644 index 87716d1f..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_any.go +++ /dev/null @@ -1,245 +0,0 @@ -package jsoniter - -import ( - "errors" - "fmt" - "io" - "reflect" -) - -// Any generic object representation. -// The lazy json implementation holds []byte and parse lazily. -type Any interface { - LastError() error - ValueType() ValueType - MustBeValid() Any - ToBool() bool - ToInt() int - ToInt32() int32 - ToInt64() int64 - ToUint() uint - ToUint32() uint32 - ToUint64() uint64 - ToFloat32() float32 - ToFloat64() float64 - ToString() string - ToVal(val interface{}) - Get(path ...interface{}) Any - // TODO: add Set - Size() int - Keys() []string - GetInterface() interface{} - WriteTo(stream *Stream) -} - -type baseAny struct{} - -func (any *baseAny) Get(path ...interface{}) Any { - return &invalidAny{baseAny{}, fmt.Errorf("Get %v from simple value", path)} -} - -func (any *baseAny) Size() int { - return 0 -} - -func (any *baseAny) Keys() []string { - return []string{} -} - -func (any *baseAny) ToVal(obj interface{}) { - panic("not implemented") -} - -// WrapInt32 turn int32 into Any interface -func WrapInt32(val int32) Any { - return &int32Any{baseAny{}, val} -} - -// WrapInt64 turn int64 into Any interface -func WrapInt64(val int64) Any { - return &int64Any{baseAny{}, val} -} - -// WrapUint32 turn uint32 into Any interface -func WrapUint32(val uint32) Any { - return &uint32Any{baseAny{}, val} -} - -// WrapUint64 turn uint64 into Any interface -func WrapUint64(val uint64) Any { - return &uint64Any{baseAny{}, val} -} - -// WrapFloat64 turn float64 into Any interface -func WrapFloat64(val float64) Any { - return &floatAny{baseAny{}, val} -} - -// WrapString turn string into Any interface -func WrapString(val string) Any { - return &stringAny{baseAny{}, val} -} - -// Wrap turn a go object into Any interface -func Wrap(val interface{}) Any { - if val == nil { - return &nilAny{} - } - asAny, isAny := val.(Any) - if isAny { - return asAny - } - typ := reflect.TypeOf(val) - switch typ.Kind() { - case reflect.Slice: - return wrapArray(val) - case reflect.Struct: - return wrapStruct(val) - case reflect.Map: - return wrapMap(val) - case reflect.String: - return WrapString(val.(string)) - case reflect.Int: - return WrapInt64(int64(val.(int))) - case reflect.Int8: - return WrapInt32(int32(val.(int8))) - case reflect.Int16: - return WrapInt32(int32(val.(int16))) - case reflect.Int32: - return WrapInt32(val.(int32)) - case reflect.Int64: - return WrapInt64(val.(int64)) - case reflect.Uint: - return WrapUint64(uint64(val.(uint))) - case reflect.Uint8: - return WrapUint32(uint32(val.(uint8))) - case reflect.Uint16: - return WrapUint32(uint32(val.(uint16))) - case reflect.Uint32: - return WrapUint32(uint32(val.(uint32))) - case reflect.Uint64: - return WrapUint64(val.(uint64)) - case reflect.Float32: - return WrapFloat64(float64(val.(float32))) - case reflect.Float64: - return WrapFloat64(val.(float64)) - case reflect.Bool: - if val.(bool) == true { - return &trueAny{} - } - return &falseAny{} - } - return &invalidAny{baseAny{}, fmt.Errorf("unsupported type: %v", typ)} -} - -// ReadAny read next JSON element as an Any object. It is a better json.RawMessage. -func (iter *Iterator) ReadAny() Any { - return iter.readAny() -} - -func (iter *Iterator) readAny() Any { - c := iter.nextToken() - switch c { - case '"': - iter.unreadByte() - return &stringAny{baseAny{}, iter.ReadString()} - case 'n': - iter.skipThreeBytes('u', 'l', 'l') // null - return &nilAny{} - case 't': - iter.skipThreeBytes('r', 'u', 'e') // true - return &trueAny{} - case 'f': - iter.skipFourBytes('a', 'l', 's', 'e') // false - return &falseAny{} - case '{': - return iter.readObjectAny() - case '[': - return iter.readArrayAny() - case '-': - return iter.readNumberAny(false) - case 0: - return &invalidAny{baseAny{}, errors.New("input is empty")} - default: - return iter.readNumberAny(true) - } -} - -func (iter *Iterator) readNumberAny(positive bool) Any { - iter.startCapture(iter.head - 1) - iter.skipNumber() - lazyBuf := iter.stopCapture() - return &numberLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} -} - -func (iter *Iterator) readObjectAny() Any { - iter.startCapture(iter.head - 1) - iter.skipObject() - lazyBuf := iter.stopCapture() - return &objectLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} -} - -func (iter *Iterator) readArrayAny() Any { - iter.startCapture(iter.head - 1) - iter.skipArray() - lazyBuf := iter.stopCapture() - return &arrayLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} -} - -func locateObjectField(iter *Iterator, target string) []byte { - var found []byte - iter.ReadObjectCB(func(iter *Iterator, field string) bool { - if field == target { - found = iter.SkipAndReturnBytes() - return false - } - iter.Skip() - return true - }) - return found -} - -func locateArrayElement(iter *Iterator, target int) []byte { - var found []byte - n := 0 - iter.ReadArrayCB(func(iter *Iterator) bool { - if n == target { - found = iter.SkipAndReturnBytes() - return false - } - iter.Skip() - n++ - return true - }) - return found -} - -func locatePath(iter *Iterator, path []interface{}) Any { - for i, pathKeyObj := range path { - switch pathKey := pathKeyObj.(type) { - case string: - valueBytes := locateObjectField(iter, pathKey) - if valueBytes == nil { - return newInvalidAny(path[i:]) - } - iter.ResetBytes(valueBytes) - case int: - valueBytes := locateArrayElement(iter, pathKey) - if valueBytes == nil { - return newInvalidAny(path[i:]) - } - iter.ResetBytes(valueBytes) - case int32: - if '*' == pathKey { - return iter.readAny().Get(path[i:]...) - } - return newInvalidAny(path[i:]) - default: - return newInvalidAny(path[i:]) - } - } - if iter.Error != nil && iter.Error != io.EOF { - return &invalidAny{baseAny{}, iter.Error} - } - return iter.readAny() -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_number.go b/discovery/vendor/github.com/json-iterator/go/feature_any_number.go deleted file mode 100644 index 4e1c2764..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_any_number.go +++ /dev/null @@ -1,104 +0,0 @@ -package jsoniter - -import "unsafe" - -type numberLazyAny struct { - baseAny - cfg *frozenConfig - buf []byte - err error -} - -func (any *numberLazyAny) ValueType() ValueType { - return NumberValue -} - -func (any *numberLazyAny) MustBeValid() Any { - return any -} - -func (any *numberLazyAny) LastError() error { - return any.err -} - -func (any *numberLazyAny) ToBool() bool { - return any.ToFloat64() != 0 -} - -func (any *numberLazyAny) ToInt() int { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadInt() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToInt32() int32 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadInt32() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToInt64() int64 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadInt64() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToUint() uint { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadUint() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToUint32() uint32 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadUint32() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToUint64() uint64 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadUint64() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToFloat32() float32 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadFloat32() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToFloat64() float64 { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - val := iter.ReadFloat64() - any.err = iter.Error - return val -} - -func (any *numberLazyAny) ToString() string { - return *(*string)(unsafe.Pointer(&any.buf)) -} - -func (any *numberLazyAny) WriteTo(stream *Stream) { - stream.Write(any.buf) -} - -func (any *numberLazyAny) GetInterface() interface{} { - iter := any.cfg.BorrowIterator(any.buf) - defer any.cfg.ReturnIterator(iter) - return iter.Read() -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_any_string.go b/discovery/vendor/github.com/json-iterator/go/feature_any_string.go deleted file mode 100644 index abf060bd..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_any_string.go +++ /dev/null @@ -1,166 +0,0 @@ -package jsoniter - -import ( - "fmt" - "strconv" -) - -type stringAny struct { - baseAny - val string -} - -func (any *stringAny) Get(path ...interface{}) Any { - if len(path) == 0 { - return any - } - return &invalidAny{baseAny{}, fmt.Errorf("Get %v from simple value", path)} -} - -func (any *stringAny) Parse() *Iterator { - return nil -} - -func (any *stringAny) ValueType() ValueType { - return StringValue -} - -func (any *stringAny) MustBeValid() Any { - return any -} - -func (any *stringAny) LastError() error { - return nil -} - -func (any *stringAny) ToBool() bool { - str := any.ToString() - if str == "0" { - return false - } - for _, c := range str { - switch c { - case ' ', '\n', '\r', '\t': - default: - return true - } - } - return false -} - -func (any *stringAny) ToInt() int { - return int(any.ToInt64()) - -} - -func (any *stringAny) ToInt32() int32 { - return int32(any.ToInt64()) -} - -func (any *stringAny) ToInt64() int64 { - if any.val == "" { - return 0 - } - - flag := 1 - startPos := 0 - endPos := 0 - if any.val[0] == '+' || any.val[0] == '-' { - startPos = 1 - } - - if any.val[0] == '-' { - flag = -1 - } - - for i := startPos; i < len(any.val); i++ { - if any.val[i] >= '0' && any.val[i] <= '9' { - endPos = i + 1 - } else { - break - } - } - parsed, _ := strconv.ParseInt(any.val[startPos:endPos], 10, 64) - return int64(flag) * parsed -} - -func (any *stringAny) ToUint() uint { - return uint(any.ToUint64()) -} - -func (any *stringAny) ToUint32() uint32 { - return uint32(any.ToUint64()) -} - -func (any *stringAny) ToUint64() uint64 { - if any.val == "" { - return 0 - } - - startPos := 0 - endPos := 0 - - if any.val[0] == '-' { - return 0 - } - if any.val[0] == '+' { - startPos = 1 - } - - for i := startPos; i < len(any.val); i++ { - if any.val[i] >= '0' && any.val[i] <= '9' { - endPos = i + 1 - } else { - break - } - } - parsed, _ := strconv.ParseUint(any.val[startPos:endPos], 10, 64) - return parsed -} - -func (any *stringAny) ToFloat32() float32 { - return float32(any.ToFloat64()) -} - -func (any *stringAny) ToFloat64() float64 { - if len(any.val) == 0 { - return 0 - } - - // first char invalid - if any.val[0] != '+' && any.val[0] != '-' && (any.val[0] > '9' || any.val[0] < '0') { - return 0 - } - - // extract valid num expression from string - // eg 123true => 123, -12.12xxa => -12.12 - endPos := 1 - for i := 1; i < len(any.val); i++ { - if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' { - endPos = i + 1 - continue - } - - // end position is the first char which is not digit - if any.val[i] >= '0' && any.val[i] <= '9' { - endPos = i + 1 - } else { - endPos = i - break - } - } - parsed, _ := strconv.ParseFloat(any.val[:endPos], 64) - return parsed -} - -func (any *stringAny) ToString() string { - return any.val -} - -func (any *stringAny) WriteTo(stream *Stream) { - stream.WriteString(any.val) -} - -func (any *stringAny) GetInterface() interface{} { - return any.val -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_config.go b/discovery/vendor/github.com/json-iterator/go/feature_config.go deleted file mode 100644 index 14067953..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_config.go +++ /dev/null @@ -1,347 +0,0 @@ -package jsoniter - -import ( - "encoding/json" - "errors" - "io" - "reflect" - "sync/atomic" - "unsafe" -) - -// Config customize how the API should behave. -// The API is created from Config by Froze. -type Config struct { - IndentionStep int - MarshalFloatWith6Digits bool - EscapeHTML bool - SortMapKeys bool - UseNumber bool - TagKey string - ValidateJsonRawMessage bool - ObjectFieldMustBeSimpleString bool -} - -type frozenConfig struct { - configBeforeFrozen Config - sortMapKeys bool - indentionStep int - objectFieldMustBeSimpleString bool - decoderCache unsafe.Pointer - encoderCache unsafe.Pointer - extensions []Extension - streamPool chan *Stream - iteratorPool chan *Iterator -} - -// API the public interface of this package. -// Primary Marshal and Unmarshal. -type API interface { - IteratorPool - StreamPool - MarshalToString(v interface{}) (string, error) - Marshal(v interface{}) ([]byte, error) - MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) - UnmarshalFromString(str string, v interface{}) error - Unmarshal(data []byte, v interface{}) error - Get(data []byte, path ...interface{}) Any - NewEncoder(writer io.Writer) *Encoder - NewDecoder(reader io.Reader) *Decoder - Valid(data []byte) bool -} - -// ConfigDefault the default API -var ConfigDefault = Config{ - EscapeHTML: true, -}.Froze() - -// ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior -var ConfigCompatibleWithStandardLibrary = Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, -}.Froze() - -// ConfigFastest marshals float with only 6 digits precision -var ConfigFastest = Config{ - EscapeHTML: false, - MarshalFloatWith6Digits: true, // will lose precession - ObjectFieldMustBeSimpleString: true, // do not unescape object field -}.Froze() - -// Froze forge API from config -func (cfg Config) Froze() API { - // TODO: cache frozen config - frozenConfig := &frozenConfig{ - sortMapKeys: cfg.SortMapKeys, - indentionStep: cfg.IndentionStep, - objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString, - streamPool: make(chan *Stream, 16), - iteratorPool: make(chan *Iterator, 16), - } - atomic.StorePointer(&frozenConfig.decoderCache, unsafe.Pointer(&map[string]ValDecoder{})) - atomic.StorePointer(&frozenConfig.encoderCache, unsafe.Pointer(&map[string]ValEncoder{})) - if cfg.MarshalFloatWith6Digits { - frozenConfig.marshalFloatWith6Digits() - } - if cfg.EscapeHTML { - frozenConfig.escapeHTML() - } - if cfg.UseNumber { - frozenConfig.useNumber() - } - if cfg.ValidateJsonRawMessage { - frozenConfig.validateJsonRawMessage() - } - frozenConfig.configBeforeFrozen = cfg - return frozenConfig -} - -func (cfg *frozenConfig) validateJsonRawMessage() { - encoder := &funcEncoder{func(ptr unsafe.Pointer, stream *Stream) { - rawMessage := *(*json.RawMessage)(ptr) - iter := cfg.BorrowIterator([]byte(rawMessage)) - iter.Read() - if iter.Error != nil { - stream.WriteRaw("null") - } else { - cfg.ReturnIterator(iter) - stream.WriteRaw(string(rawMessage)) - } - }, func(ptr unsafe.Pointer) bool { - return false - }} - cfg.addEncoderToCache(reflect.TypeOf((*json.RawMessage)(nil)).Elem(), encoder) - cfg.addEncoderToCache(reflect.TypeOf((*RawMessage)(nil)).Elem(), encoder) -} - -func (cfg *frozenConfig) useNumber() { - cfg.addDecoderToCache(reflect.TypeOf((*interface{})(nil)).Elem(), &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) { - if iter.WhatIsNext() == NumberValue { - *((*interface{})(ptr)) = json.Number(iter.readNumberAsString()) - } else { - *((*interface{})(ptr)) = iter.Read() - } - }}) -} -func (cfg *frozenConfig) getTagKey() string { - tagKey := cfg.configBeforeFrozen.TagKey - if tagKey == "" { - return "json" - } - return tagKey -} - -func (cfg *frozenConfig) registerExtension(extension Extension) { - cfg.extensions = append(cfg.extensions, extension) -} - -type lossyFloat32Encoder struct { -} - -func (encoder *lossyFloat32Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteFloat32Lossy(*((*float32)(ptr))) -} - -func (encoder *lossyFloat32Encoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *lossyFloat32Encoder) IsEmpty(ptr unsafe.Pointer) bool { - return *((*float32)(ptr)) == 0 -} - -type lossyFloat64Encoder struct { -} - -func (encoder *lossyFloat64Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteFloat64Lossy(*((*float64)(ptr))) -} - -func (encoder *lossyFloat64Encoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *lossyFloat64Encoder) IsEmpty(ptr unsafe.Pointer) bool { - return *((*float64)(ptr)) == 0 -} - -// EnableLossyFloatMarshalling keeps 10**(-6) precision -// for float variables for better performance. -func (cfg *frozenConfig) marshalFloatWith6Digits() { - // for better performance - cfg.addEncoderToCache(reflect.TypeOf((*float32)(nil)).Elem(), &lossyFloat32Encoder{}) - cfg.addEncoderToCache(reflect.TypeOf((*float64)(nil)).Elem(), &lossyFloat64Encoder{}) -} - -type htmlEscapedStringEncoder struct { -} - -func (encoder *htmlEscapedStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - str := *((*string)(ptr)) - stream.WriteStringWithHTMLEscaped(str) -} - -func (encoder *htmlEscapedStringEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *htmlEscapedStringEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return *((*string)(ptr)) == "" -} - -func (cfg *frozenConfig) escapeHTML() { - cfg.addEncoderToCache(reflect.TypeOf((*string)(nil)).Elem(), &htmlEscapedStringEncoder{}) -} - -func (cfg *frozenConfig) addDecoderToCache(cacheKey reflect.Type, decoder ValDecoder) { - done := false - for !done { - ptr := atomic.LoadPointer(&cfg.decoderCache) - cache := *(*map[reflect.Type]ValDecoder)(ptr) - copied := map[reflect.Type]ValDecoder{} - for k, v := range cache { - copied[k] = v - } - copied[cacheKey] = decoder - done = atomic.CompareAndSwapPointer(&cfg.decoderCache, ptr, unsafe.Pointer(&copied)) - } -} - -func (cfg *frozenConfig) addEncoderToCache(cacheKey reflect.Type, encoder ValEncoder) { - done := false - for !done { - ptr := atomic.LoadPointer(&cfg.encoderCache) - cache := *(*map[reflect.Type]ValEncoder)(ptr) - copied := map[reflect.Type]ValEncoder{} - for k, v := range cache { - copied[k] = v - } - copied[cacheKey] = encoder - done = atomic.CompareAndSwapPointer(&cfg.encoderCache, ptr, unsafe.Pointer(&copied)) - } -} - -func (cfg *frozenConfig) getDecoderFromCache(cacheKey reflect.Type) ValDecoder { - ptr := atomic.LoadPointer(&cfg.decoderCache) - cache := *(*map[reflect.Type]ValDecoder)(ptr) - return cache[cacheKey] -} - -func (cfg *frozenConfig) getEncoderFromCache(cacheKey reflect.Type) ValEncoder { - ptr := atomic.LoadPointer(&cfg.encoderCache) - cache := *(*map[reflect.Type]ValEncoder)(ptr) - return cache[cacheKey] -} - -func (cfg *frozenConfig) cleanDecoders() { - typeDecoders = map[string]ValDecoder{} - fieldDecoders = map[string]ValDecoder{} - *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) -} - -func (cfg *frozenConfig) cleanEncoders() { - typeEncoders = map[string]ValEncoder{} - fieldEncoders = map[string]ValEncoder{} - *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) -} - -func (cfg *frozenConfig) MarshalToString(v interface{}) (string, error) { - stream := cfg.BorrowStream(nil) - defer cfg.ReturnStream(stream) - stream.WriteVal(v) - if stream.Error != nil { - return "", stream.Error - } - return string(stream.Buffer()), nil -} - -func (cfg *frozenConfig) Marshal(v interface{}) ([]byte, error) { - stream := cfg.BorrowStream(nil) - defer cfg.ReturnStream(stream) - stream.WriteVal(v) - if stream.Error != nil { - return nil, stream.Error - } - result := stream.Buffer() - copied := make([]byte, len(result)) - copy(copied, result) - return copied, nil -} - -func (cfg *frozenConfig) MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { - if prefix != "" { - panic("prefix is not supported") - } - for _, r := range indent { - if r != ' ' { - panic("indent can only be space") - } - } - newCfg := cfg.configBeforeFrozen - newCfg.IndentionStep = len(indent) - return newCfg.Froze().Marshal(v) -} - -func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error { - data := []byte(str) - data = data[:lastNotSpacePos(data)] - iter := cfg.BorrowIterator(data) - defer cfg.ReturnIterator(iter) - iter.ReadVal(v) - if iter.head == iter.tail { - iter.loadMore() - } - if iter.Error == io.EOF { - return nil - } - if iter.Error == nil { - iter.ReportError("UnmarshalFromString", "there are bytes left after unmarshal") - } - return iter.Error -} - -func (cfg *frozenConfig) Get(data []byte, path ...interface{}) Any { - iter := cfg.BorrowIterator(data) - defer cfg.ReturnIterator(iter) - return locatePath(iter, path) -} - -func (cfg *frozenConfig) Unmarshal(data []byte, v interface{}) error { - data = data[:lastNotSpacePos(data)] - iter := cfg.BorrowIterator(data) - defer cfg.ReturnIterator(iter) - typ := reflect.TypeOf(v) - if typ.Kind() != reflect.Ptr { - // return non-pointer error - return errors.New("the second param must be ptr type") - } - iter.ReadVal(v) - if iter.head == iter.tail { - iter.loadMore() - } - if iter.Error == io.EOF { - return nil - } - if iter.Error == nil { - iter.ReportError("Unmarshal", "there are bytes left after unmarshal") - } - return iter.Error -} - -func (cfg *frozenConfig) NewEncoder(writer io.Writer) *Encoder { - stream := NewStream(cfg, writer, 512) - return &Encoder{stream} -} - -func (cfg *frozenConfig) NewDecoder(reader io.Reader) *Decoder { - iter := Parse(cfg, reader, 512) - return &Decoder{iter} -} - -func (cfg *frozenConfig) Valid(data []byte) bool { - iter := cfg.BorrowIterator(data) - defer cfg.ReturnIterator(iter) - iter.Skip() - return iter.Error == nil -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_iter_float.go b/discovery/vendor/github.com/json-iterator/go/feature_iter_float.go deleted file mode 100644 index 86f45991..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_iter_float.go +++ /dev/null @@ -1,341 +0,0 @@ -package jsoniter - -import ( - "io" - "math/big" - "strconv" - "strings" - "unsafe" -) - -var floatDigits []int8 - -const invalidCharForNumber = int8(-1) -const endOfNumber = int8(-2) -const dotInNumber = int8(-3) - -func init() { - floatDigits = make([]int8, 256) - for i := 0; i < len(floatDigits); i++ { - floatDigits[i] = invalidCharForNumber - } - for i := int8('0'); i <= int8('9'); i++ { - floatDigits[i] = i - int8('0') - } - floatDigits[','] = endOfNumber - floatDigits[']'] = endOfNumber - floatDigits['}'] = endOfNumber - floatDigits[' '] = endOfNumber - floatDigits['\t'] = endOfNumber - floatDigits['\n'] = endOfNumber - floatDigits['.'] = dotInNumber -} - -// ReadBigFloat read big.Float -func (iter *Iterator) ReadBigFloat() (ret *big.Float) { - str := iter.readNumberAsString() - if iter.Error != nil && iter.Error != io.EOF { - return nil - } - prec := 64 - if len(str) > prec { - prec = len(str) - } - val, _, err := big.ParseFloat(str, 10, uint(prec), big.ToZero) - if err != nil { - iter.Error = err - return nil - } - return val -} - -// ReadBigInt read big.Int -func (iter *Iterator) ReadBigInt() (ret *big.Int) { - str := iter.readNumberAsString() - if iter.Error != nil && iter.Error != io.EOF { - return nil - } - ret = big.NewInt(0) - var success bool - ret, success = ret.SetString(str, 10) - if !success { - iter.ReportError("ReadBigInt", "invalid big int") - return nil - } - return ret -} - -//ReadFloat32 read float32 -func (iter *Iterator) ReadFloat32() (ret float32) { - c := iter.nextToken() - if c == '-' { - return -iter.readPositiveFloat32() - } - iter.unreadByte() - return iter.readPositiveFloat32() -} - -func (iter *Iterator) readPositiveFloat32() (ret float32) { - value := uint64(0) - c := byte(' ') - i := iter.head - // first char - if i == iter.tail { - return iter.readFloat32SlowPath() - } - c = iter.buf[i] - i++ - ind := floatDigits[c] - switch ind { - case invalidCharForNumber: - return iter.readFloat32SlowPath() - case endOfNumber: - iter.ReportError("readFloat32", "empty number") - return - case dotInNumber: - iter.ReportError("readFloat32", "leading dot is invalid") - return - case 0: - if i == iter.tail { - return iter.readFloat32SlowPath() - } - c = iter.buf[i] - switch c { - case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - iter.ReportError("readFloat32", "leading zero is invalid") - return - } - } - value = uint64(ind) - // chars before dot -non_decimal_loop: - for ; i < iter.tail; i++ { - c = iter.buf[i] - ind := floatDigits[c] - switch ind { - case invalidCharForNumber: - return iter.readFloat32SlowPath() - case endOfNumber: - iter.head = i - return float32(value) - case dotInNumber: - break non_decimal_loop - } - if value > uint64SafeToMultiple10 { - return iter.readFloat32SlowPath() - } - value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind; - } - // chars after dot - if c == '.' { - i++ - decimalPlaces := 0 - if i == iter.tail { - return iter.readFloat32SlowPath() - } - for ; i < iter.tail; i++ { - c = iter.buf[i] - ind := floatDigits[c] - switch ind { - case endOfNumber: - if decimalPlaces > 0 && decimalPlaces < len(pow10) { - iter.head = i - return float32(float64(value) / float64(pow10[decimalPlaces])) - } - // too many decimal places - return iter.readFloat32SlowPath() - case invalidCharForNumber: - fallthrough - case dotInNumber: - return iter.readFloat32SlowPath() - } - decimalPlaces++ - if value > uint64SafeToMultiple10 { - return iter.readFloat32SlowPath() - } - value = (value << 3) + (value << 1) + uint64(ind) - } - } - return iter.readFloat32SlowPath() -} - -func (iter *Iterator) readNumberAsString() (ret string) { - strBuf := [16]byte{} - str := strBuf[0:0] -load_loop: - for { - for i := iter.head; i < iter.tail; i++ { - c := iter.buf[i] - switch c { - case '+', '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - str = append(str, c) - continue - default: - iter.head = i - break load_loop - } - } - if !iter.loadMore() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - return - } - if len(str) == 0 { - iter.ReportError("readNumberAsString", "invalid number") - } - return *(*string)(unsafe.Pointer(&str)) -} - -func (iter *Iterator) readFloat32SlowPath() (ret float32) { - str := iter.readNumberAsString() - if iter.Error != nil && iter.Error != io.EOF { - return - } - errMsg := validateFloat(str) - if errMsg != "" { - iter.ReportError("readFloat32SlowPath", errMsg) - return - } - val, err := strconv.ParseFloat(str, 32) - if err != nil { - iter.Error = err - return - } - return float32(val) -} - -// ReadFloat64 read float64 -func (iter *Iterator) ReadFloat64() (ret float64) { - c := iter.nextToken() - if c == '-' { - return -iter.readPositiveFloat64() - } - iter.unreadByte() - return iter.readPositiveFloat64() -} - -func (iter *Iterator) readPositiveFloat64() (ret float64) { - value := uint64(0) - c := byte(' ') - i := iter.head - // first char - if i == iter.tail { - return iter.readFloat64SlowPath() - } - c = iter.buf[i] - i++ - ind := floatDigits[c] - switch ind { - case invalidCharForNumber: - return iter.readFloat64SlowPath() - case endOfNumber: - iter.ReportError("readFloat64", "empty number") - return - case dotInNumber: - iter.ReportError("readFloat64", "leading dot is invalid") - return - case 0: - if i == iter.tail { - return iter.readFloat64SlowPath() - } - c = iter.buf[i] - switch c { - case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - iter.ReportError("readFloat64", "leading zero is invalid") - return - } - } - value = uint64(ind) - // chars before dot -non_decimal_loop: - for ; i < iter.tail; i++ { - c = iter.buf[i] - ind := floatDigits[c] - switch ind { - case invalidCharForNumber: - return iter.readFloat64SlowPath() - case endOfNumber: - iter.head = i - return float64(value) - case dotInNumber: - break non_decimal_loop - } - if value > uint64SafeToMultiple10 { - return iter.readFloat64SlowPath() - } - value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind; - } - // chars after dot - if c == '.' { - i++ - decimalPlaces := 0 - if i == iter.tail { - return iter.readFloat64SlowPath() - } - for ; i < iter.tail; i++ { - c = iter.buf[i] - ind := floatDigits[c] - switch ind { - case endOfNumber: - if decimalPlaces > 0 && decimalPlaces < len(pow10) { - iter.head = i - return float64(value) / float64(pow10[decimalPlaces]) - } - // too many decimal places - return iter.readFloat64SlowPath() - case invalidCharForNumber: - fallthrough - case dotInNumber: - return iter.readFloat64SlowPath() - } - decimalPlaces++ - if value > uint64SafeToMultiple10 { - return iter.readFloat64SlowPath() - } - value = (value << 3) + (value << 1) + uint64(ind) - } - } - return iter.readFloat64SlowPath() -} - -func (iter *Iterator) readFloat64SlowPath() (ret float64) { - str := iter.readNumberAsString() - if iter.Error != nil && iter.Error != io.EOF { - return - } - errMsg := validateFloat(str) - if errMsg != "" { - iter.ReportError("readFloat64SlowPath", errMsg) - return - } - val, err := strconv.ParseFloat(str, 64) - if err != nil { - iter.Error = err - return - } - return val -} - -func validateFloat(str string) string { - // strconv.ParseFloat is not validating `1.` or `1.e1` - if len(str) == 0 { - return "empty number" - } - if str[0] == '-' { - return "-- is not valid" - } - dotPos := strings.IndexByte(str, '.') - if dotPos != -1 { - if dotPos == len(str)-1 { - return "dot can not be last character" - } - switch str[dotPos+1] { - case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - default: - return "missing digit after dot" - } - } - return "" -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_iter_int.go b/discovery/vendor/github.com/json-iterator/go/feature_iter_int.go deleted file mode 100644 index 6137348c..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_iter_int.go +++ /dev/null @@ -1,268 +0,0 @@ -package jsoniter - -import ( - "math" - "strconv" -) - -var intDigits []int8 - -const uint32SafeToMultiply10 = uint32(0xffffffff)/10 - 1 -const uint64SafeToMultiple10 = uint64(0xffffffffffffffff)/10 - 1 - -func init() { - intDigits = make([]int8, 256) - for i := 0; i < len(intDigits); i++ { - intDigits[i] = invalidCharForNumber - } - for i := int8('0'); i <= int8('9'); i++ { - intDigits[i] = i - int8('0') - } -} - -// ReadUint read uint -func (iter *Iterator) ReadUint() uint { - return uint(iter.ReadUint64()) -} - -// ReadInt read int -func (iter *Iterator) ReadInt() int { - return int(iter.ReadInt64()) -} - -// ReadInt8 read int8 -func (iter *Iterator) ReadInt8() (ret int8) { - c := iter.nextToken() - if c == '-' { - val := iter.readUint32(iter.readByte()) - if val > math.MaxInt8+1 { - iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return -int8(val) - } - val := iter.readUint32(c) - if val > math.MaxInt8 { - iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return int8(val) -} - -// ReadUint8 read uint8 -func (iter *Iterator) ReadUint8() (ret uint8) { - val := iter.readUint32(iter.nextToken()) - if val > math.MaxUint8 { - iter.ReportError("ReadUint8", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return uint8(val) -} - -// ReadInt16 read int16 -func (iter *Iterator) ReadInt16() (ret int16) { - c := iter.nextToken() - if c == '-' { - val := iter.readUint32(iter.readByte()) - if val > math.MaxInt16+1 { - iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return -int16(val) - } - val := iter.readUint32(c) - if val > math.MaxInt16 { - iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return int16(val) -} - -// ReadUint16 read uint16 -func (iter *Iterator) ReadUint16() (ret uint16) { - val := iter.readUint32(iter.nextToken()) - if val > math.MaxUint16 { - iter.ReportError("ReadUint16", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return uint16(val) -} - -// ReadInt32 read int32 -func (iter *Iterator) ReadInt32() (ret int32) { - c := iter.nextToken() - if c == '-' { - val := iter.readUint32(iter.readByte()) - if val > math.MaxInt32+1 { - iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return -int32(val) - } - val := iter.readUint32(c) - if val > math.MaxInt32 { - iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10)) - return - } - return int32(val) -} - -// ReadUint32 read uint32 -func (iter *Iterator) ReadUint32() (ret uint32) { - return iter.readUint32(iter.nextToken()) -} - -func (iter *Iterator) readUint32(c byte) (ret uint32) { - defer func() { - if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' { - iter.ReportError("readUint32", "can not decode float as int") - } - }() - ind := intDigits[c] - if ind == 0 { - return 0 // single zero - } - if ind == invalidCharForNumber { - iter.ReportError("readUint32", "unexpected character: "+string([]byte{byte(ind)})) - return - } - value := uint32(ind) - if iter.tail-iter.head > 10 { - i := iter.head - ind2 := intDigits[iter.buf[i]] - if ind2 == invalidCharForNumber { - iter.head = i - return value - } - i++ - ind3 := intDigits[iter.buf[i]] - if ind3 == invalidCharForNumber { - iter.head = i - return value*10 + uint32(ind2) - } - //iter.head = i + 1 - //value = value * 100 + uint32(ind2) * 10 + uint32(ind3) - i++ - ind4 := intDigits[iter.buf[i]] - if ind4 == invalidCharForNumber { - iter.head = i - return value*100 + uint32(ind2)*10 + uint32(ind3) - } - i++ - ind5 := intDigits[iter.buf[i]] - if ind5 == invalidCharForNumber { - iter.head = i - return value*1000 + uint32(ind2)*100 + uint32(ind3)*10 + uint32(ind4) - } - i++ - ind6 := intDigits[iter.buf[i]] - if ind6 == invalidCharForNumber { - iter.head = i - return value*10000 + uint32(ind2)*1000 + uint32(ind3)*100 + uint32(ind4)*10 + uint32(ind5) - } - i++ - ind7 := intDigits[iter.buf[i]] - if ind7 == invalidCharForNumber { - iter.head = i - return value*100000 + uint32(ind2)*10000 + uint32(ind3)*1000 + uint32(ind4)*100 + uint32(ind5)*10 + uint32(ind6) - } - i++ - ind8 := intDigits[iter.buf[i]] - if ind8 == invalidCharForNumber { - iter.head = i - return value*1000000 + uint32(ind2)*100000 + uint32(ind3)*10000 + uint32(ind4)*1000 + uint32(ind5)*100 + uint32(ind6)*10 + uint32(ind7) - } - i++ - ind9 := intDigits[iter.buf[i]] - value = value*10000000 + uint32(ind2)*1000000 + uint32(ind3)*100000 + uint32(ind4)*10000 + uint32(ind5)*1000 + uint32(ind6)*100 + uint32(ind7)*10 + uint32(ind8) - iter.head = i - if ind9 == invalidCharForNumber { - return value - } - } - for { - for i := iter.head; i < iter.tail; i++ { - ind = intDigits[iter.buf[i]] - if ind == invalidCharForNumber { - iter.head = i - return value - } - if value > uint32SafeToMultiply10 { - value2 := (value << 3) + (value << 1) + uint32(ind) - if value2 < value { - iter.ReportError("readUint32", "overflow") - return - } - value = value2 - continue - } - value = (value << 3) + (value << 1) + uint32(ind) - } - if !iter.loadMore() { - return value - } - } -} - -// ReadInt64 read int64 -func (iter *Iterator) ReadInt64() (ret int64) { - c := iter.nextToken() - if c == '-' { - val := iter.readUint64(iter.readByte()) - if val > math.MaxInt64+1 { - iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10)) - return - } - return -int64(val) - } - val := iter.readUint64(c) - if val > math.MaxInt64 { - iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10)) - return - } - return int64(val) -} - -// ReadUint64 read uint64 -func (iter *Iterator) ReadUint64() uint64 { - return iter.readUint64(iter.nextToken()) -} - -func (iter *Iterator) readUint64(c byte) (ret uint64) { - defer func() { - if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' { - iter.ReportError("readUint64", "can not decode float as int") - } - }() - ind := intDigits[c] - if ind == 0 { - return 0 // single zero - } - if ind == invalidCharForNumber { - iter.ReportError("readUint64", "unexpected character: "+string([]byte{byte(ind)})) - return - } - value := uint64(ind) - for { - for i := iter.head; i < iter.tail; i++ { - ind = intDigits[iter.buf[i]] - if ind == invalidCharForNumber { - iter.head = i - return value - } - if value > uint64SafeToMultiple10 { - value2 := (value << 3) + (value << 1) + uint64(ind) - if value2 < value { - iter.ReportError("readUint64", "overflow") - return - } - value = value2 - continue - } - value = (value << 3) + (value << 1) + uint64(ind) - } - if !iter.loadMore() { - return value - } - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_iter_object.go b/discovery/vendor/github.com/json-iterator/go/feature_iter_object.go deleted file mode 100644 index dfd91fa6..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_iter_object.go +++ /dev/null @@ -1,267 +0,0 @@ -package jsoniter - -import ( - "fmt" - "unicode" - "unsafe" -) - -// ReadObject read one field from object. -// If object ended, returns empty string. -// Otherwise, returns the field name. -func (iter *Iterator) ReadObject() (ret string) { - c := iter.nextToken() - switch c { - case 'n': - iter.skipThreeBytes('u', 'l', 'l') - return "" // null - case '{': - c = iter.nextToken() - if c == '"' { - iter.unreadByte() - if iter.cfg.objectFieldMustBeSimpleString { - return string(iter.readObjectFieldAsBytes()) - } else { - field := iter.ReadString() - c = iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - return field - } - } - if c == '}' { - return "" // end of object - } - iter.ReportError("ReadObject", `expect " after {, but found `+string([]byte{c})) - return - case ',': - if iter.cfg.objectFieldMustBeSimpleString { - return string(iter.readObjectFieldAsBytes()) - } else { - field := iter.ReadString() - c = iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - return field - } - case '}': - return "" // end of object - default: - iter.ReportError("ReadObject", fmt.Sprintf(`expect { or , or } or n, but found %s`, string([]byte{c}))) - return - } -} - -func (iter *Iterator) readFieldHash() int32 { - hash := int64(0x811c9dc5) - c := iter.nextToken() - if c == '"' { - for { - for i := iter.head; i < iter.tail; i++ { - // require ascii string and no escape - b := iter.buf[i] - if !iter.cfg.objectFieldMustBeSimpleString && b == '\\' { - iter.head = i - for _, b := range iter.readStringSlowPath() { - if 'A' <= b && b <= 'Z' { - b += 'a' - 'A' - } - hash ^= int64(b) - hash *= 0x1000193 - } - c = iter.nextToken() - if c != ':' { - iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c})) - return 0 - } - return int32(hash) - } - if b == '"' { - iter.head = i + 1 - c = iter.nextToken() - if c != ':' { - iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c})) - return 0 - } - return int32(hash) - } - if 'A' <= b && b <= 'Z' { - b += 'a' - 'A' - } - hash ^= int64(b) - hash *= 0x1000193 - } - if !iter.loadMore() { - iter.ReportError("readFieldHash", `incomplete field name`) - return 0 - } - } - } - iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c})) - return 0 -} - -func calcHash(str string) int32 { - hash := int64(0x811c9dc5) - for _, b := range str { - hash ^= int64(unicode.ToLower(b)) - hash *= 0x1000193 - } - return int32(hash) -} - -// ReadObjectCB read object with callback, the key is ascii only and field name not copied -func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool { - c := iter.nextToken() - var fieldBytes []byte - var field string - if c == '{' { - c = iter.nextToken() - if c == '"' { - iter.unreadByte() - if iter.cfg.objectFieldMustBeSimpleString { - fieldBytes = iter.readObjectFieldAsBytes() - field = *(*string)(unsafe.Pointer(&fieldBytes)) - } else { - field = iter.ReadString() - c = iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - } - if !callback(iter, field) { - return false - } - c = iter.nextToken() - for c == ',' { - if iter.cfg.objectFieldMustBeSimpleString { - fieldBytes = iter.readObjectFieldAsBytes() - field = *(*string)(unsafe.Pointer(&fieldBytes)) - } else { - field = iter.ReadString() - c = iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - } - if !callback(iter, field) { - return false - } - c = iter.nextToken() - } - if c != '}' { - iter.ReportError("ReadObjectCB", `object not ended with }`) - return false - } - return true - } - if c == '}' { - return true - } - iter.ReportError("ReadObjectCB", `expect " after }, but found `+string([]byte{c})) - return false - } - if c == 'n' { - iter.skipThreeBytes('u', 'l', 'l') - return true // null - } - iter.ReportError("ReadObjectCB", `expect { or n, but found `+string([]byte{c})) - return false -} - -// ReadMapCB read map with callback, the key can be any string -func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool { - c := iter.nextToken() - if c == '{' { - c = iter.nextToken() - if c == '"' { - iter.unreadByte() - field := iter.ReadString() - if iter.nextToken() != ':' { - iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) - return false - } - if !callback(iter, field) { - return false - } - c = iter.nextToken() - for c == ',' { - field = iter.ReadString() - if iter.nextToken() != ':' { - iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) - return false - } - if !callback(iter, field) { - return false - } - c = iter.nextToken() - } - if c != '}' { - iter.ReportError("ReadMapCB", `object not ended with }`) - return false - } - return true - } - if c == '}' { - return true - } - iter.ReportError("ReadMapCB", `expect " after }, but found `+string([]byte{c})) - return false - } - if c == 'n' { - iter.skipThreeBytes('u', 'l', 'l') - return true // null - } - iter.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{c})) - return false -} - -func (iter *Iterator) readObjectStart() bool { - c := iter.nextToken() - if c == '{' { - c = iter.nextToken() - if c == '}' { - return false - } - iter.unreadByte() - return true - } else if c == 'n' { - iter.skipThreeBytes('u', 'l', 'l') - return false - } - iter.ReportError("readObjectStart", "expect { or n, but found "+string([]byte{c})) - return false -} - -func (iter *Iterator) readObjectFieldAsBytes() (ret []byte) { - str := iter.ReadStringAsSlice() - if iter.skipWhitespacesWithoutLoadMore() { - if ret == nil { - ret = make([]byte, len(str)) - copy(ret, str) - } - if !iter.loadMore() { - return - } - } - if iter.buf[iter.head] != ':' { - iter.ReportError("readObjectFieldAsBytes", "expect : after object field, but found "+string([]byte{iter.buf[iter.head]})) - return - } - iter.head++ - if iter.skipWhitespacesWithoutLoadMore() { - if ret == nil { - ret = make([]byte, len(str)) - copy(ret, str) - } - if !iter.loadMore() { - return - } - } - if ret == nil { - return str - } - return ret -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_json_number.go b/discovery/vendor/github.com/json-iterator/go/feature_json_number.go deleted file mode 100644 index e187b200..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_json_number.go +++ /dev/null @@ -1,31 +0,0 @@ -package jsoniter - -import ( - "encoding/json" - "strconv" -) - -type Number string - -// String returns the literal text of the number. -func (n Number) String() string { return string(n) } - -// Float64 returns the number as a float64. -func (n Number) Float64() (float64, error) { - return strconv.ParseFloat(string(n), 64) -} - -// Int64 returns the number as an int64. -func (n Number) Int64() (int64, error) { - return strconv.ParseInt(string(n), 10, 64) -} - -func CastJsonNumber(val interface{}) (string, bool) { - switch typedVal := val.(type) { - case json.Number: - return string(typedVal), true - case Number: - return string(typedVal), true - } - return "", false -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_pool.go b/discovery/vendor/github.com/json-iterator/go/feature_pool.go deleted file mode 100644 index 52d38e68..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_pool.go +++ /dev/null @@ -1,59 +0,0 @@ -package jsoniter - -import ( - "io" -) - -// IteratorPool a thread safe pool of iterators with same configuration -type IteratorPool interface { - BorrowIterator(data []byte) *Iterator - ReturnIterator(iter *Iterator) -} - -// StreamPool a thread safe pool of streams with same configuration -type StreamPool interface { - BorrowStream(writer io.Writer) *Stream - ReturnStream(stream *Stream) -} - -func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream { - select { - case stream := <-cfg.streamPool: - stream.Reset(writer) - return stream - default: - return NewStream(cfg, writer, 512) - } -} - -func (cfg *frozenConfig) ReturnStream(stream *Stream) { - stream.Error = nil - stream.Attachment = nil - select { - case cfg.streamPool <- stream: - return - default: - return - } -} - -func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator { - select { - case iter := <-cfg.iteratorPool: - iter.ResetBytes(data) - return iter - default: - return ParseBytes(cfg, data) - } -} - -func (cfg *frozenConfig) ReturnIterator(iter *Iterator) { - iter.Error = nil - iter.Attachment = nil - select { - case cfg.iteratorPool <- iter: - return - default: - return - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect.go deleted file mode 100644 index 1bd8987f..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect.go +++ /dev/null @@ -1,721 +0,0 @@ -package jsoniter - -import ( - "encoding" - "encoding/json" - "fmt" - "reflect" - "time" - "unsafe" -) - -// ValDecoder is an internal type registered to cache as needed. -// Don't confuse jsoniter.ValDecoder with json.Decoder. -// For json.Decoder's adapter, refer to jsoniter.AdapterDecoder(todo link). -// -// Reflection on type to create decoders, which is then cached -// Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions -// 1. create instance of new value, for example *int will need a int to be allocated -// 2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New -// 3. assignment to map, both key and value will be reflect.Value -// For a simple struct binding, it will be reflect.Value free and allocation free -type ValDecoder interface { - Decode(ptr unsafe.Pointer, iter *Iterator) -} - -// ValEncoder is an internal type registered to cache as needed. -// Don't confuse jsoniter.ValEncoder with json.Encoder. -// For json.Encoder's adapter, refer to jsoniter.AdapterEncoder(todo godoc link). -type ValEncoder interface { - IsEmpty(ptr unsafe.Pointer) bool - Encode(ptr unsafe.Pointer, stream *Stream) - EncodeInterface(val interface{}, stream *Stream) -} - -type checkIsEmpty interface { - IsEmpty(ptr unsafe.Pointer) bool -} - -// WriteToStream the default implementation for TypeEncoder method EncodeInterface -func WriteToStream(val interface{}, stream *Stream, encoder ValEncoder) { - e := (*emptyInterface)(unsafe.Pointer(&val)) - if e.word == nil { - stream.WriteNil() - return - } - if reflect.TypeOf(val).Kind() == reflect.Ptr { - encoder.Encode(unsafe.Pointer(&e.word), stream) - } else { - encoder.Encode(e.word, stream) - } -} - -var jsonNumberType reflect.Type -var jsoniterNumberType reflect.Type -var jsonRawMessageType reflect.Type -var jsoniterRawMessageType reflect.Type -var anyType reflect.Type -var marshalerType reflect.Type -var unmarshalerType reflect.Type -var textMarshalerType reflect.Type -var textUnmarshalerType reflect.Type - -func init() { - jsonNumberType = reflect.TypeOf((*json.Number)(nil)).Elem() - jsoniterNumberType = reflect.TypeOf((*Number)(nil)).Elem() - jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem() - jsoniterRawMessageType = reflect.TypeOf((*RawMessage)(nil)).Elem() - anyType = reflect.TypeOf((*Any)(nil)).Elem() - marshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem() - unmarshalerType = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem() - textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() - textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem() -} - -type OptionalDecoder struct { - ValueType reflect.Type - ValueDecoder ValDecoder -} - -func (decoder *OptionalDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if iter.ReadNil() { - *((*unsafe.Pointer)(ptr)) = nil - } else { - if *((*unsafe.Pointer)(ptr)) == nil { - //pointer to null, we have to allocate memory to hold the value - value := reflect.New(decoder.ValueType) - newPtr := extractInterface(value.Interface()).word - decoder.ValueDecoder.Decode(newPtr, iter) - *((*uintptr)(ptr)) = uintptr(newPtr) - } else { - //reuse existing instance - decoder.ValueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter) - } - } -} - -type deferenceDecoder struct { - // only to deference a pointer - valueType reflect.Type - valueDecoder ValDecoder -} - -func (decoder *deferenceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if *((*unsafe.Pointer)(ptr)) == nil { - //pointer to null, we have to allocate memory to hold the value - value := reflect.New(decoder.valueType) - newPtr := extractInterface(value.Interface()).word - decoder.valueDecoder.Decode(newPtr, iter) - *((*uintptr)(ptr)) = uintptr(newPtr) - } else { - //reuse existing instance - decoder.valueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter) - } -} - -type OptionalEncoder struct { - ValueEncoder ValEncoder -} - -func (encoder *OptionalEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - if *((*unsafe.Pointer)(ptr)) == nil { - stream.WriteNil() - } else { - encoder.ValueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream) - } -} - -func (encoder *OptionalEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *OptionalEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return *((*unsafe.Pointer)(ptr)) == nil -} - -type optionalMapEncoder struct { - valueEncoder ValEncoder -} - -func (encoder *optionalMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - if *((*unsafe.Pointer)(ptr)) == nil { - stream.WriteNil() - } else { - encoder.valueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream) - } -} - -func (encoder *optionalMapEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *optionalMapEncoder) IsEmpty(ptr unsafe.Pointer) bool { - p := *((*unsafe.Pointer)(ptr)) - return p == nil || encoder.valueEncoder.IsEmpty(p) -} - -type placeholderEncoder struct { - cfg *frozenConfig - cacheKey reflect.Type -} - -func (encoder *placeholderEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - encoder.getRealEncoder().Encode(ptr, stream) -} - -func (encoder *placeholderEncoder) EncodeInterface(val interface{}, stream *Stream) { - encoder.getRealEncoder().EncodeInterface(val, stream) -} - -func (encoder *placeholderEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return encoder.getRealEncoder().IsEmpty(ptr) -} - -func (encoder *placeholderEncoder) getRealEncoder() ValEncoder { - for i := 0; i < 500; i++ { - realDecoder := encoder.cfg.getEncoderFromCache(encoder.cacheKey) - _, isPlaceholder := realDecoder.(*placeholderEncoder) - if isPlaceholder { - time.Sleep(10 * time.Millisecond) - } else { - return realDecoder - } - } - panic(fmt.Sprintf("real encoder not found for cache key: %v", encoder.cacheKey)) -} - -type placeholderDecoder struct { - cfg *frozenConfig - cacheKey reflect.Type -} - -func (decoder *placeholderDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - for i := 0; i < 500; i++ { - realDecoder := decoder.cfg.getDecoderFromCache(decoder.cacheKey) - _, isPlaceholder := realDecoder.(*placeholderDecoder) - if isPlaceholder { - time.Sleep(10 * time.Millisecond) - } else { - realDecoder.Decode(ptr, iter) - return - } - } - panic(fmt.Sprintf("real decoder not found for cache key: %v", decoder.cacheKey)) -} - -// emptyInterface is the header for an interface{} value. -type emptyInterface struct { - typ unsafe.Pointer - word unsafe.Pointer -} - -// emptyInterface is the header for an interface with method (not interface{}) -type nonEmptyInterface struct { - // see ../runtime/iface.go:/Itab - itab *struct { - ityp unsafe.Pointer // static interface type - typ unsafe.Pointer // dynamic concrete type - link unsafe.Pointer - bad int32 - unused int32 - fun [100000]unsafe.Pointer // method table - } - word unsafe.Pointer -} - -// ReadVal copy the underlying JSON into go interface, same as json.Unmarshal -func (iter *Iterator) ReadVal(obj interface{}) { - typ := reflect.TypeOf(obj) - cacheKey := typ.Elem() - decoder, err := decoderOfType(iter.cfg, cacheKey) - if err != nil { - iter.Error = err - return - } - e := (*emptyInterface)(unsafe.Pointer(&obj)) - decoder.Decode(e.word, iter) -} - -// WriteVal copy the go interface into underlying JSON, same as json.Marshal -func (stream *Stream) WriteVal(val interface{}) { - if nil == val { - stream.WriteNil() - return - } - typ := reflect.TypeOf(val) - cacheKey := typ - encoder, err := encoderOfType(stream.cfg, cacheKey) - if err != nil { - stream.Error = err - return - } - encoder.EncodeInterface(val, stream) -} - -type prefix string - -func (p prefix) addToDecoder(decoder ValDecoder, err error) (ValDecoder, error) { - if err != nil { - return nil, fmt.Errorf("%s: %s", p, err.Error()) - } - return decoder, err -} - -func (p prefix) addToEncoder(encoder ValEncoder, err error) (ValEncoder, error) { - if err != nil { - return nil, fmt.Errorf("%s: %s", p, err.Error()) - } - return encoder, err -} - -func decoderOfType(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - cacheKey := typ - decoder := cfg.getDecoderFromCache(cacheKey) - if decoder != nil { - return decoder, nil - } - decoder = getTypeDecoderFromExtension(typ) - if decoder != nil { - cfg.addDecoderToCache(cacheKey, decoder) - return decoder, nil - } - decoder = &placeholderDecoder{cfg: cfg, cacheKey: cacheKey} - cfg.addDecoderToCache(cacheKey, decoder) - decoder, err := createDecoderOfType(cfg, typ) - for _, extension := range extensions { - decoder = extension.DecorateDecoder(typ, decoder) - } - cfg.addDecoderToCache(cacheKey, decoder) - return decoder, err -} - -func createDecoderOfType(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - typeName := typ.String() - if typ == jsonRawMessageType { - return &jsonRawMessageCodec{}, nil - } - if typ == jsoniterRawMessageType { - return &jsoniterRawMessageCodec{}, nil - } - if typ.AssignableTo(jsonNumberType) { - return &jsonNumberCodec{}, nil - } - if typ.AssignableTo(jsoniterNumberType) { - return &jsoniterNumberCodec{}, nil - } - if typ.Implements(unmarshalerType) { - templateInterface := reflect.New(typ).Elem().Interface() - var decoder ValDecoder = &unmarshalerDecoder{extractInterface(templateInterface)} - if typ.Kind() == reflect.Ptr { - decoder = &OptionalDecoder{typ.Elem(), decoder} - } - return decoder, nil - } - if reflect.PtrTo(typ).Implements(unmarshalerType) { - templateInterface := reflect.New(typ).Interface() - var decoder ValDecoder = &unmarshalerDecoder{extractInterface(templateInterface)} - return decoder, nil - } - if typ.Implements(textUnmarshalerType) { - templateInterface := reflect.New(typ).Elem().Interface() - var decoder ValDecoder = &textUnmarshalerDecoder{extractInterface(templateInterface)} - if typ.Kind() == reflect.Ptr { - decoder = &OptionalDecoder{typ.Elem(), decoder} - } - return decoder, nil - } - if reflect.PtrTo(typ).Implements(textUnmarshalerType) { - templateInterface := reflect.New(typ).Interface() - var decoder ValDecoder = &textUnmarshalerDecoder{extractInterface(templateInterface)} - return decoder, nil - } - if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Uint8 { - sliceDecoder, err := prefix("[slice]").addToDecoder(decoderOfSlice(cfg, typ)) - if err != nil { - return nil, err - } - return &base64Codec{sliceDecoder: sliceDecoder}, nil - } - if typ.Implements(anyType) { - return &anyCodec{}, nil - } - switch typ.Kind() { - case reflect.String: - if typeName != "string" { - return decoderOfType(cfg, reflect.TypeOf((*string)(nil)).Elem()) - } - return &stringCodec{}, nil - case reflect.Int: - if typeName != "int" { - return decoderOfType(cfg, reflect.TypeOf((*int)(nil)).Elem()) - } - return &intCodec{}, nil - case reflect.Int8: - if typeName != "int8" { - return decoderOfType(cfg, reflect.TypeOf((*int8)(nil)).Elem()) - } - return &int8Codec{}, nil - case reflect.Int16: - if typeName != "int16" { - return decoderOfType(cfg, reflect.TypeOf((*int16)(nil)).Elem()) - } - return &int16Codec{}, nil - case reflect.Int32: - if typeName != "int32" { - return decoderOfType(cfg, reflect.TypeOf((*int32)(nil)).Elem()) - } - return &int32Codec{}, nil - case reflect.Int64: - if typeName != "int64" { - return decoderOfType(cfg, reflect.TypeOf((*int64)(nil)).Elem()) - } - return &int64Codec{}, nil - case reflect.Uint: - if typeName != "uint" { - return decoderOfType(cfg, reflect.TypeOf((*uint)(nil)).Elem()) - } - return &uintCodec{}, nil - case reflect.Uint8: - if typeName != "uint8" { - return decoderOfType(cfg, reflect.TypeOf((*uint8)(nil)).Elem()) - } - return &uint8Codec{}, nil - case reflect.Uint16: - if typeName != "uint16" { - return decoderOfType(cfg, reflect.TypeOf((*uint16)(nil)).Elem()) - } - return &uint16Codec{}, nil - case reflect.Uint32: - if typeName != "uint32" { - return decoderOfType(cfg, reflect.TypeOf((*uint32)(nil)).Elem()) - } - return &uint32Codec{}, nil - case reflect.Uintptr: - if typeName != "uintptr" { - return decoderOfType(cfg, reflect.TypeOf((*uintptr)(nil)).Elem()) - } - return &uintptrCodec{}, nil - case reflect.Uint64: - if typeName != "uint64" { - return decoderOfType(cfg, reflect.TypeOf((*uint64)(nil)).Elem()) - } - return &uint64Codec{}, nil - case reflect.Float32: - if typeName != "float32" { - return decoderOfType(cfg, reflect.TypeOf((*float32)(nil)).Elem()) - } - return &float32Codec{}, nil - case reflect.Float64: - if typeName != "float64" { - return decoderOfType(cfg, reflect.TypeOf((*float64)(nil)).Elem()) - } - return &float64Codec{}, nil - case reflect.Bool: - if typeName != "bool" { - return decoderOfType(cfg, reflect.TypeOf((*bool)(nil)).Elem()) - } - return &boolCodec{}, nil - case reflect.Interface: - if typ.NumMethod() == 0 { - return &emptyInterfaceCodec{}, nil - } - return &nonEmptyInterfaceCodec{}, nil - case reflect.Struct: - return prefix(fmt.Sprintf("[%s]", typeName)).addToDecoder(decoderOfStruct(cfg, typ)) - case reflect.Array: - return prefix("[array]").addToDecoder(decoderOfArray(cfg, typ)) - case reflect.Slice: - return prefix("[slice]").addToDecoder(decoderOfSlice(cfg, typ)) - case reflect.Map: - return prefix("[map]").addToDecoder(decoderOfMap(cfg, typ)) - case reflect.Ptr: - return prefix("[optional]").addToDecoder(decoderOfOptional(cfg, typ)) - default: - return nil, fmt.Errorf("unsupported type: %v", typ) - } -} - -func encoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - cacheKey := typ - encoder := cfg.getEncoderFromCache(cacheKey) - if encoder != nil { - return encoder, nil - } - encoder = getTypeEncoderFromExtension(typ) - if encoder != nil { - cfg.addEncoderToCache(cacheKey, encoder) - return encoder, nil - } - encoder = &placeholderEncoder{cfg: cfg, cacheKey: cacheKey} - cfg.addEncoderToCache(cacheKey, encoder) - encoder, err := createEncoderOfType(cfg, typ) - for _, extension := range extensions { - encoder = extension.DecorateEncoder(typ, encoder) - } - cfg.addEncoderToCache(cacheKey, encoder) - return encoder, err -} - -func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - if typ == jsonRawMessageType { - return &jsonRawMessageCodec{}, nil - } - if typ == jsoniterRawMessageType { - return &jsoniterRawMessageCodec{}, nil - } - if typ.AssignableTo(jsonNumberType) { - return &jsonNumberCodec{}, nil - } - if typ.AssignableTo(jsoniterNumberType) { - return &jsoniterNumberCodec{}, nil - } - if typ.Implements(marshalerType) { - checkIsEmpty, err := createCheckIsEmpty(typ) - if err != nil { - return nil, err - } - templateInterface := reflect.New(typ).Elem().Interface() - var encoder ValEncoder = &marshalerEncoder{ - templateInterface: extractInterface(templateInterface), - checkIsEmpty: checkIsEmpty, - } - if typ.Kind() == reflect.Ptr { - encoder = &OptionalEncoder{encoder} - } - return encoder, nil - } - if reflect.PtrTo(typ).Implements(marshalerType) { - checkIsEmpty, err := createCheckIsEmpty(reflect.PtrTo(typ)) - if err != nil { - return nil, err - } - templateInterface := reflect.New(typ).Interface() - var encoder ValEncoder = &marshalerEncoder{ - templateInterface: extractInterface(templateInterface), - checkIsEmpty: checkIsEmpty, - } - return encoder, nil - } - if typ.Implements(textMarshalerType) { - checkIsEmpty, err := createCheckIsEmpty(typ) - if err != nil { - return nil, err - } - templateInterface := reflect.New(typ).Elem().Interface() - var encoder ValEncoder = &textMarshalerEncoder{ - templateInterface: extractInterface(templateInterface), - checkIsEmpty: checkIsEmpty, - } - if typ.Kind() == reflect.Ptr { - encoder = &OptionalEncoder{encoder} - } - return encoder, nil - } - if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Uint8 { - return &base64Codec{}, nil - } - if typ.Implements(anyType) { - return &anyCodec{}, nil - } - return createEncoderOfSimpleType(cfg, typ) -} - -func createCheckIsEmpty(typ reflect.Type) (checkIsEmpty, error) { - kind := typ.Kind() - switch kind { - case reflect.String: - return &stringCodec{}, nil - case reflect.Int: - return &intCodec{}, nil - case reflect.Int8: - return &int8Codec{}, nil - case reflect.Int16: - return &int16Codec{}, nil - case reflect.Int32: - return &int32Codec{}, nil - case reflect.Int64: - return &int64Codec{}, nil - case reflect.Uint: - return &uintCodec{}, nil - case reflect.Uint8: - return &uint8Codec{}, nil - case reflect.Uint16: - return &uint16Codec{}, nil - case reflect.Uint32: - return &uint32Codec{}, nil - case reflect.Uintptr: - return &uintptrCodec{}, nil - case reflect.Uint64: - return &uint64Codec{}, nil - case reflect.Float32: - return &float32Codec{}, nil - case reflect.Float64: - return &float64Codec{}, nil - case reflect.Bool: - return &boolCodec{}, nil - case reflect.Interface: - if typ.NumMethod() == 0 { - return &emptyInterfaceCodec{}, nil - } - return &nonEmptyInterfaceCodec{}, nil - case reflect.Struct: - return &structEncoder{}, nil - case reflect.Array: - return &arrayEncoder{}, nil - case reflect.Slice: - return &sliceEncoder{}, nil - case reflect.Map: - return &mapEncoder{}, nil - case reflect.Ptr: - return &OptionalEncoder{}, nil - default: - return nil, fmt.Errorf("unsupported type: %v", typ) - } -} - -func createEncoderOfSimpleType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - typeName := typ.String() - kind := typ.Kind() - switch kind { - case reflect.String: - if typeName != "string" { - return encoderOfType(cfg, reflect.TypeOf((*string)(nil)).Elem()) - } - return &stringCodec{}, nil - case reflect.Int: - if typeName != "int" { - return encoderOfType(cfg, reflect.TypeOf((*int)(nil)).Elem()) - } - return &intCodec{}, nil - case reflect.Int8: - if typeName != "int8" { - return encoderOfType(cfg, reflect.TypeOf((*int8)(nil)).Elem()) - } - return &int8Codec{}, nil - case reflect.Int16: - if typeName != "int16" { - return encoderOfType(cfg, reflect.TypeOf((*int16)(nil)).Elem()) - } - return &int16Codec{}, nil - case reflect.Int32: - if typeName != "int32" { - return encoderOfType(cfg, reflect.TypeOf((*int32)(nil)).Elem()) - } - return &int32Codec{}, nil - case reflect.Int64: - if typeName != "int64" { - return encoderOfType(cfg, reflect.TypeOf((*int64)(nil)).Elem()) - } - return &int64Codec{}, nil - case reflect.Uint: - if typeName != "uint" { - return encoderOfType(cfg, reflect.TypeOf((*uint)(nil)).Elem()) - } - return &uintCodec{}, nil - case reflect.Uint8: - if typeName != "uint8" { - return encoderOfType(cfg, reflect.TypeOf((*uint8)(nil)).Elem()) - } - return &uint8Codec{}, nil - case reflect.Uint16: - if typeName != "uint16" { - return encoderOfType(cfg, reflect.TypeOf((*uint16)(nil)).Elem()) - } - return &uint16Codec{}, nil - case reflect.Uint32: - if typeName != "uint32" { - return encoderOfType(cfg, reflect.TypeOf((*uint32)(nil)).Elem()) - } - return &uint32Codec{}, nil - case reflect.Uintptr: - if typeName != "uintptr" { - return encoderOfType(cfg, reflect.TypeOf((*uintptr)(nil)).Elem()) - } - return &uintptrCodec{}, nil - case reflect.Uint64: - if typeName != "uint64" { - return encoderOfType(cfg, reflect.TypeOf((*uint64)(nil)).Elem()) - } - return &uint64Codec{}, nil - case reflect.Float32: - if typeName != "float32" { - return encoderOfType(cfg, reflect.TypeOf((*float32)(nil)).Elem()) - } - return &float32Codec{}, nil - case reflect.Float64: - if typeName != "float64" { - return encoderOfType(cfg, reflect.TypeOf((*float64)(nil)).Elem()) - } - return &float64Codec{}, nil - case reflect.Bool: - if typeName != "bool" { - return encoderOfType(cfg, reflect.TypeOf((*bool)(nil)).Elem()) - } - return &boolCodec{}, nil - case reflect.Interface: - if typ.NumMethod() == 0 { - return &emptyInterfaceCodec{}, nil - } - return &nonEmptyInterfaceCodec{}, nil - case reflect.Struct: - return prefix(fmt.Sprintf("[%s]", typeName)).addToEncoder(encoderOfStruct(cfg, typ)) - case reflect.Array: - return prefix("[array]").addToEncoder(encoderOfArray(cfg, typ)) - case reflect.Slice: - return prefix("[slice]").addToEncoder(encoderOfSlice(cfg, typ)) - case reflect.Map: - return prefix("[map]").addToEncoder(encoderOfMap(cfg, typ)) - case reflect.Ptr: - return prefix("[optional]").addToEncoder(encoderOfOptional(cfg, typ)) - default: - return nil, fmt.Errorf("unsupported type: %v", typ) - } -} - -func decoderOfOptional(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - elemType := typ.Elem() - decoder, err := decoderOfType(cfg, elemType) - if err != nil { - return nil, err - } - return &OptionalDecoder{elemType, decoder}, nil -} - -func encoderOfOptional(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - elemType := typ.Elem() - elemEncoder, err := encoderOfType(cfg, elemType) - if err != nil { - return nil, err - } - encoder := &OptionalEncoder{elemEncoder} - if elemType.Kind() == reflect.Map { - encoder = &OptionalEncoder{encoder} - } - return encoder, nil -} - -func decoderOfMap(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - decoder, err := decoderOfType(cfg, typ.Elem()) - if err != nil { - return nil, err - } - mapInterface := reflect.New(typ).Interface() - return &mapDecoder{typ, typ.Key(), typ.Elem(), decoder, extractInterface(mapInterface)}, nil -} - -func extractInterface(val interface{}) emptyInterface { - return *((*emptyInterface)(unsafe.Pointer(&val))) -} - -func encoderOfMap(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - elemType := typ.Elem() - encoder, err := encoderOfType(cfg, elemType) - if err != nil { - return nil, err - } - mapInterface := reflect.New(typ).Elem().Interface() - if cfg.sortMapKeys { - return &sortKeysMapEncoder{typ, elemType, encoder, *((*emptyInterface)(unsafe.Pointer(&mapInterface)))}, nil - } - return &mapEncoder{typ, elemType, encoder, *((*emptyInterface)(unsafe.Pointer(&mapInterface)))}, nil -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_array.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_array.go deleted file mode 100644 index d661fb6f..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_array.go +++ /dev/null @@ -1,99 +0,0 @@ -package jsoniter - -import ( - "fmt" - "io" - "reflect" - "unsafe" -) - -func decoderOfArray(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - decoder, err := decoderOfType(cfg, typ.Elem()) - if err != nil { - return nil, err - } - return &arrayDecoder{typ, typ.Elem(), decoder}, nil -} - -func encoderOfArray(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - encoder, err := encoderOfType(cfg, typ.Elem()) - if err != nil { - return nil, err - } - if typ.Elem().Kind() == reflect.Map { - encoder = &OptionalEncoder{encoder} - } - return &arrayEncoder{typ, typ.Elem(), encoder}, nil -} - -type arrayEncoder struct { - arrayType reflect.Type - elemType reflect.Type - elemEncoder ValEncoder -} - -func (encoder *arrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteArrayStart() - elemPtr := unsafe.Pointer(ptr) - encoder.elemEncoder.Encode(elemPtr, stream) - for i := 1; i < encoder.arrayType.Len(); i++ { - stream.WriteMore() - elemPtr = unsafe.Pointer(uintptr(elemPtr) + encoder.elemType.Size()) - encoder.elemEncoder.Encode(unsafe.Pointer(elemPtr), stream) - } - stream.WriteArrayEnd() - if stream.Error != nil && stream.Error != io.EOF { - stream.Error = fmt.Errorf("%v: %s", encoder.arrayType, stream.Error.Error()) - } -} - -func (encoder *arrayEncoder) EncodeInterface(val interface{}, stream *Stream) { - // special optimization for interface{} - e := (*emptyInterface)(unsafe.Pointer(&val)) - if e.word == nil { - stream.WriteArrayStart() - stream.WriteNil() - stream.WriteArrayEnd() - return - } - elemType := encoder.arrayType.Elem() - if encoder.arrayType.Len() == 1 && (elemType.Kind() == reflect.Ptr || elemType.Kind() == reflect.Map) { - ptr := uintptr(e.word) - e.word = unsafe.Pointer(&ptr) - } - if reflect.TypeOf(val).Kind() == reflect.Ptr { - encoder.Encode(unsafe.Pointer(&e.word), stream) - } else { - encoder.Encode(e.word, stream) - } -} - -func (encoder *arrayEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return false -} - -type arrayDecoder struct { - arrayType reflect.Type - elemType reflect.Type - elemDecoder ValDecoder -} - -func (decoder *arrayDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - decoder.doDecode(ptr, iter) - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.arrayType, iter.Error.Error()) - } -} - -func (decoder *arrayDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) { - offset := uintptr(0) - iter.ReadArrayCB(func(iter *Iterator) bool { - if offset < decoder.arrayType.Size() { - decoder.elemDecoder.Decode(unsafe.Pointer(uintptr(ptr)+offset), iter) - offset += decoder.elemType.Size() - } else { - iter.Skip() - } - return true - }) -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_extension.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_extension.go deleted file mode 100644 index 177df2c8..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_extension.go +++ /dev/null @@ -1,414 +0,0 @@ -package jsoniter - -import ( - "fmt" - "reflect" - "sort" - "strings" - "unicode" - "unsafe" -) - -var typeDecoders = map[string]ValDecoder{} -var fieldDecoders = map[string]ValDecoder{} -var typeEncoders = map[string]ValEncoder{} -var fieldEncoders = map[string]ValEncoder{} -var extensions = []Extension{} - -// StructDescriptor describe how should we encode/decode the struct -type StructDescriptor struct { - onePtrEmbedded bool - onePtrOptimization bool - Type reflect.Type - Fields []*Binding -} - -// GetField get one field from the descriptor by its name. -// Can not use map here to keep field orders. -func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding { - for _, binding := range structDescriptor.Fields { - if binding.Field.Name == fieldName { - return binding - } - } - return nil -} - -// Binding describe how should we encode/decode the struct field -type Binding struct { - levels []int - Field *reflect.StructField - FromNames []string - ToNames []string - Encoder ValEncoder - Decoder ValDecoder -} - -// Extension the one for all SPI. Customize encoding/decoding by specifying alternate encoder/decoder. -// Can also rename fields by UpdateStructDescriptor. -type Extension interface { - UpdateStructDescriptor(structDescriptor *StructDescriptor) - CreateDecoder(typ reflect.Type) ValDecoder - CreateEncoder(typ reflect.Type) ValEncoder - DecorateDecoder(typ reflect.Type, decoder ValDecoder) ValDecoder - DecorateEncoder(typ reflect.Type, encoder ValEncoder) ValEncoder -} - -// DummyExtension embed this type get dummy implementation for all methods of Extension -type DummyExtension struct { -} - -// UpdateStructDescriptor No-op -func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) { -} - -// CreateDecoder No-op -func (extension *DummyExtension) CreateDecoder(typ reflect.Type) ValDecoder { - return nil -} - -// CreateEncoder No-op -func (extension *DummyExtension) CreateEncoder(typ reflect.Type) ValEncoder { - return nil -} - -// DecorateDecoder No-op -func (extension *DummyExtension) DecorateDecoder(typ reflect.Type, decoder ValDecoder) ValDecoder { - return decoder -} - -// DecorateEncoder No-op -func (extension *DummyExtension) DecorateEncoder(typ reflect.Type, encoder ValEncoder) ValEncoder { - return encoder -} - -type funcDecoder struct { - fun DecoderFunc -} - -func (decoder *funcDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - decoder.fun(ptr, iter) -} - -type funcEncoder struct { - fun EncoderFunc - isEmptyFunc func(ptr unsafe.Pointer) bool -} - -func (encoder *funcEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - encoder.fun(ptr, stream) -} - -func (encoder *funcEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *funcEncoder) IsEmpty(ptr unsafe.Pointer) bool { - if encoder.isEmptyFunc == nil { - return false - } - return encoder.isEmptyFunc(ptr) -} - -// DecoderFunc the function form of TypeDecoder -type DecoderFunc func(ptr unsafe.Pointer, iter *Iterator) - -// EncoderFunc the function form of TypeEncoder -type EncoderFunc func(ptr unsafe.Pointer, stream *Stream) - -// RegisterTypeDecoderFunc register TypeDecoder for a type with function -func RegisterTypeDecoderFunc(typ string, fun DecoderFunc) { - typeDecoders[typ] = &funcDecoder{fun} -} - -// RegisterTypeDecoder register TypeDecoder for a typ -func RegisterTypeDecoder(typ string, decoder ValDecoder) { - typeDecoders[typ] = decoder -} - -// RegisterFieldDecoderFunc register TypeDecoder for a struct field with function -func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc) { - RegisterFieldDecoder(typ, field, &funcDecoder{fun}) -} - -// RegisterFieldDecoder register TypeDecoder for a struct field -func RegisterFieldDecoder(typ string, field string, decoder ValDecoder) { - fieldDecoders[fmt.Sprintf("%s/%s", typ, field)] = decoder -} - -// RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function -func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) { - typeEncoders[typ] = &funcEncoder{fun, isEmptyFunc} -} - -// RegisterTypeEncoder register TypeEncoder for a type -func RegisterTypeEncoder(typ string, encoder ValEncoder) { - typeEncoders[typ] = encoder -} - -// RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function -func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) { - RegisterFieldEncoder(typ, field, &funcEncoder{fun, isEmptyFunc}) -} - -// RegisterFieldEncoder register TypeEncoder for a struct field -func RegisterFieldEncoder(typ string, field string, encoder ValEncoder) { - fieldEncoders[fmt.Sprintf("%s/%s", typ, field)] = encoder -} - -// RegisterExtension register extension -func RegisterExtension(extension Extension) { - extensions = append(extensions, extension) -} - -func getTypeDecoderFromExtension(typ reflect.Type) ValDecoder { - decoder := _getTypeDecoderFromExtension(typ) - if decoder != nil { - for _, extension := range extensions { - decoder = extension.DecorateDecoder(typ, decoder) - } - } - return decoder -} -func _getTypeDecoderFromExtension(typ reflect.Type) ValDecoder { - for _, extension := range extensions { - decoder := extension.CreateDecoder(typ) - if decoder != nil { - return decoder - } - } - typeName := typ.String() - decoder := typeDecoders[typeName] - if decoder != nil { - return decoder - } - if typ.Kind() == reflect.Ptr { - decoder := typeDecoders[typ.Elem().String()] - if decoder != nil { - return &OptionalDecoder{typ.Elem(), decoder} - } - } - return nil -} - -func getTypeEncoderFromExtension(typ reflect.Type) ValEncoder { - encoder := _getTypeEncoderFromExtension(typ) - if encoder != nil { - for _, extension := range extensions { - encoder = extension.DecorateEncoder(typ, encoder) - } - } - return encoder -} - -func _getTypeEncoderFromExtension(typ reflect.Type) ValEncoder { - for _, extension := range extensions { - encoder := extension.CreateEncoder(typ) - if encoder != nil { - return encoder - } - } - typeName := typ.String() - encoder := typeEncoders[typeName] - if encoder != nil { - return encoder - } - if typ.Kind() == reflect.Ptr { - encoder := typeEncoders[typ.Elem().String()] - if encoder != nil { - return &OptionalEncoder{encoder} - } - } - return nil -} - -func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, error) { - embeddedBindings := []*Binding{} - bindings := []*Binding{} - for i := 0; i < typ.NumField(); i++ { - field := typ.Field(i) - tag := field.Tag.Get(cfg.getTagKey()) - tagParts := strings.Split(tag, ",") - if tag == "-" { - continue - } - if field.Anonymous && (tag == "" || tagParts[0] == "") { - if field.Type.Kind() == reflect.Struct { - structDescriptor, err := describeStruct(cfg, field.Type) - if err != nil { - return nil, err - } - for _, binding := range structDescriptor.Fields { - binding.levels = append([]int{i}, binding.levels...) - omitempty := binding.Encoder.(*structFieldEncoder).omitempty - binding.Encoder = &structFieldEncoder{&field, binding.Encoder, omitempty} - binding.Decoder = &structFieldDecoder{&field, binding.Decoder} - embeddedBindings = append(embeddedBindings, binding) - } - continue - } else if field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct { - structDescriptor, err := describeStruct(cfg, field.Type.Elem()) - if err != nil { - return nil, err - } - for _, binding := range structDescriptor.Fields { - binding.levels = append([]int{i}, binding.levels...) - omitempty := binding.Encoder.(*structFieldEncoder).omitempty - binding.Encoder = &OptionalEncoder{binding.Encoder} - binding.Encoder = &structFieldEncoder{&field, binding.Encoder, omitempty} - binding.Decoder = &deferenceDecoder{field.Type.Elem(), binding.Decoder} - binding.Decoder = &structFieldDecoder{&field, binding.Decoder} - embeddedBindings = append(embeddedBindings, binding) - } - continue - } - } - fieldNames := calcFieldNames(field.Name, tagParts[0], tag) - fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name) - decoder := fieldDecoders[fieldCacheKey] - if decoder == nil { - var err error - decoder, err = decoderOfType(cfg, field.Type) - if len(fieldNames) > 0 && err != nil { - return nil, err - } - } - encoder := fieldEncoders[fieldCacheKey] - if encoder == nil { - var err error - encoder, err = encoderOfType(cfg, field.Type) - if len(fieldNames) > 0 && err != nil { - return nil, err - } - // map is stored as pointer in the struct, - // and treat nil or empty map as empty field - if encoder != nil && field.Type.Kind() == reflect.Map { - encoder = &optionalMapEncoder{encoder} - } - } - binding := &Binding{ - Field: &field, - FromNames: fieldNames, - ToNames: fieldNames, - Decoder: decoder, - Encoder: encoder, - } - binding.levels = []int{i} - bindings = append(bindings, binding) - } - return createStructDescriptor(cfg, typ, bindings, embeddedBindings), nil -} -func createStructDescriptor(cfg *frozenConfig, typ reflect.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor { - onePtrEmbedded := false - onePtrOptimization := false - if typ.NumField() == 1 { - firstField := typ.Field(0) - switch firstField.Type.Kind() { - case reflect.Ptr: - if firstField.Anonymous && firstField.Type.Elem().Kind() == reflect.Struct { - onePtrEmbedded = true - } - fallthrough - case reflect.Map: - onePtrOptimization = true - case reflect.Struct: - onePtrOptimization = isStructOnePtr(firstField.Type) - } - } - structDescriptor := &StructDescriptor{ - onePtrEmbedded: onePtrEmbedded, - onePtrOptimization: onePtrOptimization, - Type: typ, - Fields: bindings, - } - for _, extension := range extensions { - extension.UpdateStructDescriptor(structDescriptor) - } - processTags(structDescriptor, cfg) - // merge normal & embedded bindings & sort with original order - allBindings := sortableBindings(append(embeddedBindings, structDescriptor.Fields...)) - sort.Sort(allBindings) - structDescriptor.Fields = allBindings - return structDescriptor -} - -func isStructOnePtr(typ reflect.Type) bool { - if typ.NumField() == 1 { - firstField := typ.Field(0) - switch firstField.Type.Kind() { - case reflect.Ptr: - return true - case reflect.Map: - return true - case reflect.Struct: - return isStructOnePtr(firstField.Type) - } - } - return false -} - -type sortableBindings []*Binding - -func (bindings sortableBindings) Len() int { - return len(bindings) -} - -func (bindings sortableBindings) Less(i, j int) bool { - left := bindings[i].levels - right := bindings[j].levels - k := 0 - for { - if left[k] < right[k] { - return true - } else if left[k] > right[k] { - return false - } - k++ - } -} - -func (bindings sortableBindings) Swap(i, j int) { - bindings[i], bindings[j] = bindings[j], bindings[i] -} - -func processTags(structDescriptor *StructDescriptor, cfg *frozenConfig) { - for _, binding := range structDescriptor.Fields { - shouldOmitEmpty := false - tagParts := strings.Split(binding.Field.Tag.Get(cfg.getTagKey()), ",") - for _, tagPart := range tagParts[1:] { - if tagPart == "omitempty" { - shouldOmitEmpty = true - } else if tagPart == "string" { - if binding.Field.Type.Kind() == reflect.String { - binding.Decoder = &stringModeStringDecoder{binding.Decoder, cfg} - binding.Encoder = &stringModeStringEncoder{binding.Encoder, cfg} - } else { - binding.Decoder = &stringModeNumberDecoder{binding.Decoder} - binding.Encoder = &stringModeNumberEncoder{binding.Encoder} - } - } - } - binding.Decoder = &structFieldDecoder{binding.Field, binding.Decoder} - binding.Encoder = &structFieldEncoder{binding.Field, binding.Encoder, shouldOmitEmpty} - } -} - -func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string { - // ignore? - if wholeTag == "-" { - return []string{} - } - // rename? - var fieldNames []string - if tagProvidedFieldName == "" { - fieldNames = []string{originalFieldName} - } else { - fieldNames = []string{tagProvidedFieldName} - } - // private? - isNotExported := unicode.IsLower(rune(originalFieldName[0])) - if isNotExported { - fieldNames = []string{} - } - return fieldNames -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_map.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_map.go deleted file mode 100644 index 005671e0..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_map.go +++ /dev/null @@ -1,244 +0,0 @@ -package jsoniter - -import ( - "encoding" - "encoding/json" - "reflect" - "sort" - "strconv" - "unsafe" -) - -type mapDecoder struct { - mapType reflect.Type - keyType reflect.Type - elemType reflect.Type - elemDecoder ValDecoder - mapInterface emptyInterface -} - -func (decoder *mapDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - // dark magic to cast unsafe.Pointer back to interface{} using reflect.Type - mapInterface := decoder.mapInterface - mapInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&mapInterface)) - realVal := reflect.ValueOf(*realInterface).Elem() - if iter.ReadNil() { - realVal.Set(reflect.Zero(decoder.mapType)) - return - } - if realVal.IsNil() { - realVal.Set(reflect.MakeMap(realVal.Type())) - } - iter.ReadMapCB(func(iter *Iterator, keyStr string) bool { - elem := reflect.New(decoder.elemType) - decoder.elemDecoder.Decode(unsafe.Pointer(elem.Pointer()), iter) - // to put into map, we have to use reflection - keyType := decoder.keyType - // TODO: remove this from loop - switch { - case keyType.Kind() == reflect.String: - realVal.SetMapIndex(reflect.ValueOf(keyStr).Convert(keyType), elem.Elem()) - return true - case keyType.Implements(textUnmarshalerType): - textUnmarshaler := reflect.New(keyType.Elem()).Interface().(encoding.TextUnmarshaler) - err := textUnmarshaler.UnmarshalText([]byte(keyStr)) - if err != nil { - iter.ReportError("read map key as TextUnmarshaler", err.Error()) - return false - } - realVal.SetMapIndex(reflect.ValueOf(textUnmarshaler), elem.Elem()) - return true - case reflect.PtrTo(keyType).Implements(textUnmarshalerType): - textUnmarshaler := reflect.New(keyType).Interface().(encoding.TextUnmarshaler) - err := textUnmarshaler.UnmarshalText([]byte(keyStr)) - if err != nil { - iter.ReportError("read map key as TextUnmarshaler", err.Error()) - return false - } - realVal.SetMapIndex(reflect.ValueOf(textUnmarshaler).Elem(), elem.Elem()) - return true - default: - switch keyType.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - n, err := strconv.ParseInt(keyStr, 10, 64) - if err != nil || reflect.Zero(keyType).OverflowInt(n) { - iter.ReportError("read map key as int64", "read int64 failed") - return false - } - realVal.SetMapIndex(reflect.ValueOf(n).Convert(keyType), elem.Elem()) - return true - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - n, err := strconv.ParseUint(keyStr, 10, 64) - if err != nil || reflect.Zero(keyType).OverflowUint(n) { - iter.ReportError("read map key as uint64", "read uint64 failed") - return false - } - realVal.SetMapIndex(reflect.ValueOf(n).Convert(keyType), elem.Elem()) - return true - } - } - iter.ReportError("read map key", "unexpected map key type "+keyType.String()) - return true - }) -} - -type mapEncoder struct { - mapType reflect.Type - elemType reflect.Type - elemEncoder ValEncoder - mapInterface emptyInterface -} - -func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - mapInterface := encoder.mapInterface - mapInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&mapInterface)) - realVal := reflect.ValueOf(*realInterface) - stream.WriteObjectStart() - for i, key := range realVal.MapKeys() { - if i != 0 { - stream.WriteMore() - } - encodeMapKey(key, stream) - if stream.indention > 0 { - stream.writeTwoBytes(byte(':'), byte(' ')) - } else { - stream.writeByte(':') - } - val := realVal.MapIndex(key).Interface() - encoder.elemEncoder.EncodeInterface(val, stream) - } - stream.WriteObjectEnd() -} - -func encodeMapKey(key reflect.Value, stream *Stream) { - if key.Kind() == reflect.String { - stream.WriteString(key.String()) - return - } - if tm, ok := key.Interface().(encoding.TextMarshaler); ok { - buf, err := tm.MarshalText() - if err != nil { - stream.Error = err - return - } - stream.writeByte('"') - stream.Write(buf) - stream.writeByte('"') - return - } - switch key.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - stream.writeByte('"') - stream.WriteInt64(key.Int()) - stream.writeByte('"') - return - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - stream.writeByte('"') - stream.WriteUint64(key.Uint()) - stream.writeByte('"') - return - } - stream.Error = &json.UnsupportedTypeError{Type: key.Type()} -} - -func (encoder *mapEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *mapEncoder) IsEmpty(ptr unsafe.Pointer) bool { - mapInterface := encoder.mapInterface - mapInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&mapInterface)) - realVal := reflect.ValueOf(*realInterface) - return realVal.Len() == 0 -} - -type sortKeysMapEncoder struct { - mapType reflect.Type - elemType reflect.Type - elemEncoder ValEncoder - mapInterface emptyInterface -} - -func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - mapInterface := encoder.mapInterface - mapInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&mapInterface)) - realVal := reflect.ValueOf(*realInterface) - - // Extract and sort the keys. - keys := realVal.MapKeys() - sv := stringValues(make([]reflectWithString, len(keys))) - for i, v := range keys { - sv[i].v = v - if err := sv[i].resolve(); err != nil { - stream.Error = err - return - } - } - sort.Sort(sv) - - stream.WriteObjectStart() - for i, key := range sv { - if i != 0 { - stream.WriteMore() - } - stream.WriteVal(key.s) // might need html escape, so can not WriteString directly - if stream.indention > 0 { - stream.writeTwoBytes(byte(':'), byte(' ')) - } else { - stream.writeByte(':') - } - val := realVal.MapIndex(key.v).Interface() - encoder.elemEncoder.EncodeInterface(val, stream) - } - stream.WriteObjectEnd() -} - -// stringValues is a slice of reflect.Value holding *reflect.StringValue. -// It implements the methods to sort by string. -type stringValues []reflectWithString - -type reflectWithString struct { - v reflect.Value - s string -} - -func (w *reflectWithString) resolve() error { - if w.v.Kind() == reflect.String { - w.s = w.v.String() - return nil - } - if tm, ok := w.v.Interface().(encoding.TextMarshaler); ok { - buf, err := tm.MarshalText() - w.s = string(buf) - return err - } - switch w.v.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - w.s = strconv.FormatInt(w.v.Int(), 10) - return nil - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - w.s = strconv.FormatUint(w.v.Uint(), 10) - return nil - } - return &json.UnsupportedTypeError{Type: w.v.Type()} -} - -func (sv stringValues) Len() int { return len(sv) } -func (sv stringValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] } -func (sv stringValues) Less(i, j int) bool { return sv[i].s < sv[j].s } - -func (encoder *sortKeysMapEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *sortKeysMapEncoder) IsEmpty(ptr unsafe.Pointer) bool { - mapInterface := encoder.mapInterface - mapInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&mapInterface)) - realVal := reflect.ValueOf(*realInterface) - return realVal.Len() == 0 -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_native.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_native.go deleted file mode 100644 index 95bd1e87..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_native.go +++ /dev/null @@ -1,764 +0,0 @@ -package jsoniter - -import ( - "encoding" - "encoding/base64" - "encoding/json" - "reflect" - "unsafe" -) - -type stringCodec struct { -} - -func (codec *stringCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - *((*string)(ptr)) = iter.ReadString() -} - -func (codec *stringCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - str := *((*string)(ptr)) - stream.WriteString(str) -} - -func (codec *stringCodec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *stringCodec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*string)(ptr)) == "" -} - -type intCodec struct { -} - -func (codec *intCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*int)(ptr)) = iter.ReadInt() - } -} - -func (codec *intCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteInt(*((*int)(ptr))) -} - -func (codec *intCodec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *intCodec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*int)(ptr)) == 0 -} - -type uintptrCodec struct { -} - -func (codec *uintptrCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uintptr)(ptr)) = uintptr(iter.ReadUint64()) - } -} - -func (codec *uintptrCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint64(uint64(*((*uintptr)(ptr)))) -} - -func (codec *uintptrCodec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uintptrCodec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uintptr)(ptr)) == 0 -} - -type int8Codec struct { -} - -func (codec *int8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*int8)(ptr)) = iter.ReadInt8() - } -} - -func (codec *int8Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteInt8(*((*int8)(ptr))) -} - -func (codec *int8Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *int8Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*int8)(ptr)) == 0 -} - -type int16Codec struct { -} - -func (codec *int16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*int16)(ptr)) = iter.ReadInt16() - } -} - -func (codec *int16Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteInt16(*((*int16)(ptr))) -} - -func (codec *int16Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *int16Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*int16)(ptr)) == 0 -} - -type int32Codec struct { -} - -func (codec *int32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*int32)(ptr)) = iter.ReadInt32() - } -} - -func (codec *int32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteInt32(*((*int32)(ptr))) -} - -func (codec *int32Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *int32Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*int32)(ptr)) == 0 -} - -type int64Codec struct { -} - -func (codec *int64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*int64)(ptr)) = iter.ReadInt64() - } -} - -func (codec *int64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteInt64(*((*int64)(ptr))) -} - -func (codec *int64Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *int64Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*int64)(ptr)) == 0 -} - -type uintCodec struct { -} - -func (codec *uintCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uint)(ptr)) = iter.ReadUint() - return - } -} - -func (codec *uintCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint(*((*uint)(ptr))) -} - -func (codec *uintCodec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uintCodec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uint)(ptr)) == 0 -} - -type uint8Codec struct { -} - -func (codec *uint8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uint8)(ptr)) = iter.ReadUint8() - } -} - -func (codec *uint8Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint8(*((*uint8)(ptr))) -} - -func (codec *uint8Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uint8Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uint8)(ptr)) == 0 -} - -type uint16Codec struct { -} - -func (codec *uint16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uint16)(ptr)) = iter.ReadUint16() - } -} - -func (codec *uint16Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint16(*((*uint16)(ptr))) -} - -func (codec *uint16Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uint16Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uint16)(ptr)) == 0 -} - -type uint32Codec struct { -} - -func (codec *uint32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uint32)(ptr)) = iter.ReadUint32() - } -} - -func (codec *uint32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint32(*((*uint32)(ptr))) -} - -func (codec *uint32Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uint32Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uint32)(ptr)) == 0 -} - -type uint64Codec struct { -} - -func (codec *uint64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*uint64)(ptr)) = iter.ReadUint64() - } -} - -func (codec *uint64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteUint64(*((*uint64)(ptr))) -} - -func (codec *uint64Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *uint64Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*uint64)(ptr)) == 0 -} - -type float32Codec struct { -} - -func (codec *float32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*float32)(ptr)) = iter.ReadFloat32() - } -} - -func (codec *float32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteFloat32(*((*float32)(ptr))) -} - -func (codec *float32Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *float32Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*float32)(ptr)) == 0 -} - -type float64Codec struct { -} - -func (codec *float64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*float64)(ptr)) = iter.ReadFloat64() - } -} - -func (codec *float64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteFloat64(*((*float64)(ptr))) -} - -func (codec *float64Codec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *float64Codec) IsEmpty(ptr unsafe.Pointer) bool { - return *((*float64)(ptr)) == 0 -} - -type boolCodec struct { -} - -func (codec *boolCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.ReadNil() { - *((*bool)(ptr)) = iter.ReadBool() - } -} - -func (codec *boolCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteBool(*((*bool)(ptr))) -} - -func (codec *boolCodec) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, codec) -} - -func (codec *boolCodec) IsEmpty(ptr unsafe.Pointer) bool { - return !(*((*bool)(ptr))) -} - -type emptyInterfaceCodec struct { -} - -func (codec *emptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - existing := *((*interface{})(ptr)) - - // Checking for both typed and untyped nil pointers. - if existing != nil && - reflect.TypeOf(existing).Kind() == reflect.Ptr && - !reflect.ValueOf(existing).IsNil() { - - var ptrToExisting interface{} - for { - elem := reflect.ValueOf(existing).Elem() - if elem.Kind() != reflect.Ptr || elem.IsNil() { - break - } - ptrToExisting = existing - existing = elem.Interface() - } - - if iter.ReadNil() { - if ptrToExisting != nil { - nilPtr := reflect.Zero(reflect.TypeOf(ptrToExisting).Elem()) - reflect.ValueOf(ptrToExisting).Elem().Set(nilPtr) - } else { - *((*interface{})(ptr)) = nil - } - } else { - iter.ReadVal(existing) - } - - return - } - - if iter.ReadNil() { - *((*interface{})(ptr)) = nil - } else { - *((*interface{})(ptr)) = iter.Read() - } -} - -func (codec *emptyInterfaceCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteVal(*((*interface{})(ptr))) -} - -func (codec *emptyInterfaceCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteVal(val) -} - -func (codec *emptyInterfaceCodec) IsEmpty(ptr unsafe.Pointer) bool { - emptyInterface := (*emptyInterface)(ptr) - return emptyInterface.typ == nil -} - -type nonEmptyInterfaceCodec struct { -} - -func (codec *nonEmptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - nonEmptyInterface := (*nonEmptyInterface)(ptr) - if nonEmptyInterface.itab == nil { - iter.ReportError("read non-empty interface", "do not know which concrete type to decode to") - return - } - var i interface{} - e := (*emptyInterface)(unsafe.Pointer(&i)) - e.typ = nonEmptyInterface.itab.typ - e.word = nonEmptyInterface.word - iter.ReadVal(&i) - if e.word == nil { - nonEmptyInterface.itab = nil - } - nonEmptyInterface.word = e.word -} - -func (codec *nonEmptyInterfaceCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - nonEmptyInterface := (*nonEmptyInterface)(ptr) - var i interface{} - if nonEmptyInterface.itab != nil { - e := (*emptyInterface)(unsafe.Pointer(&i)) - e.typ = nonEmptyInterface.itab.typ - e.word = nonEmptyInterface.word - } - stream.WriteVal(i) -} - -func (codec *nonEmptyInterfaceCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteVal(val) -} - -func (codec *nonEmptyInterfaceCodec) IsEmpty(ptr unsafe.Pointer) bool { - nonEmptyInterface := (*nonEmptyInterface)(ptr) - return nonEmptyInterface.word == nil -} - -type anyCodec struct { -} - -func (codec *anyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - *((*Any)(ptr)) = iter.ReadAny() -} - -func (codec *anyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - (*((*Any)(ptr))).WriteTo(stream) -} - -func (codec *anyCodec) EncodeInterface(val interface{}, stream *Stream) { - (val.(Any)).WriteTo(stream) -} - -func (codec *anyCodec) IsEmpty(ptr unsafe.Pointer) bool { - return (*((*Any)(ptr))).Size() == 0 -} - -type jsonNumberCodec struct { -} - -func (codec *jsonNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - switch iter.WhatIsNext() { - case StringValue: - *((*json.Number)(ptr)) = json.Number(iter.ReadString()) - case NilValue: - iter.skipFourBytes('n', 'u', 'l', 'l') - *((*json.Number)(ptr)) = "" - default: - *((*json.Number)(ptr)) = json.Number([]byte(iter.readNumberAsString())) - } -} - -func (codec *jsonNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteRaw(string(*((*json.Number)(ptr)))) -} - -func (codec *jsonNumberCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteRaw(string(val.(json.Number))) -} - -func (codec *jsonNumberCodec) IsEmpty(ptr unsafe.Pointer) bool { - return len(*((*json.Number)(ptr))) == 0 -} - -type jsoniterNumberCodec struct { -} - -func (codec *jsoniterNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - switch iter.WhatIsNext() { - case StringValue: - *((*Number)(ptr)) = Number(iter.ReadString()) - case NilValue: - iter.skipFourBytes('n', 'u', 'l', 'l') - *((*Number)(ptr)) = "" - default: - *((*Number)(ptr)) = Number([]byte(iter.readNumberAsString())) - } -} - -func (codec *jsoniterNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteRaw(string(*((*Number)(ptr)))) -} - -func (codec *jsoniterNumberCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteRaw(string(val.(Number))) -} - -func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool { - return len(*((*Number)(ptr))) == 0 -} - -type jsonRawMessageCodec struct { -} - -func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - *((*json.RawMessage)(ptr)) = json.RawMessage(iter.SkipAndReturnBytes()) -} - -func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteRaw(string(*((*json.RawMessage)(ptr)))) -} - -func (codec *jsonRawMessageCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteRaw(string(val.(json.RawMessage))) -} - -func (codec *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { - return len(*((*json.RawMessage)(ptr))) == 0 -} - -type jsoniterRawMessageCodec struct { -} - -func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { - *((*RawMessage)(ptr)) = RawMessage(iter.SkipAndReturnBytes()) -} - -func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteRaw(string(*((*RawMessage)(ptr)))) -} - -func (codec *jsoniterRawMessageCodec) EncodeInterface(val interface{}, stream *Stream) { - stream.WriteRaw(string(val.(RawMessage))) -} - -func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { - return len(*((*RawMessage)(ptr))) == 0 -} - -type base64Codec struct { - sliceDecoder ValDecoder -} - -func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { - if iter.ReadNil() { - ptrSlice := (*sliceHeader)(ptr) - ptrSlice.Len = 0 - ptrSlice.Cap = 0 - ptrSlice.Data = nil - return - } - switch iter.WhatIsNext() { - case StringValue: - encoding := base64.StdEncoding - src := iter.SkipAndReturnBytes() - src = src[1 : len(src)-1] - decodedLen := encoding.DecodedLen(len(src)) - dst := make([]byte, decodedLen) - len, err := encoding.Decode(dst, src) - if err != nil { - iter.ReportError("decode base64", err.Error()) - } else { - dst = dst[:len] - dstSlice := (*sliceHeader)(unsafe.Pointer(&dst)) - ptrSlice := (*sliceHeader)(ptr) - ptrSlice.Data = dstSlice.Data - ptrSlice.Cap = dstSlice.Cap - ptrSlice.Len = dstSlice.Len - } - case ArrayValue: - codec.sliceDecoder.Decode(ptr, iter) - default: - iter.ReportError("base64Codec", "invalid input") - } -} - -func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - src := *((*[]byte)(ptr)) - if len(src) == 0 { - stream.WriteNil() - return - } - encoding := base64.StdEncoding - stream.writeByte('"') - toGrow := encoding.EncodedLen(len(src)) - stream.ensure(toGrow) - encoding.Encode(stream.buf[stream.n:], src) - stream.n += toGrow - stream.writeByte('"') -} - -func (codec *base64Codec) EncodeInterface(val interface{}, stream *Stream) { - ptr := extractInterface(val).word - src := *((*[]byte)(ptr)) - if len(src) == 0 { - stream.WriteNil() - return - } - encoding := base64.StdEncoding - stream.writeByte('"') - toGrow := encoding.EncodedLen(len(src)) - stream.ensure(toGrow) - encoding.Encode(stream.buf[stream.n:], src) - stream.n += toGrow - stream.writeByte('"') -} - -func (codec *base64Codec) IsEmpty(ptr unsafe.Pointer) bool { - return len(*((*[]byte)(ptr))) == 0 -} - -type stringModeNumberDecoder struct { - elemDecoder ValDecoder -} - -func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - c := iter.nextToken() - if c != '"' { - iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c})) - return - } - decoder.elemDecoder.Decode(ptr, iter) - if iter.Error != nil { - return - } - c = iter.readByte() - if c != '"' { - iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c})) - return - } -} - -type stringModeStringDecoder struct { - elemDecoder ValDecoder - cfg *frozenConfig -} - -func (decoder *stringModeStringDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - decoder.elemDecoder.Decode(ptr, iter) - str := *((*string)(ptr)) - tempIter := decoder.cfg.BorrowIterator([]byte(str)) - defer decoder.cfg.ReturnIterator(tempIter) - *((*string)(ptr)) = tempIter.ReadString() -} - -type stringModeNumberEncoder struct { - elemEncoder ValEncoder -} - -func (encoder *stringModeNumberEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.writeByte('"') - encoder.elemEncoder.Encode(ptr, stream) - stream.writeByte('"') -} - -func (encoder *stringModeNumberEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *stringModeNumberEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return encoder.elemEncoder.IsEmpty(ptr) -} - -type stringModeStringEncoder struct { - elemEncoder ValEncoder - cfg *frozenConfig -} - -func (encoder *stringModeStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - tempStream := encoder.cfg.BorrowStream(nil) - defer encoder.cfg.ReturnStream(tempStream) - encoder.elemEncoder.Encode(ptr, tempStream) - stream.WriteString(string(tempStream.Buffer())) -} - -func (encoder *stringModeStringEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *stringModeStringEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return encoder.elemEncoder.IsEmpty(ptr) -} - -type marshalerEncoder struct { - templateInterface emptyInterface - checkIsEmpty checkIsEmpty -} - -func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - templateInterface := encoder.templateInterface - templateInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&templateInterface)) - marshaler, ok := (*realInterface).(json.Marshaler) - if !ok { - stream.WriteVal(nil) - return - } - - bytes, err := marshaler.MarshalJSON() - if err != nil { - stream.Error = err - } else { - stream.Write(bytes) - } -} -func (encoder *marshalerEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *marshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return encoder.checkIsEmpty.IsEmpty(ptr) -} - -type textMarshalerEncoder struct { - templateInterface emptyInterface - checkIsEmpty checkIsEmpty -} - -func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - templateInterface := encoder.templateInterface - templateInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&templateInterface)) - marshaler := (*realInterface).(encoding.TextMarshaler) - bytes, err := marshaler.MarshalText() - if err != nil { - stream.Error = err - } else { - stream.WriteString(string(bytes)) - } -} - -func (encoder *textMarshalerEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *textMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return encoder.checkIsEmpty.IsEmpty(ptr) -} - -type unmarshalerDecoder struct { - templateInterface emptyInterface -} - -func (decoder *unmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - templateInterface := decoder.templateInterface - templateInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&templateInterface)) - unmarshaler := (*realInterface).(json.Unmarshaler) - iter.nextToken() - iter.unreadByte() // skip spaces - bytes := iter.SkipAndReturnBytes() - err := unmarshaler.UnmarshalJSON(bytes) - if err != nil { - iter.ReportError("unmarshalerDecoder", err.Error()) - } -} - -type textUnmarshalerDecoder struct { - templateInterface emptyInterface -} - -func (decoder *textUnmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - templateInterface := decoder.templateInterface - templateInterface.word = ptr - realInterface := (*interface{})(unsafe.Pointer(&templateInterface)) - unmarshaler := (*realInterface).(encoding.TextUnmarshaler) - str := iter.ReadString() - err := unmarshaler.UnmarshalText([]byte(str)) - if err != nil { - iter.ReportError("textUnmarshalerDecoder", err.Error()) - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_object.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_object.go deleted file mode 100644 index 59b1235c..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_object.go +++ /dev/null @@ -1,196 +0,0 @@ -package jsoniter - -import ( - "fmt" - "io" - "reflect" - "strings" - "unsafe" -) - -func encoderOfStruct(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - type bindingTo struct { - binding *Binding - toName string - ignored bool - } - orderedBindings := []*bindingTo{} - structDescriptor, err := describeStruct(cfg, typ) - if err != nil { - return nil, err - } - for _, binding := range structDescriptor.Fields { - for _, toName := range binding.ToNames { - new := &bindingTo{ - binding: binding, - toName: toName, - } - for _, old := range orderedBindings { - if old.toName != toName { - continue - } - old.ignored, new.ignored = resolveConflictBinding(cfg, old.binding, new.binding) - } - orderedBindings = append(orderedBindings, new) - } - } - if len(orderedBindings) == 0 { - return &emptyStructEncoder{}, nil - } - finalOrderedFields := []structFieldTo{} - for _, bindingTo := range orderedBindings { - if !bindingTo.ignored { - finalOrderedFields = append(finalOrderedFields, structFieldTo{ - encoder: bindingTo.binding.Encoder.(*structFieldEncoder), - toName: bindingTo.toName, - }) - } - } - return &structEncoder{structDescriptor.onePtrEmbedded, structDescriptor.onePtrOptimization, finalOrderedFields}, nil -} - -func resolveConflictBinding(cfg *frozenConfig, old, new *Binding) (ignoreOld, ignoreNew bool) { - newTagged := new.Field.Tag.Get(cfg.getTagKey()) != "" - oldTagged := old.Field.Tag.Get(cfg.getTagKey()) != "" - if newTagged { - if oldTagged { - if len(old.levels) > len(new.levels) { - return true, false - } else if len(new.levels) > len(old.levels) { - return false, true - } else { - return true, true - } - } else { - return true, false - } - } else { - if oldTagged { - return true, false - } - if len(old.levels) > len(new.levels) { - return true, false - } else if len(new.levels) > len(old.levels) { - return false, true - } else { - return true, true - } - } -} - -func decoderOfStruct(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - bindings := map[string]*Binding{} - structDescriptor, err := describeStruct(cfg, typ) - if err != nil { - return nil, err - } - for _, binding := range structDescriptor.Fields { - for _, fromName := range binding.FromNames { - old := bindings[fromName] - if old == nil { - bindings[fromName] = binding - continue - } - ignoreOld, ignoreNew := resolveConflictBinding(cfg, old, binding) - if ignoreOld { - delete(bindings, fromName) - } - if !ignoreNew { - bindings[fromName] = binding - } - } - } - fields := map[string]*structFieldDecoder{} - for k, binding := range bindings { - fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder) - } - return createStructDecoder(typ, fields) -} - -type structFieldEncoder struct { - field *reflect.StructField - fieldEncoder ValEncoder - omitempty bool -} - -func (encoder *structFieldEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - fieldPtr := unsafe.Pointer(uintptr(ptr) + encoder.field.Offset) - encoder.fieldEncoder.Encode(fieldPtr, stream) - if stream.Error != nil && stream.Error != io.EOF { - stream.Error = fmt.Errorf("%s: %s", encoder.field.Name, stream.Error.Error()) - } -} - -func (encoder *structFieldEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *structFieldEncoder) IsEmpty(ptr unsafe.Pointer) bool { - fieldPtr := unsafe.Pointer(uintptr(ptr) + encoder.field.Offset) - return encoder.fieldEncoder.IsEmpty(fieldPtr) -} - -type structEncoder struct { - onePtrEmbedded bool - onePtrOptimization bool - fields []structFieldTo -} - -type structFieldTo struct { - encoder *structFieldEncoder - toName string -} - -func (encoder *structEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteObjectStart() - isNotFirst := false - for _, field := range encoder.fields { - if field.encoder.omitempty && field.encoder.IsEmpty(ptr) { - continue - } - if isNotFirst { - stream.WriteMore() - } - stream.WriteObjectField(field.toName) - field.encoder.Encode(ptr, stream) - isNotFirst = true - } - stream.WriteObjectEnd() -} - -func (encoder *structEncoder) EncodeInterface(val interface{}, stream *Stream) { - e := (*emptyInterface)(unsafe.Pointer(&val)) - if encoder.onePtrOptimization { - if e.word == nil && encoder.onePtrEmbedded { - stream.WriteObjectStart() - stream.WriteObjectEnd() - return - } - ptr := uintptr(e.word) - e.word = unsafe.Pointer(&ptr) - } - if reflect.TypeOf(val).Kind() == reflect.Ptr { - encoder.Encode(unsafe.Pointer(&e.word), stream) - } else { - encoder.Encode(e.word, stream) - } -} - -func (encoder *structEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return false -} - -type emptyStructEncoder struct { -} - -func (encoder *emptyStructEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - stream.WriteEmptyObject() -} - -func (encoder *emptyStructEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *emptyStructEncoder) IsEmpty(ptr unsafe.Pointer) bool { - return false -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_slice.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_slice.go deleted file mode 100644 index 51a8daec..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_slice.go +++ /dev/null @@ -1,147 +0,0 @@ -package jsoniter - -import ( - "fmt" - "io" - "reflect" - "unsafe" -) - -func decoderOfSlice(cfg *frozenConfig, typ reflect.Type) (ValDecoder, error) { - decoder, err := decoderOfType(cfg, typ.Elem()) - if err != nil { - return nil, err - } - return &sliceDecoder{typ, typ.Elem(), decoder}, nil -} - -func encoderOfSlice(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error) { - encoder, err := encoderOfType(cfg, typ.Elem()) - if err != nil { - return nil, err - } - if typ.Elem().Kind() == reflect.Map { - encoder = &OptionalEncoder{encoder} - } - return &sliceEncoder{typ, typ.Elem(), encoder}, nil -} - -type sliceEncoder struct { - sliceType reflect.Type - elemType reflect.Type - elemEncoder ValEncoder -} - -func (encoder *sliceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { - slice := (*sliceHeader)(ptr) - if slice.Data == nil { - stream.WriteNil() - return - } - if slice.Len == 0 { - stream.WriteEmptyArray() - return - } - stream.WriteArrayStart() - elemPtr := unsafe.Pointer(slice.Data) - encoder.elemEncoder.Encode(unsafe.Pointer(elemPtr), stream) - for i := 1; i < slice.Len; i++ { - stream.WriteMore() - elemPtr = unsafe.Pointer(uintptr(elemPtr) + encoder.elemType.Size()) - encoder.elemEncoder.Encode(unsafe.Pointer(elemPtr), stream) - } - stream.WriteArrayEnd() - if stream.Error != nil && stream.Error != io.EOF { - stream.Error = fmt.Errorf("%v: %s", encoder.sliceType, stream.Error.Error()) - } -} - -func (encoder *sliceEncoder) EncodeInterface(val interface{}, stream *Stream) { - WriteToStream(val, stream, encoder) -} - -func (encoder *sliceEncoder) IsEmpty(ptr unsafe.Pointer) bool { - slice := (*sliceHeader)(ptr) - return slice.Len == 0 -} - -type sliceDecoder struct { - sliceType reflect.Type - elemType reflect.Type - elemDecoder ValDecoder -} - -// sliceHeader is a safe version of SliceHeader used within this package. -type sliceHeader struct { - Data unsafe.Pointer - Len int - Cap int -} - -func (decoder *sliceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - decoder.doDecode(ptr, iter) - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.sliceType, iter.Error.Error()) - } -} - -func (decoder *sliceDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) { - slice := (*sliceHeader)(ptr) - if iter.ReadNil() { - slice.Len = 0 - slice.Cap = 0 - slice.Data = nil - return - } - reuseSlice(slice, decoder.sliceType, 4) - slice.Len = 0 - offset := uintptr(0) - iter.ReadArrayCB(func(iter *Iterator) bool { - growOne(slice, decoder.sliceType, decoder.elemType) - decoder.elemDecoder.Decode(unsafe.Pointer(uintptr(slice.Data)+offset), iter) - offset += decoder.elemType.Size() - return true - }) -} - -// grow grows the slice s so that it can hold extra more values, allocating -// more capacity if needed. It also returns the old and new slice lengths. -func growOne(slice *sliceHeader, sliceType reflect.Type, elementType reflect.Type) { - newLen := slice.Len + 1 - if newLen <= slice.Cap { - slice.Len = newLen - return - } - newCap := slice.Cap - if newCap == 0 { - newCap = 1 - } else { - for newCap < newLen { - if slice.Len < 1024 { - newCap += newCap - } else { - newCap += newCap / 4 - } - } - } - newVal := reflect.MakeSlice(sliceType, newLen, newCap) - dst := unsafe.Pointer(newVal.Pointer()) - // copy old array into new array - originalBytesCount := slice.Len * int(elementType.Size()) - srcSliceHeader := (unsafe.Pointer)(&sliceHeader{slice.Data, originalBytesCount, originalBytesCount}) - dstSliceHeader := (unsafe.Pointer)(&sliceHeader{dst, originalBytesCount, originalBytesCount}) - copy(*(*[]byte)(dstSliceHeader), *(*[]byte)(srcSliceHeader)) - slice.Data = dst - slice.Len = newLen - slice.Cap = newCap -} - -func reuseSlice(slice *sliceHeader, sliceType reflect.Type, expectedCap int) { - if expectedCap <= slice.Cap { - return - } - newVal := reflect.MakeSlice(sliceType, 0, expectedCap) - dst := unsafe.Pointer(newVal.Pointer()) - slice.Data = dst - slice.Cap = expectedCap -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_reflect_struct_decoder.go b/discovery/vendor/github.com/json-iterator/go/feature_reflect_struct_decoder.go deleted file mode 100644 index e6ced77c..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_reflect_struct_decoder.go +++ /dev/null @@ -1,934 +0,0 @@ -package jsoniter - -import ( - "fmt" - "io" - "reflect" - "strings" - "unsafe" -) - -func createStructDecoder(typ reflect.Type, fields map[string]*structFieldDecoder) (ValDecoder, error) { - knownHash := map[int32]struct{}{ - 0: {}, - } - switch len(fields) { - case 0: - return &skipObjectDecoder{typ}, nil - case 1: - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - return &oneFieldStructDecoder{typ, fieldHash, fieldDecoder}, nil - } - case 2: - var fieldHash1 int32 - var fieldHash2 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldHash1 == 0 { - fieldHash1 = fieldHash - fieldDecoder1 = fieldDecoder - } else { - fieldHash2 = fieldHash - fieldDecoder2 = fieldDecoder - } - } - return &twoFieldsStructDecoder{typ, fieldHash1, fieldDecoder1, fieldHash2, fieldDecoder2}, nil - case 3: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } - } - return &threeFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3}, nil - case 4: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } - } - return &fourFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4}, nil - case 5: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } - } - return &fiveFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5}, nil - case 6: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldName6 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - var fieldDecoder6 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else if fieldName5 == 0 { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } else { - fieldName6 = fieldHash - fieldDecoder6 = fieldDecoder - } - } - return &sixFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5, fieldName6, fieldDecoder6}, nil - case 7: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldName6 int32 - var fieldName7 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - var fieldDecoder6 *structFieldDecoder - var fieldDecoder7 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else if fieldName5 == 0 { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } else if fieldName6 == 0 { - fieldName6 = fieldHash - fieldDecoder6 = fieldDecoder - } else { - fieldName7 = fieldHash - fieldDecoder7 = fieldDecoder - } - } - return &sevenFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5, fieldName6, fieldDecoder6, - fieldName7, fieldDecoder7}, nil - case 8: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldName6 int32 - var fieldName7 int32 - var fieldName8 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - var fieldDecoder6 *structFieldDecoder - var fieldDecoder7 *structFieldDecoder - var fieldDecoder8 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else if fieldName5 == 0 { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } else if fieldName6 == 0 { - fieldName6 = fieldHash - fieldDecoder6 = fieldDecoder - } else if fieldName7 == 0 { - fieldName7 = fieldHash - fieldDecoder7 = fieldDecoder - } else { - fieldName8 = fieldHash - fieldDecoder8 = fieldDecoder - } - } - return &eightFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5, fieldName6, fieldDecoder6, - fieldName7, fieldDecoder7, fieldName8, fieldDecoder8}, nil - case 9: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldName6 int32 - var fieldName7 int32 - var fieldName8 int32 - var fieldName9 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - var fieldDecoder6 *structFieldDecoder - var fieldDecoder7 *structFieldDecoder - var fieldDecoder8 *structFieldDecoder - var fieldDecoder9 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else if fieldName5 == 0 { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } else if fieldName6 == 0 { - fieldName6 = fieldHash - fieldDecoder6 = fieldDecoder - } else if fieldName7 == 0 { - fieldName7 = fieldHash - fieldDecoder7 = fieldDecoder - } else if fieldName8 == 0 { - fieldName8 = fieldHash - fieldDecoder8 = fieldDecoder - } else { - fieldName9 = fieldHash - fieldDecoder9 = fieldDecoder - } - } - return &nineFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5, fieldName6, fieldDecoder6, - fieldName7, fieldDecoder7, fieldName8, fieldDecoder8, fieldName9, fieldDecoder9}, nil - case 10: - var fieldName1 int32 - var fieldName2 int32 - var fieldName3 int32 - var fieldName4 int32 - var fieldName5 int32 - var fieldName6 int32 - var fieldName7 int32 - var fieldName8 int32 - var fieldName9 int32 - var fieldName10 int32 - var fieldDecoder1 *structFieldDecoder - var fieldDecoder2 *structFieldDecoder - var fieldDecoder3 *structFieldDecoder - var fieldDecoder4 *structFieldDecoder - var fieldDecoder5 *structFieldDecoder - var fieldDecoder6 *structFieldDecoder - var fieldDecoder7 *structFieldDecoder - var fieldDecoder8 *structFieldDecoder - var fieldDecoder9 *structFieldDecoder - var fieldDecoder10 *structFieldDecoder - for fieldName, fieldDecoder := range fields { - fieldHash := calcHash(fieldName) - _, known := knownHash[fieldHash] - if known { - return &generalStructDecoder{typ, fields}, nil - } - knownHash[fieldHash] = struct{}{} - if fieldName1 == 0 { - fieldName1 = fieldHash - fieldDecoder1 = fieldDecoder - } else if fieldName2 == 0 { - fieldName2 = fieldHash - fieldDecoder2 = fieldDecoder - } else if fieldName3 == 0 { - fieldName3 = fieldHash - fieldDecoder3 = fieldDecoder - } else if fieldName4 == 0 { - fieldName4 = fieldHash - fieldDecoder4 = fieldDecoder - } else if fieldName5 == 0 { - fieldName5 = fieldHash - fieldDecoder5 = fieldDecoder - } else if fieldName6 == 0 { - fieldName6 = fieldHash - fieldDecoder6 = fieldDecoder - } else if fieldName7 == 0 { - fieldName7 = fieldHash - fieldDecoder7 = fieldDecoder - } else if fieldName8 == 0 { - fieldName8 = fieldHash - fieldDecoder8 = fieldDecoder - } else if fieldName9 == 0 { - fieldName9 = fieldHash - fieldDecoder9 = fieldDecoder - } else { - fieldName10 = fieldHash - fieldDecoder10 = fieldDecoder - } - } - return &tenFieldsStructDecoder{typ, - fieldName1, fieldDecoder1, fieldName2, fieldDecoder2, fieldName3, fieldDecoder3, - fieldName4, fieldDecoder4, fieldName5, fieldDecoder5, fieldName6, fieldDecoder6, - fieldName7, fieldDecoder7, fieldName8, fieldDecoder8, fieldName9, fieldDecoder9, - fieldName10, fieldDecoder10}, nil - } - return &generalStructDecoder{typ, fields}, nil -} - -type generalStructDecoder struct { - typ reflect.Type - fields map[string]*structFieldDecoder -} - -func (decoder *generalStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - var fieldBytes []byte - var field string - if iter.cfg.objectFieldMustBeSimpleString { - fieldBytes = iter.readObjectFieldAsBytes() - field = *(*string)(unsafe.Pointer(&fieldBytes)) - } else { - field = iter.ReadString() - c := iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - } - fieldDecoder := decoder.fields[strings.ToLower(field)] - if fieldDecoder == nil { - iter.Skip() - } else { - fieldDecoder.Decode(ptr, iter) - } - for iter.nextToken() == ',' { - if iter.cfg.objectFieldMustBeSimpleString { - fieldBytes := iter.readObjectFieldAsBytes() - field = *(*string)(unsafe.Pointer(&fieldBytes)) - } else { - field = iter.ReadString() - c := iter.nextToken() - if c != ':' { - iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) - } - } - fieldDecoder = decoder.fields[strings.ToLower(field)] - if fieldDecoder == nil { - iter.Skip() - } else { - fieldDecoder.Decode(ptr, iter) - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type skipObjectDecoder struct { - typ reflect.Type -} - -func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - valueType := iter.WhatIsNext() - if valueType != ObjectValue && valueType != NilValue { - iter.ReportError("skipObjectDecoder", "expect object or null") - return - } - iter.Skip() -} - -type oneFieldStructDecoder struct { - typ reflect.Type - fieldHash int32 - fieldDecoder *structFieldDecoder -} - -func (decoder *oneFieldStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - if iter.readFieldHash() == decoder.fieldHash { - decoder.fieldDecoder.Decode(ptr, iter) - } else { - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type twoFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder -} - -func (decoder *twoFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type threeFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder -} - -func (decoder *threeFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type fourFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder -} - -func (decoder *fourFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type fiveFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder -} - -func (decoder *fiveFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type sixFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder - fieldHash6 int32 - fieldDecoder6 *structFieldDecoder -} - -func (decoder *sixFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - case decoder.fieldHash6: - decoder.fieldDecoder6.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type sevenFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder - fieldHash6 int32 - fieldDecoder6 *structFieldDecoder - fieldHash7 int32 - fieldDecoder7 *structFieldDecoder -} - -func (decoder *sevenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - case decoder.fieldHash6: - decoder.fieldDecoder6.Decode(ptr, iter) - case decoder.fieldHash7: - decoder.fieldDecoder7.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type eightFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder - fieldHash6 int32 - fieldDecoder6 *structFieldDecoder - fieldHash7 int32 - fieldDecoder7 *structFieldDecoder - fieldHash8 int32 - fieldDecoder8 *structFieldDecoder -} - -func (decoder *eightFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - case decoder.fieldHash6: - decoder.fieldDecoder6.Decode(ptr, iter) - case decoder.fieldHash7: - decoder.fieldDecoder7.Decode(ptr, iter) - case decoder.fieldHash8: - decoder.fieldDecoder8.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type nineFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder - fieldHash6 int32 - fieldDecoder6 *structFieldDecoder - fieldHash7 int32 - fieldDecoder7 *structFieldDecoder - fieldHash8 int32 - fieldDecoder8 *structFieldDecoder - fieldHash9 int32 - fieldDecoder9 *structFieldDecoder -} - -func (decoder *nineFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - case decoder.fieldHash6: - decoder.fieldDecoder6.Decode(ptr, iter) - case decoder.fieldHash7: - decoder.fieldDecoder7.Decode(ptr, iter) - case decoder.fieldHash8: - decoder.fieldDecoder8.Decode(ptr, iter) - case decoder.fieldHash9: - decoder.fieldDecoder9.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type tenFieldsStructDecoder struct { - typ reflect.Type - fieldHash1 int32 - fieldDecoder1 *structFieldDecoder - fieldHash2 int32 - fieldDecoder2 *structFieldDecoder - fieldHash3 int32 - fieldDecoder3 *structFieldDecoder - fieldHash4 int32 - fieldDecoder4 *structFieldDecoder - fieldHash5 int32 - fieldDecoder5 *structFieldDecoder - fieldHash6 int32 - fieldDecoder6 *structFieldDecoder - fieldHash7 int32 - fieldDecoder7 *structFieldDecoder - fieldHash8 int32 - fieldDecoder8 *structFieldDecoder - fieldHash9 int32 - fieldDecoder9 *structFieldDecoder - fieldHash10 int32 - fieldDecoder10 *structFieldDecoder -} - -func (decoder *tenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - if !iter.readObjectStart() { - return - } - for { - switch iter.readFieldHash() { - case decoder.fieldHash1: - decoder.fieldDecoder1.Decode(ptr, iter) - case decoder.fieldHash2: - decoder.fieldDecoder2.Decode(ptr, iter) - case decoder.fieldHash3: - decoder.fieldDecoder3.Decode(ptr, iter) - case decoder.fieldHash4: - decoder.fieldDecoder4.Decode(ptr, iter) - case decoder.fieldHash5: - decoder.fieldDecoder5.Decode(ptr, iter) - case decoder.fieldHash6: - decoder.fieldDecoder6.Decode(ptr, iter) - case decoder.fieldHash7: - decoder.fieldDecoder7.Decode(ptr, iter) - case decoder.fieldHash8: - decoder.fieldDecoder8.Decode(ptr, iter) - case decoder.fieldHash9: - decoder.fieldDecoder9.Decode(ptr, iter) - case decoder.fieldHash10: - decoder.fieldDecoder10.Decode(ptr, iter) - default: - iter.Skip() - } - if iter.isObjectEnd() { - break - } - } - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%v: %s", decoder.typ, iter.Error.Error()) - } -} - -type structFieldDecoder struct { - field *reflect.StructField - fieldDecoder ValDecoder -} - -func (decoder *structFieldDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { - fieldPtr := unsafe.Pointer(uintptr(ptr) + decoder.field.Offset) - decoder.fieldDecoder.Decode(fieldPtr, iter) - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = fmt.Errorf("%s: %s", decoder.field.Name, iter.Error.Error()) - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_stream.go b/discovery/vendor/github.com/json-iterator/go/feature_stream.go deleted file mode 100644 index 97355eb5..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_stream.go +++ /dev/null @@ -1,308 +0,0 @@ -package jsoniter - -import ( - "io" -) - -// stream is a io.Writer like object, with JSON specific write functions. -// Error is not returned as return value, but stored as Error member on this stream instance. -type Stream struct { - cfg *frozenConfig - out io.Writer - buf []byte - n int - Error error - indention int - Attachment interface{} // open for customized encoder -} - -// NewStream create new stream instance. -// cfg can be jsoniter.ConfigDefault. -// out can be nil if write to internal buffer. -// bufSize is the initial size for the internal buffer in bytes. -func NewStream(cfg API, out io.Writer, bufSize int) *Stream { - return &Stream{ - cfg: cfg.(*frozenConfig), - out: out, - buf: make([]byte, bufSize), - n: 0, - Error: nil, - indention: 0, - } -} - -// Pool returns a pool can provide more stream with same configuration -func (stream *Stream) Pool() StreamPool { - return stream.cfg -} - -// Reset reuse this stream instance by assign a new writer -func (stream *Stream) Reset(out io.Writer) { - stream.out = out - stream.n = 0 -} - -// Available returns how many bytes are unused in the buffer. -func (stream *Stream) Available() int { - return len(stream.buf) - stream.n -} - -// Buffered returns the number of bytes that have been written into the current buffer. -func (stream *Stream) Buffered() int { - return stream.n -} - -// Buffer if writer is nil, use this method to take the result -func (stream *Stream) Buffer() []byte { - return stream.buf[:stream.n] -} - -// Write writes the contents of p into the buffer. -// It returns the number of bytes written. -// If nn < len(p), it also returns an error explaining -// why the write is short. -func (stream *Stream) Write(p []byte) (nn int, err error) { - for len(p) > stream.Available() && stream.Error == nil { - if stream.out == nil { - stream.growAtLeast(len(p)) - } else { - var n int - if stream.Buffered() == 0 { - // Large write, empty buffer. - // Write directly from p to avoid copy. - n, stream.Error = stream.out.Write(p) - } else { - n = copy(stream.buf[stream.n:], p) - stream.n += n - stream.Flush() - } - nn += n - p = p[n:] - } - } - if stream.Error != nil { - return nn, stream.Error - } - n := copy(stream.buf[stream.n:], p) - stream.n += n - nn += n - return nn, nil -} - -// WriteByte writes a single byte. -func (stream *Stream) writeByte(c byte) { - if stream.Error != nil { - return - } - if stream.Available() < 1 { - stream.growAtLeast(1) - } - stream.buf[stream.n] = c - stream.n++ -} - -func (stream *Stream) writeTwoBytes(c1 byte, c2 byte) { - if stream.Error != nil { - return - } - if stream.Available() < 2 { - stream.growAtLeast(2) - } - stream.buf[stream.n] = c1 - stream.buf[stream.n+1] = c2 - stream.n += 2 -} - -func (stream *Stream) writeThreeBytes(c1 byte, c2 byte, c3 byte) { - if stream.Error != nil { - return - } - if stream.Available() < 3 { - stream.growAtLeast(3) - } - stream.buf[stream.n] = c1 - stream.buf[stream.n+1] = c2 - stream.buf[stream.n+2] = c3 - stream.n += 3 -} - -func (stream *Stream) writeFourBytes(c1 byte, c2 byte, c3 byte, c4 byte) { - if stream.Error != nil { - return - } - if stream.Available() < 4 { - stream.growAtLeast(4) - } - stream.buf[stream.n] = c1 - stream.buf[stream.n+1] = c2 - stream.buf[stream.n+2] = c3 - stream.buf[stream.n+3] = c4 - stream.n += 4 -} - -func (stream *Stream) writeFiveBytes(c1 byte, c2 byte, c3 byte, c4 byte, c5 byte) { - if stream.Error != nil { - return - } - if stream.Available() < 5 { - stream.growAtLeast(5) - } - stream.buf[stream.n] = c1 - stream.buf[stream.n+1] = c2 - stream.buf[stream.n+2] = c3 - stream.buf[stream.n+3] = c4 - stream.buf[stream.n+4] = c5 - stream.n += 5 -} - -// Flush writes any buffered data to the underlying io.Writer. -func (stream *Stream) Flush() error { - if stream.out == nil { - return nil - } - if stream.Error != nil { - return stream.Error - } - if stream.n == 0 { - return nil - } - n, err := stream.out.Write(stream.buf[0:stream.n]) - if n < stream.n && err == nil { - err = io.ErrShortWrite - } - if err != nil { - if n > 0 && n < stream.n { - copy(stream.buf[0:stream.n-n], stream.buf[n:stream.n]) - } - stream.n -= n - stream.Error = err - return err - } - stream.n = 0 - return nil -} - -func (stream *Stream) ensure(minimal int) { - available := stream.Available() - if available < minimal { - stream.growAtLeast(minimal) - } -} - -func (stream *Stream) growAtLeast(minimal int) { - if stream.out != nil { - stream.Flush() - if stream.Available() >= minimal { - return - } - } - toGrow := len(stream.buf) - if toGrow < minimal { - toGrow = minimal - } - newBuf := make([]byte, len(stream.buf)+toGrow) - copy(newBuf, stream.Buffer()) - stream.buf = newBuf -} - -// WriteRaw write string out without quotes, just like []byte -func (stream *Stream) WriteRaw(s string) { - stream.ensure(len(s)) - if stream.Error != nil { - return - } - n := copy(stream.buf[stream.n:], s) - stream.n += n -} - -// WriteNil write null to stream -func (stream *Stream) WriteNil() { - stream.writeFourBytes('n', 'u', 'l', 'l') -} - -// WriteTrue write true to stream -func (stream *Stream) WriteTrue() { - stream.writeFourBytes('t', 'r', 'u', 'e') -} - -// WriteFalse write false to stream -func (stream *Stream) WriteFalse() { - stream.writeFiveBytes('f', 'a', 'l', 's', 'e') -} - -// WriteBool write true or false into stream -func (stream *Stream) WriteBool(val bool) { - if val { - stream.WriteTrue() - } else { - stream.WriteFalse() - } -} - -// WriteObjectStart write { with possible indention -func (stream *Stream) WriteObjectStart() { - stream.indention += stream.cfg.indentionStep - stream.writeByte('{') - stream.writeIndention(0) -} - -// WriteObjectField write "field": with possible indention -func (stream *Stream) WriteObjectField(field string) { - stream.WriteString(field) - if stream.indention > 0 { - stream.writeTwoBytes(':', ' ') - } else { - stream.writeByte(':') - } -} - -// WriteObjectEnd write } with possible indention -func (stream *Stream) WriteObjectEnd() { - stream.writeIndention(stream.cfg.indentionStep) - stream.indention -= stream.cfg.indentionStep - stream.writeByte('}') -} - -// WriteEmptyObject write {} -func (stream *Stream) WriteEmptyObject() { - stream.writeByte('{') - stream.writeByte('}') -} - -// WriteMore write , with possible indention -func (stream *Stream) WriteMore() { - stream.writeByte(',') - stream.writeIndention(0) -} - -// WriteArrayStart write [ with possible indention -func (stream *Stream) WriteArrayStart() { - stream.indention += stream.cfg.indentionStep - stream.writeByte('[') - stream.writeIndention(0) -} - -// WriteEmptyArray write [] -func (stream *Stream) WriteEmptyArray() { - stream.writeTwoBytes('[', ']') -} - -// WriteArrayEnd write ] with possible indention -func (stream *Stream) WriteArrayEnd() { - stream.writeIndention(stream.cfg.indentionStep) - stream.indention -= stream.cfg.indentionStep - stream.writeByte(']') -} - -func (stream *Stream) writeIndention(delta int) { - if stream.indention == 0 { - return - } - stream.writeByte('\n') - toWrite := stream.indention - delta - stream.ensure(toWrite) - for i := 0; i < toWrite && stream.n < len(stream.buf); i++ { - stream.buf[stream.n] = ' ' - stream.n++ - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_stream_float.go b/discovery/vendor/github.com/json-iterator/go/feature_stream_float.go deleted file mode 100644 index 9a404e11..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_stream_float.go +++ /dev/null @@ -1,96 +0,0 @@ -package jsoniter - -import ( - "math" - "strconv" -) - -var pow10 []uint64 - -func init() { - pow10 = []uint64{1, 10, 100, 1000, 10000, 100000, 1000000} -} - -// WriteFloat32 write float32 to stream -func (stream *Stream) WriteFloat32(val float32) { - abs := math.Abs(float64(val)) - fmt := byte('f') - // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. - if abs != 0 { - if float32(abs) < 1e-6 || float32(abs) >= 1e21 { - fmt = 'e' - } - } - stream.WriteRaw(strconv.FormatFloat(float64(val), fmt, -1, 32)) -} - -// WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster -func (stream *Stream) WriteFloat32Lossy(val float32) { - if val < 0 { - stream.writeByte('-') - val = -val - } - if val > 0x4ffffff { - stream.WriteFloat32(val) - return - } - precision := 6 - exp := uint64(1000000) // 6 - lval := uint64(float64(val)*float64(exp) + 0.5) - stream.WriteUint64(lval / exp) - fval := lval % exp - if fval == 0 { - return - } - stream.writeByte('.') - stream.ensure(10) - for p := precision - 1; p > 0 && fval < pow10[p]; p-- { - stream.writeByte('0') - } - stream.WriteUint64(fval) - for stream.buf[stream.n-1] == '0' { - stream.n-- - } -} - -// WriteFloat64 write float64 to stream -func (stream *Stream) WriteFloat64(val float64) { - abs := math.Abs(val) - fmt := byte('f') - // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. - if abs != 0 { - if abs < 1e-6 || abs >= 1e21 { - fmt = 'e' - } - } - stream.WriteRaw(strconv.FormatFloat(float64(val), fmt, -1, 64)) -} - -// WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster -func (stream *Stream) WriteFloat64Lossy(val float64) { - if val < 0 { - stream.writeByte('-') - val = -val - } - if val > 0x4ffffff { - stream.WriteFloat64(val) - return - } - precision := 6 - exp := uint64(1000000) // 6 - lval := uint64(val*float64(exp) + 0.5) - stream.WriteUint64(lval / exp) - fval := lval % exp - if fval == 0 { - return - } - stream.writeByte('.') - stream.ensure(10) - for p := precision - 1; p > 0 && fval < pow10[p]; p-- { - stream.writeByte('0') - } - stream.WriteUint64(fval) - for stream.buf[stream.n-1] == '0' { - stream.n-- - } -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_stream_int.go b/discovery/vendor/github.com/json-iterator/go/feature_stream_int.go deleted file mode 100644 index 7cfd522c..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_stream_int.go +++ /dev/null @@ -1,320 +0,0 @@ -package jsoniter - -var digits []uint32 - -func init() { - digits = make([]uint32, 1000) - for i := uint32(0); i < 1000; i++ { - digits[i] = (((i / 100) + '0') << 16) + ((((i / 10) % 10) + '0') << 8) + i%10 + '0' - if i < 10 { - digits[i] += 2 << 24 - } else if i < 100 { - digits[i] += 1 << 24 - } - } -} - -func writeFirstBuf(buf []byte, v uint32, n int) int { - start := v >> 24 - if start == 0 { - buf[n] = byte(v >> 16) - n++ - buf[n] = byte(v >> 8) - n++ - } else if start == 1 { - buf[n] = byte(v >> 8) - n++ - } - buf[n] = byte(v) - n++ - return n -} - -func writeBuf(buf []byte, v uint32, n int) { - buf[n] = byte(v >> 16) - buf[n+1] = byte(v >> 8) - buf[n+2] = byte(v) -} - -// WriteUint8 write uint8 to stream -func (stream *Stream) WriteUint8(val uint8) { - stream.ensure(3) - stream.n = writeFirstBuf(stream.buf, digits[val], stream.n) -} - -// WriteInt8 write int8 to stream -func (stream *Stream) WriteInt8(nval int8) { - stream.ensure(4) - n := stream.n - var val uint8 - if nval < 0 { - val = uint8(-nval) - stream.buf[n] = '-' - n++ - } else { - val = uint8(nval) - } - stream.n = writeFirstBuf(stream.buf, digits[val], n) -} - -// WriteUint16 write uint16 to stream -func (stream *Stream) WriteUint16(val uint16) { - stream.ensure(5) - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], stream.n) - return - } - r1 := val - q1*1000 - n := writeFirstBuf(stream.buf, digits[q1], stream.n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return -} - -// WriteInt16 write int16 to stream -func (stream *Stream) WriteInt16(nval int16) { - stream.ensure(6) - n := stream.n - var val uint16 - if nval < 0 { - val = uint16(-nval) - stream.buf[n] = '-' - n++ - } else { - val = uint16(nval) - } - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], n) - return - } - r1 := val - q1*1000 - n = writeFirstBuf(stream.buf, digits[q1], n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return -} - -// WriteUint32 write uint32 to stream -func (stream *Stream) WriteUint32(val uint32) { - stream.ensure(10) - n := stream.n - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], n) - return - } - r1 := val - q1*1000 - q2 := q1 / 1000 - if q2 == 0 { - n := writeFirstBuf(stream.buf, digits[q1], n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return - } - r2 := q1 - q2*1000 - q3 := q2 / 1000 - if q3 == 0 { - n = writeFirstBuf(stream.buf, digits[q2], n) - } else { - r3 := q2 - q3*1000 - stream.buf[n] = byte(q3 + '0') - n++ - writeBuf(stream.buf, digits[r3], n) - n += 3 - } - writeBuf(stream.buf, digits[r2], n) - writeBuf(stream.buf, digits[r1], n+3) - stream.n = n + 6 -} - -// WriteInt32 write int32 to stream -func (stream *Stream) WriteInt32(nval int32) { - stream.ensure(11) - n := stream.n - var val uint32 - if nval < 0 { - val = uint32(-nval) - stream.buf[n] = '-' - n++ - } else { - val = uint32(nval) - } - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], n) - return - } - r1 := val - q1*1000 - q2 := q1 / 1000 - if q2 == 0 { - n := writeFirstBuf(stream.buf, digits[q1], n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return - } - r2 := q1 - q2*1000 - q3 := q2 / 1000 - if q3 == 0 { - n = writeFirstBuf(stream.buf, digits[q2], n) - } else { - r3 := q2 - q3*1000 - stream.buf[n] = byte(q3 + '0') - n++ - writeBuf(stream.buf, digits[r3], n) - n += 3 - } - writeBuf(stream.buf, digits[r2], n) - writeBuf(stream.buf, digits[r1], n+3) - stream.n = n + 6 -} - -// WriteUint64 write uint64 to stream -func (stream *Stream) WriteUint64(val uint64) { - stream.ensure(20) - n := stream.n - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], n) - return - } - r1 := val - q1*1000 - q2 := q1 / 1000 - if q2 == 0 { - n := writeFirstBuf(stream.buf, digits[q1], n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return - } - r2 := q1 - q2*1000 - q3 := q2 / 1000 - if q3 == 0 { - n = writeFirstBuf(stream.buf, digits[q2], n) - writeBuf(stream.buf, digits[r2], n) - writeBuf(stream.buf, digits[r1], n+3) - stream.n = n + 6 - return - } - r3 := q2 - q3*1000 - q4 := q3 / 1000 - if q4 == 0 { - n = writeFirstBuf(stream.buf, digits[q3], n) - writeBuf(stream.buf, digits[r3], n) - writeBuf(stream.buf, digits[r2], n+3) - writeBuf(stream.buf, digits[r1], n+6) - stream.n = n + 9 - return - } - r4 := q3 - q4*1000 - q5 := q4 / 1000 - if q5 == 0 { - n = writeFirstBuf(stream.buf, digits[q4], n) - writeBuf(stream.buf, digits[r4], n) - writeBuf(stream.buf, digits[r3], n+3) - writeBuf(stream.buf, digits[r2], n+6) - writeBuf(stream.buf, digits[r1], n+9) - stream.n = n + 12 - return - } - r5 := q4 - q5*1000 - q6 := q5 / 1000 - if q6 == 0 { - n = writeFirstBuf(stream.buf, digits[q5], n) - } else { - n = writeFirstBuf(stream.buf, digits[q6], n) - r6 := q5 - q6*1000 - writeBuf(stream.buf, digits[r6], n) - n += 3 - } - writeBuf(stream.buf, digits[r5], n) - writeBuf(stream.buf, digits[r4], n+3) - writeBuf(stream.buf, digits[r3], n+6) - writeBuf(stream.buf, digits[r2], n+9) - writeBuf(stream.buf, digits[r1], n+12) - stream.n = n + 15 -} - -// WriteInt64 write int64 to stream -func (stream *Stream) WriteInt64(nval int64) { - stream.ensure(20) - n := stream.n - var val uint64 - if nval < 0 { - val = uint64(-nval) - stream.buf[n] = '-' - n++ - } else { - val = uint64(nval) - } - q1 := val / 1000 - if q1 == 0 { - stream.n = writeFirstBuf(stream.buf, digits[val], n) - return - } - r1 := val - q1*1000 - q2 := q1 / 1000 - if q2 == 0 { - n := writeFirstBuf(stream.buf, digits[q1], n) - writeBuf(stream.buf, digits[r1], n) - stream.n = n + 3 - return - } - r2 := q1 - q2*1000 - q3 := q2 / 1000 - if q3 == 0 { - n = writeFirstBuf(stream.buf, digits[q2], n) - writeBuf(stream.buf, digits[r2], n) - writeBuf(stream.buf, digits[r1], n+3) - stream.n = n + 6 - return - } - r3 := q2 - q3*1000 - q4 := q3 / 1000 - if q4 == 0 { - n = writeFirstBuf(stream.buf, digits[q3], n) - writeBuf(stream.buf, digits[r3], n) - writeBuf(stream.buf, digits[r2], n+3) - writeBuf(stream.buf, digits[r1], n+6) - stream.n = n + 9 - return - } - r4 := q3 - q4*1000 - q5 := q4 / 1000 - if q5 == 0 { - n = writeFirstBuf(stream.buf, digits[q4], n) - writeBuf(stream.buf, digits[r4], n) - writeBuf(stream.buf, digits[r3], n+3) - writeBuf(stream.buf, digits[r2], n+6) - writeBuf(stream.buf, digits[r1], n+9) - stream.n = n + 12 - return - } - r5 := q4 - q5*1000 - q6 := q5 / 1000 - if q6 == 0 { - n = writeFirstBuf(stream.buf, digits[q5], n) - } else { - stream.buf[n] = byte(q6 + '0') - n++ - r6 := q5 - q6*1000 - writeBuf(stream.buf, digits[r6], n) - n += 3 - } - writeBuf(stream.buf, digits[r5], n) - writeBuf(stream.buf, digits[r4], n+3) - writeBuf(stream.buf, digits[r3], n+6) - writeBuf(stream.buf, digits[r2], n+9) - writeBuf(stream.buf, digits[r1], n+12) - stream.n = n + 15 -} - -// WriteInt write int to stream -func (stream *Stream) WriteInt(val int) { - stream.WriteInt64(int64(val)) -} - -// WriteUint write uint to stream -func (stream *Stream) WriteUint(val uint) { - stream.WriteUint64(uint64(val)) -} diff --git a/discovery/vendor/github.com/json-iterator/go/feature_stream_string.go b/discovery/vendor/github.com/json-iterator/go/feature_stream_string.go deleted file mode 100644 index 334282f0..00000000 --- a/discovery/vendor/github.com/json-iterator/go/feature_stream_string.go +++ /dev/null @@ -1,396 +0,0 @@ -package jsoniter - -import ( - "unicode/utf8" -) - -// htmlSafeSet holds the value true if the ASCII character with the given -// array position can be safely represented inside a JSON string, embedded -// inside of HTML ", + "", + }, + { + "unfinished script end tag", + "$a", + }, + { + "'>' completes script end tag", + "", + "", + }, + { + "self-closing script end tag", + "", + "", + }, + { + "nested script tag", + "", + "", + }, + { + "script/style mismatched tags", + "", false}, + {"too long", "system:bootstrappers:" + strings.Repeat("x", 300), false}, + } + for _, test := range tests { + err := ValidateBootstrapGroupName(test.input) + if err != nil && test.valid { + t.Errorf("test %q: ValidateBootstrapGroupName(%q) returned unexpected error: %v", test.name, test.input, err) + } + if err == nil && !test.valid { + t.Errorf("test %q: ValidateBootstrapGroupName(%q) was supposed to return an error but didn't", test.name, test.input) + } + } +} + +func TestValidateUsages(t *testing.T) { + tests := []struct { + name string + input []string + valid bool + }{ + {"valid of signing", []string{"signing"}, true}, + {"valid of authentication", []string{"authentication"}, true}, + {"all valid", []string{"authentication", "signing"}, true}, + {"single invalid", []string{"authentication", "foo"}, false}, + {"all invalid", []string{"foo", "bar"}, false}, + } + + for _, test := range tests { + err := ValidateUsages(test.input) + if err != nil && test.valid { + t.Errorf("test %q: ValidateUsages(%v) returned unexpected error: %v", test.name, test.input, err) + } + if err == nil && !test.valid { + t.Errorf("test %q: ValidateUsages(%v) was supposed to return an error but didn't", test.name, test.input) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/BUILD b/discovery/vendor/k8s.io/client-go/tools/cache/BUILD new file mode 100644 index 00000000..524354e8 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/BUILD @@ -0,0 +1,103 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "controller_test.go", + "delta_fifo_test.go", + "expiration_cache_test.go", + "fifo_test.go", + "heap_test.go", + "index_test.go", + "mutation_detector_test.go", + "processor_listener_test.go", + "reflector_test.go", + "shared_informer_test.go", + "store_test.go", + "undelta_store_test.go", + ], + embed = [":go_default_library"], + race = "off", + deps = [ + "//vendor/github.com/google/gofuzz:go_default_library", + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/tools/cache/testing:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "controller.go", + "delta_fifo.go", + "doc.go", + "expiration_cache.go", + "expiration_cache_fakes.go", + "fake_custom_store.go", + "fifo.go", + "heap.go", + "index.go", + "listers.go", + "listwatch.go", + "mutation_cache.go", + "mutation_detector.go", + "reflector.go", + "reflector_metrics.go", + "shared_informer.go", + "store.go", + "thread_safe_store.go", + "undelta_store.go", + ], + importpath = "k8s.io/client-go/tools/cache", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/golang.org/x/net/context:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/cache:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/tools/pager:go_default_library", + "//vendor/k8s.io/client-go/util/buffer:go_default_library", + "//vendor/k8s.io/client-go/util/retry:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/tools/cache/testing:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/controller.go b/discovery/vendor/k8s.io/client-go/tools/cache/controller.go index e7b98bef..028c75e8 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/controller.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/controller.go @@ -288,7 +288,7 @@ func NewInformer( // This will hold incoming changes. Note how we pass clientState in as a // KeyLister, that way resync operations will result in the correct set // of update/delete deltas. - fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, nil, clientState) + fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, clientState) cfg := &Config{ Queue: fifo, @@ -355,7 +355,7 @@ func NewIndexerInformer( // This will hold incoming changes. Note how we pass clientState in as a // KeyLister, that way resync operations will result in the correct set // of update/delete deltas. - fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, nil, clientState) + fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, clientState) cfg := &Config{ Queue: fifo, diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/controller_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/controller_test.go new file mode 100644 index 00000000..64aca8d7 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/controller_test.go @@ -0,0 +1,405 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "fmt" + "math/rand" + "sync" + "testing" + "time" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apimachinery/pkg/watch" + fcache "k8s.io/client-go/tools/cache/testing" + + "github.com/google/gofuzz" +) + +func Example() { + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + + // This will hold the downstream state, as we know it. + downstream := NewStore(DeletionHandlingMetaNamespaceKeyFunc) + + // This will hold incoming changes. Note how we pass downstream in as a + // KeyLister, that way resync operations will result in the correct set + // of update/delete deltas. + fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, downstream) + + // Let's do threadsafe output to get predictable test results. + deletionCounter := make(chan string, 1000) + + cfg := &Config{ + Queue: fifo, + ListerWatcher: source, + ObjectType: &v1.Pod{}, + FullResyncPeriod: time.Millisecond * 100, + RetryOnError: false, + + // Let's implement a simple controller that just deletes + // everything that comes in. + Process: func(obj interface{}) error { + // Obj is from the Pop method of the Queue we make above. + newest := obj.(Deltas).Newest() + + if newest.Type != Deleted { + // Update our downstream store. + err := downstream.Add(newest.Object) + if err != nil { + return err + } + + // Delete this object. + source.Delete(newest.Object.(runtime.Object)) + } else { + // Update our downstream store. + err := downstream.Delete(newest.Object) + if err != nil { + return err + } + + // fifo's KeyOf is easiest, because it handles + // DeletedFinalStateUnknown markers. + key, err := fifo.KeyOf(newest.Object) + if err != nil { + return err + } + + // Report this deletion. + deletionCounter <- key + } + return nil + }, + } + + // Create the controller and run it until we close stop. + stop := make(chan struct{}) + defer close(stop) + go New(cfg).Run(stop) + + // Let's add a few objects to the source. + testIDs := []string{"a-hello", "b-controller", "c-framework"} + for _, name := range testIDs { + // Note that these pods are not valid-- the fake source doesn't + // call validation or anything. + source.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: name}}) + } + + // Let's wait for the controller to process the things we just added. + outputSet := sets.String{} + for i := 0; i < len(testIDs); i++ { + outputSet.Insert(<-deletionCounter) + } + + for _, key := range outputSet.List() { + fmt.Println(key) + } + // Output: + // a-hello + // b-controller + // c-framework +} + +func ExampleNewInformer() { + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + + // Let's do threadsafe output to get predictable test results. + deletionCounter := make(chan string, 1000) + + // Make a controller that immediately deletes anything added to it, and + // logs anything deleted. + _, controller := NewInformer( + source, + &v1.Pod{}, + time.Millisecond*100, + ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + source.Delete(obj.(runtime.Object)) + }, + DeleteFunc: func(obj interface{}) { + key, err := DeletionHandlingMetaNamespaceKeyFunc(obj) + if err != nil { + key = "oops something went wrong with the key" + } + + // Report this deletion. + deletionCounter <- key + }, + }, + ) + + // Run the controller and run it until we close stop. + stop := make(chan struct{}) + defer close(stop) + go controller.Run(stop) + + // Let's add a few objects to the source. + testIDs := []string{"a-hello", "b-controller", "c-framework"} + for _, name := range testIDs { + // Note that these pods are not valid-- the fake source doesn't + // call validation or anything. + source.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: name}}) + } + + // Let's wait for the controller to process the things we just added. + outputSet := sets.String{} + for i := 0; i < len(testIDs); i++ { + outputSet.Insert(<-deletionCounter) + } + + for _, key := range outputSet.List() { + fmt.Println(key) + } + // Output: + // a-hello + // b-controller + // c-framework +} + +func TestHammerController(t *testing.T) { + // This test executes a bunch of requests through the fake source and + // controller framework to make sure there's no locking/threading + // errors. If an error happens, it should hang forever or trigger the + // race detector. + + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + + // Let's do threadsafe output to get predictable test results. + outputSetLock := sync.Mutex{} + // map of key to operations done on the key + outputSet := map[string][]string{} + + recordFunc := func(eventType string, obj interface{}) { + key, err := DeletionHandlingMetaNamespaceKeyFunc(obj) + if err != nil { + t.Errorf("something wrong with key: %v", err) + key = "oops something went wrong with the key" + } + + // Record some output when items are deleted. + outputSetLock.Lock() + defer outputSetLock.Unlock() + outputSet[key] = append(outputSet[key], eventType) + } + + // Make a controller which just logs all the changes it gets. + _, controller := NewInformer( + source, + &v1.Pod{}, + time.Millisecond*100, + ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { recordFunc("add", obj) }, + UpdateFunc: func(oldObj, newObj interface{}) { recordFunc("update", newObj) }, + DeleteFunc: func(obj interface{}) { recordFunc("delete", obj) }, + }, + ) + + if controller.HasSynced() { + t.Errorf("Expected HasSynced() to return false before we started the controller") + } + + // Run the controller and run it until we close stop. + stop := make(chan struct{}) + go controller.Run(stop) + + // Let's wait for the controller to do its initial sync + wait.Poll(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { + return controller.HasSynced(), nil + }) + if !controller.HasSynced() { + t.Errorf("Expected HasSynced() to return true after the initial sync") + } + + wg := sync.WaitGroup{} + const threads = 3 + wg.Add(threads) + for i := 0; i < threads; i++ { + go func() { + defer wg.Done() + // Let's add a few objects to the source. + currentNames := sets.String{} + rs := rand.NewSource(rand.Int63()) + f := fuzz.New().NilChance(.5).NumElements(0, 2).RandSource(rs) + r := rand.New(rs) // Mustn't use r and f concurrently! + for i := 0; i < 100; i++ { + var name string + var isNew bool + if currentNames.Len() == 0 || r.Intn(3) == 1 { + f.Fuzz(&name) + isNew = true + } else { + l := currentNames.List() + name = l[r.Intn(len(l))] + } + + pod := &v1.Pod{} + f.Fuzz(pod) + pod.ObjectMeta.Name = name + pod.ObjectMeta.Namespace = "default" + // Add, update, or delete randomly. + // Note that these pods are not valid-- the fake source doesn't + // call validation or perform any other checking. + if isNew { + currentNames.Insert(name) + source.Add(pod) + continue + } + switch r.Intn(2) { + case 0: + currentNames.Insert(name) + source.Modify(pod) + case 1: + currentNames.Delete(name) + source.Delete(pod) + } + } + }() + } + wg.Wait() + + // Let's wait for the controller to finish processing the things we just added. + // TODO: look in the queue to see how many items need to be processed. + time.Sleep(100 * time.Millisecond) + close(stop) + + // TODO: Verify that no goroutines were leaked here and that everything shut + // down cleanly. + + outputSetLock.Lock() + t.Logf("got: %#v", outputSet) +} + +func TestUpdate(t *testing.T) { + // This test is going to exercise the various paths that result in a + // call to update. + + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + + const ( + FROM = "from" + TO = "to" + ) + + // These are the transitions we expect to see; because this is + // asynchronous, there are a lot of valid possibilities. + type pair struct{ from, to string } + allowedTransitions := map[pair]bool{ + {FROM, TO}: true, + + // Because a resync can happen when we've already observed one + // of the above but before the item is deleted. + {TO, TO}: true, + // Because a resync could happen before we observe an update. + {FROM, FROM}: true, + } + + pod := func(name, check string, final bool) *v1.Pod { + p := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Labels: map[string]string{"check": check}, + }, + } + if final { + p.Labels["final"] = "true" + } + return p + } + deletePod := func(p *v1.Pod) bool { + return p.Labels["final"] == "true" + } + + tests := []func(string){ + func(name string) { + name = "a-" + name + source.Add(pod(name, FROM, false)) + source.Modify(pod(name, TO, true)) + }, + } + + const threads = 3 + + var testDoneWG sync.WaitGroup + testDoneWG.Add(threads * len(tests)) + + // Make a controller that deletes things once it observes an update. + // It calls Done() on the wait group on deletions so we can tell when + // everything we've added has been deleted. + watchCh := make(chan struct{}) + _, controller := NewInformer( + &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + watch, err := source.Watch(options) + close(watchCh) + return watch, err + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return source.List(options) + }, + }, + &v1.Pod{}, + 0, + ResourceEventHandlerFuncs{ + UpdateFunc: func(oldObj, newObj interface{}) { + o, n := oldObj.(*v1.Pod), newObj.(*v1.Pod) + from, to := o.Labels["check"], n.Labels["check"] + if !allowedTransitions[pair{from, to}] { + t.Errorf("observed transition %q -> %q for %v", from, to, n.Name) + } + if deletePod(n) { + source.Delete(n) + } + }, + DeleteFunc: func(obj interface{}) { + testDoneWG.Done() + }, + }, + ) + + // Run the controller and run it until we close stop. + // Once Run() is called, calls to testDoneWG.Done() might start, so + // all testDoneWG.Add() calls must happen before this point + stop := make(chan struct{}) + go controller.Run(stop) + <-watchCh + + // run every test a few times, in parallel + var wg sync.WaitGroup + wg.Add(threads * len(tests)) + for i := 0; i < threads; i++ { + for j, f := range tests { + go func(name string, f func(string)) { + defer wg.Done() + f(name) + }(fmt.Sprintf("%v-%v", i, j), f) + } + } + wg.Wait() + + // Let's wait for the controller to process the things we just added. + testDoneWG.Wait() + close(stop) +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo.go b/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo.go index f06d1c5b..45c3b500 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo.go @@ -31,11 +31,6 @@ import ( // keyFunc is used to figure out what key an object should have. (It's // exposed in the returned DeltaFIFO's KeyOf() method, with bonus features.) // -// 'compressor' may compress as many or as few items as it wants -// (including returning an empty slice), but it should do what it -// does quickly since it is called while the queue is locked. -// 'compressor' may be nil if you don't want any delta compression. -// // 'keyLister' is expected to return a list of keys that the consumer of // this queue "knows about". It is used to decide which items are missing // when Replace() is called; 'Deleted' deltas are produced for these items. @@ -43,18 +38,30 @@ import ( // TODO: consider merging keyLister with this object, tracking a list of // "known" keys when Pop() is called. Have to think about how that // affects error retrying. -// TODO(lavalamp): I believe there is a possible race only when using an -// external known object source that the above TODO would -// fix. +// NOTE: It is possible to misuse this and cause a race when using an +// external known object source. +// Whether there is a potential race depends on how the comsumer +// modifies knownObjects. In Pop(), process function is called under +// lock, so it is safe to update data structures in it that need to be +// in sync with the queue (e.g. knownObjects). +// +// Example: +// In case of sharedIndexInformer being a consumer +// (https://github.com/kubernetes/kubernetes/blob/0cdd940f/staging/ +// src/k8s.io/client-go/tools/cache/shared_informer.go#L192), +// there is no race as knownObjects (s.indexer) is modified safely +// under DeltaFIFO's lock. The only exceptions are GetStore() and +// GetIndexer() methods, which expose ways to modify the underlying +// storage. Currently these two methods are used for creating Lister +// and internal tests. // // Also see the comment on DeltaFIFO. -func NewDeltaFIFO(keyFunc KeyFunc, compressor DeltaCompressor, knownObjects KeyListerGetter) *DeltaFIFO { +func NewDeltaFIFO(keyFunc KeyFunc, knownObjects KeyListerGetter) *DeltaFIFO { f := &DeltaFIFO{ - items: map[string]Deltas{}, - queue: []string{}, - keyFunc: keyFunc, - deltaCompressor: compressor, - knownObjects: knownObjects, + items: map[string]Deltas{}, + queue: []string{}, + keyFunc: keyFunc, + knownObjects: knownObjects, } f.cond.L = &f.lock return f @@ -86,9 +93,6 @@ func NewDeltaFIFO(keyFunc KeyFunc, compressor DeltaCompressor, knownObjects KeyL // items have been deleted when Replace() or Delete() are called. The deleted // object will be included in the DeleteFinalStateUnknown markers. These objects // could be stale. -// -// You may provide a function to compress deltas (e.g., represent a -// series of Updates as a single Update). type DeltaFIFO struct { // lock/cond protects access to 'items' and 'queue'. lock sync.RWMutex @@ -110,10 +114,6 @@ type DeltaFIFO struct { // insertion and retrieval, and should be deterministic. keyFunc KeyFunc - // deltaCompressor tells us how to combine two or more - // deltas. It may be nil. - deltaCompressor DeltaCompressor - // knownObjects list keys that are "known", for the // purpose of figuring out which items have been deleted // when Replace() or Delete() is called. @@ -133,7 +133,6 @@ var ( var ( // ErrZeroLengthDeltasObject is returned in a KeyError if a Deltas // object with zero length is encountered (should be impossible, - // even if such an object is accidentally produced by a DeltaCompressor-- // but included for completeness). ErrZeroLengthDeltasObject = errors.New("0 length Deltas object; can't get key") ) @@ -213,8 +212,6 @@ func (f *DeltaFIFO) Delete(obj interface{}) error { if err == nil && !exists && !itemsExist { // Presumably, this was deleted when a relist happened. // Don't provide a second report of the same deletion. - // TODO(lavalamp): This may be racy-- we aren't properly locked - // with knownObjects. return nil } } @@ -305,8 +302,8 @@ func (f *DeltaFIFO) willObjectBeDeletedLocked(id string) bool { return len(deltas) > 0 && deltas[len(deltas)-1].Type == Deleted } -// queueActionLocked appends to the delta list for the object, calling -// f.deltaCompressor if needed. Caller must lock first. +// queueActionLocked appends to the delta list for the object. +// Caller must lock first. func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) error { id, err := f.KeyOf(obj) if err != nil { @@ -322,9 +319,6 @@ func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) err newDeltas := append(f.items[id], Delta{actionType, obj}) newDeltas = dedupDeltas(newDeltas) - if f.deltaCompressor != nil { - newDeltas = f.deltaCompressor.Compress(newDeltas) - } _, exists := f.items[id] if len(newDeltas) > 0 { @@ -334,8 +328,7 @@ func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) err f.items[id] = newDeltas f.cond.Broadcast() } else if exists { - // The compression step removed all deltas, so - // we need to remove this from our map (extra items + // We need to remove this from our map (extra items // in the queue are ignored if they are not in the // map). delete(f.items, id) @@ -355,8 +348,8 @@ func (f *DeltaFIFO) List() []interface{} { func (f *DeltaFIFO) listLocked() []interface{} { list := make([]interface{}, 0, len(f.items)) for _, item := range f.items { - // Copy item's slice so operations on this slice (delta - // compression) won't interfere with the object we return. + // Copy item's slice so operations on this slice + // won't interfere with the object we return. item = copyDeltas(item) list = append(list, item.Newest().Object) } @@ -394,8 +387,8 @@ func (f *DeltaFIFO) GetByKey(key string) (item interface{}, exists bool, err err defer f.lock.RUnlock() d, exists := f.items[key] if exists { - // Copy item's slice so operations on this slice (delta - // compression) won't interfere with the object we return. + // Copy item's slice so operations on this slice + // won't interfere with the object we return. d = copyDeltas(d) } return d, exists, nil @@ -503,8 +496,6 @@ func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error { } // Detect deletions not already in the queue. - // TODO(lavalamp): This may be racy-- we aren't properly locked - // with knownObjects. Unproven. knownKeys := f.knownObjects.ListKeys() queuedDeletions := 0 for _, k := range knownKeys { @@ -603,23 +594,6 @@ type KeyGetter interface { GetByKey(key string) (interface{}, bool, error) } -// DeltaCompressor is an algorithm that removes redundant changes. -type DeltaCompressor interface { - Compress(Deltas) Deltas -} - -// DeltaCompressorFunc should remove redundant changes; but changes that -// are redundant depend on one's desired semantics, so this is an -// injectable function. -// -// DeltaCompressorFunc adapts a raw function to be a DeltaCompressor. -type DeltaCompressorFunc func(Deltas) Deltas - -// Compress just calls dc. -func (dc DeltaCompressorFunc) Compress(d Deltas) Deltas { - return dc(d) -} - // DeltaType is the type of a change (addition, deletion, etc) type DeltaType string @@ -668,7 +642,7 @@ func (d Deltas) Newest() *Delta { // copyDeltas returns a shallow copy of d; that is, it copies the slice but not // the objects in the slice. This allows Get/List to return an object that we -// know won't be clobbered by a subsequent call to a delta compressor. +// know won't be clobbered by a subsequent modifications. func copyDeltas(d Deltas) Deltas { d2 := make(Deltas, len(d)) copy(d2, d) diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo_test.go new file mode 100644 index 00000000..9f8e5758 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/delta_fifo_test.go @@ -0,0 +1,492 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "fmt" + "reflect" + "testing" + "time" +) + +// helper function to reduce stuttering +func testPop(f *DeltaFIFO) testFifoObject { + return Pop(f).(Deltas).Newest().Object.(testFifoObject) +} + +// keyLookupFunc adapts a raw function to be a KeyLookup. +type keyLookupFunc func() []testFifoObject + +// ListKeys just calls kl. +func (kl keyLookupFunc) ListKeys() []string { + result := []string{} + for _, fifoObj := range kl() { + result = append(result, fifoObj.name) + } + return result +} + +// GetByKey returns the key if it exists in the list returned by kl. +func (kl keyLookupFunc) GetByKey(key string) (interface{}, bool, error) { + for _, v := range kl() { + if v.name == key { + return v, true, nil + } + } + return nil, false, nil +} + +func TestDeltaFIFO_basic(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + const amount = 500 + go func() { + for i := 0; i < amount; i++ { + f.Add(mkFifoObj(string([]rune{'a', rune(i)}), i+1)) + } + }() + go func() { + for u := uint64(0); u < amount; u++ { + f.Add(mkFifoObj(string([]rune{'b', rune(u)}), u+1)) + } + }() + + lastInt := int(0) + lastUint := uint64(0) + for i := 0; i < amount*2; i++ { + switch obj := testPop(f).val.(type) { + case int: + if obj <= lastInt { + t.Errorf("got %v (int) out of order, last was %v", obj, lastInt) + } + lastInt = obj + case uint64: + if obj <= lastUint { + t.Errorf("got %v (uint) out of order, last was %v", obj, lastUint) + } else { + lastUint = obj + } + default: + t.Fatalf("unexpected type %#v", obj) + } + } +} + +func TestDeltaFIFO_requeueOnPop(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + + f.Add(mkFifoObj("foo", 10)) + _, err := f.Pop(func(obj interface{}) error { + if obj.(Deltas)[0].Object.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return ErrRequeue{Err: nil} + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); !ok || err != nil { + t.Fatalf("object should have been requeued: %t %v", ok, err) + } + + _, err = f.Pop(func(obj interface{}) error { + if obj.(Deltas)[0].Object.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return ErrRequeue{Err: fmt.Errorf("test error")} + }) + if err == nil || err.Error() != "test error" { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); !ok || err != nil { + t.Fatalf("object should have been requeued: %t %v", ok, err) + } + + _, err = f.Pop(func(obj interface{}) error { + if obj.(Deltas)[0].Object.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return nil + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); ok || err != nil { + t.Fatalf("object should have been removed: %t %v", ok, err) + } +} + +func TestDeltaFIFO_addUpdate(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f.Add(mkFifoObj("foo", 10)) + f.Update(mkFifoObj("foo", 12)) + f.Delete(mkFifoObj("foo", 15)) + + if e, a := []interface{}{mkFifoObj("foo", 15)}, f.List(); !reflect.DeepEqual(e, a) { + t.Errorf("Expected %+v, got %+v", e, a) + } + if e, a := []string{"foo"}, f.ListKeys(); !reflect.DeepEqual(e, a) { + t.Errorf("Expected %+v, got %+v", e, a) + } + + got := make(chan testFifoObject, 2) + go func() { + for { + obj := testPop(f) + t.Logf("got a thing %#v", obj) + t.Logf("D len: %v", len(f.queue)) + got <- obj + } + }() + + first := <-got + if e, a := 15, first.val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + select { + case unexpected := <-got: + t.Errorf("Got second value %v", unexpected.val) + case <-time.After(50 * time.Millisecond): + } + _, exists, _ := f.Get(mkFifoObj("foo", "")) + if exists { + t.Errorf("item did not get removed") + } +} + +func TestDeltaFIFO_enqueueingNoLister(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f.Add(mkFifoObj("foo", 10)) + f.Update(mkFifoObj("bar", 15)) + f.Add(mkFifoObj("qux", 17)) + f.Delete(mkFifoObj("qux", 18)) + + // This delete does not enqueue anything because baz doesn't exist. + f.Delete(mkFifoObj("baz", 20)) + + expectList := []int{10, 15, 18} + for _, expect := range expectList { + if e, a := expect, testPop(f).val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + } + if e, a := 0, len(f.items); e != a { + t.Errorf("queue unexpectedly not empty: %v != %v\n%#v", e, a, f.items) + } +} + +func TestDeltaFIFO_enqueueingWithLister(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} + }), + ) + f.Add(mkFifoObj("foo", 10)) + f.Update(mkFifoObj("bar", 15)) + + // This delete does enqueue the deletion, because "baz" is in the key lister. + f.Delete(mkFifoObj("baz", 20)) + + expectList := []int{10, 15, 20} + for _, expect := range expectList { + if e, a := expect, testPop(f).val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + } + if e, a := 0, len(f.items); e != a { + t.Errorf("queue unexpectedly not empty: %v != %v", e, a) + } +} + +func TestDeltaFIFO_addReplace(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f.Add(mkFifoObj("foo", 10)) + f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0") + got := make(chan testFifoObject, 2) + go func() { + for { + got <- testPop(f) + } + }() + + first := <-got + if e, a := 15, first.val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + select { + case unexpected := <-got: + t.Errorf("Got second value %v", unexpected.val) + case <-time.After(50 * time.Millisecond): + } + _, exists, _ := f.Get(mkFifoObj("foo", "")) + if exists { + t.Errorf("item did not get removed") + } +} + +func TestDeltaFIFO_ResyncNonExisting(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{mkFifoObj("foo", 5)} + }), + ) + f.Delete(mkFifoObj("foo", 10)) + f.Resync() + + deltas := f.items["foo"] + if len(deltas) != 1 { + t.Fatalf("unexpected deltas length: %v", deltas) + } + if deltas[0].Type != Deleted { + t.Errorf("unexpected delta: %v", deltas[0]) + } +} + +func TestDeltaFIFO_DeleteExistingNonPropagated(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{} + }), + ) + f.Add(mkFifoObj("foo", 5)) + f.Delete(mkFifoObj("foo", 6)) + + deltas := f.items["foo"] + if len(deltas) != 2 { + t.Fatalf("unexpected deltas length: %v", deltas) + } + if deltas[len(deltas)-1].Type != Deleted { + t.Errorf("unexpected delta: %v", deltas[len(deltas)-1]) + } +} + +func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} + }), + ) + f.Delete(mkFifoObj("baz", 10)) + f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") + + expectedList := []Deltas{ + {{Deleted, mkFifoObj("baz", 10)}}, + {{Sync, mkFifoObj("foo", 5)}}, + // Since "bar" didn't have a delete event and wasn't in the Replace list + // it should get a tombstone key with the right Obj. + {{Deleted, DeletedFinalStateUnknown{Key: "bar", Obj: mkFifoObj("bar", 6)}}}, + } + + for _, expected := range expectedList { + cur := Pop(f).(Deltas) + if e, a := expected, cur; !reflect.DeepEqual(e, a) { + t.Errorf("Expected %#v, got %#v", e, a) + } + } +} + +func TestDeltaFIFO_UpdateResyncRace(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{mkFifoObj("foo", 5)} + }), + ) + f.Update(mkFifoObj("foo", 6)) + f.Resync() + + expectedList := []Deltas{ + {{Updated, mkFifoObj("foo", 6)}}, + } + + for _, expected := range expectedList { + cur := Pop(f).(Deltas) + if e, a := expected, cur; !reflect.DeepEqual(e, a) { + t.Errorf("Expected %#v, got %#v", e, a) + } + } +} + +func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) { + f := NewDeltaFIFO( + testFifoObjectKeyFunc, + keyLookupFunc(func() []testFifoObject { + return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} + }), + ) + f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") + + expectedList := []Deltas{ + {{Sync, mkFifoObj("foo", 5)}}, + // Since "bar" didn't have a delete event and wasn't in the Replace list + // it should get a tombstone key with the right Obj. + {{Deleted, DeletedFinalStateUnknown{Key: "bar", Obj: mkFifoObj("bar", 6)}}}, + } + + for _, expected := range expectedList { + if f.HasSynced() { + t.Errorf("Expected HasSynced to be false") + } + cur := Pop(f).(Deltas) + if e, a := expected, cur; !reflect.DeepEqual(e, a) { + t.Errorf("Expected %#v, got %#v", e, a) + } + } + if f.HasSynced() { + t.Errorf("Expected HasSynced to be true") + } +} + +func TestDeltaFIFO_detectLineJumpers(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + + f.Add(mkFifoObj("foo", 10)) + f.Add(mkFifoObj("bar", 1)) + f.Add(mkFifoObj("foo", 11)) + f.Add(mkFifoObj("foo", 13)) + f.Add(mkFifoObj("zab", 30)) + + if e, a := 13, testPop(f).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + f.Add(mkFifoObj("foo", 14)) // ensure foo doesn't jump back in line + + if e, a := 1, testPop(f).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + if e, a := 30, testPop(f).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + if e, a := 14, testPop(f).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } +} + +func TestDeltaFIFO_addIfNotPresent(t *testing.T) { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + + f.Add(mkFifoObj("b", 3)) + b3 := Pop(f) + f.Add(mkFifoObj("c", 4)) + c4 := Pop(f) + if e, a := 0, len(f.items); e != a { + t.Fatalf("Expected %v, got %v items in queue", e, a) + } + + f.Add(mkFifoObj("a", 1)) + f.Add(mkFifoObj("b", 2)) + f.AddIfNotPresent(b3) + f.AddIfNotPresent(c4) + + if e, a := 3, len(f.items); a != e { + t.Fatalf("expected queue length %d, got %d", e, a) + } + + expectedValues := []int{1, 2, 4} + for _, expected := range expectedValues { + if actual := testPop(f).val; actual != expected { + t.Fatalf("expected value %d, got %d", expected, actual) + } + } +} + +func TestDeltaFIFO_KeyOf(t *testing.T) { + f := DeltaFIFO{keyFunc: testFifoObjectKeyFunc} + + table := []struct { + obj interface{} + key string + }{ + {obj: testFifoObject{name: "A"}, key: "A"}, + {obj: DeletedFinalStateUnknown{Key: "B", Obj: nil}, key: "B"}, + {obj: Deltas{{Object: testFifoObject{name: "C"}}}, key: "C"}, + {obj: Deltas{{Object: DeletedFinalStateUnknown{Key: "D", Obj: nil}}}, key: "D"}, + } + + for _, item := range table { + got, err := f.KeyOf(item.obj) + if err != nil { + t.Errorf("Unexpected error for %q: %v", item.obj, err) + continue + } + if e, a := item.key, got; e != a { + t.Errorf("Expected %v, got %v", e, a) + } + } +} + +func TestDeltaFIFO_HasSynced(t *testing.T) { + tests := []struct { + actions []func(f *DeltaFIFO) + expectedSynced bool + }{ + { + actions: []func(f *DeltaFIFO){}, + expectedSynced: false, + }, + { + actions: []func(f *DeltaFIFO){ + func(f *DeltaFIFO) { f.Add(mkFifoObj("a", 1)) }, + }, + expectedSynced: true, + }, + { + actions: []func(f *DeltaFIFO){ + func(f *DeltaFIFO) { f.Replace([]interface{}{}, "0") }, + }, + expectedSynced: true, + }, + { + actions: []func(f *DeltaFIFO){ + func(f *DeltaFIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + }, + expectedSynced: false, + }, + { + actions: []func(f *DeltaFIFO){ + func(f *DeltaFIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + func(f *DeltaFIFO) { Pop(f) }, + }, + expectedSynced: false, + }, + { + actions: []func(f *DeltaFIFO){ + func(f *DeltaFIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + func(f *DeltaFIFO) { Pop(f) }, + func(f *DeltaFIFO) { Pop(f) }, + }, + expectedSynced: true, + }, + } + + for i, test := range tests { + f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + + for _, action := range test.actions { + action(f) + } + if e, a := test.expectedSynced, f.HasSynced(); a != e { + t.Errorf("test case %v failed, expected: %v , got %v", i, e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/expiration_cache_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/expiration_cache_test.go new file mode 100644 index 00000000..fac621cb --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/expiration_cache_test.go @@ -0,0 +1,189 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "reflect" + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/apimachinery/pkg/util/wait" +) + +func TestTTLExpirationBasic(t *testing.T) { + testObj := testStoreObject{id: "foo", val: "bar"} + deleteChan := make(chan string, 1) + ttlStore := NewFakeExpirationStore( + testStoreKeyFunc, deleteChan, + &FakeExpirationPolicy{ + NeverExpire: sets.NewString(), + RetrieveKeyFunc: func(obj interface{}) (string, error) { + return obj.(*timestampedEntry).obj.(testStoreObject).id, nil + }, + }, + clock.RealClock{}, + ) + err := ttlStore.Add(testObj) + if err != nil { + t.Errorf("Unable to add obj %#v", testObj) + } + item, exists, err := ttlStore.Get(testObj) + if err != nil { + t.Errorf("Failed to get from store, %v", err) + } + if exists || item != nil { + t.Errorf("Got unexpected item %#v", item) + } + key, _ := testStoreKeyFunc(testObj) + select { + case delKey := <-deleteChan: + if delKey != key { + t.Errorf("Unexpected delete for key %s", key) + } + case <-time.After(wait.ForeverTestTimeout): + t.Errorf("Unexpected timeout waiting on delete") + } + close(deleteChan) +} + +func TestReAddExpiredItem(t *testing.T) { + deleteChan := make(chan string, 1) + exp := &FakeExpirationPolicy{ + NeverExpire: sets.NewString(), + RetrieveKeyFunc: func(obj interface{}) (string, error) { + return obj.(*timestampedEntry).obj.(testStoreObject).id, nil + }, + } + ttlStore := NewFakeExpirationStore( + testStoreKeyFunc, deleteChan, exp, clock.RealClock{}) + testKey := "foo" + testObj := testStoreObject{id: testKey, val: "bar"} + err := ttlStore.Add(testObj) + if err != nil { + t.Errorf("Unable to add obj %#v", testObj) + } + + // This get will expire the item. + item, exists, err := ttlStore.Get(testObj) + if err != nil { + t.Errorf("Failed to get from store, %v", err) + } + if exists || item != nil { + t.Errorf("Got unexpected item %#v", item) + } + + key, _ := testStoreKeyFunc(testObj) + differentValue := "different_bar" + err = ttlStore.Add( + testStoreObject{id: testKey, val: differentValue}) + if err != nil { + t.Errorf("Failed to add second value") + } + + select { + case delKey := <-deleteChan: + if delKey != key { + t.Errorf("Unexpected delete for key %s", key) + } + case <-time.After(wait.ForeverTestTimeout): + t.Errorf("Unexpected timeout waiting on delete") + } + exp.NeverExpire = sets.NewString(testKey) + item, exists, err = ttlStore.GetByKey(testKey) + if err != nil { + t.Errorf("Failed to get from store, %v", err) + } + if !exists || item == nil || item.(testStoreObject).val != differentValue { + t.Errorf("Got unexpected item %#v", item) + } + close(deleteChan) +} + +func TestTTLList(t *testing.T) { + testObjs := []testStoreObject{ + {id: "foo", val: "bar"}, + {id: "foo1", val: "bar1"}, + {id: "foo2", val: "bar2"}, + } + expireKeys := sets.NewString(testObjs[0].id, testObjs[2].id) + deleteChan := make(chan string, len(testObjs)) + defer close(deleteChan) + + ttlStore := NewFakeExpirationStore( + testStoreKeyFunc, deleteChan, + &FakeExpirationPolicy{ + NeverExpire: sets.NewString(testObjs[1].id), + RetrieveKeyFunc: func(obj interface{}) (string, error) { + return obj.(*timestampedEntry).obj.(testStoreObject).id, nil + }, + }, + clock.RealClock{}, + ) + for _, obj := range testObjs { + err := ttlStore.Add(obj) + if err != nil { + t.Errorf("Unable to add obj %#v", obj) + } + } + listObjs := ttlStore.List() + if len(listObjs) != 1 || !reflect.DeepEqual(listObjs[0], testObjs[1]) { + t.Errorf("List returned unexpected results %#v", listObjs) + } + + // Make sure all our deletes come through in an acceptable rate (1/100ms) + for expireKeys.Len() != 0 { + select { + case delKey := <-deleteChan: + if !expireKeys.Has(delKey) { + t.Errorf("Unexpected delete for key %s", delKey) + } + expireKeys.Delete(delKey) + case <-time.After(wait.ForeverTestTimeout): + t.Errorf("Unexpected timeout waiting on delete") + return + } + } +} + +func TestTTLPolicy(t *testing.T) { + fakeTime := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + ttl := 30 * time.Second + exactlyOnTTL := fakeTime.Add(-ttl) + expiredTime := fakeTime.Add(-(ttl + 1)) + + policy := TTLPolicy{ttl, clock.NewFakeClock(fakeTime)} + fakeTimestampedEntry := ×tampedEntry{obj: struct{}{}, timestamp: exactlyOnTTL} + if policy.IsExpired(fakeTimestampedEntry) { + t.Errorf("TTL cache should not expire entries exactly on ttl") + } + fakeTimestampedEntry.timestamp = fakeTime + if policy.IsExpired(fakeTimestampedEntry) { + t.Errorf("TTL Cache should not expire entries before ttl") + } + fakeTimestampedEntry.timestamp = expiredTime + if !policy.IsExpired(fakeTimestampedEntry) { + t.Errorf("TTL Cache should expire entries older than ttl") + } + for _, ttl = range []time.Duration{0, -1} { + policy.Ttl = ttl + if policy.IsExpired(fakeTimestampedEntry) { + t.Errorf("TTL policy should only expire entries when initialized with a ttl > 0") + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/fifo.go b/discovery/vendor/k8s.io/client-go/tools/cache/fifo.go index ef70b7ac..e05c01ee 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/fifo.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/fifo.go @@ -59,7 +59,7 @@ type Queue interface { // has since been added. AddIfNotPresent(interface{}) error - // Return true if the first batch of items has been popped + // HasSynced returns true if the first batch of items has been popped HasSynced() bool // Close queue diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/fifo_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/fifo_test.go new file mode 100644 index 00000000..afd311d7 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/fifo_test.go @@ -0,0 +1,280 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "fmt" + "reflect" + "testing" + "time" +) + +func testFifoObjectKeyFunc(obj interface{}) (string, error) { + return obj.(testFifoObject).name, nil +} + +type testFifoObject struct { + name string + val interface{} +} + +func mkFifoObj(name string, val interface{}) testFifoObject { + return testFifoObject{name: name, val: val} +} + +func TestFIFO_basic(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + const amount = 500 + go func() { + for i := 0; i < amount; i++ { + f.Add(mkFifoObj(string([]rune{'a', rune(i)}), i+1)) + } + }() + go func() { + for u := uint64(0); u < amount; u++ { + f.Add(mkFifoObj(string([]rune{'b', rune(u)}), u+1)) + } + }() + + lastInt := int(0) + lastUint := uint64(0) + for i := 0; i < amount*2; i++ { + switch obj := Pop(f).(testFifoObject).val.(type) { + case int: + if obj <= lastInt { + t.Errorf("got %v (int) out of order, last was %v", obj, lastInt) + } + lastInt = obj + case uint64: + if obj <= lastUint { + t.Errorf("got %v (uint) out of order, last was %v", obj, lastUint) + } else { + lastUint = obj + } + default: + t.Fatalf("unexpected type %#v", obj) + } + } +} + +func TestFIFO_requeueOnPop(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + + f.Add(mkFifoObj("foo", 10)) + _, err := f.Pop(func(obj interface{}) error { + if obj.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return ErrRequeue{Err: nil} + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); !ok || err != nil { + t.Fatalf("object should have been requeued: %t %v", ok, err) + } + + _, err = f.Pop(func(obj interface{}) error { + if obj.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return ErrRequeue{Err: fmt.Errorf("test error")} + }) + if err == nil || err.Error() != "test error" { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); !ok || err != nil { + t.Fatalf("object should have been requeued: %t %v", ok, err) + } + + _, err = f.Pop(func(obj interface{}) error { + if obj.(testFifoObject).name != "foo" { + t.Fatalf("unexpected object: %#v", obj) + } + return nil + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if _, ok, err := f.GetByKey("foo"); ok || err != nil { + t.Fatalf("object should have been removed: %t %v", ok, err) + } +} + +func TestFIFO_addUpdate(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + f.Add(mkFifoObj("foo", 10)) + f.Update(mkFifoObj("foo", 15)) + + if e, a := []interface{}{mkFifoObj("foo", 15)}, f.List(); !reflect.DeepEqual(e, a) { + t.Errorf("Expected %+v, got %+v", e, a) + } + if e, a := []string{"foo"}, f.ListKeys(); !reflect.DeepEqual(e, a) { + t.Errorf("Expected %+v, got %+v", e, a) + } + + got := make(chan testFifoObject, 2) + go func() { + for { + got <- Pop(f).(testFifoObject) + } + }() + + first := <-got + if e, a := 15, first.val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + select { + case unexpected := <-got: + t.Errorf("Got second value %v", unexpected.val) + case <-time.After(50 * time.Millisecond): + } + _, exists, _ := f.Get(mkFifoObj("foo", "")) + if exists { + t.Errorf("item did not get removed") + } +} + +func TestFIFO_addReplace(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + f.Add(mkFifoObj("foo", 10)) + f.Replace([]interface{}{mkFifoObj("foo", 15)}, "15") + got := make(chan testFifoObject, 2) + go func() { + for { + got <- Pop(f).(testFifoObject) + } + }() + + first := <-got + if e, a := 15, first.val; e != a { + t.Errorf("Didn't get updated value (%v), got %v", e, a) + } + select { + case unexpected := <-got: + t.Errorf("Got second value %v", unexpected.val) + case <-time.After(50 * time.Millisecond): + } + _, exists, _ := f.Get(mkFifoObj("foo", "")) + if exists { + t.Errorf("item did not get removed") + } +} + +func TestFIFO_detectLineJumpers(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + + f.Add(mkFifoObj("foo", 10)) + f.Add(mkFifoObj("bar", 1)) + f.Add(mkFifoObj("foo", 11)) + f.Add(mkFifoObj("foo", 13)) + f.Add(mkFifoObj("zab", 30)) + + if e, a := 13, Pop(f).(testFifoObject).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + f.Add(mkFifoObj("foo", 14)) // ensure foo doesn't jump back in line + + if e, a := 1, Pop(f).(testFifoObject).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + if e, a := 30, Pop(f).(testFifoObject).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } + + if e, a := 14, Pop(f).(testFifoObject).val; a != e { + t.Fatalf("expected %d, got %d", e, a) + } +} + +func TestFIFO_addIfNotPresent(t *testing.T) { + f := NewFIFO(testFifoObjectKeyFunc) + + f.Add(mkFifoObj("a", 1)) + f.Add(mkFifoObj("b", 2)) + f.AddIfNotPresent(mkFifoObj("b", 3)) + f.AddIfNotPresent(mkFifoObj("c", 4)) + + if e, a := 3, len(f.items); a != e { + t.Fatalf("expected queue length %d, got %d", e, a) + } + + expectedValues := []int{1, 2, 4} + for _, expected := range expectedValues { + if actual := Pop(f).(testFifoObject).val; actual != expected { + t.Fatalf("expected value %d, got %d", expected, actual) + } + } +} + +func TestFIFO_HasSynced(t *testing.T) { + tests := []struct { + actions []func(f *FIFO) + expectedSynced bool + }{ + { + actions: []func(f *FIFO){}, + expectedSynced: false, + }, + { + actions: []func(f *FIFO){ + func(f *FIFO) { f.Add(mkFifoObj("a", 1)) }, + }, + expectedSynced: true, + }, + { + actions: []func(f *FIFO){ + func(f *FIFO) { f.Replace([]interface{}{}, "0") }, + }, + expectedSynced: true, + }, + { + actions: []func(f *FIFO){ + func(f *FIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + }, + expectedSynced: false, + }, + { + actions: []func(f *FIFO){ + func(f *FIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + func(f *FIFO) { Pop(f) }, + }, + expectedSynced: false, + }, + { + actions: []func(f *FIFO){ + func(f *FIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("b", 2)}, "0") }, + func(f *FIFO) { Pop(f) }, + func(f *FIFO) { Pop(f) }, + }, + expectedSynced: true, + }, + } + + for i, test := range tests { + f := NewFIFO(testFifoObjectKeyFunc) + + for _, action := range test.actions { + action(f) + } + if e, a := test.expectedSynced, f.HasSynced(); a != e { + t.Errorf("test case %v failed, expected: %v , got %v", i, e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/heap_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/heap_test.go new file mode 100644 index 00000000..c2e47698 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/heap_test.go @@ -0,0 +1,382 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "sync" + "testing" + "time" +) + +func testHeapObjectKeyFunc(obj interface{}) (string, error) { + return obj.(testHeapObject).name, nil +} + +type testHeapObject struct { + name string + val interface{} +} + +func mkHeapObj(name string, val interface{}) testHeapObject { + return testHeapObject{name: name, val: val} +} + +func compareInts(val1 interface{}, val2 interface{}) bool { + first := val1.(testHeapObject).val.(int) + second := val2.(testHeapObject).val.(int) + return first < second +} + +// TestHeapBasic tests Heap invariant and synchronization. +func TestHeapBasic(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + var wg sync.WaitGroup + wg.Add(2) + const amount = 500 + var i, u int + // Insert items in the heap in opposite orders in two go routines. + go func() { + for i = amount; i > 0; i-- { + h.Add(mkHeapObj(string([]rune{'a', rune(i)}), i)) + } + wg.Done() + }() + go func() { + for u = 0; u < amount; u++ { + h.Add(mkHeapObj(string([]rune{'b', rune(u)}), u+1)) + } + wg.Done() + }() + // Wait for the two go routines to finish. + wg.Wait() + // Make sure that the numbers are popped in ascending order. + prevNum := 0 + for i := 0; i < amount*2; i++ { + obj, err := h.Pop() + num := obj.(testHeapObject).val.(int) + // All the items must be sorted. + if err != nil || prevNum > num { + t.Errorf("got %v out of order, last was %v", obj, prevNum) + } + prevNum = num + } +} + +// Tests Heap.Add and ensures that heap invariant is preserved after adding items. +func TestHeap_Add(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + h.Add(mkHeapObj("baz", 11)) + h.Add(mkHeapObj("zab", 30)) + h.Add(mkHeapObj("foo", 13)) // This updates "foo". + + item, err := h.Pop() + if e, a := 1, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + item, err = h.Pop() + if e, a := 11, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + h.Delete(mkHeapObj("baz", 11)) // Nothing is deleted. + h.Add(mkHeapObj("foo", 14)) // foo is updated. + item, err = h.Pop() + if e, a := 14, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + item, err = h.Pop() + if e, a := 30, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } +} + +// TestHeap_BulkAdd tests Heap.BulkAdd functionality and ensures that all the +// items given to BulkAdd are added to the queue before Pop reads them. +func TestHeap_BulkAdd(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + const amount = 500 + // Insert items in the heap in opposite orders in a go routine. + go func() { + l := []interface{}{} + for i := amount; i > 0; i-- { + l = append(l, mkHeapObj(string([]rune{'a', rune(i)}), i)) + } + h.BulkAdd(l) + }() + prevNum := -1 + for i := 0; i < amount; i++ { + obj, err := h.Pop() + num := obj.(testHeapObject).val.(int) + // All the items must be sorted. + if err != nil || prevNum >= num { + t.Errorf("got %v out of order, last was %v", obj, prevNum) + } + prevNum = num + } +} + +// TestHeapEmptyPop tests that pop returns properly after heap is closed. +func TestHeapEmptyPop(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + go func() { + time.Sleep(1 * time.Second) + h.Close() + }() + _, err := h.Pop() + if err == nil || err.Error() != closedMsg { + t.Errorf("pop should have returned heap closed error: %v", err) + } +} + +// TestHeap_AddIfNotPresent tests Heap.AddIfNotPresent and ensures that heap +// invariant is preserved after adding items. +func TestHeap_AddIfNotPresent(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.AddIfNotPresent(mkHeapObj("foo", 10)) + h.AddIfNotPresent(mkHeapObj("bar", 1)) + h.AddIfNotPresent(mkHeapObj("baz", 11)) + h.AddIfNotPresent(mkHeapObj("zab", 30)) + h.AddIfNotPresent(mkHeapObj("foo", 13)) // This is not added. + + if len := len(h.data.items); len != 4 { + t.Errorf("unexpected number of items: %d", len) + } + if val := h.data.items["foo"].obj.(testHeapObject).val; val != 10 { + t.Errorf("unexpected value: %d", val) + } + item, err := h.Pop() + if e, a := 1, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + item, err = h.Pop() + if e, a := 10, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + // bar is already popped. Let's add another one. + h.AddIfNotPresent(mkHeapObj("bar", 14)) + item, err = h.Pop() + if e, a := 11, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + item, err = h.Pop() + if e, a := 14, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } +} + +// TestHeap_Delete tests Heap.Delete and ensures that heap invariant is +// preserved after deleting items. +func TestHeap_Delete(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + h.Add(mkHeapObj("bal", 31)) + h.Add(mkHeapObj("baz", 11)) + + // Delete head. Delete should work with "key" and doesn't care about the value. + if err := h.Delete(mkHeapObj("bar", 200)); err != nil { + t.Fatalf("Failed to delete head.") + } + item, err := h.Pop() + if e, a := 10, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + h.Add(mkHeapObj("zab", 30)) + h.Add(mkHeapObj("faz", 30)) + len := h.data.Len() + // Delete non-existing item. + if err = h.Delete(mkHeapObj("non-existent", 10)); err == nil || len != h.data.Len() { + t.Fatalf("Didn't expect any item removal") + } + // Delete tail. + if err = h.Delete(mkHeapObj("bal", 31)); err != nil { + t.Fatalf("Failed to delete tail.") + } + // Delete one of the items with value 30. + if err = h.Delete(mkHeapObj("zab", 30)); err != nil { + t.Fatalf("Failed to delete item.") + } + item, err = h.Pop() + if e, a := 11, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + item, err = h.Pop() + if e, a := 30, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + if h.data.Len() != 0 { + t.Fatalf("expected an empty heap.") + } +} + +// TestHeap_Update tests Heap.Update and ensures that heap invariant is +// preserved after adding items. +func TestHeap_Update(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + h.Add(mkHeapObj("bal", 31)) + h.Add(mkHeapObj("baz", 11)) + + // Update an item to a value that should push it to the head. + h.Update(mkHeapObj("baz", 0)) + if h.data.queue[0] != "baz" || h.data.items["baz"].index != 0 { + t.Fatalf("expected baz to be at the head") + } + item, err := h.Pop() + if e, a := 0, item.(testHeapObject).val; err != nil || a != e { + t.Fatalf("expected %d, got %d", e, a) + } + // Update bar to push it farther back in the queue. + h.Update(mkHeapObj("bar", 100)) + if h.data.queue[0] != "foo" || h.data.items["foo"].index != 0 { + t.Fatalf("expected foo to be at the head") + } +} + +// TestHeap_Get tests Heap.Get. +func TestHeap_Get(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + h.Add(mkHeapObj("bal", 31)) + h.Add(mkHeapObj("baz", 11)) + + // Get works with the key. + obj, exists, err := h.Get(mkHeapObj("baz", 0)) + if err != nil || exists == false || obj.(testHeapObject).val != 11 { + t.Fatalf("unexpected error in getting element") + } + // Get non-existing object. + _, exists, err = h.Get(mkHeapObj("non-existing", 0)) + if err != nil || exists == true { + t.Fatalf("didn't expect to get any object") + } +} + +// TestHeap_GetByKey tests Heap.GetByKey and is very similar to TestHeap_Get. +func TestHeap_GetByKey(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + h.Add(mkHeapObj("bal", 31)) + h.Add(mkHeapObj("baz", 11)) + + obj, exists, err := h.GetByKey("baz") + if err != nil || exists == false || obj.(testHeapObject).val != 11 { + t.Fatalf("unexpected error in getting element") + } + // Get non-existing object. + _, exists, err = h.GetByKey("non-existing") + if err != nil || exists == true { + t.Fatalf("didn't expect to get any object") + } +} + +// TestHeap_Close tests Heap.Close and Heap.IsClosed functions. +func TestHeap_Close(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Add(mkHeapObj("foo", 10)) + h.Add(mkHeapObj("bar", 1)) + + if h.IsClosed() { + t.Fatalf("didn't expect heap to be closed") + } + h.Close() + if !h.IsClosed() { + t.Fatalf("expect heap to be closed") + } +} + +// TestHeap_List tests Heap.List function. +func TestHeap_List(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + list := h.List() + if len(list) != 0 { + t.Errorf("expected an empty list") + } + + items := map[string]int{ + "foo": 10, + "bar": 1, + "bal": 30, + "baz": 11, + "faz": 30, + } + for k, v := range items { + h.Add(mkHeapObj(k, v)) + } + list = h.List() + if len(list) != len(items) { + t.Errorf("expected %d items, got %d", len(items), len(list)) + } + for _, obj := range list { + heapObj := obj.(testHeapObject) + v, ok := items[heapObj.name] + if !ok || v != heapObj.val { + t.Errorf("unexpected item in the list: %v", heapObj) + } + } +} + +// TestHeap_ListKeys tests Heap.ListKeys function. Scenario is the same as +// TestHeap_list. +func TestHeap_ListKeys(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + list := h.ListKeys() + if len(list) != 0 { + t.Errorf("expected an empty list") + } + + items := map[string]int{ + "foo": 10, + "bar": 1, + "bal": 30, + "baz": 11, + "faz": 30, + } + for k, v := range items { + h.Add(mkHeapObj(k, v)) + } + list = h.ListKeys() + if len(list) != len(items) { + t.Errorf("expected %d items, got %d", len(items), len(list)) + } + for _, key := range list { + _, ok := items[key] + if !ok { + t.Errorf("unexpected item in the list: %v", key) + } + } +} + +// TestHeapAddAfterClose tests that heap returns an error if anything is added +// after it is closed. +func TestHeapAddAfterClose(t *testing.T) { + h := NewHeap(testHeapObjectKeyFunc, compareInts) + h.Close() + if err := h.Add(mkHeapObj("test", 1)); err == nil || err.Error() != closedMsg { + t.Errorf("expected heap closed error") + } + if err := h.AddIfNotPresent(mkHeapObj("test", 1)); err == nil || err.Error() != closedMsg { + t.Errorf("expected heap closed error") + } + if err := h.BulkAdd([]interface{}{mkHeapObj("test", 1)}); err == nil || err.Error() != closedMsg { + t.Errorf("expected heap closed error") + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/index_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/index_test.go new file mode 100644 index 00000000..ecc104c0 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/index_test.go @@ -0,0 +1,163 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "strings" + "testing" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func testIndexFunc(obj interface{}) ([]string, error) { + pod := obj.(*v1.Pod) + return []string{pod.Labels["foo"]}, nil +} + +func TestGetIndexFuncValues(t *testing.T) { + index := NewIndexer(MetaNamespaceKeyFunc, Indexers{"testmodes": testIndexFunc}) + + pod1 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "one", Labels: map[string]string{"foo": "bar"}}} + pod2 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "two", Labels: map[string]string{"foo": "bar"}}} + pod3 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "tre", Labels: map[string]string{"foo": "biz"}}} + + index.Add(pod1) + index.Add(pod2) + index.Add(pod3) + + keys := index.ListIndexFuncValues("testmodes") + if len(keys) != 2 { + t.Errorf("Expected 2 keys but got %v", len(keys)) + } + + for _, key := range keys { + if key != "bar" && key != "biz" { + t.Errorf("Expected only 'bar' or 'biz' but got %s", key) + } + } +} + +func testUsersIndexFunc(obj interface{}) ([]string, error) { + pod := obj.(*v1.Pod) + usersString := pod.Annotations["users"] + + return strings.Split(usersString, ","), nil +} + +func TestMultiIndexKeys(t *testing.T) { + index := NewIndexer(MetaNamespaceKeyFunc, Indexers{"byUser": testUsersIndexFunc}) + + pod1 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "one", Annotations: map[string]string{"users": "ernie,bert"}}} + pod2 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "two", Annotations: map[string]string{"users": "bert,oscar"}}} + pod3 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "tre", Annotations: map[string]string{"users": "ernie,elmo"}}} + + index.Add(pod1) + index.Add(pod2) + index.Add(pod3) + + erniePods, err := index.ByIndex("byUser", "ernie") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(erniePods) != 2 { + t.Errorf("Expected 2 pods but got %v", len(erniePods)) + } + for _, erniePod := range erniePods { + if erniePod.(*v1.Pod).Name != "one" && erniePod.(*v1.Pod).Name != "tre" { + t.Errorf("Expected only 'one' or 'tre' but got %s", erniePod.(*v1.Pod).Name) + } + } + + bertPods, err := index.ByIndex("byUser", "bert") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(bertPods) != 2 { + t.Errorf("Expected 2 pods but got %v", len(bertPods)) + } + for _, bertPod := range bertPods { + if bertPod.(*v1.Pod).Name != "one" && bertPod.(*v1.Pod).Name != "two" { + t.Errorf("Expected only 'one' or 'two' but got %s", bertPod.(*v1.Pod).Name) + } + } + + oscarPods, err := index.ByIndex("byUser", "oscar") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(oscarPods) != 1 { + t.Errorf("Expected 1 pods but got %v", len(erniePods)) + } + for _, oscarPod := range oscarPods { + if oscarPod.(*v1.Pod).Name != "two" { + t.Errorf("Expected only 'two' but got %s", oscarPod.(*v1.Pod).Name) + } + } + + ernieAndBertKeys, err := index.Index("byUser", pod1) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(ernieAndBertKeys) != 3 { + t.Errorf("Expected 3 pods but got %v", len(ernieAndBertKeys)) + } + for _, ernieAndBertKey := range ernieAndBertKeys { + if ernieAndBertKey.(*v1.Pod).Name != "one" && ernieAndBertKey.(*v1.Pod).Name != "two" && ernieAndBertKey.(*v1.Pod).Name != "tre" { + t.Errorf("Expected only 'one', 'two' or 'tre' but got %s", ernieAndBertKey.(*v1.Pod).Name) + } + } + + index.Delete(pod3) + erniePods, err = index.ByIndex("byUser", "ernie") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(erniePods) != 1 { + t.Errorf("Expected 1 pods but got %v", len(erniePods)) + } + for _, erniePod := range erniePods { + if erniePod.(*v1.Pod).Name != "one" { + t.Errorf("Expected only 'one' but got %s", erniePod.(*v1.Pod).Name) + } + } + + elmoPods, err := index.ByIndex("byUser", "elmo") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(elmoPods) != 0 { + t.Errorf("Expected 0 pods but got %v", len(elmoPods)) + } + + copyOfPod2 := pod2.DeepCopy() + copyOfPod2.Annotations["users"] = "oscar" + index.Update(copyOfPod2) + bertPods, err = index.ByIndex("byUser", "bert") + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(bertPods) != 1 { + t.Errorf("Expected 1 pods but got %v", len(bertPods)) + } + for _, bertPod := range bertPods { + if bertPod.(*v1.Pod).Name != "one" { + t.Errorf("Expected only 'one' but got %s", bertPod.(*v1.Pod).Name) + } + } + +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/listwatch.go b/discovery/vendor/k8s.io/client-go/tools/cache/listwatch.go index db2329c5..06657a3b 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/listwatch.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/listwatch.go @@ -63,8 +63,18 @@ type Getter interface { // NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector. func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch { - listFunc := func(options metav1.ListOptions) (runtime.Object, error) { + optionsModifier := func(options *metav1.ListOptions) { options.FieldSelector = fieldSelector.String() + } + return NewFilteredListWatchFromClient(c, resource, namespace, optionsModifier) +} + +// NewFilteredListWatchFromClient creates a new ListWatch from the specified client, resource, namespace, and option modifier. +// Option modifier is a function takes a ListOptions and modifies the consumed ListOptions. Provide customized modifier function +// to apply modification to ListOptions with a field selector, a label selector, or any other desired options. +func NewFilteredListWatchFromClient(c Getter, resource string, namespace string, optionsModifier func(options *metav1.ListOptions)) *ListWatch { + listFunc := func(options metav1.ListOptions) (runtime.Object, error) { + optionsModifier(&options) return c.Get(). Namespace(namespace). Resource(resource). @@ -74,7 +84,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe } watchFunc := func(options metav1.ListOptions) (watch.Interface, error) { options.Watch = true - options.FieldSelector = fieldSelector.String() + optionsModifier(&options) return c.Get(). Namespace(namespace). Resource(resource). diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/mutation_detector_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/mutation_detector_test.go new file mode 100644 index 00000000..41b6942f --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/mutation_detector_test.go @@ -0,0 +1,81 @@ +// +build !race + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "testing" + "time" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" +) + +func TestMutationDetector(t *testing.T) { + fakeWatch := watch.NewFake() + lw := &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + return fakeWatch, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return &v1.PodList{}, nil + }, + } + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "anything", + Labels: map[string]string{"check": "foo"}, + }, + } + stopCh := make(chan struct{}) + defer close(stopCh) + addReceived := make(chan bool) + mutationFound := make(chan bool) + + informer := NewSharedInformer(lw, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer) + informer.cacheMutationDetector = &defaultCacheMutationDetector{ + name: "name", + period: 1 * time.Second, + failureFunc: func(message string) { + mutationFound <- true + }, + } + informer.AddEventHandler( + ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + addReceived <- true + }, + }, + ) + go informer.Run(stopCh) + + fakeWatch.Add(pod) + + select { + case <-addReceived: + } + + pod.Labels["change"] = "true" + + select { + case <-mutationFound: + } + +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/processor_listener_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/processor_listener_test.go new file mode 100644 index 00000000..1da73420 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/processor_listener_test.go @@ -0,0 +1,58 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "sync" + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/wait" +) + +const ( + concurrencyLevel = 5 +) + +func BenchmarkListener(b *testing.B) { + var notification addNotification + + var swg sync.WaitGroup + swg.Add(b.N) + b.SetParallelism(concurrencyLevel) + // Preallocate enough space so that benchmark does not run out of it + pl := newProcessListener(&ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + swg.Done() + }, + }, 0, 0, time.Now(), 1024*1024) + var wg wait.Group + defer wg.Wait() // Wait for .run and .pop to stop + defer close(pl.addCh) // Tell .run and .pop to stop + wg.Start(pl.run) + wg.Start(pl.pop) + + b.ReportAllocs() + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + pl.add(notification) + } + }) + swg.Wait() // Block until all notifications have been received + b.StopTimer() +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/reflector.go b/discovery/vendor/k8s.io/client-go/tools/cache/reflector.go index a97b5f98..054a7373 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/reflector.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/reflector.go @@ -108,8 +108,8 @@ func NewNamedReflector(name string, lw ListerWatcher, expectedType interface{}, reflectorSuffix := atomic.AddInt64(&reflectorDisambiguator, 1) r := &Reflector{ name: name, - // we need this to be unique per process (some names are still the same)but obvious who it belongs to - metrics: newReflectorMetrics(makeValidPromethusMetricLabel(fmt.Sprintf("reflector_"+name+"_%d", reflectorSuffix))), + // we need this to be unique per process (some names are still the same) but obvious who it belongs to + metrics: newReflectorMetrics(makeValidPrometheusMetricLabel(fmt.Sprintf("reflector_"+name+"_%d", reflectorSuffix))), listerWatcher: lw, store: store, expectedType: reflect.TypeOf(expectedType), @@ -120,7 +120,7 @@ func NewNamedReflector(name string, lw ListerWatcher, expectedType interface{}, return r } -func makeValidPromethusMetricLabel(in string) string { +func makeValidPrometheusMetricLabel(in string) string { // this isn't perfect, but it removes our common characters return strings.NewReplacer("/", "_", ".", "_", "-", "_", ":", "_").Replace(in) } @@ -302,12 +302,12 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error { default: } - timemoutseconds := int64(minWatchTimeout.Seconds() * (rand.Float64() + 1.0)) + timeoutSeconds := int64(minWatchTimeout.Seconds() * (rand.Float64() + 1.0)) options = metav1.ListOptions{ ResourceVersion: resourceVersion, // We want to avoid situations of hanging watchers. Stop any wachers that do not // receive any events within the timeout window. - TimeoutSeconds: &timemoutseconds, + TimeoutSeconds: &timeoutSeconds, } r.metrics.numberOfWatches.Inc() diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/reflector_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/reflector_test.go new file mode 100644 index 00000000..bb06059f --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/reflector_test.go @@ -0,0 +1,389 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "errors" + "fmt" + "math/rand" + "strconv" + "testing" + "time" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apimachinery/pkg/watch" +) + +var nevererrc chan error + +type testLW struct { + ListFunc func(options metav1.ListOptions) (runtime.Object, error) + WatchFunc func(options metav1.ListOptions) (watch.Interface, error) +} + +func (t *testLW) List(options metav1.ListOptions) (runtime.Object, error) { + return t.ListFunc(options) +} +func (t *testLW) Watch(options metav1.ListOptions) (watch.Interface, error) { + return t.WatchFunc(options) +} + +func TestCloseWatchChannelOnError(t *testing.T) { + r := NewReflector(&testLW{}, &v1.Pod{}, NewStore(MetaNamespaceKeyFunc), 0) + pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar"}} + fw := watch.NewFake() + r.listerWatcher = &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + return fw, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil + }, + } + go r.ListAndWatch(wait.NeverStop) + fw.Error(pod) + select { + case _, ok := <-fw.ResultChan(): + if ok { + t.Errorf("Watch channel left open after cancellation") + } + case <-time.After(wait.ForeverTestTimeout): + t.Errorf("the cancellation is at least %s late", wait.ForeverTestTimeout.String()) + break + } +} + +func TestRunUntil(t *testing.T) { + stopCh := make(chan struct{}) + store := NewStore(MetaNamespaceKeyFunc) + r := NewReflector(&testLW{}, &v1.Pod{}, store, 0) + fw := watch.NewFake() + r.listerWatcher = &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + return fw, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil + }, + } + go r.Run(stopCh) + // Synchronously add a dummy pod into the watch channel so we + // know the RunUntil go routine is in the watch handler. + fw.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar"}}) + close(stopCh) + select { + case _, ok := <-fw.ResultChan(): + if ok { + t.Errorf("Watch channel left open after stopping the watch") + } + case <-time.After(wait.ForeverTestTimeout): + t.Errorf("the cancellation is at least %s late", wait.ForeverTestTimeout.String()) + break + } +} + +func TestReflectorResyncChan(t *testing.T) { + s := NewStore(MetaNamespaceKeyFunc) + g := NewReflector(&testLW{}, &v1.Pod{}, s, time.Millisecond) + a, _ := g.resyncChan() + b := time.After(wait.ForeverTestTimeout) + select { + case <-a: + t.Logf("got timeout as expected") + case <-b: + t.Errorf("resyncChan() is at least 99 milliseconds late??") + } +} + +func BenchmarkReflectorResyncChanMany(b *testing.B) { + s := NewStore(MetaNamespaceKeyFunc) + g := NewReflector(&testLW{}, &v1.Pod{}, s, 25*time.Millisecond) + // The improvement to this (calling the timer's Stop() method) makes + // this benchmark about 40% faster. + for i := 0; i < b.N; i++ { + g.resyncPeriod = time.Duration(rand.Float64() * float64(time.Millisecond) * 25) + _, stop := g.resyncChan() + stop() + } +} + +func TestReflectorWatchHandlerError(t *testing.T) { + s := NewStore(MetaNamespaceKeyFunc) + g := NewReflector(&testLW{}, &v1.Pod{}, s, 0) + fw := watch.NewFake() + go func() { + fw.Stop() + }() + var resumeRV string + err := g.watchHandler(fw, &resumeRV, nevererrc, wait.NeverStop) + if err == nil { + t.Errorf("unexpected non-error") + } +} + +func TestReflectorWatchHandler(t *testing.T) { + s := NewStore(MetaNamespaceKeyFunc) + g := NewReflector(&testLW{}, &v1.Pod{}, s, 0) + fw := watch.NewFake() + s.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}) + s.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar"}}) + go func() { + fw.Add(&v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "rejected"}}) + fw.Delete(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}) + fw.Modify(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar", ResourceVersion: "55"}}) + fw.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "baz", ResourceVersion: "32"}}) + fw.Stop() + }() + var resumeRV string + err := g.watchHandler(fw, &resumeRV, nevererrc, wait.NeverStop) + if err != nil { + t.Errorf("unexpected error %v", err) + } + + mkPod := func(id string, rv string) *v1.Pod { + return &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: id, ResourceVersion: rv}} + } + + table := []struct { + Pod *v1.Pod + exists bool + }{ + {mkPod("foo", ""), false}, + {mkPod("rejected", ""), false}, + {mkPod("bar", "55"), true}, + {mkPod("baz", "32"), true}, + } + for _, item := range table { + obj, exists, _ := s.Get(item.Pod) + if e, a := item.exists, exists; e != a { + t.Errorf("%v: expected %v, got %v", item.Pod, e, a) + } + if !exists { + continue + } + if e, a := item.Pod.ResourceVersion, obj.(*v1.Pod).ResourceVersion; e != a { + t.Errorf("%v: expected %v, got %v", item.Pod, e, a) + } + } + + // RV should send the last version we see. + if e, a := "32", resumeRV; e != a { + t.Errorf("expected %v, got %v", e, a) + } + + // last sync resource version should be the last version synced with store + if e, a := "32", g.LastSyncResourceVersion(); e != a { + t.Errorf("expected %v, got %v", e, a) + } +} + +func TestReflectorStopWatch(t *testing.T) { + s := NewStore(MetaNamespaceKeyFunc) + g := NewReflector(&testLW{}, &v1.Pod{}, s, 0) + fw := watch.NewFake() + var resumeRV string + stopWatch := make(chan struct{}, 1) + stopWatch <- struct{}{} + err := g.watchHandler(fw, &resumeRV, nevererrc, stopWatch) + if err != errorStopRequested { + t.Errorf("expected stop error, got %q", err) + } +} + +func TestReflectorListAndWatch(t *testing.T) { + createdFakes := make(chan *watch.FakeWatcher) + + // The ListFunc says that it's at revision 1. Therefore, we expect our WatchFunc + // to get called at the beginning of the watch with 1, and again with 3 when we + // inject an error. + expectedRVs := []string{"1", "3"} + lw := &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + rv := options.ResourceVersion + fw := watch.NewFake() + if e, a := expectedRVs[0], rv; e != a { + t.Errorf("Expected rv %v, but got %v", e, a) + } + expectedRVs = expectedRVs[1:] + // channel is not buffered because the for loop below needs to block. But + // we don't want to block here, so report the new fake via a go routine. + go func() { createdFakes <- fw }() + return fw, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil + }, + } + s := NewFIFO(MetaNamespaceKeyFunc) + r := NewReflector(lw, &v1.Pod{}, s, 0) + go r.ListAndWatch(wait.NeverStop) + + ids := []string{"foo", "bar", "baz", "qux", "zoo"} + var fw *watch.FakeWatcher + for i, id := range ids { + if fw == nil { + fw = <-createdFakes + } + sendingRV := strconv.FormatUint(uint64(i+2), 10) + fw.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: id, ResourceVersion: sendingRV}}) + if sendingRV == "3" { + // Inject a failure. + fw.Stop() + fw = nil + } + } + + // Verify we received the right ids with the right resource versions. + for i, id := range ids { + pod := Pop(s).(*v1.Pod) + if e, a := id, pod.Name; e != a { + t.Errorf("%v: Expected %v, got %v", i, e, a) + } + if e, a := strconv.FormatUint(uint64(i+2), 10), pod.ResourceVersion; e != a { + t.Errorf("%v: Expected %v, got %v", i, e, a) + } + } + + if len(expectedRVs) != 0 { + t.Error("called watchStarter an unexpected number of times") + } +} + +func TestReflectorListAndWatchWithErrors(t *testing.T) { + mkPod := func(id string, rv string) *v1.Pod { + return &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: id, ResourceVersion: rv}} + } + mkList := func(rv string, pods ...*v1.Pod) *v1.PodList { + list := &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: rv}} + for _, pod := range pods { + list.Items = append(list.Items, *pod) + } + return list + } + table := []struct { + list *v1.PodList + listErr error + events []watch.Event + watchErr error + }{ + { + list: mkList("1"), + events: []watch.Event{ + {Type: watch.Added, Object: mkPod("foo", "2")}, + {Type: watch.Added, Object: mkPod("bar", "3")}, + }, + }, { + list: mkList("3", mkPod("foo", "2"), mkPod("bar", "3")), + events: []watch.Event{ + {Type: watch.Deleted, Object: mkPod("foo", "4")}, + {Type: watch.Added, Object: mkPod("qux", "5")}, + }, + }, { + listErr: fmt.Errorf("a list error"), + }, { + list: mkList("5", mkPod("bar", "3"), mkPod("qux", "5")), + watchErr: fmt.Errorf("a watch error"), + }, { + list: mkList("5", mkPod("bar", "3"), mkPod("qux", "5")), + events: []watch.Event{ + {Type: watch.Added, Object: mkPod("baz", "6")}, + }, + }, { + list: mkList("6", mkPod("bar", "3"), mkPod("qux", "5"), mkPod("baz", "6")), + }, + } + + s := NewFIFO(MetaNamespaceKeyFunc) + for line, item := range table { + if item.list != nil { + // Test that the list is what currently exists in the store. + current := s.List() + checkMap := map[string]string{} + for _, item := range current { + pod := item.(*v1.Pod) + checkMap[pod.Name] = pod.ResourceVersion + } + for _, pod := range item.list.Items { + if e, a := pod.ResourceVersion, checkMap[pod.Name]; e != a { + t.Errorf("%v: expected %v, got %v for pod %v", line, e, a, pod.Name) + } + } + if e, a := len(item.list.Items), len(checkMap); e != a { + t.Errorf("%v: expected %v, got %v", line, e, a) + } + } + watchRet, watchErr := item.events, item.watchErr + lw := &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if watchErr != nil { + return nil, watchErr + } + watchErr = fmt.Errorf("second watch") + fw := watch.NewFake() + go func() { + for _, e := range watchRet { + fw.Action(e.Type, e.Object) + } + fw.Stop() + }() + return fw, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return item.list, item.listErr + }, + } + r := NewReflector(lw, &v1.Pod{}, s, 0) + r.ListAndWatch(wait.NeverStop) + } +} + +func TestReflectorResync(t *testing.T) { + iteration := 0 + stopCh := make(chan struct{}) + rerr := errors.New("expected resync reached") + s := &FakeCustomStore{ + ResyncFunc: func() error { + iteration++ + if iteration == 2 { + return rerr + } + return nil + }, + } + + lw := &testLW{ + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + fw := watch.NewFake() + return fw, nil + }, + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "0"}}, nil + }, + } + resyncPeriod := 1 * time.Millisecond + r := NewReflector(lw, &v1.Pod{}, s, resyncPeriod) + if err := r.ListAndWatch(stopCh); err != nil { + // error from Resync is not propaged up to here. + t.Errorf("expected error %v", err) + } + if iteration != 2 { + t.Errorf("exactly 2 iterations were expected, got: %v", iteration) + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer.go b/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer.go index b11f0ebd..5f8c507f 100644 --- a/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer.go +++ b/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer.go @@ -26,6 +26,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/buffer" + "k8s.io/client-go/util/retry" "github.com/golang/glog" ) @@ -188,7 +189,7 @@ type deleteNotification struct { func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() - fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, nil, s.indexer) + fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, s.indexer) cfg := &Config{ Queue: fifo, @@ -334,7 +335,7 @@ func (s *sharedIndexInformer) AddEventHandlerWithResyncPeriod(handler ResourceEv s.blockDeltas.Lock() defer s.blockDeltas.Unlock() - s.processor.addAndStartListener(listener) + s.processor.addListener(listener) for _, item := range s.indexer.List() { listener.add(addNotification{newObj: item}) } @@ -372,6 +373,7 @@ func (s *sharedIndexInformer) HandleDeltas(obj interface{}) error { } type sharedProcessor struct { + listenersStarted bool listenersLock sync.RWMutex listeners []*processorListener syncingListeners []*processorListener @@ -379,20 +381,15 @@ type sharedProcessor struct { wg wait.Group } -func (p *sharedProcessor) addAndStartListener(listener *processorListener) { - p.listenersLock.Lock() - defer p.listenersLock.Unlock() - - p.addListenerLocked(listener) - p.wg.Start(listener.run) - p.wg.Start(listener.pop) -} - func (p *sharedProcessor) addListener(listener *processorListener) { p.listenersLock.Lock() defer p.listenersLock.Unlock() p.addListenerLocked(listener) + if p.listenersStarted { + p.wg.Start(listener.run) + p.wg.Start(listener.pop) + } } func (p *sharedProcessor) addListenerLocked(listener *processorListener) { @@ -423,6 +420,7 @@ func (p *sharedProcessor) run(stopCh <-chan struct{}) { p.wg.Start(listener.run) p.wg.Start(listener.pop) } + p.listenersStarted = true }() <-stopCh p.listenersLock.RLock() @@ -540,20 +538,35 @@ func (p *processorListener) pop() { } func (p *processorListener) run() { - defer utilruntime.HandleCrash() + // this call blocks until the channel is closed. When a panic happens during the notification + // we will catch it, **the offending item will be skipped!**, and after a short delay (one second) + // the next notification will be attempted. This is usually better than the alternative of never + // delivering again. + stopCh := make(chan struct{}) + wait.Until(func() { + // this gives us a few quick retries before a long pause and then a few more quick retries + err := wait.ExponentialBackoff(retry.DefaultRetry, func() (bool, error) { + for next := range p.nextCh { + switch notification := next.(type) { + case updateNotification: + p.handler.OnUpdate(notification.oldObj, notification.newObj) + case addNotification: + p.handler.OnAdd(notification.newObj) + case deleteNotification: + p.handler.OnDelete(notification.oldObj) + default: + utilruntime.HandleError(fmt.Errorf("unrecognized notification: %#v", next)) + } + } + // the only way to get here is if the p.nextCh is empty and closed + return true, nil + }) - for next := range p.nextCh { - switch notification := next.(type) { - case updateNotification: - p.handler.OnUpdate(notification.oldObj, notification.newObj) - case addNotification: - p.handler.OnAdd(notification.newObj) - case deleteNotification: - p.handler.OnDelete(notification.oldObj) - default: - utilruntime.HandleError(fmt.Errorf("unrecognized notification: %#v", next)) + // the only way to get here is if the p.nextCh is empty and closed + if err == nil { + close(stopCh) } - } + }, 1*time.Minute, stopCh) } // shouldResync deterimines if the listener needs a resync. If the listener's resyncPeriod is 0, diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer_test.go new file mode 100644 index 00000000..22e4a90d --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/shared_informer_test.go @@ -0,0 +1,265 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "fmt" + "sync" + "testing" + "time" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/apimachinery/pkg/util/wait" + fcache "k8s.io/client-go/tools/cache/testing" +) + +type testListener struct { + lock sync.RWMutex + resyncPeriod time.Duration + expectedItemNames sets.String + receivedItemNames []string + name string +} + +func newTestListener(name string, resyncPeriod time.Duration, expected ...string) *testListener { + l := &testListener{ + resyncPeriod: resyncPeriod, + expectedItemNames: sets.NewString(expected...), + name: name, + } + return l +} + +func (l *testListener) OnAdd(obj interface{}) { + l.handle(obj) +} + +func (l *testListener) OnUpdate(old, new interface{}) { + l.handle(new) +} + +func (l *testListener) OnDelete(obj interface{}) { +} + +func (l *testListener) handle(obj interface{}) { + key, _ := MetaNamespaceKeyFunc(obj) + fmt.Printf("%s: handle: %v\n", l.name, key) + l.lock.Lock() + defer l.lock.Unlock() + + objectMeta, _ := meta.Accessor(obj) + l.receivedItemNames = append(l.receivedItemNames, objectMeta.GetName()) +} + +func (l *testListener) ok() bool { + fmt.Println("polling") + err := wait.PollImmediate(100*time.Millisecond, 2*time.Second, func() (bool, error) { + if l.satisfiedExpectations() { + return true, nil + } + return false, nil + }) + if err != nil { + return false + } + + // wait just a bit to allow any unexpected stragglers to come in + fmt.Println("sleeping") + time.Sleep(1 * time.Second) + fmt.Println("final check") + return l.satisfiedExpectations() +} + +func (l *testListener) satisfiedExpectations() bool { + l.lock.RLock() + defer l.lock.RUnlock() + + return len(l.receivedItemNames) == l.expectedItemNames.Len() && sets.NewString(l.receivedItemNames...).Equal(l.expectedItemNames) +} + +func TestListenerResyncPeriods(t *testing.T) { + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + source.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1"}}) + source.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod2"}}) + + // create the shared informer and resync every 1s + informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer) + + clock := clock.NewFakeClock(time.Now()) + informer.clock = clock + informer.processor.clock = clock + + // listener 1, never resync + listener1 := newTestListener("listener1", 0, "pod1", "pod2") + informer.AddEventHandlerWithResyncPeriod(listener1, listener1.resyncPeriod) + + // listener 2, resync every 2s + listener2 := newTestListener("listener2", 2*time.Second, "pod1", "pod2") + informer.AddEventHandlerWithResyncPeriod(listener2, listener2.resyncPeriod) + + // listener 3, resync every 3s + listener3 := newTestListener("listener3", 3*time.Second, "pod1", "pod2") + informer.AddEventHandlerWithResyncPeriod(listener3, listener3.resyncPeriod) + listeners := []*testListener{listener1, listener2, listener3} + + stop := make(chan struct{}) + defer close(stop) + + go informer.Run(stop) + + // ensure all listeners got the initial List + for _, listener := range listeners { + if !listener.ok() { + t.Errorf("%s: expected %v, got %v", listener.name, listener.expectedItemNames, listener.receivedItemNames) + } + } + + // reset + for _, listener := range listeners { + listener.receivedItemNames = []string{} + } + + // advance so listener2 gets a resync + clock.Step(2 * time.Second) + + // make sure listener2 got the resync + if !listener2.ok() { + t.Errorf("%s: expected %v, got %v", listener2.name, listener2.expectedItemNames, listener2.receivedItemNames) + } + + // wait a bit to give errant items a chance to go to 1 and 3 + time.Sleep(1 * time.Second) + + // make sure listeners 1 and 3 got nothing + if len(listener1.receivedItemNames) != 0 { + t.Errorf("listener1: should not have resynced (got %d)", len(listener1.receivedItemNames)) + } + if len(listener3.receivedItemNames) != 0 { + t.Errorf("listener3: should not have resynced (got %d)", len(listener3.receivedItemNames)) + } + + // reset + for _, listener := range listeners { + listener.receivedItemNames = []string{} + } + + // advance so listener3 gets a resync + clock.Step(1 * time.Second) + + // make sure listener3 got the resync + if !listener3.ok() { + t.Errorf("%s: expected %v, got %v", listener3.name, listener3.expectedItemNames, listener3.receivedItemNames) + } + + // wait a bit to give errant items a chance to go to 1 and 2 + time.Sleep(1 * time.Second) + + // make sure listeners 1 and 2 got nothing + if len(listener1.receivedItemNames) != 0 { + t.Errorf("listener1: should not have resynced (got %d)", len(listener1.receivedItemNames)) + } + if len(listener2.receivedItemNames) != 0 { + t.Errorf("listener2: should not have resynced (got %d)", len(listener2.receivedItemNames)) + } +} + +func TestResyncCheckPeriod(t *testing.T) { + // source simulates an apiserver object endpoint. + source := fcache.NewFakeControllerSource() + + // create the shared informer and resync every 12 hours + informer := NewSharedInformer(source, &v1.Pod{}, 12*time.Hour).(*sharedIndexInformer) + + clock := clock.NewFakeClock(time.Now()) + informer.clock = clock + informer.processor.clock = clock + + // listener 1, never resync + listener1 := newTestListener("listener1", 0) + informer.AddEventHandlerWithResyncPeriod(listener1, listener1.resyncPeriod) + if e, a := 12*time.Hour, informer.resyncCheckPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + + // listener 2, resync every minute + listener2 := newTestListener("listener2", 1*time.Minute) + informer.AddEventHandlerWithResyncPeriod(listener2, listener2.resyncPeriod) + if e, a := 1*time.Minute, informer.resyncCheckPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 1*time.Minute, informer.processor.listeners[1].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + + // listener 3, resync every 55 seconds + listener3 := newTestListener("listener3", 55*time.Second) + informer.AddEventHandlerWithResyncPeriod(listener3, listener3.resyncPeriod) + if e, a := 55*time.Second, informer.resyncCheckPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 1*time.Minute, informer.processor.listeners[1].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 55*time.Second, informer.processor.listeners[2].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + + // listener 4, resync every 5 seconds + listener4 := newTestListener("listener4", 5*time.Second) + informer.AddEventHandlerWithResyncPeriod(listener4, listener4.resyncPeriod) + if e, a := 5*time.Second, informer.resyncCheckPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 1*time.Minute, informer.processor.listeners[1].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 55*time.Second, informer.processor.listeners[2].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } + if e, a := 5*time.Second, informer.processor.listeners[3].resyncPeriod; e != a { + t.Errorf("expected %d, got %d", e, a) + } +} + +// verify that https://github.com/kubernetes/kubernetes/issues/59822 is fixed +func TestSharedInformerInitializationRace(t *testing.T) { + source := fcache.NewFakeControllerSource() + informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer) + listener := newTestListener("raceListener", 0) + + stop := make(chan struct{}) + go informer.AddEventHandlerWithResyncPeriod(listener, listener.resyncPeriod) + go informer.Run(stop) + close(stop) +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/store_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/store_test.go new file mode 100644 index 00000000..52c9585a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/store_test.go @@ -0,0 +1,156 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "testing" + + "k8s.io/apimachinery/pkg/util/sets" +) + +// Test public interface +func doTestStore(t *testing.T, store Store) { + mkObj := func(id string, val string) testStoreObject { + return testStoreObject{id: id, val: val} + } + + store.Add(mkObj("foo", "bar")) + if item, ok, _ := store.Get(mkObj("foo", "")); !ok { + t.Errorf("didn't find inserted item") + } else { + if e, a := "bar", item.(testStoreObject).val; e != a { + t.Errorf("expected %v, got %v", e, a) + } + } + store.Update(mkObj("foo", "baz")) + if item, ok, _ := store.Get(mkObj("foo", "")); !ok { + t.Errorf("didn't find inserted item") + } else { + if e, a := "baz", item.(testStoreObject).val; e != a { + t.Errorf("expected %v, got %v", e, a) + } + } + store.Delete(mkObj("foo", "")) + if _, ok, _ := store.Get(mkObj("foo", "")); ok { + t.Errorf("found deleted item??") + } + + // Test List. + store.Add(mkObj("a", "b")) + store.Add(mkObj("c", "d")) + store.Add(mkObj("e", "e")) + { + found := sets.String{} + for _, item := range store.List() { + found.Insert(item.(testStoreObject).val) + } + if !found.HasAll("b", "d", "e") { + t.Errorf("missing items, found: %v", found) + } + if len(found) != 3 { + t.Errorf("extra items") + } + } + + // Test Replace. + store.Replace([]interface{}{ + mkObj("foo", "foo"), + mkObj("bar", "bar"), + }, "0") + + { + found := sets.String{} + for _, item := range store.List() { + found.Insert(item.(testStoreObject).val) + } + if !found.HasAll("foo", "bar") { + t.Errorf("missing items") + } + if len(found) != 2 { + t.Errorf("extra items") + } + } +} + +// Test public interface +func doTestIndex(t *testing.T, indexer Indexer) { + mkObj := func(id string, val string) testStoreObject { + return testStoreObject{id: id, val: val} + } + + // Test Index + expected := map[string]sets.String{} + expected["b"] = sets.NewString("a", "c") + expected["f"] = sets.NewString("e") + expected["h"] = sets.NewString("g") + indexer.Add(mkObj("a", "b")) + indexer.Add(mkObj("c", "b")) + indexer.Add(mkObj("e", "f")) + indexer.Add(mkObj("g", "h")) + { + for k, v := range expected { + found := sets.String{} + indexResults, err := indexer.Index("by_val", mkObj("", k)) + if err != nil { + t.Errorf("Unexpected error %v", err) + } + for _, item := range indexResults { + found.Insert(item.(testStoreObject).id) + } + items := v.List() + if !found.HasAll(items...) { + t.Errorf("missing items, index %s, expected %v but found %v", k, items, found.List()) + } + } + } +} + +func testStoreKeyFunc(obj interface{}) (string, error) { + return obj.(testStoreObject).id, nil +} + +func testStoreIndexFunc(obj interface{}) ([]string, error) { + return []string{obj.(testStoreObject).val}, nil +} + +func testStoreIndexers() Indexers { + indexers := Indexers{} + indexers["by_val"] = testStoreIndexFunc + return indexers +} + +type testStoreObject struct { + id string + val string +} + +func TestCache(t *testing.T) { + doTestStore(t, NewStore(testStoreKeyFunc)) +} + +func TestFIFOCache(t *testing.T) { + doTestStore(t, NewFIFO(testStoreKeyFunc)) +} + +func TestUndeltaStore(t *testing.T) { + nop := func([]interface{}) {} + doTestStore(t, NewUndeltaStore(nop, testStoreKeyFunc)) +} + +func TestIndex(t *testing.T) { + doTestIndex(t, NewIndexer(testStoreKeyFunc, testStoreIndexers())) +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/testing/BUILD b/discovery/vendor/k8s.io/client-go/tools/cache/testing/BUILD new file mode 100644 index 00000000..d1658af4 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/testing/BUILD @@ -0,0 +1,45 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = ["fake_controller_source_test.go"], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = ["fake_controller_source.go"], + importpath = "k8s.io/client-go/tools/cache/testing", + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/types:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/testing/fake_controller_source_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/testing/fake_controller_source_test.go new file mode 100644 index 00000000..e5097c7a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/testing/fake_controller_source_test.go @@ -0,0 +1,95 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package framework + +import ( + "sync" + "testing" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" +) + +// ensure the watch delivers the requested and only the requested items. +func consume(t *testing.T, w watch.Interface, rvs []string, done *sync.WaitGroup) { + defer done.Done() + for _, rv := range rvs { + got, ok := <-w.ResultChan() + if !ok { + t.Errorf("%#v: unexpected channel close, wanted %v", rvs, rv) + return + } + gotRV := got.Object.(*v1.Pod).ObjectMeta.ResourceVersion + if e, a := rv, gotRV; e != a { + t.Errorf("wanted %v, got %v", e, a) + } else { + t.Logf("Got %v as expected", gotRV) + } + } + // We should not get anything else. + got, open := <-w.ResultChan() + if open { + t.Errorf("%#v: unwanted object %#v", rvs, got) + } +} + +func TestRCNumber(t *testing.T) { + pod := func(name string) *v1.Pod { + return &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + } + } + + wg := &sync.WaitGroup{} + wg.Add(3) + + source := NewFakeControllerSource() + source.Add(pod("foo")) + source.Modify(pod("foo")) + source.Modify(pod("foo")) + + w, err := source.Watch(metav1.ListOptions{ResourceVersion: "1"}) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + go consume(t, w, []string{"2", "3"}, wg) + + list, err := source.List(metav1.ListOptions{}) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + if e, a := "3", list.(*v1.List).ResourceVersion; e != a { + t.Errorf("wanted %v, got %v", e, a) + } + + w2, err := source.Watch(metav1.ListOptions{ResourceVersion: "2"}) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + go consume(t, w2, []string{"3"}, wg) + + w3, err := source.Watch(metav1.ListOptions{ResourceVersion: "3"}) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + go consume(t, w3, []string{}, wg) + source.Shutdown() + wg.Wait() +} diff --git a/discovery/vendor/k8s.io/client-go/tools/cache/undelta_store_test.go b/discovery/vendor/k8s.io/client-go/tools/cache/undelta_store_test.go new file mode 100644 index 00000000..6316442e --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/cache/undelta_store_test.go @@ -0,0 +1,131 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cache + +import ( + "reflect" + "testing" +) + +// store_test.go checks that UndeltaStore conforms to the Store interface +// behavior. This test just tests that it calls the push func in addition. + +type testUndeltaObject struct { + name string + val interface{} +} + +func testUndeltaKeyFunc(obj interface{}) (string, error) { + return obj.(testUndeltaObject).name, nil +} + +/* +var ( + o1 interface{} = t{1} + o2 interface{} = t{2} + l1 []interface{} = []interface{}{t{1}} +) +*/ + +func TestUpdateCallsPush(t *testing.T) { + mkObj := func(name string, val interface{}) testUndeltaObject { + return testUndeltaObject{name: name, val: val} + } + + var got []interface{} + var callcount int = 0 + push := func(m []interface{}) { + callcount++ + got = m + } + + u := NewUndeltaStore(push, testUndeltaKeyFunc) + + u.Add(mkObj("a", 2)) + u.Update(mkObj("a", 1)) + if callcount != 2 { + t.Errorf("Expected 2 calls, got %d", callcount) + } + + l := []interface{}{mkObj("a", 1)} + if !reflect.DeepEqual(l, got) { + t.Errorf("Expected %#v, Got %#v", l, got) + } +} + +func TestDeleteCallsPush(t *testing.T) { + mkObj := func(name string, val interface{}) testUndeltaObject { + return testUndeltaObject{name: name, val: val} + } + + var got []interface{} + var callcount int = 0 + push := func(m []interface{}) { + callcount++ + got = m + } + + u := NewUndeltaStore(push, testUndeltaKeyFunc) + + u.Add(mkObj("a", 2)) + u.Delete(mkObj("a", "")) + if callcount != 2 { + t.Errorf("Expected 2 calls, got %d", callcount) + } + expected := []interface{}{} + if !reflect.DeepEqual(expected, got) { + t.Errorf("Expected %#v, Got %#v", expected, got) + } +} + +func TestReadsDoNotCallPush(t *testing.T) { + push := func(m []interface{}) { + t.Errorf("Unexpected call to push!") + } + + u := NewUndeltaStore(push, testUndeltaKeyFunc) + + // These should not call push. + _ = u.List() + _, _, _ = u.Get(testUndeltaObject{"a", ""}) +} + +func TestReplaceCallsPush(t *testing.T) { + mkObj := func(name string, val interface{}) testUndeltaObject { + return testUndeltaObject{name: name, val: val} + } + + var got []interface{} + var callcount int = 0 + push := func(m []interface{}) { + callcount++ + got = m + } + + u := NewUndeltaStore(push, testUndeltaKeyFunc) + + m := []interface{}{mkObj("a", 1)} + + u.Replace(m, "0") + if callcount != 1 { + t.Errorf("Expected 1 calls, got %d", callcount) + } + expected := []interface{}{mkObj("a", 1)} + if !reflect.DeepEqual(expected, got) { + t.Errorf("Expected %#v, Got %#v", expected, got) + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/BUILD b/discovery/vendor/k8s.io/client-go/tools/clientcmd/BUILD new file mode 100644 index 00000000..c46c76d5 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/BUILD @@ -0,0 +1,78 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "client_config_test.go", + "loader_test.go", + "merged_client_builder_test.go", + "overrides_test.go", + "validation_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//vendor/github.com/ghodss/yaml:go_default_library", + "//vendor/github.com/imdario/mergo:go_default_library", + "//vendor/github.com/spf13/pflag:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api/latest:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "auth_loaders.go", + "client_config.go", + "config.go", + "doc.go", + "flag.go", + "helpers.go", + "loader.go", + "merged_client_builder.go", + "overrides.go", + "validation.go", + ], + importpath = "k8s.io/client-go/tools/clientcmd", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/github.com/howeyc/gopass:go_default_library", + "//vendor/github.com/imdario/mergo:go_default_library", + "//vendor/github.com/spf13/pflag:go_default_library", + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/validation:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/tools/auth:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api/latest:go_default_library", + "//vendor/k8s.io/client-go/util/homedir:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/tools/clientcmd/api:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/BUILD b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/BUILD new file mode 100644 index 00000000..b2fd1382 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/BUILD @@ -0,0 +1,50 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "helpers_test.go", + "types_test.go", + ], + embed = [":go_default_library"], + deps = ["//vendor/github.com/ghodss/yaml:go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "helpers.go", + "register.go", + "types.go", + "zz_generated.deepcopy.go", + ], + importpath = "k8s.io/client-go/tools/clientcmd/api", + deps = [ + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/tools/clientcmd/api/latest:all-srcs", + "//staging/src/k8s.io/client-go/tools/clientcmd/api/v1:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/helpers_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/helpers_test.go new file mode 100644 index 00000000..43020845 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/helpers_test.go @@ -0,0 +1,301 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "fmt" + "io/ioutil" + "os" + "reflect" + "testing" + + "github.com/ghodss/yaml" +) + +func newMergedConfig(certFile, certContent, keyFile, keyContent, caFile, caContent string, t *testing.T) Config { + if err := ioutil.WriteFile(certFile, []byte(certContent), 0644); err != nil { + t.Errorf("unexpected error: %v", err) + } + if err := ioutil.WriteFile(keyFile, []byte(keyContent), 0600); err != nil { + t.Errorf("unexpected error: %v", err) + } + if err := ioutil.WriteFile(caFile, []byte(caContent), 0644); err != nil { + t.Errorf("unexpected error: %v", err) + } + + return Config{ + AuthInfos: map[string]*AuthInfo{ + "red-user": {Token: "red-token", ClientCertificateData: []byte(certContent), ClientKeyData: []byte(keyContent)}, + "blue-user": {Token: "blue-token", ClientCertificate: certFile, ClientKey: keyFile}}, + Clusters: map[string]*Cluster{ + "cow-cluster": {Server: "http://cow.org:8080", CertificateAuthorityData: []byte(caContent)}, + "chicken-cluster": {Server: "http://chicken.org:8080", CertificateAuthority: caFile}}, + Contexts: map[string]*Context{ + "federal-context": {AuthInfo: "red-user", Cluster: "cow-cluster"}, + "shaker-context": {AuthInfo: "blue-user", Cluster: "chicken-cluster"}}, + CurrentContext: "federal-context", + } +} + +func TestMinifySuccess(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + mutatingConfig := newMergedConfig(certFile.Name(), "cert", keyFile.Name(), "key", caFile.Name(), "ca", t) + + if err := MinifyConfig(&mutatingConfig); err != nil { + t.Errorf("unexpected error: %v", err) + } + + if len(mutatingConfig.Contexts) > 1 { + t.Errorf("unexpected contexts: %v", mutatingConfig.Contexts) + } + if _, exists := mutatingConfig.Contexts["federal-context"]; !exists { + t.Errorf("missing context") + } + + if len(mutatingConfig.Clusters) > 1 { + t.Errorf("unexpected clusters: %v", mutatingConfig.Clusters) + } + if _, exists := mutatingConfig.Clusters["cow-cluster"]; !exists { + t.Errorf("missing cluster") + } + + if len(mutatingConfig.AuthInfos) > 1 { + t.Errorf("unexpected users: %v", mutatingConfig.AuthInfos) + } + if _, exists := mutatingConfig.AuthInfos["red-user"]; !exists { + t.Errorf("missing user") + } +} + +func TestMinifyMissingContext(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + mutatingConfig := newMergedConfig(certFile.Name(), "cert", keyFile.Name(), "key", caFile.Name(), "ca", t) + mutatingConfig.CurrentContext = "missing" + + errMsg := "cannot locate context missing" + + if err := MinifyConfig(&mutatingConfig); err == nil || err.Error() != errMsg { + t.Errorf("expected %v, got %v", errMsg, err) + } +} + +func TestMinifyMissingCluster(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + mutatingConfig := newMergedConfig(certFile.Name(), "cert", keyFile.Name(), "key", caFile.Name(), "ca", t) + delete(mutatingConfig.Clusters, mutatingConfig.Contexts[mutatingConfig.CurrentContext].Cluster) + + errMsg := "cannot locate cluster cow-cluster" + + if err := MinifyConfig(&mutatingConfig); err == nil || err.Error() != errMsg { + t.Errorf("expected %v, got %v", errMsg, err) + } +} + +func TestMinifyMissingAuthInfo(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + mutatingConfig := newMergedConfig(certFile.Name(), "cert", keyFile.Name(), "key", caFile.Name(), "ca", t) + delete(mutatingConfig.AuthInfos, mutatingConfig.Contexts[mutatingConfig.CurrentContext].AuthInfo) + + errMsg := "cannot locate user red-user" + + if err := MinifyConfig(&mutatingConfig); err == nil || err.Error() != errMsg { + t.Errorf("expected %v, got %v", errMsg, err) + } +} + +func TestFlattenSuccess(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + certData := "cert" + keyData := "key" + caData := "ca" + + unchangingCluster := "cow-cluster" + unchangingAuthInfo := "red-user" + changingCluster := "chicken-cluster" + changingAuthInfo := "blue-user" + + startingConfig := newMergedConfig(certFile.Name(), certData, keyFile.Name(), keyData, caFile.Name(), caData, t) + mutatingConfig := startingConfig + + if err := FlattenConfig(&mutatingConfig); err != nil { + t.Errorf("unexpected error: %v", err) + } + + if len(mutatingConfig.Contexts) != 2 { + t.Errorf("unexpected contexts: %v", mutatingConfig.Contexts) + } + if !reflect.DeepEqual(startingConfig.Contexts, mutatingConfig.Contexts) { + t.Errorf("expected %v, got %v", startingConfig.Contexts, mutatingConfig.Contexts) + } + + if len(mutatingConfig.Clusters) != 2 { + t.Errorf("unexpected clusters: %v", mutatingConfig.Clusters) + } + if !reflect.DeepEqual(startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) { + t.Errorf("expected %v, got %v", startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) + } + if len(mutatingConfig.Clusters[changingCluster].CertificateAuthority) != 0 { + t.Errorf("unexpected caFile") + } + if string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData) != caData { + t.Errorf("expected %v, got %v", caData, string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData)) + } + + if len(mutatingConfig.AuthInfos) != 2 { + t.Errorf("unexpected users: %v", mutatingConfig.AuthInfos) + } + if !reflect.DeepEqual(startingConfig.AuthInfos[unchangingAuthInfo], mutatingConfig.AuthInfos[unchangingAuthInfo]) { + t.Errorf("expected %v, got %v", startingConfig.AuthInfos[unchangingAuthInfo], mutatingConfig.AuthInfos[unchangingAuthInfo]) + } + if len(mutatingConfig.AuthInfos[changingAuthInfo].ClientCertificate) != 0 { + t.Errorf("unexpected caFile") + } + if string(mutatingConfig.AuthInfos[changingAuthInfo].ClientCertificateData) != certData { + t.Errorf("expected %v, got %v", certData, string(mutatingConfig.AuthInfos[changingAuthInfo].ClientCertificateData)) + } + if len(mutatingConfig.AuthInfos[changingAuthInfo].ClientKey) != 0 { + t.Errorf("unexpected caFile") + } + if string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData) != keyData { + t.Errorf("expected %v, got %v", keyData, string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData)) + } + +} + +func Example_minifyAndShorten() { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + certData := "cert" + keyData := "key" + caData := "ca" + + config := newMergedConfig(certFile.Name(), certData, keyFile.Name(), keyData, caFile.Name(), caData, nil) + + MinifyConfig(&config) + ShortenConfig(&config) + + output, _ := yaml.Marshal(config) + fmt.Printf("%s", string(output)) + // Output: + // clusters: + // cow-cluster: + // LocationOfOrigin: "" + // certificate-authority-data: REDACTED + // server: http://cow.org:8080 + // contexts: + // federal-context: + // LocationOfOrigin: "" + // cluster: cow-cluster + // user: red-user + // current-context: federal-context + // preferences: {} + // users: + // red-user: + // LocationOfOrigin: "" + // client-certificate-data: REDACTED + // client-key-data: REDACTED + // token: red-token +} + +func TestShortenSuccess(t *testing.T) { + certFile, _ := ioutil.TempFile("", "") + defer os.Remove(certFile.Name()) + keyFile, _ := ioutil.TempFile("", "") + defer os.Remove(keyFile.Name()) + caFile, _ := ioutil.TempFile("", "") + defer os.Remove(caFile.Name()) + + certData := "cert" + keyData := "key" + caData := "ca" + + unchangingCluster := "chicken-cluster" + unchangingAuthInfo := "blue-user" + changingCluster := "cow-cluster" + changingAuthInfo := "red-user" + + startingConfig := newMergedConfig(certFile.Name(), certData, keyFile.Name(), keyData, caFile.Name(), caData, t) + mutatingConfig := startingConfig + + ShortenConfig(&mutatingConfig) + + if len(mutatingConfig.Contexts) != 2 { + t.Errorf("unexpected contexts: %v", mutatingConfig.Contexts) + } + if !reflect.DeepEqual(startingConfig.Contexts, mutatingConfig.Contexts) { + t.Errorf("expected %v, got %v", startingConfig.Contexts, mutatingConfig.Contexts) + } + + redacted := string(redactedBytes) + if len(mutatingConfig.Clusters) != 2 { + t.Errorf("unexpected clusters: %v", mutatingConfig.Clusters) + } + if !reflect.DeepEqual(startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) { + t.Errorf("expected %v, got %v", startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) + } + if string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData) != redacted { + t.Errorf("expected %v, got %v", redacted, string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData)) + } + + if len(mutatingConfig.AuthInfos) != 2 { + t.Errorf("unexpected users: %v", mutatingConfig.AuthInfos) + } + if !reflect.DeepEqual(startingConfig.AuthInfos[unchangingAuthInfo], mutatingConfig.AuthInfos[unchangingAuthInfo]) { + t.Errorf("expected %v, got %v", startingConfig.AuthInfos[unchangingAuthInfo], mutatingConfig.AuthInfos[unchangingAuthInfo]) + } + if string(mutatingConfig.AuthInfos[changingAuthInfo].ClientCertificateData) != redacted { + t.Errorf("expected %v, got %v", redacted, string(mutatingConfig.AuthInfos[changingAuthInfo].ClientCertificateData)) + } + if string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData) != redacted { + t.Errorf("expected %v, got %v", redacted, string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData)) + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/latest/BUILD b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/latest/BUILD new file mode 100644 index 00000000..308319e2 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/latest/BUILD @@ -0,0 +1,33 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["latest.go"], + importpath = "k8s.io/client-go/tools/clientcmd/api/latest", + deps = [ + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api/v1:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types.go index 407dec83..1391df70 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types.go @@ -119,6 +119,9 @@ type AuthInfo struct { // AuthProvider specifies a custom authentication plugin for the kubernetes cluster. // +optional AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"` + // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster. + // +optional + Exec *ExecConfig `json:"exec,omitempty"` // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields // +optional Extensions map[string]runtime.Object `json:"extensions,omitempty"` @@ -147,6 +150,35 @@ type AuthProviderConfig struct { Config map[string]string `json:"config,omitempty"` } +// ExecConfig specifies a command to provide client credentials. The command is exec'd +// and outputs structured stdout holding credentials. +// +// See the client.authentiction.k8s.io API group for specifications of the exact input +// and output format +type ExecConfig struct { + // Command to execute. + Command string `json:"command"` + // Arguments to pass to the command when executing it. + // +optional + Args []string `json:"args"` + // Env defines additional environment variables to expose to the process. These + // are unioned with the host's environment, as well as variables client-go uses + // to pass argument to the plugin. + // +optional + Env []ExecEnvVar `json:"env"` + + // Preferred input version of the ExecInfo. The returned ExecCredentials MUST use + // the same encoding version as the input. + APIVersion string `json:"apiVersion,omitempty"` +} + +// ExecEnvVar is used for setting environment variables when executing an exec-based +// credential plugin. +type ExecEnvVar struct { + Name string `json:"name"` + Value string `json:"value"` +} + // NewConfig is a convenience function that returns a new Config object with non-nil maps func NewConfig() *Config { return &Config{ diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types_test.go new file mode 100644 index 00000000..bd348345 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/types_test.go @@ -0,0 +1,135 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "fmt" + + "github.com/ghodss/yaml" +) + +func Example_emptyConfig() { + defaultConfig := NewConfig() + + output, err := yaml.Marshal(defaultConfig) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + + fmt.Printf("%v", string(output)) + // Output: + // clusters: {} + // contexts: {} + // current-context: "" + // preferences: {} + // users: {} +} + +func Example_ofOptionsConfig() { + defaultConfig := NewConfig() + defaultConfig.Preferences.Colors = true + defaultConfig.Clusters["alfa"] = &Cluster{ + Server: "https://alfa.org:8080", + InsecureSkipTLSVerify: true, + CertificateAuthority: "path/to/my/cert-ca-filename", + } + defaultConfig.Clusters["bravo"] = &Cluster{ + Server: "https://bravo.org:8080", + InsecureSkipTLSVerify: false, + } + defaultConfig.AuthInfos["white-mage-via-cert"] = &AuthInfo{ + ClientCertificate: "path/to/my/client-cert-filename", + ClientKey: "path/to/my/client-key-filename", + } + defaultConfig.AuthInfos["red-mage-via-token"] = &AuthInfo{ + Token: "my-secret-token", + } + defaultConfig.AuthInfos["black-mage-via-auth-provider"] = &AuthInfo{ + AuthProvider: &AuthProviderConfig{ + Name: "gcp", + Config: map[string]string{ + "foo": "bar", + "token": "s3cr3t-t0k3n", + }, + }, + } + defaultConfig.Contexts["bravo-as-black-mage"] = &Context{ + Cluster: "bravo", + AuthInfo: "black-mage-via-auth-provider", + Namespace: "yankee", + } + defaultConfig.Contexts["alfa-as-black-mage"] = &Context{ + Cluster: "alfa", + AuthInfo: "black-mage-via-auth-provider", + Namespace: "zulu", + } + defaultConfig.Contexts["alfa-as-white-mage"] = &Context{ + Cluster: "alfa", + AuthInfo: "white-mage-via-cert", + } + defaultConfig.CurrentContext = "alfa-as-white-mage" + + output, err := yaml.Marshal(defaultConfig) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + + fmt.Printf("%v", string(output)) + // Output: + // clusters: + // alfa: + // LocationOfOrigin: "" + // certificate-authority: path/to/my/cert-ca-filename + // insecure-skip-tls-verify: true + // server: https://alfa.org:8080 + // bravo: + // LocationOfOrigin: "" + // server: https://bravo.org:8080 + // contexts: + // alfa-as-black-mage: + // LocationOfOrigin: "" + // cluster: alfa + // namespace: zulu + // user: black-mage-via-auth-provider + // alfa-as-white-mage: + // LocationOfOrigin: "" + // cluster: alfa + // user: white-mage-via-cert + // bravo-as-black-mage: + // LocationOfOrigin: "" + // cluster: bravo + // namespace: yankee + // user: black-mage-via-auth-provider + // current-context: alfa-as-white-mage + // preferences: + // colors: true + // users: + // black-mage-via-auth-provider: + // LocationOfOrigin: "" + // auth-provider: + // config: + // foo: bar + // token: s3cr3t-t0k3n + // name: gcp + // red-mage-via-token: + // LocationOfOrigin: "" + // token: my-secret-token + // white-mage-via-cert: + // LocationOfOrigin: "" + // client-certificate: path/to/my/client-cert-filename + // client-key: path/to/my/client-key-filename +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/BUILD b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/BUILD new file mode 100644 index 00000000..2b9daaf0 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/BUILD @@ -0,0 +1,37 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = [ + "conversion.go", + "doc.go", + "register.go", + "types.go", + "zz_generated.deepcopy.go", + ], + importpath = "k8s.io/client-go/tools/clientcmd/api/v1", + deps = [ + "//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/types.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/types.go index 53568135..56afb608 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/types.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/types.go @@ -113,6 +113,9 @@ type AuthInfo struct { // AuthProvider specifies a custom authentication plugin for the kubernetes cluster. // +optional AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"` + // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster. + // +optional + Exec *ExecConfig `json:"exec,omitempty"` // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields // +optional Extensions []NamedExtension `json:"extensions,omitempty"` @@ -169,3 +172,32 @@ type AuthProviderConfig struct { Name string `json:"name"` Config map[string]string `json:"config"` } + +// ExecConfig specifies a command to provide client credentials. The command is exec'd +// and outputs structured stdout holding credentials. +// +// See the client.authentiction.k8s.io API group for specifications of the exact input +// and output format +type ExecConfig struct { + // Command to execute. + Command string `json:"command"` + // Arguments to pass to the command when executing it. + // +optional + Args []string `json:"args"` + // Env defines additional environment variables to expose to the process. These + // are unioned with the host's environment, as well as variables client-go uses + // to pass argument to the plugin. + // +optional + Env []ExecEnvVar `json:"env"` + + // Preferred input version of the ExecInfo. The returned ExecCredentials MUST use + // the same encoding version as the input. + APIVersion string `json:"apiVersion,omitempty"` +} + +// ExecEnvVar is used for setting environment variables when executing an exec-based +// credential plugin. +type ExecEnvVar struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/zz_generated.deepcopy.go index 8d634671..83d05b7c 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/v1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2017 The Kubernetes Authors. +Copyright 2018 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 @@ -63,6 +63,15 @@ func (in *AuthInfo) DeepCopyInto(out *AuthInfo) { (*in).DeepCopyInto(*out) } } + if in.Exec != nil { + in, out := &in.Exec, &out.Exec + if *in == nil { + *out = nil + } else { + *out = new(ExecConfig) + (*in).DeepCopyInto(*out) + } + } if in.Extensions != nil { in, out := &in.Extensions, &out.Extensions *out = make([]NamedExtension, len(*in)) @@ -183,9 +192,8 @@ func (in *Config) DeepCopy() *Config { func (in *Config) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -211,6 +219,48 @@ func (in *Context) DeepCopy() *Context { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExecConfig) DeepCopyInto(out *ExecConfig) { + *out = *in + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]ExecEnvVar, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecConfig. +func (in *ExecConfig) DeepCopy() *ExecConfig { + if in == nil { + return nil + } + out := new(ExecConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExecEnvVar) DeepCopyInto(out *ExecEnvVar) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecEnvVar. +func (in *ExecEnvVar) DeepCopy() *ExecEnvVar { + if in == nil { + return nil + } + out := new(ExecEnvVar) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NamedAuthInfo) DeepCopyInto(out *NamedAuthInfo) { *out = *in diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/zz_generated.deepcopy.go index 51668f05..085c088e 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/api/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2017 The Kubernetes Authors. +Copyright 2018 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package api @@ -63,6 +63,15 @@ func (in *AuthInfo) DeepCopyInto(out *AuthInfo) { (*in).DeepCopyInto(*out) } } + if in.Exec != nil { + in, out := &in.Exec, &out.Exec + if *in == nil { + *out = nil + } else { + *out = new(ExecConfig) + (*in).DeepCopyInto(*out) + } + } if in.Extensions != nil { in, out := &in.Extensions, &out.Extensions *out = make(map[string]runtime.Object, len(*in)) @@ -210,9 +219,8 @@ func (in *Config) DeepCopy() *Config { func (in *Config) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -242,6 +250,48 @@ func (in *Context) DeepCopy() *Context { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExecConfig) DeepCopyInto(out *ExecConfig) { + *out = *in + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]ExecEnvVar, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecConfig. +func (in *ExecConfig) DeepCopy() *ExecConfig { + if in == nil { + return nil + } + out := new(ExecConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExecEnvVar) DeepCopyInto(out *ExecEnvVar) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecEnvVar. +func (in *ExecEnvVar) DeepCopy() *ExecEnvVar { + if in == nil { + return nil + } + out := new(ExecEnvVar) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Preferences) DeepCopyInto(out *Preferences) { *out = *in diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config.go index a8698af2..c202e6b2 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config.go @@ -107,7 +107,7 @@ func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) { // ClientConfig implements ClientConfig func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) { // check that getAuthInfo, getContext, and getCluster do not return an error. - // Do this before checking if the curent config is usable in the event that an + // Do this before checking if the current config is usable in the event that an // AuthInfo, Context, or Cluster config with user-defined names are not found. // This provides a user with the immediate cause for error if one is found configAuthInfo, err := config.getAuthInfo() @@ -202,7 +202,7 @@ func getServerIdentificationPartialConfig(configAuthInfo clientcmdapi.AuthInfo, // clientauth.Info object contain both user identification and server identification. We want different precedence orders for // both, so we have to split the objects and merge them separately -// we want this order of precedence for user identifcation +// we want this order of precedence for user identification // 1. configAuthInfo minus auth-path (the final result of command line flags and merged .kubeconfig files) // 2. configAuthInfo.auth-path (this file can contain information that conflicts with #1, and we want #1 to win the priority) // 3. if there is not enough information to identify the user, load try the ~/.kubernetes_auth file @@ -241,6 +241,9 @@ func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthI mergedConfig.AuthProvider = configAuthInfo.AuthProvider mergedConfig.AuthConfigPersister = persistAuthConfig } + if configAuthInfo.Exec != nil { + mergedConfig.ExecProvider = configAuthInfo.Exec + } // if there still isn't enough information to authenticate the user, try prompting if !canIdentifyUser(*mergedConfig) && (fallbackReader != nil) { @@ -291,7 +294,8 @@ func canIdentifyUser(config restclient.Config) bool { return len(config.Username) > 0 || (len(config.CertFile) > 0 || len(config.CertData) > 0) || len(config.BearerToken) > 0 || - config.AuthProvider != nil + config.AuthProvider != nil || + config.ExecProvider != nil } // Namespace implements ClientConfig @@ -474,7 +478,7 @@ func (config *inClusterClientConfig) ClientConfig() (*restclient.Config, error) } // in-cluster configs only takes a host, token, or CA file - // if any of them were individually provided, ovewrite anything else + // if any of them were individually provided, overwrite anything else if config.overrides != nil { if server := config.overrides.ClusterInfo.Server; len(server) > 0 { icc.Host = server diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config_test.go new file mode 100644 index 00000000..0a9288bc --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/client_config_test.go @@ -0,0 +1,528 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package clientcmd + +import ( + "io/ioutil" + "os" + "reflect" + "strings" + "testing" + + "github.com/imdario/mergo" + restclient "k8s.io/client-go/rest" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" +) + +func TestOldMergoLib(t *testing.T) { + type T struct { + X string + } + dst := T{X: "one"} + src := T{X: "two"} + mergo.Merge(&dst, &src) + if dst.X != "two" { + // mergo.Merge changed in an incompatible way with + // + // https://github.com/imdario/mergo/commit/d304790b2ed594794496464fadd89d2bb266600a + // + // We have to stay with the old version which still does eager + // copying from src to dst in structs. + t.Errorf("mergo.Merge library found with incompatible, new behavior") + } +} + +func createValidTestConfig() *clientcmdapi.Config { + const ( + server = "https://anything.com:8080" + token = "the-token" + ) + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: server, + } + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + Token: token, + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + config.CurrentContext = "clean" + + return config +} + +func createCAValidTestConfig() *clientcmdapi.Config { + + config := createValidTestConfig() + config.Clusters["clean"].CertificateAuthorityData = []byte{0, 0} + return config +} + +func TestInsecureOverridesCA(t *testing.T) { + config := createCAValidTestConfig() + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + InsecureSkipTLSVerify: true, + }, + }, nil) + + actualCfg, err := clientBuilder.ClientConfig() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + matchBoolArg(true, actualCfg.Insecure, t) + matchStringArg("", actualCfg.TLSClientConfig.CAFile, t) + matchByteArg(nil, actualCfg.TLSClientConfig.CAData, t) +} + +func TestMergeContext(t *testing.T) { + const namespace = "overridden-namespace" + + config := createValidTestConfig() + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + _, overridden, err := clientBuilder.Namespace() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + if overridden { + t.Error("Expected namespace to not be overridden") + } + + clientBuilder = NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{ + Context: clientcmdapi.Context{ + Namespace: namespace, + }, + }, nil) + + actual, overridden, err := clientBuilder.Namespace() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + if !overridden { + t.Error("Expected namespace to be overridden") + } + + matchStringArg(namespace, actual, t) +} + +func TestCertificateData(t *testing.T) { + caData := []byte("ca-data") + certData := []byte("cert-data") + keyData := []byte("key-data") + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "https://localhost:8443", + CertificateAuthorityData: caData, + } + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + ClientCertificateData: certData, + ClientKeyData: keyData, + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + config.CurrentContext = "clean" + + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + // Make sure cert data gets into config (will override file paths) + matchByteArg(caData, clientConfig.TLSClientConfig.CAData, t) + matchByteArg(certData, clientConfig.TLSClientConfig.CertData, t) + matchByteArg(keyData, clientConfig.TLSClientConfig.KeyData, t) +} + +func TestBasicAuthData(t *testing.T) { + username := "myuser" + password := "mypass" + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "https://localhost:8443", + } + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + Username: username, + Password: password, + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + config.CurrentContext = "clean" + + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + // Make sure basic auth data gets into config + matchStringArg(username, clientConfig.Username, t) + matchStringArg(password, clientConfig.Password, t) +} + +func TestBasicTokenFile(t *testing.T) { + token := "exampletoken" + f, err := ioutil.TempFile("", "tokenfile") + if err != nil { + t.Errorf("Unexpected error: %v", err) + return + } + defer os.Remove(f.Name()) + if err := ioutil.WriteFile(f.Name(), []byte(token), 0644); err != nil { + t.Errorf("Unexpected error: %v", err) + return + } + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "https://localhost:8443", + } + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + TokenFile: f.Name(), + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + config.CurrentContext = "clean" + + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + matchStringArg(token, clientConfig.BearerToken, t) +} + +func TestPrecedenceTokenFile(t *testing.T) { + token := "exampletoken" + f, err := ioutil.TempFile("", "tokenfile") + if err != nil { + t.Errorf("Unexpected error: %v", err) + return + } + defer os.Remove(f.Name()) + if err := ioutil.WriteFile(f.Name(), []byte(token), 0644); err != nil { + t.Errorf("Unexpected error: %v", err) + return + } + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "https://localhost:8443", + } + expectedToken := "expected" + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + Token: expectedToken, + TokenFile: f.Name(), + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + config.CurrentContext = "clean" + + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + matchStringArg(expectedToken, clientConfig.BearerToken, t) +} + +func TestCreateClean(t *testing.T) { + config := createValidTestConfig() + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{}, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + matchStringArg(config.Clusters["clean"].Server, clientConfig.Host, t) + matchStringArg("", clientConfig.APIPath, t) + matchBoolArg(config.Clusters["clean"].InsecureSkipTLSVerify, clientConfig.Insecure, t) + matchStringArg(config.AuthInfos["clean"].Token, clientConfig.BearerToken, t) +} + +func TestCreateCleanWithPrefix(t *testing.T) { + tt := []struct { + server string + host string + }{ + {"https://anything.com:8080/foo/bar", "https://anything.com:8080/foo/bar"}, + {"http://anything.com:8080/foo/bar", "http://anything.com:8080/foo/bar"}, + {"http://anything.com:8080/foo/bar/", "http://anything.com:8080/foo/bar/"}, + {"http://anything.com:8080/", "http://anything.com:8080/"}, + {"http://anything.com:8080//", "http://anything.com:8080//"}, + {"anything.com:8080/foo/bar", "anything.com:8080/foo/bar"}, + {"anything.com:8080", "anything.com:8080"}, + {"anything.com", "anything.com"}, + {"anything", "anything"}, + } + + tt = append(tt, struct{ server, host string }{"", "http://localhost:8080"}) + + for _, tc := range tt { + config := createValidTestConfig() + + cleanConfig := config.Clusters["clean"] + cleanConfig.Server = tc.server + config.Clusters["clean"] = cleanConfig + + clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{ + ClusterDefaults: clientcmdapi.Cluster{Server: "http://localhost:8080"}, + }, nil) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + matchStringArg(tc.host, clientConfig.Host, t) + } +} + +func TestCreateCleanDefault(t *testing.T) { + config := createValidTestConfig() + clientBuilder := NewDefaultClientConfig(*config, &ConfigOverrides{}) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + matchStringArg(config.Clusters["clean"].Server, clientConfig.Host, t) + matchBoolArg(config.Clusters["clean"].InsecureSkipTLSVerify, clientConfig.Insecure, t) + matchStringArg(config.AuthInfos["clean"].Token, clientConfig.BearerToken, t) +} + +func TestCreateCleanDefaultCluster(t *testing.T) { + config := createValidTestConfig() + clientBuilder := NewDefaultClientConfig(*config, &ConfigOverrides{ + ClusterDefaults: clientcmdapi.Cluster{Server: "http://localhost:8080"}, + }) + + clientConfig, err := clientBuilder.ClientConfig() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + matchStringArg(config.Clusters["clean"].Server, clientConfig.Host, t) + matchBoolArg(config.Clusters["clean"].InsecureSkipTLSVerify, clientConfig.Insecure, t) + matchStringArg(config.AuthInfos["clean"].Token, clientConfig.BearerToken, t) +} + +func TestCreateMissingContextNoDefault(t *testing.T) { + const expectedErrorContains = "Context was not found for specified context" + config := createValidTestConfig() + clientBuilder := NewNonInteractiveClientConfig(*config, "not-present", &ConfigOverrides{}, nil) + + _, err := clientBuilder.ClientConfig() + if err == nil { + t.Fatalf("Unexpected error: %v", err) + } +} + +func TestCreateMissingContext(t *testing.T) { + const expectedErrorContains = "context was not found for specified context: not-present" + config := createValidTestConfig() + clientBuilder := NewNonInteractiveClientConfig(*config, "not-present", &ConfigOverrides{ + ClusterDefaults: clientcmdapi.Cluster{Server: "http://localhost:8080"}, + }, nil) + + _, err := clientBuilder.ClientConfig() + if err == nil { + t.Fatalf("Expected error: %v", expectedErrorContains) + } + if !strings.Contains(err.Error(), expectedErrorContains) { + t.Fatalf("Expected error: %v, but got %v", expectedErrorContains, err) + } +} + +func TestInClusterClientConfigPrecedence(t *testing.T) { + tt := []struct { + overrides *ConfigOverrides + }{ + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + Server: "https://host-from-overrides.com", + }, + }, + }, + { + overrides: &ConfigOverrides{ + AuthInfo: clientcmdapi.AuthInfo{ + Token: "https://host-from-overrides.com", + }, + }, + }, + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + CertificateAuthority: "/path/to/ca-from-overrides.crt", + }, + }, + }, + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + Server: "https://host-from-overrides.com", + }, + AuthInfo: clientcmdapi.AuthInfo{ + Token: "https://host-from-overrides.com", + }, + }, + }, + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + Server: "https://host-from-overrides.com", + CertificateAuthority: "/path/to/ca-from-overrides.crt", + }, + }, + }, + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + CertificateAuthority: "/path/to/ca-from-overrides.crt", + }, + AuthInfo: clientcmdapi.AuthInfo{ + Token: "https://host-from-overrides.com", + }, + }, + }, + { + overrides: &ConfigOverrides{ + ClusterInfo: clientcmdapi.Cluster{ + Server: "https://host-from-overrides.com", + CertificateAuthority: "/path/to/ca-from-overrides.crt", + }, + AuthInfo: clientcmdapi.AuthInfo{ + Token: "https://host-from-overrides.com", + }, + }, + }, + { + overrides: &ConfigOverrides{}, + }, + } + + for _, tc := range tt { + expectedServer := "https://host-from-cluster.com" + expectedToken := "token-from-cluster" + expectedCAFile := "/path/to/ca-from-cluster.crt" + + icc := &inClusterClientConfig{ + inClusterConfigProvider: func() (*restclient.Config, error) { + return &restclient.Config{ + Host: expectedServer, + BearerToken: expectedToken, + TLSClientConfig: restclient.TLSClientConfig{ + CAFile: expectedCAFile, + }, + }, nil + }, + overrides: tc.overrides, + } + + clientConfig, err := icc.ClientConfig() + if err != nil { + t.Fatalf("Unxpected error: %v", err) + } + + if overridenServer := tc.overrides.ClusterInfo.Server; len(overridenServer) > 0 { + expectedServer = overridenServer + } + if overridenToken := tc.overrides.AuthInfo.Token; len(overridenToken) > 0 { + expectedToken = overridenToken + } + if overridenCAFile := tc.overrides.ClusterInfo.CertificateAuthority; len(overridenCAFile) > 0 { + expectedCAFile = overridenCAFile + } + + if clientConfig.Host != expectedServer { + t.Errorf("Expected server %v, got %v", expectedServer, clientConfig.Host) + } + if clientConfig.BearerToken != expectedToken { + t.Errorf("Expected token %v, got %v", expectedToken, clientConfig.BearerToken) + } + if clientConfig.TLSClientConfig.CAFile != expectedCAFile { + t.Errorf("Expected Certificate Authority %v, got %v", expectedCAFile, clientConfig.TLSClientConfig.CAFile) + } + } +} + +func matchBoolArg(expected, got bool, t *testing.T) { + if expected != got { + t.Errorf("Expected %v, got %v", expected, got) + } +} + +func matchStringArg(expected, got string, t *testing.T) { + if expected != got { + t.Errorf("Expected %q, got %q", expected, got) + } +} + +func matchByteArg(expected, got []byte, t *testing.T) { + if !reflect.DeepEqual(expected, got) { + t.Errorf("Expected %v, got %v", expected, got) + } +} + +func TestNamespaceOverride(t *testing.T) { + config := &DirectClientConfig{ + overrides: &ConfigOverrides{ + Context: clientcmdapi.Context{ + Namespace: "foo", + }, + }, + } + + ns, overridden, err := config.Namespace() + + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + if !overridden { + t.Errorf("Expected overridden = true") + } + + matchStringArg("foo", ns, t) +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader.go index 6ac83b5c..95e7b154 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader.go @@ -111,7 +111,7 @@ func (g *ClientConfigGetter) IsDefaultConfig(config *restclient.Config) bool { // ClientConfigLoadingRules is an ExplicitPath and string slice of specific locations that are used for merging together a Config // Callers can put the chain together however they want, but we'd recommend: // EnvVarPathFiles if set (a list of files if set) OR the HomeDirectoryPath -// ExplicitPath is special, because if a user specifically requests a certain file be used and error is reported if thie file is not present +// ExplicitPath is special, because if a user specifically requests a certain file be used and error is reported if this file is not present type ClientConfigLoadingRules struct { ExplicitPath string Precedence []string @@ -420,7 +420,7 @@ func WriteToFile(config clientcmdapi.Config, filename string) error { func lockFile(filename string) error { // TODO: find a way to do this with actual file locks. Will - // probably need seperate solution for windows and linux. + // probably need separate solution for windows and Linux. // Make sure the dir exists before we try to create a lock file. dir := filepath.Dir(filename) @@ -557,7 +557,12 @@ func GetClusterFileReferences(cluster *clientcmdapi.Cluster) []*string { } func GetAuthInfoFileReferences(authInfo *clientcmdapi.AuthInfo) []*string { - return []*string{&authInfo.ClientCertificate, &authInfo.ClientKey, &authInfo.TokenFile} + s := []*string{&authInfo.ClientCertificate, &authInfo.ClientKey, &authInfo.TokenFile} + // Only resolve exec command if it isn't PATH based. + if authInfo.Exec != nil && strings.ContainsRune(authInfo.Exec.Command, filepath.Separator) { + s = append(s, &authInfo.Exec.Command) + } + return s } // ResolvePaths updates the given refs to be absolute paths, relative to the given base directory diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader_test.go new file mode 100644 index 00000000..c2dbd019 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/loader_test.go @@ -0,0 +1,594 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package clientcmd + +import ( + "fmt" + "io/ioutil" + "os" + "path" + "path/filepath" + "reflect" + "strings" + "testing" + + "github.com/ghodss/yaml" + + "k8s.io/apimachinery/pkg/runtime" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" + clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest" +) + +var ( + testConfigAlfa = clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "red-user": {Token: "red-token"}}, + Clusters: map[string]*clientcmdapi.Cluster{ + "cow-cluster": {Server: "http://cow.org:8080"}}, + Contexts: map[string]*clientcmdapi.Context{ + "federal-context": {AuthInfo: "red-user", Cluster: "cow-cluster", Namespace: "hammer-ns"}}, + } + testConfigBravo = clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "black-user": {Token: "black-token"}}, + Clusters: map[string]*clientcmdapi.Cluster{ + "pig-cluster": {Server: "http://pig.org:8080"}}, + Contexts: map[string]*clientcmdapi.Context{ + "queen-anne-context": {AuthInfo: "black-user", Cluster: "pig-cluster", Namespace: "saw-ns"}}, + } + testConfigCharlie = clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "green-user": {Token: "green-token"}}, + Clusters: map[string]*clientcmdapi.Cluster{ + "horse-cluster": {Server: "http://horse.org:8080"}}, + Contexts: map[string]*clientcmdapi.Context{ + "shaker-context": {AuthInfo: "green-user", Cluster: "horse-cluster", Namespace: "chisel-ns"}}, + } + testConfigDelta = clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "blue-user": {Token: "blue-token"}}, + Clusters: map[string]*clientcmdapi.Cluster{ + "chicken-cluster": {Server: "http://chicken.org:8080"}}, + Contexts: map[string]*clientcmdapi.Context{ + "gothic-context": {AuthInfo: "blue-user", Cluster: "chicken-cluster", Namespace: "plane-ns"}}, + } + + testConfigConflictAlfa = clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "red-user": {Token: "a-different-red-token"}, + "yellow-user": {Token: "yellow-token"}}, + Clusters: map[string]*clientcmdapi.Cluster{ + "cow-cluster": {Server: "http://a-different-cow.org:8080", InsecureSkipTLSVerify: true}, + "donkey-cluster": {Server: "http://donkey.org:8080", InsecureSkipTLSVerify: true}}, + CurrentContext: "federal-context", + } +) + +func TestNonExistentCommandLineFile(t *testing.T) { + loadingRules := ClientConfigLoadingRules{ + ExplicitPath: "bogus_file", + } + + _, err := loadingRules.Load() + if err == nil { + t.Fatalf("Expected error for missing command-line file, got none") + } + if !strings.Contains(err.Error(), "bogus_file") { + t.Fatalf("Expected error about 'bogus_file', got %s", err.Error()) + } +} + +func TestToleratingMissingFiles(t *testing.T) { + loadingRules := ClientConfigLoadingRules{ + Precedence: []string{"bogus1", "bogus2", "bogus3"}, + } + + _, err := loadingRules.Load() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } +} + +func TestErrorReadingFile(t *testing.T) { + commandLineFile, _ := ioutil.TempFile("", "") + defer os.Remove(commandLineFile.Name()) + + if err := ioutil.WriteFile(commandLineFile.Name(), []byte("bogus value"), 0644); err != nil { + t.Fatalf("Error creating tempfile: %v", err) + } + + loadingRules := ClientConfigLoadingRules{ + ExplicitPath: commandLineFile.Name(), + } + + _, err := loadingRules.Load() + if err == nil { + t.Fatalf("Expected error for unloadable file, got none") + } + if !strings.Contains(err.Error(), commandLineFile.Name()) { + t.Fatalf("Expected error about '%s', got %s", commandLineFile.Name(), err.Error()) + } +} + +func TestErrorReadingNonFile(t *testing.T) { + tmpdir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatalf("Couldn't create tmpdir") + } + defer os.RemoveAll(tmpdir) + + loadingRules := ClientConfigLoadingRules{ + ExplicitPath: tmpdir, + } + + _, err = loadingRules.Load() + if err == nil { + t.Fatalf("Expected error for non-file, got none") + } + if !strings.Contains(err.Error(), tmpdir) { + t.Fatalf("Expected error about '%s', got %s", tmpdir, err.Error()) + } +} + +func TestConflictingCurrentContext(t *testing.T) { + commandLineFile, _ := ioutil.TempFile("", "") + defer os.Remove(commandLineFile.Name()) + envVarFile, _ := ioutil.TempFile("", "") + defer os.Remove(envVarFile.Name()) + + mockCommandLineConfig := clientcmdapi.Config{ + CurrentContext: "any-context-value", + } + mockEnvVarConfig := clientcmdapi.Config{ + CurrentContext: "a-different-context", + } + + WriteToFile(mockCommandLineConfig, commandLineFile.Name()) + WriteToFile(mockEnvVarConfig, envVarFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + ExplicitPath: commandLineFile.Name(), + Precedence: []string{envVarFile.Name()}, + } + + mergedConfig, err := loadingRules.Load() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + if mergedConfig.CurrentContext != mockCommandLineConfig.CurrentContext { + t.Errorf("expected %v, got %v", mockCommandLineConfig.CurrentContext, mergedConfig.CurrentContext) + } +} + +func TestLoadingEmptyMaps(t *testing.T) { + configFile, _ := ioutil.TempFile("", "") + defer os.Remove(configFile.Name()) + + mockConfig := clientcmdapi.Config{ + CurrentContext: "any-context-value", + } + + WriteToFile(mockConfig, configFile.Name()) + + config, err := LoadFromFile(configFile.Name()) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + if config.Clusters == nil { + t.Error("expected config.Clusters to be non-nil") + } + if config.AuthInfos == nil { + t.Error("expected config.AuthInfos to be non-nil") + } + if config.Contexts == nil { + t.Error("expected config.Contexts to be non-nil") + } +} + +func TestResolveRelativePaths(t *testing.T) { + pathResolutionConfig1 := clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "relative-user-1": {ClientCertificate: "relative/client/cert", ClientKey: "../relative/client/key"}, + "absolute-user-1": {ClientCertificate: "/absolute/client/cert", ClientKey: "/absolute/client/key"}, + "relative-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "../relative/client/cmd"}}, + "absolute-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "/absolute/client/cmd"}}, + "PATH-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "cmd"}}, + }, + Clusters: map[string]*clientcmdapi.Cluster{ + "relative-server-1": {CertificateAuthority: "../relative/ca"}, + "absolute-server-1": {CertificateAuthority: "/absolute/ca"}, + }, + } + pathResolutionConfig2 := clientcmdapi.Config{ + AuthInfos: map[string]*clientcmdapi.AuthInfo{ + "relative-user-2": {ClientCertificate: "relative/client/cert2", ClientKey: "../relative/client/key2"}, + "absolute-user-2": {ClientCertificate: "/absolute/client/cert2", ClientKey: "/absolute/client/key2"}, + }, + Clusters: map[string]*clientcmdapi.Cluster{ + "relative-server-2": {CertificateAuthority: "../relative/ca2"}, + "absolute-server-2": {CertificateAuthority: "/absolute/ca2"}, + }, + } + + configDir1, _ := ioutil.TempDir("", "") + defer os.RemoveAll(configDir1) + configFile1 := path.Join(configDir1, ".kubeconfig") + configDir1, _ = filepath.Abs(configDir1) + + configDir2, _ := ioutil.TempDir("", "") + defer os.RemoveAll(configDir2) + configDir2, _ = ioutil.TempDir(configDir2, "") + configFile2 := path.Join(configDir2, ".kubeconfig") + configDir2, _ = filepath.Abs(configDir2) + + WriteToFile(pathResolutionConfig1, configFile1) + WriteToFile(pathResolutionConfig2, configFile2) + + loadingRules := ClientConfigLoadingRules{ + Precedence: []string{configFile1, configFile2}, + } + + mergedConfig, err := loadingRules.Load() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + foundClusterCount := 0 + for key, cluster := range mergedConfig.Clusters { + if key == "relative-server-1" { + foundClusterCount++ + matchStringArg(path.Join(configDir1, pathResolutionConfig1.Clusters["relative-server-1"].CertificateAuthority), cluster.CertificateAuthority, t) + } + if key == "relative-server-2" { + foundClusterCount++ + matchStringArg(path.Join(configDir2, pathResolutionConfig2.Clusters["relative-server-2"].CertificateAuthority), cluster.CertificateAuthority, t) + } + if key == "absolute-server-1" { + foundClusterCount++ + matchStringArg(pathResolutionConfig1.Clusters["absolute-server-1"].CertificateAuthority, cluster.CertificateAuthority, t) + } + if key == "absolute-server-2" { + foundClusterCount++ + matchStringArg(pathResolutionConfig2.Clusters["absolute-server-2"].CertificateAuthority, cluster.CertificateAuthority, t) + } + } + if foundClusterCount != 4 { + t.Errorf("Expected 4 clusters, found %v: %v", foundClusterCount, mergedConfig.Clusters) + } + + foundAuthInfoCount := 0 + for key, authInfo := range mergedConfig.AuthInfos { + if key == "relative-user-1" { + foundAuthInfoCount++ + matchStringArg(path.Join(configDir1, pathResolutionConfig1.AuthInfos["relative-user-1"].ClientCertificate), authInfo.ClientCertificate, t) + matchStringArg(path.Join(configDir1, pathResolutionConfig1.AuthInfos["relative-user-1"].ClientKey), authInfo.ClientKey, t) + } + if key == "relative-user-2" { + foundAuthInfoCount++ + matchStringArg(path.Join(configDir2, pathResolutionConfig2.AuthInfos["relative-user-2"].ClientCertificate), authInfo.ClientCertificate, t) + matchStringArg(path.Join(configDir2, pathResolutionConfig2.AuthInfos["relative-user-2"].ClientKey), authInfo.ClientKey, t) + } + if key == "absolute-user-1" { + foundAuthInfoCount++ + matchStringArg(pathResolutionConfig1.AuthInfos["absolute-user-1"].ClientCertificate, authInfo.ClientCertificate, t) + matchStringArg(pathResolutionConfig1.AuthInfos["absolute-user-1"].ClientKey, authInfo.ClientKey, t) + } + if key == "absolute-user-2" { + foundAuthInfoCount++ + matchStringArg(pathResolutionConfig2.AuthInfos["absolute-user-2"].ClientCertificate, authInfo.ClientCertificate, t) + matchStringArg(pathResolutionConfig2.AuthInfos["absolute-user-2"].ClientKey, authInfo.ClientKey, t) + } + if key == "relative-cmd-1" { + foundAuthInfoCount++ + matchStringArg(path.Join(configDir1, pathResolutionConfig1.AuthInfos[key].Exec.Command), authInfo.Exec.Command, t) + } + if key == "absolute-cmd-1" { + foundAuthInfoCount++ + matchStringArg(pathResolutionConfig1.AuthInfos[key].Exec.Command, authInfo.Exec.Command, t) + } + if key == "PATH-cmd-1" { + foundAuthInfoCount++ + matchStringArg(pathResolutionConfig1.AuthInfos[key].Exec.Command, authInfo.Exec.Command, t) + } + } + if foundAuthInfoCount != 7 { + t.Errorf("Expected 7 users, found %v: %v", foundAuthInfoCount, mergedConfig.AuthInfos) + } + +} + +func TestMigratingFile(t *testing.T) { + sourceFile, _ := ioutil.TempFile("", "") + defer os.Remove(sourceFile.Name()) + destinationFile, _ := ioutil.TempFile("", "") + // delete the file so that we'll write to it + os.Remove(destinationFile.Name()) + + WriteToFile(testConfigAlfa, sourceFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + MigrationRules: map[string]string{destinationFile.Name(): sourceFile.Name()}, + } + + if _, err := loadingRules.Load(); err != nil { + t.Errorf("unexpected error %v", err) + } + + // the load should have recreated this file + defer os.Remove(destinationFile.Name()) + + sourceContent, err := ioutil.ReadFile(sourceFile.Name()) + if err != nil { + t.Errorf("unexpected error %v", err) + } + destinationContent, err := ioutil.ReadFile(destinationFile.Name()) + if err != nil { + t.Errorf("unexpected error %v", err) + } + + if !reflect.DeepEqual(sourceContent, destinationContent) { + t.Errorf("source and destination do not match") + } +} + +func TestMigratingFileLeaveExistingFileAlone(t *testing.T) { + sourceFile, _ := ioutil.TempFile("", "") + defer os.Remove(sourceFile.Name()) + destinationFile, _ := ioutil.TempFile("", "") + defer os.Remove(destinationFile.Name()) + + WriteToFile(testConfigAlfa, sourceFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + MigrationRules: map[string]string{destinationFile.Name(): sourceFile.Name()}, + } + + if _, err := loadingRules.Load(); err != nil { + t.Errorf("unexpected error %v", err) + } + + destinationContent, err := ioutil.ReadFile(destinationFile.Name()) + if err != nil { + t.Errorf("unexpected error %v", err) + } + + if len(destinationContent) > 0 { + t.Errorf("destination should not have been touched") + } +} + +func TestMigratingFileSourceMissingSkip(t *testing.T) { + sourceFilename := "some-missing-file" + destinationFile, _ := ioutil.TempFile("", "") + // delete the file so that we'll write to it + os.Remove(destinationFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + MigrationRules: map[string]string{destinationFile.Name(): sourceFilename}, + } + + if _, err := loadingRules.Load(); err != nil { + t.Errorf("unexpected error %v", err) + } + + if _, err := os.Stat(destinationFile.Name()); !os.IsNotExist(err) { + t.Errorf("destination should not exist") + } +} + +func TestFileLocking(t *testing.T) { + f, _ := ioutil.TempFile("", "") + defer os.Remove(f.Name()) + + err := lockFile(f.Name()) + if err != nil { + t.Errorf("unexpected error while locking file: %v", err) + } + defer unlockFile(f.Name()) + + err = lockFile(f.Name()) + if err == nil { + t.Error("expected error while locking file.") + } +} + +func Example_noMergingOnExplicitPaths() { + commandLineFile, _ := ioutil.TempFile("", "") + defer os.Remove(commandLineFile.Name()) + envVarFile, _ := ioutil.TempFile("", "") + defer os.Remove(envVarFile.Name()) + + WriteToFile(testConfigAlfa, commandLineFile.Name()) + WriteToFile(testConfigConflictAlfa, envVarFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + ExplicitPath: commandLineFile.Name(), + Precedence: []string{envVarFile.Name()}, + } + + mergedConfig, err := loadingRules.Load() + + json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + output, err := yaml.JSONToYAML(json) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + + fmt.Printf("%v", string(output)) + // Output: + // apiVersion: v1 + // clusters: + // - cluster: + // server: http://cow.org:8080 + // name: cow-cluster + // contexts: + // - context: + // cluster: cow-cluster + // namespace: hammer-ns + // user: red-user + // name: federal-context + // current-context: "" + // kind: Config + // preferences: {} + // users: + // - name: red-user + // user: + // token: red-token +} + +func Example_mergingSomeWithConflict() { + commandLineFile, _ := ioutil.TempFile("", "") + defer os.Remove(commandLineFile.Name()) + envVarFile, _ := ioutil.TempFile("", "") + defer os.Remove(envVarFile.Name()) + + WriteToFile(testConfigAlfa, commandLineFile.Name()) + WriteToFile(testConfigConflictAlfa, envVarFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + Precedence: []string{commandLineFile.Name(), envVarFile.Name()}, + } + + mergedConfig, err := loadingRules.Load() + + json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + output, err := yaml.JSONToYAML(json) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + + fmt.Printf("%v", string(output)) + // Output: + // apiVersion: v1 + // clusters: + // - cluster: + // server: http://cow.org:8080 + // name: cow-cluster + // - cluster: + // insecure-skip-tls-verify: true + // server: http://donkey.org:8080 + // name: donkey-cluster + // contexts: + // - context: + // cluster: cow-cluster + // namespace: hammer-ns + // user: red-user + // name: federal-context + // current-context: federal-context + // kind: Config + // preferences: {} + // users: + // - name: red-user + // user: + // token: red-token + // - name: yellow-user + // user: + // token: yellow-token +} + +func Example_mergingEverythingNoConflicts() { + commandLineFile, _ := ioutil.TempFile("", "") + defer os.Remove(commandLineFile.Name()) + envVarFile, _ := ioutil.TempFile("", "") + defer os.Remove(envVarFile.Name()) + currentDirFile, _ := ioutil.TempFile("", "") + defer os.Remove(currentDirFile.Name()) + homeDirFile, _ := ioutil.TempFile("", "") + defer os.Remove(homeDirFile.Name()) + + WriteToFile(testConfigAlfa, commandLineFile.Name()) + WriteToFile(testConfigBravo, envVarFile.Name()) + WriteToFile(testConfigCharlie, currentDirFile.Name()) + WriteToFile(testConfigDelta, homeDirFile.Name()) + + loadingRules := ClientConfigLoadingRules{ + Precedence: []string{commandLineFile.Name(), envVarFile.Name(), currentDirFile.Name(), homeDirFile.Name()}, + } + + mergedConfig, err := loadingRules.Load() + + json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + output, err := yaml.JSONToYAML(json) + if err != nil { + fmt.Printf("Unexpected error: %v", err) + } + + fmt.Printf("%v", string(output)) + // Output: + // apiVersion: v1 + // clusters: + // - cluster: + // server: http://chicken.org:8080 + // name: chicken-cluster + // - cluster: + // server: http://cow.org:8080 + // name: cow-cluster + // - cluster: + // server: http://horse.org:8080 + // name: horse-cluster + // - cluster: + // server: http://pig.org:8080 + // name: pig-cluster + // contexts: + // - context: + // cluster: cow-cluster + // namespace: hammer-ns + // user: red-user + // name: federal-context + // - context: + // cluster: chicken-cluster + // namespace: plane-ns + // user: blue-user + // name: gothic-context + // - context: + // cluster: pig-cluster + // namespace: saw-ns + // user: black-user + // name: queen-anne-context + // - context: + // cluster: horse-cluster + // namespace: chisel-ns + // user: green-user + // name: shaker-context + // current-context: "" + // kind: Config + // preferences: {} + // users: + // - name: black-user + // user: + // token: black-token + // - name: blue-user + // user: + // token: blue-token + // - name: green-user + // user: + // token: green-token + // - name: red-user + // user: + // token: red-token +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/merged_client_builder_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/merged_client_builder_test.go new file mode 100644 index 00000000..8b038676 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/merged_client_builder_test.go @@ -0,0 +1,328 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package clientcmd + +import ( + "fmt" + "testing" + + restclient "k8s.io/client-go/rest" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" +) + +type testLoader struct { + ClientConfigLoader + + called bool + config *clientcmdapi.Config + err error +} + +func (l *testLoader) Load() (*clientcmdapi.Config, error) { + l.called = true + return l.config, l.err +} + +type testClientConfig struct { + config *restclient.Config + namespace string + namespaceSpecified bool + err error +} + +func (c *testClientConfig) RawConfig() (clientcmdapi.Config, error) { + return clientcmdapi.Config{}, fmt.Errorf("unexpected call") +} +func (c *testClientConfig) ClientConfig() (*restclient.Config, error) { + return c.config, c.err +} +func (c *testClientConfig) Namespace() (string, bool, error) { + return c.namespace, c.namespaceSpecified, c.err +} +func (c *testClientConfig) ConfigAccess() ConfigAccess { + return nil +} + +type testICC struct { + testClientConfig + + possible bool + called bool +} + +func (icc *testICC) Possible() bool { + icc.called = true + return icc.possible +} + +func TestInClusterConfig(t *testing.T) { + default1 := &DirectClientConfig{ + config: *createValidTestConfig(), + contextName: "clean", + overrides: &ConfigOverrides{}, + } + invalidDefaultConfig := clientcmdapi.NewConfig() + invalidDefaultConfig.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "http://localhost:8080", + } + invalidDefaultConfig.Contexts["other"] = &clientcmdapi.Context{ + Cluster: "clean", + } + invalidDefaultConfig.CurrentContext = "clean" + + defaultInvalid := &DirectClientConfig{ + config: *invalidDefaultConfig, + overrides: &ConfigOverrides{}, + } + if _, err := defaultInvalid.ClientConfig(); err == nil || !IsConfigurationInvalid(err) { + t.Fatal(err) + } + config1, err := default1.ClientConfig() + if err != nil { + t.Fatal(err) + } + config2 := &restclient.Config{Host: "config2"} + err1 := fmt.Errorf("unique error") + + testCases := map[string]struct { + clientConfig *testClientConfig + icc *testICC + defaultConfig *DirectClientConfig + + checkedICC bool + result *restclient.Config + err error + }{ + "in-cluster checked on other error": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{}, + + checkedICC: true, + result: nil, + err: ErrEmptyConfig, + }, + + "in-cluster not checked on non-empty error": { + clientConfig: &testClientConfig{err: ErrEmptyCluster}, + icc: &testICC{}, + + checkedICC: false, + result: nil, + err: ErrEmptyCluster, + }, + + "in-cluster checked when config is default": { + defaultConfig: default1, + clientConfig: &testClientConfig{config: config1}, + icc: &testICC{}, + + checkedICC: true, + result: config1, + err: nil, + }, + + "in-cluster not checked when default config is invalid": { + defaultConfig: defaultInvalid, + clientConfig: &testClientConfig{config: config1}, + icc: &testICC{}, + + checkedICC: false, + result: config1, + err: nil, + }, + + "in-cluster not checked when config is not equal to default": { + defaultConfig: default1, + clientConfig: &testClientConfig{config: config2}, + icc: &testICC{}, + + checkedICC: false, + result: config2, + err: nil, + }, + + "in-cluster checked when config is not equal to default and error is empty": { + clientConfig: &testClientConfig{config: config2, err: ErrEmptyConfig}, + icc: &testICC{}, + + checkedICC: true, + result: config2, + err: ErrEmptyConfig, + }, + + "in-cluster error returned when config is empty": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{ + possible: true, + testClientConfig: testClientConfig{ + err: err1, + }, + }, + + checkedICC: true, + result: nil, + err: err1, + }, + + "in-cluster config returned when config is empty": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{ + possible: true, + testClientConfig: testClientConfig{ + config: config2, + }, + }, + + checkedICC: true, + result: config2, + err: nil, + }, + + "in-cluster not checked when standard default is invalid": { + defaultConfig: &DefaultClientConfig, + clientConfig: &testClientConfig{config: config2}, + icc: &testICC{}, + + checkedICC: false, + result: config2, + err: nil, + }, + } + + for name, test := range testCases { + c := &DeferredLoadingClientConfig{icc: test.icc} + c.loader = &ClientConfigLoadingRules{DefaultClientConfig: test.defaultConfig} + c.clientConfig = test.clientConfig + + cfg, err := c.ClientConfig() + if test.icc.called != test.checkedICC { + t.Errorf("%s: unexpected in-cluster-config call %t", name, test.icc.called) + } + if err != test.err || cfg != test.result { + t.Errorf("%s: unexpected result: %v %#v", name, err, cfg) + } + } +} + +func TestInClusterConfigNamespace(t *testing.T) { + err1 := fmt.Errorf("unique error") + + testCases := map[string]struct { + clientConfig *testClientConfig + icc *testICC + + checkedICC bool + result string + ok bool + err error + }{ + "in-cluster checked on empty error": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{}, + + checkedICC: true, + err: ErrEmptyConfig, + }, + + "in-cluster not checked on non-empty error": { + clientConfig: &testClientConfig{err: ErrEmptyCluster}, + icc: &testICC{}, + + err: ErrEmptyCluster, + }, + + "in-cluster checked when config is default": { + clientConfig: &testClientConfig{}, + icc: &testICC{}, + + checkedICC: true, + }, + + "in-cluster not checked when config is not equal to default": { + clientConfig: &testClientConfig{namespace: "test", namespaceSpecified: true}, + icc: &testICC{}, + + result: "test", + ok: true, + }, + + "in-cluster checked when namespace is not specified, but is defaulted": { + clientConfig: &testClientConfig{namespace: "test", namespaceSpecified: false}, + icc: &testICC{}, + + checkedICC: true, + result: "test", + ok: false, + }, + + "in-cluster error returned when config is empty": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{ + possible: true, + testClientConfig: testClientConfig{ + err: err1, + }, + }, + + checkedICC: true, + err: err1, + }, + + "in-cluster config returned when config is empty": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{ + possible: true, + testClientConfig: testClientConfig{ + namespace: "test", + namespaceSpecified: true, + }, + }, + + checkedICC: true, + result: "test", + ok: true, + }, + + "in-cluster config returned when config is empty and namespace is defaulted but not explicitly set": { + clientConfig: &testClientConfig{err: ErrEmptyConfig}, + icc: &testICC{ + possible: true, + testClientConfig: testClientConfig{ + namespace: "test", + namespaceSpecified: false, + }, + }, + + checkedICC: true, + result: "test", + ok: false, + }, + } + + for name, test := range testCases { + c := &DeferredLoadingClientConfig{icc: test.icc} + c.clientConfig = test.clientConfig + + ns, ok, err := c.Namespace() + if test.icc.called != test.checkedICC { + t.Errorf("%s: unexpected in-cluster-config call %t", name, test.icc.called) + } + if err != test.err || ns != test.result || ok != test.ok { + t.Errorf("%s: unexpected result: %v %s %t", name, err, ns, ok) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/overrides_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/overrides_test.go new file mode 100644 index 00000000..13a995cf --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/overrides_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package clientcmd + +import ( + "testing" + + "github.com/spf13/pflag" +) + +func TestNamespacePrefixStrip(t *testing.T) { + testData := map[string]string{ + "namespaces/foo": "foo", + "NAMESPACES/foo": "foo", + "NameSpaces/foo": "foo", + "namespace/foo": "foo", + "NAMESPACE/foo": "foo", + "nameSpace/foo": "foo", + "ns/foo": "foo", + "NS/foo": "foo", + "namespaces/": "namespaces/", + "namespace/": "namespace/", + "ns/": "ns/", + } + + for before, after := range testData { + overrides := &ConfigOverrides{} + fs := &pflag.FlagSet{} + BindOverrideFlags(overrides, fs, RecommendedConfigOverrideFlags("")) + fs.Parse([]string{"--namespace", before}) + + if overrides.Context.Namespace != after { + t.Fatalf("Expected %s, got %s", after, overrides.Context.Namespace) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation.go index 2bae0c39..629c0b30 100644 --- a/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation.go +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation.go @@ -237,6 +237,25 @@ func validateAuthInfo(authInfoName string, authInfo clientcmdapi.AuthInfo) []err } } + if authInfo.Exec != nil { + if authInfo.AuthProvider != nil { + validationErrors = append(validationErrors, fmt.Errorf("authProvider cannot be provided in combination with an exec plugin for %s", authInfoName)) + } + if len(authInfo.Exec.Command) == 0 { + validationErrors = append(validationErrors, fmt.Errorf("command must be specified for %v to use exec authentication plugin", authInfoName)) + } + if len(authInfo.Exec.APIVersion) == 0 { + validationErrors = append(validationErrors, fmt.Errorf("apiVersion must be specified for %v to use exec authentication plugin", authInfoName)) + } + for _, v := range authInfo.Exec.Env { + if len(v.Name) == 0 { + validationErrors = append(validationErrors, fmt.Errorf("env variable name must be specified for %v to use exec authentication plugin", authInfoName)) + } else if len(v.Value) == 0 { + validationErrors = append(validationErrors, fmt.Errorf("env variable %s value must be specified for %v to use exec authentication plugin", v.Name, authInfoName)) + } + } + } + // authPath also provides information for the client to identify the server, so allow multiple auth methods in that case if (len(methods) > 1) && (!usingAuthPath) { validationErrors = append(validationErrors, fmt.Errorf("more than one authentication method found for %v; found %v, only one is allowed", authInfoName, methods)) @@ -253,6 +272,10 @@ func validateAuthInfo(authInfoName string, authInfo clientcmdapi.AuthInfo) []err func validateContext(contextName string, context clientcmdapi.Context, config clientcmdapi.Config) []error { validationErrors := make([]error, 0) + if len(contextName) == 0 { + validationErrors = append(validationErrors, fmt.Errorf("empty context name for %#v is not allowed", context)) + } + if len(context.AuthInfo) == 0 { validationErrors = append(validationErrors, fmt.Errorf("user was not specified for context %q", contextName)) } else if _, exists := config.AuthInfos[context.AuthInfo]; !exists { diff --git a/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation_test.go b/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation_test.go new file mode 100644 index 00000000..4742b1a1 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/clientcmd/validation_test.go @@ -0,0 +1,574 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package clientcmd + +import ( + "io/ioutil" + "os" + "strings" + "testing" + + utilerrors "k8s.io/apimachinery/pkg/util/errors" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" +) + +func TestConfirmUsableBadInfoButOkConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + config.Clusters["missing ca"] = &clientcmdapi.Cluster{ + Server: "anything", + CertificateAuthority: "missing", + } + config.AuthInfos["error"] = &clientcmdapi.AuthInfo{ + Username: "anything", + Token: "here", + } + config.Contexts["dirty"] = &clientcmdapi.Context{ + Cluster: "missing ca", + AuthInfo: "error", + } + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "anything", + } + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + Token: "here", + } + config.Contexts["clean"] = &clientcmdapi.Context{ + Cluster: "clean", + AuthInfo: "clean", + } + + badValidation := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"unable to read certificate-authority"}, + } + okTest := configValidationTest{ + config: config, + } + + okTest.testConfirmUsable("clean", t) + badValidation.testConfig(t) +} + +func TestConfirmUsableBadInfoConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + config.Clusters["missing ca"] = &clientcmdapi.Cluster{ + Server: "anything", + CertificateAuthority: "missing", + } + config.AuthInfos["error"] = &clientcmdapi.AuthInfo{ + Username: "anything", + Token: "here", + } + config.Contexts["first"] = &clientcmdapi.Context{ + Cluster: "missing ca", + AuthInfo: "error", + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"unable to read certificate-authority"}, + } + + test.testConfirmUsable("first", t) +} + +func TestConfirmUsableEmptyConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"invalid configuration: no configuration has been provided"}, + } + + test.testConfirmUsable("", t) +} + +func TestConfirmUsableMissingConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"invalid configuration: no configuration has been provided"}, + } + + test.testConfirmUsable("not-here", t) +} + +func TestValidateEmptyConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"invalid configuration: no configuration has been provided"}, + } + + test.testConfig(t) +} + +func TestValidateMissingCurrentContextConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + config.CurrentContext = "anything" + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"context was not found for specified "}, + } + + test.testConfig(t) +} + +func TestIsContextNotFound(t *testing.T) { + config := clientcmdapi.NewConfig() + config.CurrentContext = "anything" + + err := Validate(*config) + if !IsContextNotFound(err) { + t.Errorf("Expected context not found, but got %v", err) + } + if !IsConfigurationInvalid(err) { + t.Errorf("Expected configuration invalid, but got %v", err) + } +} + +func TestIsEmptyConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + + err := Validate(*config) + if !IsEmptyConfig(err) { + t.Errorf("Expected context not found, but got %v", err) + } + if !IsConfigurationInvalid(err) { + t.Errorf("Expected configuration invalid, but got %v", err) + } +} + +func TestIsConfigurationInvalid(t *testing.T) { + if newErrConfigurationInvalid([]error{}) != nil { + t.Errorf("unexpected error") + } + if newErrConfigurationInvalid([]error{ErrNoContext}) == ErrNoContext { + t.Errorf("unexpected error") + } + if newErrConfigurationInvalid([]error{ErrNoContext, ErrNoContext}) == nil { + t.Errorf("unexpected error") + } + if !IsConfigurationInvalid(newErrConfigurationInvalid([]error{ErrNoContext, ErrNoContext})) { + t.Errorf("unexpected error") + } +} + +func TestValidateMissingReferencesConfig(t *testing.T) { + config := clientcmdapi.NewConfig() + config.CurrentContext = "anything" + config.Contexts["anything"] = &clientcmdapi.Context{Cluster: "missing", AuthInfo: "missing"} + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"user \"missing\" was not found for context \"anything\"", "cluster \"missing\" was not found for context \"anything\""}, + } + + test.testContext("anything", t) + test.testConfig(t) +} + +func TestValidateEmptyContext(t *testing.T) { + config := clientcmdapi.NewConfig() + config.CurrentContext = "anything" + config.Contexts["anything"] = &clientcmdapi.Context{} + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"user was not specified for context \"anything\"", "cluster was not specified for context \"anything\""}, + } + + test.testContext("anything", t) + test.testConfig(t) +} + +func TestValidateEmptyContextName(t *testing.T) { + config := clientcmdapi.NewConfig() + config.CurrentContext = "anything" + config.Contexts[""] = &clientcmdapi.Context{Cluster: "missing", AuthInfo: "missing"} + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"empty context name", "is not allowed"}, + } + + test.testContext("", t) + test.testConfig(t) +} + +func TestValidateEmptyClusterInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.Clusters["empty"] = clientcmdapi.NewCluster() + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"cluster has no server defined"}, + } + + test.testCluster("empty", t) + test.testConfig(t) +} + +func TestValidateClusterInfoErrEmptyCluster(t *testing.T) { + cluster := clientcmdapi.NewCluster() + errs := validateClusterInfo("", *cluster) + + if len(errs) != 1 { + t.Fatalf("unexpected errors: %v", errs) + } + if errs[0] != ErrEmptyCluster { + t.Errorf("unexpected error: %v", errs[0]) + } +} + +func TestValidateMissingCAFileClusterInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.Clusters["missing ca"] = &clientcmdapi.Cluster{ + Server: "anything", + CertificateAuthority: "missing", + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"unable to read certificate-authority"}, + } + + test.testCluster("missing ca", t) + test.testConfig(t) +} + +func TestValidateCleanClusterInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "anything", + } + test := configValidationTest{ + config: config, + } + + test.testCluster("clean", t) + test.testConfig(t) +} + +func TestValidateCleanWithCAClusterInfo(t *testing.T) { + tempFile, _ := ioutil.TempFile("", "") + defer os.Remove(tempFile.Name()) + + config := clientcmdapi.NewConfig() + config.Clusters["clean"] = &clientcmdapi.Cluster{ + Server: "anything", + CertificateAuthority: tempFile.Name(), + } + test := configValidationTest{ + config: config, + } + + test.testCluster("clean", t) + test.testConfig(t) +} + +func TestValidateEmptyAuthInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["error"] = &clientcmdapi.AuthInfo{} + test := configValidationTest{ + config: config, + } + + test.testAuthInfo("error", t) + test.testConfig(t) +} + +func TestValidateCertFilesNotFoundAuthInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["error"] = &clientcmdapi.AuthInfo{ + ClientCertificate: "missing", + ClientKey: "missing", + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"unable to read client-cert", "unable to read client-key"}, + } + + test.testAuthInfo("error", t) + test.testConfig(t) +} + +func TestValidateCertDataOverridesFiles(t *testing.T) { + tempFile, _ := ioutil.TempFile("", "") + defer os.Remove(tempFile.Name()) + + config := clientcmdapi.NewConfig() + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + ClientCertificate: tempFile.Name(), + ClientCertificateData: []byte("certdata"), + ClientKey: tempFile.Name(), + ClientKeyData: []byte("keydata"), + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"client-cert-data and client-cert are both specified", "client-key-data and client-key are both specified"}, + } + + test.testAuthInfo("clean", t) + test.testConfig(t) +} + +func TestValidateCleanCertFilesAuthInfo(t *testing.T) { + tempFile, _ := ioutil.TempFile("", "") + defer os.Remove(tempFile.Name()) + + config := clientcmdapi.NewConfig() + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + ClientCertificate: tempFile.Name(), + ClientKey: tempFile.Name(), + } + test := configValidationTest{ + config: config, + } + + test.testAuthInfo("clean", t) + test.testConfig(t) +} + +func TestValidateCleanTokenAuthInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["clean"] = &clientcmdapi.AuthInfo{ + Token: "any-value", + } + test := configValidationTest{ + config: config, + } + + test.testAuthInfo("clean", t) + test.testConfig(t) +} + +func TestValidateMultipleMethodsAuthInfo(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["error"] = &clientcmdapi.AuthInfo{ + Token: "token", + Username: "username", + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{"more than one authentication method", "token", "basicAuth"}, + } + + test.testAuthInfo("error", t) + test.testConfig(t) +} + +func TestValidateAuthInfoExec(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ + Exec: &clientcmdapi.ExecConfig{ + Command: "/bin/example", + APIVersion: "clientauthentication.k8s.io/v1alpha1", + Args: []string{"hello", "world"}, + Env: []clientcmdapi.ExecEnvVar{ + {Name: "foo", Value: "bar"}, + }, + }, + } + test := configValidationTest{ + config: config, + } + + test.testAuthInfo("user", t) + test.testConfig(t) +} + +func TestValidateAuthInfoExecNoVersion(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ + Exec: &clientcmdapi.ExecConfig{ + Command: "/bin/example", + }, + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{ + "apiVersion must be specified for user to use exec authentication plugin", + }, + } + + test.testAuthInfo("user", t) + test.testConfig(t) +} + +func TestValidateAuthInfoExecNoCommand(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ + Exec: &clientcmdapi.ExecConfig{ + APIVersion: "clientauthentication.k8s.io/v1alpha1", + }, + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{ + "command must be specified for user to use exec authentication plugin", + }, + } + + test.testAuthInfo("user", t) + test.testConfig(t) +} + +func TestValidateAuthInfoExecWithAuthProvider(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ + AuthProvider: &clientcmdapi.AuthProviderConfig{ + Name: "oidc", + }, + Exec: &clientcmdapi.ExecConfig{ + Command: "/bin/example", + APIVersion: "clientauthentication.k8s.io/v1alpha1", + }, + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{ + "authProvider cannot be provided in combination with an exec plugin for user", + }, + } + + test.testAuthInfo("user", t) + test.testConfig(t) +} + +func TestValidateAuthInfoExecInvalidEnv(t *testing.T) { + config := clientcmdapi.NewConfig() + config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ + Exec: &clientcmdapi.ExecConfig{ + Command: "/bin/example", + APIVersion: "clientauthentication.k8s.io/v1alpha1", + Env: []clientcmdapi.ExecEnvVar{ + {Name: "foo"}, // No value + }, + }, + } + test := configValidationTest{ + config: config, + expectedErrorSubstring: []string{ + "env variable foo value must be specified for user to use exec authentication plugin", + }, + } + + test.testAuthInfo("user", t) + test.testConfig(t) +} + +type configValidationTest struct { + config *clientcmdapi.Config + expectedErrorSubstring []string +} + +func (c configValidationTest) testContext(contextName string, t *testing.T) { + errs := validateContext(contextName, *c.config.Contexts[contextName], *c.config) + + if len(c.expectedErrorSubstring) != 0 { + if len(errs) == 0 { + t.Errorf("Expected error containing: %v", c.expectedErrorSubstring) + } + for _, curr := range c.expectedErrorSubstring { + if len(errs) != 0 && !strings.Contains(utilerrors.NewAggregate(errs).Error(), curr) { + t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, utilerrors.NewAggregate(errs)) + } + } + + } else { + if len(errs) != 0 { + t.Errorf("Unexpected error: %v", utilerrors.NewAggregate(errs)) + } + } +} + +func (c configValidationTest) testConfirmUsable(contextName string, t *testing.T) { + err := ConfirmUsable(*c.config, contextName) + + if len(c.expectedErrorSubstring) != 0 { + if err == nil { + t.Errorf("Expected error containing: %v", c.expectedErrorSubstring) + } else { + for _, curr := range c.expectedErrorSubstring { + if err != nil && !strings.Contains(err.Error(), curr) { + t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, err) + } + } + } + } else { + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + } +} + +func (c configValidationTest) testConfig(t *testing.T) { + err := Validate(*c.config) + + if len(c.expectedErrorSubstring) != 0 { + if err == nil { + t.Errorf("Expected error containing: %v", c.expectedErrorSubstring) + } else { + for _, curr := range c.expectedErrorSubstring { + if err != nil && !strings.Contains(err.Error(), curr) { + t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, err) + } + } + if !IsConfigurationInvalid(err) { + t.Errorf("all errors should be configuration invalid: %v", err) + } + } + } else { + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + } +} + +func (c configValidationTest) testCluster(clusterName string, t *testing.T) { + errs := validateClusterInfo(clusterName, *c.config.Clusters[clusterName]) + + if len(c.expectedErrorSubstring) != 0 { + if len(errs) == 0 { + t.Errorf("Expected error containing: %v", c.expectedErrorSubstring) + } + for _, curr := range c.expectedErrorSubstring { + if len(errs) != 0 && !strings.Contains(utilerrors.NewAggregate(errs).Error(), curr) { + t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, utilerrors.NewAggregate(errs)) + } + } + + } else { + if len(errs) != 0 { + t.Errorf("Unexpected error: %v", utilerrors.NewAggregate(errs)) + } + } +} + +func (c configValidationTest) testAuthInfo(authInfoName string, t *testing.T) { + errs := validateAuthInfo(authInfoName, *c.config.AuthInfos[authInfoName]) + + if len(c.expectedErrorSubstring) != 0 { + if len(errs) == 0 { + t.Errorf("Expected error containing: %v", c.expectedErrorSubstring) + } + for _, curr := range c.expectedErrorSubstring { + if len(errs) != 0 && !strings.Contains(utilerrors.NewAggregate(errs).Error(), curr) { + t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, utilerrors.NewAggregate(errs)) + } + } + + } else { + if len(errs) != 0 { + t.Errorf("Unexpected error: %v", utilerrors.NewAggregate(errs)) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/leaderelection/BUILD b/discovery/vendor/k8s.io/client-go/tools/leaderelection/BUILD new file mode 100644 index 00000000..22e020d8 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/leaderelection/BUILD @@ -0,0 +1,53 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_library( + name = "go_default_library", + srcs = ["leaderelection.go"], + importpath = "k8s.io/client-go/tools/leaderelection", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/client-go/tools/leaderelection/resourcelock:go_default_library", + ], +) + +go_test( + name = "go_default_test", + srcs = ["leaderelection_test.go"], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/core/v1/fake:go_default_library", + "//vendor/k8s.io/client-go/testing:go_default_library", + "//vendor/k8s.io/client-go/tools/leaderelection/resourcelock:go_default_library", + "//vendor/k8s.io/client-go/tools/record:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/tools/leaderelection/resourcelock:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go b/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go index 2ce546bc..e41b420c 100644 --- a/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go +++ b/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go @@ -171,11 +171,11 @@ func (le *LeaderElector) IsLeader() bool { // acquire loops calling tryAcquireOrRenew and returns immediately when tryAcquireOrRenew succeeds. func (le *LeaderElector) acquire() { stop := make(chan struct{}) - glog.Infof("attempting to acquire leader lease...") + desc := le.config.Lock.Describe() + glog.Infof("attempting to acquire leader lease %v...", desc) wait.JitterUntil(func() { succeeded := le.tryAcquireOrRenew() le.maybeReportTransition() - desc := le.config.Lock.Describe() if !succeeded { glog.V(4).Infof("failed to acquire lease %v", desc) return diff --git a/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection_test.go b/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection_test.go new file mode 100644 index 00000000..e99cf57a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/leaderelection/leaderelection_test.go @@ -0,0 +1,292 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package leaderelection + +import ( + "fmt" + "sync" + "testing" + "time" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + fakecorev1 "k8s.io/client-go/kubernetes/typed/core/v1/fake" + core "k8s.io/client-go/testing" + rl "k8s.io/client-go/tools/leaderelection/resourcelock" + "k8s.io/client-go/tools/record" +) + +func createLockObject(objectType string, objectMeta metav1.ObjectMeta) (obj runtime.Object) { + switch objectType { + case "endpoints": + obj = &v1.Endpoints{ObjectMeta: objectMeta} + case "configmaps": + obj = &v1.ConfigMap{ObjectMeta: objectMeta} + default: + panic("unexpected objType:" + objectType) + } + return +} + +// Will test leader election using endpoints as the resource +func TestTryAcquireOrRenewEndpoints(t *testing.T) { + testTryAcquireOrRenew(t, "endpoints") +} + +func testTryAcquireOrRenew(t *testing.T, objectType string) { + future := time.Now().Add(1000 * time.Hour) + past := time.Now().Add(-1000 * time.Hour) + + tests := []struct { + observedRecord rl.LeaderElectionRecord + observedTime time.Time + reactors []struct { + verb string + reaction core.ReactionFunc + } + + expectSuccess bool + transitionLeader bool + outHolder string + }{ + // acquire from no object + { + reactors: []struct { + verb string + reaction core.ReactionFunc + }{ + { + verb: "get", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, nil, errors.NewNotFound(action.(core.GetAction).GetResource().GroupResource(), action.(core.GetAction).GetName()) + }, + }, + { + verb: "create", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, action.(core.CreateAction).GetObject(), nil + }, + }, + }, + expectSuccess: true, + outHolder: "baz", + }, + // acquire from unled object + { + reactors: []struct { + verb string + reaction core.ReactionFunc + }{ + { + verb: "get", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + objectMeta := metav1.ObjectMeta{ + Namespace: action.GetNamespace(), + Name: action.(core.GetAction).GetName(), + } + return true, createLockObject(objectType, objectMeta), nil + }, + }, + { + verb: "update", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, action.(core.CreateAction).GetObject(), nil + }, + }, + }, + + expectSuccess: true, + transitionLeader: true, + outHolder: "baz", + }, + // acquire from led, unacked object + { + reactors: []struct { + verb string + reaction core.ReactionFunc + }{ + { + verb: "get", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + objectMeta := metav1.ObjectMeta{ + Namespace: action.GetNamespace(), + Name: action.(core.GetAction).GetName(), + Annotations: map[string]string{ + rl.LeaderElectionRecordAnnotationKey: `{"holderIdentity":"bing"}`, + }, + } + return true, createLockObject(objectType, objectMeta), nil + }, + }, + { + verb: "update", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, action.(core.CreateAction).GetObject(), nil + }, + }, + }, + observedRecord: rl.LeaderElectionRecord{HolderIdentity: "bing"}, + observedTime: past, + + expectSuccess: true, + transitionLeader: true, + outHolder: "baz", + }, + // don't acquire from led, acked object + { + reactors: []struct { + verb string + reaction core.ReactionFunc + }{ + { + verb: "get", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + objectMeta := metav1.ObjectMeta{ + Namespace: action.GetNamespace(), + Name: action.(core.GetAction).GetName(), + Annotations: map[string]string{ + rl.LeaderElectionRecordAnnotationKey: `{"holderIdentity":"bing"}`, + }, + } + return true, createLockObject(objectType, objectMeta), nil + }, + }, + }, + observedTime: future, + + expectSuccess: false, + outHolder: "bing", + }, + // renew already acquired object + { + reactors: []struct { + verb string + reaction core.ReactionFunc + }{ + { + verb: "get", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + objectMeta := metav1.ObjectMeta{ + Namespace: action.GetNamespace(), + Name: action.(core.GetAction).GetName(), + Annotations: map[string]string{ + rl.LeaderElectionRecordAnnotationKey: `{"holderIdentity":"baz"}`, + }, + } + return true, createLockObject(objectType, objectMeta), nil + }, + }, + { + verb: "update", + reaction: func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, action.(core.CreateAction).GetObject(), nil + }, + }, + }, + observedTime: future, + observedRecord: rl.LeaderElectionRecord{HolderIdentity: "baz"}, + + expectSuccess: true, + outHolder: "baz", + }, + } + + for i, test := range tests { + // OnNewLeader is called async so we have to wait for it. + var wg sync.WaitGroup + wg.Add(1) + var reportedLeader string + var lock rl.Interface + + objectMeta := metav1.ObjectMeta{Namespace: "foo", Name: "bar"} + resourceLockConfig := rl.ResourceLockConfig{ + Identity: "baz", + EventRecorder: &record.FakeRecorder{}, + } + c := &fakecorev1.FakeCoreV1{Fake: &core.Fake{}} + for _, reactor := range test.reactors { + c.AddReactor(reactor.verb, objectType, reactor.reaction) + } + c.AddReactor("*", "*", func(action core.Action) (bool, runtime.Object, error) { + t.Errorf("[%v] unreachable action. testclient called too many times: %+v", i, action) + return true, nil, fmt.Errorf("unreachable action") + }) + + switch objectType { + case "endpoints": + lock = &rl.EndpointsLock{ + EndpointsMeta: objectMeta, + LockConfig: resourceLockConfig, + Client: c, + } + case "configmaps": + lock = &rl.ConfigMapLock{ + ConfigMapMeta: objectMeta, + LockConfig: resourceLockConfig, + Client: c, + } + } + + lec := LeaderElectionConfig{ + Lock: lock, + LeaseDuration: 10 * time.Second, + Callbacks: LeaderCallbacks{ + OnNewLeader: func(l string) { + defer wg.Done() + reportedLeader = l + }, + }, + } + le := &LeaderElector{ + config: lec, + observedRecord: test.observedRecord, + observedTime: test.observedTime, + } + + if test.expectSuccess != le.tryAcquireOrRenew() { + t.Errorf("[%v]unexpected result of tryAcquireOrRenew: [succeeded=%v]", i, !test.expectSuccess) + } + + le.observedRecord.AcquireTime = metav1.Time{} + le.observedRecord.RenewTime = metav1.Time{} + if le.observedRecord.HolderIdentity != test.outHolder { + t.Errorf("[%v]expected holder:\n\t%+v\ngot:\n\t%+v", i, test.outHolder, le.observedRecord.HolderIdentity) + } + if len(test.reactors) != len(c.Actions()) { + t.Errorf("[%v]wrong number of api interactions", i) + } + if test.transitionLeader && le.observedRecord.LeaderTransitions != 1 { + t.Errorf("[%v]leader should have transitioned but did not", i) + } + if !test.transitionLeader && le.observedRecord.LeaderTransitions != 0 { + t.Errorf("[%v]leader should not have transitioned but did", i) + } + + le.maybeReportTransition() + wg.Wait() + if reportedLeader != test.outHolder { + t.Errorf("[%v]reported leader was not the new leader. expected %q, got %q", i, test.outHolder, reportedLeader) + } + } +} + +// Will test leader election using configmap as the resource +func TestTryAcquireOrRenewConfigMaps(t *testing.T) { + testTryAcquireOrRenew(t, "configmaps") +} diff --git a/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/BUILD b/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/BUILD new file mode 100644 index 00000000..8a9f8104 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/BUILD @@ -0,0 +1,35 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = [ + "configmaplock.go", + "endpointslock.go", + "interface.go", + ], + importpath = "k8s.io/client-go/tools/leaderelection/resourcelock", + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", + "//vendor/k8s.io/client-go/tools/record:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/configmaplock.go b/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/configmaplock.go index 69e8c5a7..4ff59560 100644 --- a/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/configmaplock.go +++ b/discovery/vendor/k8s.io/client-go/tools/leaderelection/resourcelock/configmaplock.go @@ -32,15 +32,15 @@ import ( // data we will likely move to deprecate the Endpoints lock. type ConfigMapLock struct { - // ConfigMapMeta should contain a Name and a Namespace of an - // ConfigMapMeta object that the Leadercmlector will attempt to lead. + // ConfigMapMeta should contain a Name and a Namespace of a + // ConfigMapMeta object that the LeaderElector will attempt to lead. ConfigMapMeta metav1.ObjectMeta Client corev1client.ConfigMapsGetter LockConfig ResourceLockConfig cm *v1.ConfigMap } -// Get returns the cmlection record from a ConfigMap Annotation +// Get returns the election record from a ConfigMap Annotation func (cml *ConfigMapLock) Get() (*LeaderElectionRecord, error) { var record LeaderElectionRecord var err error @@ -59,7 +59,7 @@ func (cml *ConfigMapLock) Get() (*LeaderElectionRecord, error) { return &record, nil } -// Create attempts to create a LeadercmlectionRecord annotation +// Create attempts to create a LeaderElectionRecord annotation func (cml *ConfigMapLock) Create(ler LeaderElectionRecord) error { recordBytes, err := json.Marshal(ler) if err != nil { @@ -77,7 +77,7 @@ func (cml *ConfigMapLock) Create(ler LeaderElectionRecord) error { return err } -// Update will update and existing annotation on a given resource. +// Update will update an existing annotation on a given resource. func (cml *ConfigMapLock) Update(ler LeaderElectionRecord) error { if cml.cm == nil { return errors.New("endpoint not initialized, call get or create first") @@ -91,7 +91,7 @@ func (cml *ConfigMapLock) Update(ler LeaderElectionRecord) error { return err } -// RecordEvent in leader cmlection while adding meta-data +// RecordEvent in leader election while adding meta-data func (cml *ConfigMapLock) RecordEvent(s string) { events := fmt.Sprintf("%v %v", cml.LockConfig.Identity, s) cml.LockConfig.EventRecorder.Eventf(&v1.ConfigMap{ObjectMeta: cml.cm.ObjectMeta}, v1.EventTypeNormal, "LeaderElection", events) diff --git a/discovery/vendor/k8s.io/client-go/tools/metrics/BUILD b/discovery/vendor/k8s.io/client-go/tools/metrics/BUILD new file mode 100644 index 00000000..7b06e0f9 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/metrics/BUILD @@ -0,0 +1,25 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["metrics.go"], + importpath = "k8s.io/client-go/tools/metrics", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/pager/BUILD b/discovery/vendor/k8s.io/client-go/tools/pager/BUILD new file mode 100644 index 00000000..4d07429a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/pager/BUILD @@ -0,0 +1,49 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_library( + name = "go_default_library", + srcs = ["pager.go"], + importpath = "k8s.io/client-go/tools/pager", + deps = [ + "//vendor/golang.org/x/net/context:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) + +go_test( + name = "go_default_test", + srcs = ["pager_test.go"], + embed = [":go_default_library"], + deps = [ + "//vendor/golang.org/x/net/context:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + ], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/pager/pager_test.go b/discovery/vendor/k8s.io/client-go/tools/pager/pager_test.go new file mode 100644 index 00000000..b905fc1f --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/pager/pager_test.go @@ -0,0 +1,206 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package pager + +import ( + "fmt" + "reflect" + "testing" + + "golang.org/x/net/context" + "k8s.io/apimachinery/pkg/api/errors" + metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" + "k8s.io/apimachinery/pkg/runtime" +) + +func list(count int, rv string) *metainternalversion.List { + var list metainternalversion.List + for i := 0; i < count; i++ { + list.Items = append(list.Items, &metav1beta1.PartialObjectMetadata{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%d", i), + }, + }) + } + list.ResourceVersion = rv + return &list +} + +type testPager struct { + t *testing.T + rv string + index int + remaining int + last int + continuing bool + done bool + expectPage int64 +} + +func (p *testPager) reset() { + p.continuing = false + p.remaining += p.index + p.index = 0 + p.last = 0 + p.done = false +} + +func (p *testPager) PagedList(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if p.done { + p.t.Errorf("did not expect additional call to paged list") + return nil, fmt.Errorf("unexpected list call") + } + expectedContinue := fmt.Sprintf("%s:%d", p.rv, p.last) + if options.Limit != p.expectPage || (p.continuing && options.Continue != expectedContinue) { + p.t.Errorf("invariant violated, expected limit %d and continue %s, got %#v", p.expectPage, expectedContinue, options) + return nil, fmt.Errorf("invariant violated") + } + var list metainternalversion.List + total := options.Limit + if total == 0 { + total = int64(p.remaining) + } + for i := int64(0); i < total; i++ { + if p.remaining <= 0 { + break + } + list.Items = append(list.Items, &metav1beta1.PartialObjectMetadata{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%d", p.index), + }, + }) + p.remaining-- + p.index++ + } + p.last = p.index + if p.remaining > 0 { + list.Continue = fmt.Sprintf("%s:%d", p.rv, p.last) + p.continuing = true + } else { + p.done = true + } + list.ResourceVersion = p.rv + return &list, nil +} + +func (p *testPager) ExpiresOnSecondPage(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if p.continuing { + p.done = true + return nil, errors.NewResourceExpired("this list has expired") + } + return p.PagedList(ctx, options) +} + +func (p *testPager) ExpiresOnSecondPageThenFullList(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if p.continuing { + p.reset() + p.expectPage = 0 + return nil, errors.NewResourceExpired("this list has expired") + } + return p.PagedList(ctx, options) +} + +func TestListPager_List(t *testing.T) { + type fields struct { + PageSize int64 + PageFn ListPageFunc + FullListIfExpired bool + } + type args struct { + ctx context.Context + options metav1.ListOptions + } + tests := []struct { + name string + fields fields + args args + want runtime.Object + wantErr bool + isExpired bool + }{ + { + name: "empty page", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 0, rv: "rv:20"}).PagedList}, + args: args{}, + want: list(0, "rv:20"), + }, + { + name: "one page", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 9, rv: "rv:20"}).PagedList}, + args: args{}, + want: list(9, "rv:20"), + }, + { + name: "one full page", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 10, rv: "rv:20"}).PagedList}, + args: args{}, + want: list(10, "rv:20"), + }, + { + name: "two pages", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 11, rv: "rv:20"}).PagedList}, + args: args{}, + want: list(11, "rv:20"), + }, + { + name: "three pages", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 21, rv: "rv:20"}).PagedList}, + args: args{}, + want: list(21, "rv:20"), + }, + { + name: "expires on second page", + fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 21, rv: "rv:20"}).ExpiresOnSecondPage}, + args: args{}, + wantErr: true, + isExpired: true, + }, + { + name: "expires on second page and then lists", + fields: fields{ + FullListIfExpired: true, + PageSize: 10, + PageFn: (&testPager{t: t, expectPage: 10, remaining: 21, rv: "rv:20"}).ExpiresOnSecondPageThenFullList, + }, + args: args{}, + want: list(21, "rv:20"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &ListPager{ + PageSize: tt.fields.PageSize, + PageFn: tt.fields.PageFn, + FullListIfExpired: tt.fields.FullListIfExpired, + } + got, err := p.List(tt.args.ctx, tt.args.options) + if (err != nil) != tt.wantErr { + t.Errorf("ListPager.List() error = %v, wantErr %v", err, tt.wantErr) + return + } + if tt.isExpired != errors.IsResourceExpired(err) { + t.Errorf("ListPager.List() error = %v, isExpired %v", err, tt.isExpired) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ListPager.List() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/portforward/BUILD b/discovery/vendor/k8s.io/client-go/tools/portforward/BUILD new file mode 100644 index 00000000..e2fb01e7 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/portforward/BUILD @@ -0,0 +1,41 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = ["portforward_test.go"], + embed = [":go_default_library"], + deps = ["//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "portforward.go", + ], + importpath = "k8s.io/client-go/tools/portforward", + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/portforward/portforward.go b/discovery/vendor/k8s.io/client-go/tools/portforward/portforward.go index 24737b9a..9d7936e7 100644 --- a/discovery/vendor/k8s.io/client-go/tools/portforward/portforward.go +++ b/discovery/vendor/k8s.io/client-go/tools/portforward/portforward.go @@ -185,7 +185,7 @@ func (pf *PortForwarder) forward() error { // If both listener creation fail, an error is raised. func (pf *PortForwarder) listenOnPort(port *ForwardedPort) error { errTcp4 := pf.listenOnPortAndAddress(port, "tcp4", "127.0.0.1") - errTcp6 := pf.listenOnPortAndAddress(port, "tcp6", "[::1]") + errTcp6 := pf.listenOnPortAndAddress(port, "tcp6", "::1") if errTcp4 != nil && errTcp6 != nil { return fmt.Errorf("All listeners failed to create with the following errors: %s, %s", errTcp4, errTcp6) } @@ -220,7 +220,7 @@ func (pf *PortForwarder) getListener(protocol string, hostname string, port *For } port.Local = uint16(localPortUInt) if pf.out != nil { - fmt.Fprintf(pf.out, "Forwarding from %s:%d -> %d\n", hostname, localPortUInt, port.Remote) + fmt.Fprintf(pf.out, "Forwarding from %s -> %d\n", net.JoinHostPort(hostname, strconv.Itoa(int(localPortUInt))), port.Remote) } return listener, nil diff --git a/discovery/vendor/k8s.io/client-go/tools/portforward/portforward_test.go b/discovery/vendor/k8s.io/client-go/tools/portforward/portforward_test.go new file mode 100644 index 00000000..2abbf16f --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/portforward/portforward_test.go @@ -0,0 +1,188 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package portforward + +import ( + "net" + "os" + "reflect" + "strings" + "testing" + + "k8s.io/apimachinery/pkg/util/httpstream" +) + +type fakeDialer struct { + dialed bool + conn httpstream.Connection + err error + negotiatedProtocol string +} + +func (d *fakeDialer) Dial(protocols ...string) (httpstream.Connection, string, error) { + d.dialed = true + return d.conn, d.negotiatedProtocol, d.err +} + +func TestParsePortsAndNew(t *testing.T) { + tests := []struct { + input []string + expected []ForwardedPort + expectParseError bool + expectNewError bool + }{ + {input: []string{}, expectNewError: true}, + {input: []string{"a"}, expectParseError: true, expectNewError: true}, + {input: []string{":a"}, expectParseError: true, expectNewError: true}, + {input: []string{"-1"}, expectParseError: true, expectNewError: true}, + {input: []string{"65536"}, expectParseError: true, expectNewError: true}, + {input: []string{"0"}, expectParseError: true, expectNewError: true}, + {input: []string{"0:0"}, expectParseError: true, expectNewError: true}, + {input: []string{"a:5000"}, expectParseError: true, expectNewError: true}, + {input: []string{"5000:a"}, expectParseError: true, expectNewError: true}, + { + input: []string{"5000", "5000:5000", "8888:5000", "5000:8888", ":5000", "0:5000"}, + expected: []ForwardedPort{ + {5000, 5000}, + {5000, 5000}, + {8888, 5000}, + {5000, 8888}, + {0, 5000}, + {0, 5000}, + }, + }, + } + + for i, test := range tests { + parsed, err := parsePorts(test.input) + haveError := err != nil + if e, a := test.expectParseError, haveError; e != a { + t.Fatalf("%d: parsePorts: error expected=%t, got %t: %s", i, e, a, err) + } + + dialer := &fakeDialer{} + expectedStopChan := make(chan struct{}) + readyChan := make(chan struct{}) + pf, err := New(dialer, test.input, expectedStopChan, readyChan, os.Stdout, os.Stderr) + haveError = err != nil + if e, a := test.expectNewError, haveError; e != a { + t.Fatalf("%d: New: error expected=%t, got %t: %s", i, e, a, err) + } + + if test.expectParseError || test.expectNewError { + continue + } + + for pi, expectedPort := range test.expected { + if e, a := expectedPort.Local, parsed[pi].Local; e != a { + t.Fatalf("%d: local expected: %d, got: %d", i, e, a) + } + if e, a := expectedPort.Remote, parsed[pi].Remote; e != a { + t.Fatalf("%d: remote expected: %d, got: %d", i, e, a) + } + } + + if dialer.dialed { + t.Fatalf("%d: expected not dialed", i) + } + if e, a := test.expected, pf.ports; !reflect.DeepEqual(e, a) { + t.Fatalf("%d: ports: expected %#v, got %#v", i, e, a) + } + if e, a := expectedStopChan, pf.stopChan; e != a { + t.Fatalf("%d: stopChan: expected %#v, got %#v", i, e, a) + } + if pf.Ready == nil { + t.Fatalf("%d: Ready should be non-nil", i) + } + } +} + +type GetListenerTestCase struct { + Hostname string + Protocol string + ShouldRaiseError bool + ExpectedListenerAddress string +} + +func TestGetListener(t *testing.T) { + var pf PortForwarder + testCases := []GetListenerTestCase{ + { + Hostname: "localhost", + Protocol: "tcp4", + ShouldRaiseError: false, + ExpectedListenerAddress: "127.0.0.1", + }, + { + Hostname: "127.0.0.1", + Protocol: "tcp4", + ShouldRaiseError: false, + ExpectedListenerAddress: "127.0.0.1", + }, + { + Hostname: "::1", + Protocol: "tcp6", + ShouldRaiseError: false, + ExpectedListenerAddress: "::1", + }, + { + Hostname: "::1", + Protocol: "tcp4", + ShouldRaiseError: true, + }, + { + Hostname: "127.0.0.1", + Protocol: "tcp6", + ShouldRaiseError: true, + }, + } + + for i, testCase := range testCases { + expectedListenerPort := "12345" + listener, err := pf.getListener(testCase.Protocol, testCase.Hostname, &ForwardedPort{12345, 12345}) + if err != nil && strings.Contains(err.Error(), "cannot assign requested address") { + t.Logf("Can't test #%d: %v", i, err) + continue + } + errorRaised := err != nil + + if testCase.ShouldRaiseError != errorRaised { + t.Errorf("Test case #%d failed: Data %v an error has been raised(%t) where it should not (or reciprocally): %v", i, testCase, testCase.ShouldRaiseError, err) + continue + } + if errorRaised { + continue + } + + if listener == nil { + t.Errorf("Test case #%d did not raise an error but failed in initializing listener", i) + continue + } + + host, port, _ := net.SplitHostPort(listener.Addr().String()) + t.Logf("Asked a %s forward for: %s:%v, got listener %s:%s, expected: %s", testCase.Protocol, testCase.Hostname, 12345, host, port, expectedListenerPort) + if host != testCase.ExpectedListenerAddress { + t.Errorf("Test case #%d failed: Listener does not listen on expected address: asked '%v' got '%v'", i, testCase.ExpectedListenerAddress, host) + } + if port != expectedListenerPort { + t.Errorf("Test case #%d failed: Listener does not listen on expected port: asked %v got %v", i, expectedListenerPort, port) + + } + listener.Close() + + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/record/BUILD b/discovery/vendor/k8s.io/client-go/tools/record/BUILD new file mode 100644 index 00000000..0799afe7 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/record/BUILD @@ -0,0 +1,68 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "event_test.go", + "events_cache_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/tools/reference:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "event.go", + "events_cache.go", + "fake.go", + ], + importpath = "k8s.io/client-go/tools/record", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/github.com/golang/groupcache/lru:go_default_library", + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/tools/reference:go_default_library", + "//vendor/k8s.io/client-go/util/flowcontrol:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/record/event_test.go b/discovery/vendor/k8s.io/client-go/tools/record/event_test.go new file mode 100644 index 00000000..4fcebc35 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/record/event_test.go @@ -0,0 +1,924 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package record + +import ( + "encoding/json" + "fmt" + "math/rand" + "net/http" + "strconv" + "testing" + "time" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + k8sruntime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/apimachinery/pkg/util/strategicpatch" + "k8s.io/client-go/kubernetes/scheme" + restclient "k8s.io/client-go/rest" + ref "k8s.io/client-go/tools/reference" +) + +type testEventSink struct { + OnCreate func(e *v1.Event) (*v1.Event, error) + OnUpdate func(e *v1.Event) (*v1.Event, error) + OnPatch func(e *v1.Event, p []byte) (*v1.Event, error) +} + +// CreateEvent records the event for testing. +func (t *testEventSink) Create(e *v1.Event) (*v1.Event, error) { + if t.OnCreate != nil { + return t.OnCreate(e) + } + return e, nil +} + +// UpdateEvent records the event for testing. +func (t *testEventSink) Update(e *v1.Event) (*v1.Event, error) { + if t.OnUpdate != nil { + return t.OnUpdate(e) + } + return e, nil +} + +// PatchEvent records the event for testing. +func (t *testEventSink) Patch(e *v1.Event, p []byte) (*v1.Event, error) { + if t.OnPatch != nil { + return t.OnPatch(e, p) + } + return e, nil +} + +type OnCreateFunc func(*v1.Event) (*v1.Event, error) + +func OnCreateFactory(testCache map[string]*v1.Event, createEvent chan<- *v1.Event) OnCreateFunc { + return func(event *v1.Event) (*v1.Event, error) { + testCache[getEventKey(event)] = event + createEvent <- event + return event, nil + } +} + +type OnPatchFunc func(*v1.Event, []byte) (*v1.Event, error) + +func OnPatchFactory(testCache map[string]*v1.Event, patchEvent chan<- *v1.Event) OnPatchFunc { + return func(event *v1.Event, patch []byte) (*v1.Event, error) { + cachedEvent, found := testCache[getEventKey(event)] + if !found { + return nil, fmt.Errorf("unexpected error: couldn't find Event in testCache.") + } + originalData, err := json.Marshal(cachedEvent) + if err != nil { + return nil, fmt.Errorf("unexpected error: %v", err) + } + patched, err := strategicpatch.StrategicMergePatch(originalData, patch, event) + if err != nil { + return nil, fmt.Errorf("unexpected error: %v", err) + } + patchedObj := &v1.Event{} + err = json.Unmarshal(patched, patchedObj) + if err != nil { + return nil, fmt.Errorf("unexpected error: %v", err) + } + patchEvent <- patchedObj + return patchedObj, nil + } +} + +func TestEventf(t *testing.T) { + testPod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + SelfLink: "/api/version/pods/foo", + Name: "foo", + Namespace: "baz", + UID: "bar", + }, + } + testPod2 := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + SelfLink: "/api/version/pods/foo", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + }, + } + testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]") + if err != nil { + t.Fatal(err) + } + testRef2, err := ref.GetPartialReference(scheme.Scheme, testPod2, "spec.containers[3]") + if err != nil { + t.Fatal(err) + } + table := []struct { + obj k8sruntime.Object + eventtype string + reason string + messageFmt string + elements []interface{} + expect *v1.Event + expectLog string + expectUpdate bool + }{ + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testPod, + eventtype: v1.EventTypeNormal, + reason: "Killed", + messageFmt: "some other verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + }, + Reason: "Killed", + Message: "some other verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 2, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: true, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 3, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: true, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Stopped", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Stopped", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Stopped", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Stopped", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 2, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`, + expectUpdate: true, + }, + } + + testCache := map[string]*v1.Event{} + logCalled := make(chan struct{}) + createEvent := make(chan *v1.Event) + updateEvent := make(chan *v1.Event) + patchEvent := make(chan *v1.Event) + testEvents := testEventSink{ + OnCreate: OnCreateFactory(testCache, createEvent), + OnUpdate: func(event *v1.Event) (*v1.Event, error) { + updateEvent <- event + return event, nil + }, + OnPatch: OnPatchFactory(testCache, patchEvent), + } + eventBroadcaster := NewBroadcasterForTests(0) + sinkWatcher := eventBroadcaster.StartRecordingToSink(&testEvents) + + clock := clock.NewFakeClock(time.Now()) + recorder := recorderWithFakeClock(v1.EventSource{Component: "eventTest"}, eventBroadcaster, clock) + for index, item := range table { + clock.Step(1 * time.Second) + logWatcher := eventBroadcaster.StartLogging(func(formatter string, args ...interface{}) { + if e, a := item.expectLog, fmt.Sprintf(formatter, args...); e != a { + t.Errorf("Expected '%v', got '%v'", e, a) + } + logCalled <- struct{}{} + }) + recorder.Eventf(item.obj, item.eventtype, item.reason, item.messageFmt, item.elements...) + + <-logCalled + + // validate event + if item.expectUpdate { + actualEvent := <-patchEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } else { + actualEvent := <-createEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } + logWatcher.Stop() + } + sinkWatcher.Stop() +} + +func recorderWithFakeClock(eventSource v1.EventSource, eventBroadcaster EventBroadcaster, clock clock.Clock) EventRecorder { + return &recorderImpl{scheme.Scheme, eventSource, eventBroadcaster.(*eventBroadcasterImpl).Broadcaster, clock} +} + +func TestWriteEventError(t *testing.T) { + type entry struct { + timesToSendError int + attemptsWanted int + err error + } + table := map[string]*entry{ + "giveUp1": { + timesToSendError: 1000, + attemptsWanted: 1, + err: &restclient.RequestConstructionError{}, + }, + "giveUp2": { + timesToSendError: 1000, + attemptsWanted: 1, + err: &errors.StatusError{}, + }, + "retry1": { + timesToSendError: 1000, + attemptsWanted: 12, + err: &errors.UnexpectedObjectError{}, + }, + "retry2": { + timesToSendError: 1000, + attemptsWanted: 12, + err: fmt.Errorf("A weird error"), + }, + "succeedEventually": { + timesToSendError: 2, + attemptsWanted: 2, + err: fmt.Errorf("A weird error"), + }, + } + + clock := clock.IntervalClock{Time: time.Now(), Duration: time.Second} + eventCorrelator := NewEventCorrelator(&clock) + randGen := rand.New(rand.NewSource(time.Now().UnixNano())) + + for caseName, ent := range table { + attempts := 0 + sink := &testEventSink{ + OnCreate: func(event *v1.Event) (*v1.Event, error) { + attempts++ + if attempts < ent.timesToSendError { + return nil, ent.err + } + return event, nil + }, + } + ev := &v1.Event{} + recordToSink(sink, ev, eventCorrelator, randGen, 0) + if attempts != ent.attemptsWanted { + t.Errorf("case %v: wanted %d, got %d attempts", caseName, ent.attemptsWanted, attempts) + } + } +} + +func TestUpdateExpiredEvent(t *testing.T) { + clock := clock.IntervalClock{Time: time.Now(), Duration: time.Second} + eventCorrelator := NewEventCorrelator(&clock) + randGen := rand.New(rand.NewSource(time.Now().UnixNano())) + + var createdEvent *v1.Event + + sink := &testEventSink{ + OnPatch: func(*v1.Event, []byte) (*v1.Event, error) { + return nil, &errors.StatusError{ + ErrStatus: metav1.Status{ + Code: http.StatusNotFound, + Reason: metav1.StatusReasonNotFound, + }} + }, + OnCreate: func(event *v1.Event) (*v1.Event, error) { + createdEvent = event + return event, nil + }, + } + + ev := &v1.Event{} + ev.ResourceVersion = "updated-resource-version" + ev.Count = 2 + recordToSink(sink, ev, eventCorrelator, randGen, 0) + + if createdEvent == nil { + t.Error("Event did not get created after patch failed") + return + } + + if createdEvent.ResourceVersion != "" { + t.Errorf("Event did not have its resource version cleared, was %s", createdEvent.ResourceVersion) + } +} + +func TestLotsOfEvents(t *testing.T) { + recorderCalled := make(chan struct{}) + loggerCalled := make(chan struct{}) + + // Fail each event a few times to ensure there's some load on the tested code. + var counts [1000]int + testEvents := testEventSink{ + OnCreate: func(event *v1.Event) (*v1.Event, error) { + num, err := strconv.Atoi(event.Message) + if err != nil { + t.Error(err) + return event, nil + } + counts[num]++ + if counts[num] < 5 { + return nil, fmt.Errorf("fake error") + } + recorderCalled <- struct{}{} + return event, nil + }, + } + + eventBroadcaster := NewBroadcasterForTests(0) + sinkWatcher := eventBroadcaster.StartRecordingToSink(&testEvents) + logWatcher := eventBroadcaster.StartLogging(func(formatter string, args ...interface{}) { + loggerCalled <- struct{}{} + }) + recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "eventTest"}) + for i := 0; i < maxQueuedEvents; i++ { + // we want a unique object to stop spam filtering + ref := &v1.ObjectReference{ + Kind: "Pod", + Name: fmt.Sprintf("foo-%v", i), + Namespace: "baz", + UID: "bar", + APIVersion: "version", + } + // we need to vary the reason to prevent aggregation + go recorder.Eventf(ref, v1.EventTypeNormal, "Reason-"+string(i), strconv.Itoa(i)) + } + // Make sure no events were dropped by either of the listeners. + for i := 0; i < maxQueuedEvents; i++ { + <-recorderCalled + <-loggerCalled + } + // Make sure that every event was attempted 5 times + for i := 0; i < maxQueuedEvents; i++ { + if counts[i] < 5 { + t.Errorf("Only attempted to record event '%d' %d times.", i, counts[i]) + } + } + sinkWatcher.Stop() + logWatcher.Stop() +} + +func TestEventfNoNamespace(t *testing.T) { + testPod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + SelfLink: "/api/version/pods/foo", + Name: "foo", + UID: "bar", + }, + } + testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]") + if err != nil { + t.Fatal(err) + } + table := []struct { + obj k8sruntime.Object + eventtype string + reason string + messageFmt string + elements []interface{} + expect *v1.Event + expectLog string + expectUpdate bool + }{ + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "default", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: false, + }, + } + + testCache := map[string]*v1.Event{} + logCalled := make(chan struct{}) + createEvent := make(chan *v1.Event) + updateEvent := make(chan *v1.Event) + patchEvent := make(chan *v1.Event) + testEvents := testEventSink{ + OnCreate: OnCreateFactory(testCache, createEvent), + OnUpdate: func(event *v1.Event) (*v1.Event, error) { + updateEvent <- event + return event, nil + }, + OnPatch: OnPatchFactory(testCache, patchEvent), + } + eventBroadcaster := NewBroadcasterForTests(0) + sinkWatcher := eventBroadcaster.StartRecordingToSink(&testEvents) + + clock := clock.NewFakeClock(time.Now()) + recorder := recorderWithFakeClock(v1.EventSource{Component: "eventTest"}, eventBroadcaster, clock) + + for index, item := range table { + clock.Step(1 * time.Second) + logWatcher := eventBroadcaster.StartLogging(func(formatter string, args ...interface{}) { + if e, a := item.expectLog, fmt.Sprintf(formatter, args...); e != a { + t.Errorf("Expected '%v', got '%v'", e, a) + } + logCalled <- struct{}{} + }) + recorder.Eventf(item.obj, item.eventtype, item.reason, item.messageFmt, item.elements...) + + <-logCalled + + // validate event + if item.expectUpdate { + actualEvent := <-patchEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } else { + actualEvent := <-createEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } + + logWatcher.Stop() + } + sinkWatcher.Stop() +} + +func TestMultiSinkCache(t *testing.T) { + testPod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + SelfLink: "/api/version/pods/foo", + Name: "foo", + Namespace: "baz", + UID: "bar", + }, + } + testPod2 := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + SelfLink: "/api/version/pods/foo", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + }, + } + testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]") + if err != nil { + t.Fatal(err) + } + testRef2, err := ref.GetPartialReference(scheme.Scheme, testPod2, "spec.containers[3]") + if err != nil { + t.Fatal(err) + } + table := []struct { + obj k8sruntime.Object + eventtype string + reason string + messageFmt string + elements []interface{} + expect *v1.Event + expectLog string + expectUpdate bool + }{ + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testPod, + eventtype: v1.EventTypeNormal, + reason: "Killed", + messageFmt: "some other verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + }, + Reason: "Killed", + Message: "some other verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 2, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: true, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef, + eventtype: v1.EventTypeNormal, + reason: "Started", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "bar", + APIVersion: "version", + FieldPath: "spec.containers[2]", + }, + Reason: "Started", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 3, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`, + expectUpdate: true, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Stopped", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Stopped", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 1, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`, + expectUpdate: false, + }, + { + obj: testRef2, + eventtype: v1.EventTypeNormal, + reason: "Stopped", + messageFmt: "some verbose message: %v", + elements: []interface{}{1}, + expect: &v1.Event{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "baz", + }, + InvolvedObject: v1.ObjectReference{ + Kind: "Pod", + Name: "foo", + Namespace: "baz", + UID: "differentUid", + APIVersion: "version", + FieldPath: "spec.containers[3]", + }, + Reason: "Stopped", + Message: "some verbose message: 1", + Source: v1.EventSource{Component: "eventTest"}, + Count: 2, + Type: v1.EventTypeNormal, + }, + expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"version", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`, + expectUpdate: true, + }, + } + + testCache := map[string]*v1.Event{} + createEvent := make(chan *v1.Event) + updateEvent := make(chan *v1.Event) + patchEvent := make(chan *v1.Event) + testEvents := testEventSink{ + OnCreate: OnCreateFactory(testCache, createEvent), + OnUpdate: func(event *v1.Event) (*v1.Event, error) { + updateEvent <- event + return event, nil + }, + OnPatch: OnPatchFactory(testCache, patchEvent), + } + + testCache2 := map[string]*v1.Event{} + createEvent2 := make(chan *v1.Event) + updateEvent2 := make(chan *v1.Event) + patchEvent2 := make(chan *v1.Event) + testEvents2 := testEventSink{ + OnCreate: OnCreateFactory(testCache2, createEvent2), + OnUpdate: func(event *v1.Event) (*v1.Event, error) { + updateEvent2 <- event + return event, nil + }, + OnPatch: OnPatchFactory(testCache2, patchEvent2), + } + + eventBroadcaster := NewBroadcasterForTests(0) + clock := clock.NewFakeClock(time.Now()) + recorder := recorderWithFakeClock(v1.EventSource{Component: "eventTest"}, eventBroadcaster, clock) + + sinkWatcher := eventBroadcaster.StartRecordingToSink(&testEvents) + for index, item := range table { + clock.Step(1 * time.Second) + recorder.Eventf(item.obj, item.eventtype, item.reason, item.messageFmt, item.elements...) + + // validate event + if item.expectUpdate { + actualEvent := <-patchEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } else { + actualEvent := <-createEvent + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } + } + + // Another StartRecordingToSink call should start to record events with new clean cache. + sinkWatcher2 := eventBroadcaster.StartRecordingToSink(&testEvents2) + for index, item := range table { + clock.Step(1 * time.Second) + recorder.Eventf(item.obj, item.eventtype, item.reason, item.messageFmt, item.elements...) + + // validate event + if item.expectUpdate { + actualEvent := <-patchEvent2 + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } else { + actualEvent := <-createEvent2 + validateEvent(strconv.Itoa(index), actualEvent, item.expect, t) + } + } + + sinkWatcher.Stop() + sinkWatcher2.Stop() +} diff --git a/discovery/vendor/k8s.io/client-go/tools/record/events_cache_test.go b/discovery/vendor/k8s.io/client-go/tools/record/events_cache_test.go new file mode 100644 index 00000000..6ccd16d8 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/record/events_cache_test.go @@ -0,0 +1,287 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package record + +import ( + "reflect" + "strings" + "testing" + "time" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/apimachinery/pkg/util/diff" +) + +func makeObjectReference(kind, name, namespace string) v1.ObjectReference { + return v1.ObjectReference{ + Kind: kind, + Name: name, + Namespace: namespace, + UID: "C934D34AFB20242", + APIVersion: "version", + FieldPath: "spec.containers{mycontainer}", + } +} + +func makeEvent(reason, message string, involvedObject v1.ObjectReference) v1.Event { + eventTime := metav1.Now() + event := v1.Event{ + Reason: reason, + Message: message, + InvolvedObject: involvedObject, + Source: v1.EventSource{ + Component: "kubelet", + Host: "kublet.node1", + }, + Count: 1, + FirstTimestamp: eventTime, + LastTimestamp: eventTime, + Type: v1.EventTypeNormal, + } + return event +} + +func makeEvents(num int, template v1.Event) []v1.Event { + events := []v1.Event{} + for i := 0; i < num; i++ { + events = append(events, template) + } + return events +} + +func makeUniqueEvents(num int) []v1.Event { + events := []v1.Event{} + kind := "Pod" + for i := 0; i < num; i++ { + reason := strings.Join([]string{"reason", string(i)}, "-") + message := strings.Join([]string{"message", string(i)}, "-") + name := strings.Join([]string{"pod", string(i)}, "-") + namespace := strings.Join([]string{"ns", string(i)}, "-") + involvedObject := makeObjectReference(kind, name, namespace) + events = append(events, makeEvent(reason, message, involvedObject)) + } + return events +} + +func makeSimilarEvents(num int, template v1.Event, messagePrefix string) []v1.Event { + events := makeEvents(num, template) + for i := range events { + events[i].Message = strings.Join([]string{messagePrefix, string(i), events[i].Message}, "-") + } + return events +} + +func setCount(event v1.Event, count int) v1.Event { + event.Count = int32(count) + return event +} + +func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v1.Event, t *testing.T) (*v1.Event, error) { + recvEvent := *actualEvent + expectCompression := expectedEvent.Count > 1 + t.Logf("%v - expectedEvent.Count is %d\n", messagePrefix, expectedEvent.Count) + // Just check that the timestamp was set. + if recvEvent.FirstTimestamp.IsZero() || recvEvent.LastTimestamp.IsZero() { + t.Errorf("%v - timestamp wasn't set: %#v", messagePrefix, recvEvent) + } + actualFirstTimestamp := recvEvent.FirstTimestamp + actualLastTimestamp := recvEvent.LastTimestamp + if actualFirstTimestamp.Equal(&actualLastTimestamp) { + if expectCompression { + t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be different to indicate event compression happened, but were the same. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent) + } + } else { + if expectedEvent.Count == 1 { + t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be equal to indicate only one occurrence of the event, but were different. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent) + } + } + // Temp clear time stamps for comparison because actual values don't matter for comparison + recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp + recvEvent.LastTimestamp = expectedEvent.LastTimestamp + // Check that name has the right prefix. + if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) { + t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en) + } + recvEvent.Name = expectedEvent.Name + if e, a := expectedEvent, &recvEvent; !reflect.DeepEqual(e, a) { + t.Errorf("%v - diff: %s", messagePrefix, diff.ObjectGoPrintDiff(e, a)) + } + recvEvent.FirstTimestamp = actualFirstTimestamp + recvEvent.LastTimestamp = actualLastTimestamp + return actualEvent, nil +} + +// TestDefaultEventFilterFunc ensures that no events are filtered +func TestDefaultEventFilterFunc(t *testing.T) { + event := makeEvent("end-of-world", "it was fun", makeObjectReference("Pod", "pod1", "other")) + if DefaultEventFilterFunc(&event) { + t.Fatalf("DefaultEventFilterFunc should always return false") + } +} + +// TestEventAggregatorByReasonFunc ensures that two events are aggregated if they vary only by event.message +func TestEventAggregatorByReasonFunc(t *testing.T) { + event1 := makeEvent("end-of-world", "it was fun", makeObjectReference("Pod", "pod1", "other")) + event2 := makeEvent("end-of-world", "it was awful", makeObjectReference("Pod", "pod1", "other")) + event3 := makeEvent("nevermind", "it was a bug", makeObjectReference("Pod", "pod1", "other")) + + aggKey1, localKey1 := EventAggregatorByReasonFunc(&event1) + aggKey2, localKey2 := EventAggregatorByReasonFunc(&event2) + aggKey3, _ := EventAggregatorByReasonFunc(&event3) + + if aggKey1 != aggKey2 { + t.Errorf("Expected %v equal %v", aggKey1, aggKey2) + } + if localKey1 == localKey2 { + t.Errorf("Expected %v to not equal %v", aggKey1, aggKey3) + } + if aggKey1 == aggKey3 { + t.Errorf("Expected %v to not equal %v", aggKey1, aggKey3) + } +} + +// TestEventAggregatorByReasonMessageFunc validates the proper output for an aggregate message +func TestEventAggregatorByReasonMessageFunc(t *testing.T) { + expectedPrefix := "(combined from similar events): " + event1 := makeEvent("end-of-world", "it was fun", makeObjectReference("Pod", "pod1", "other")) + actual := EventAggregatorByReasonMessageFunc(&event1) + if !strings.HasPrefix(actual, expectedPrefix) { + t.Errorf("Expected %v to begin with prefix %v", actual, expectedPrefix) + } +} + +// TestEventCorrelator validates proper counting, aggregation of events +func TestEventCorrelator(t *testing.T) { + firstEvent := makeEvent("first", "i am first", makeObjectReference("Pod", "my-pod", "my-ns")) + duplicateEvent := makeEvent("duplicate", "me again", makeObjectReference("Pod", "my-pod", "my-ns")) + uniqueEvent := makeEvent("unique", "snowflake", makeObjectReference("Pod", "my-pod", "my-ns")) + similarEvent := makeEvent("similar", "similar message", makeObjectReference("Pod", "my-pod", "my-ns")) + similarEvent.InvolvedObject.FieldPath = "spec.containers{container1}" + aggregateEvent := makeEvent(similarEvent.Reason, EventAggregatorByReasonMessageFunc(&similarEvent), similarEvent.InvolvedObject) + similarButDifferentContainerEvent := similarEvent + similarButDifferentContainerEvent.InvolvedObject.FieldPath = "spec.containers{container2}" + scenario := map[string]struct { + previousEvents []v1.Event + newEvent v1.Event + expectedEvent v1.Event + intervalSeconds int + expectedSkip bool + }{ + "create-a-single-event": { + previousEvents: []v1.Event{}, + newEvent: firstEvent, + expectedEvent: setCount(firstEvent, 1), + intervalSeconds: 5, + }, + "the-same-event-should-just-count": { + previousEvents: makeEvents(1, duplicateEvent), + newEvent: duplicateEvent, + expectedEvent: setCount(duplicateEvent, 2), + intervalSeconds: 5, + }, + "the-same-event-should-just-count-even-if-more-than-aggregate": { + previousEvents: makeEvents(defaultAggregateMaxEvents, duplicateEvent), + newEvent: duplicateEvent, + expectedEvent: setCount(duplicateEvent, defaultAggregateMaxEvents+1), + intervalSeconds: 30, // larger interval induces aggregation but not spam. + }, + "the-same-event-is-spam-if-happens-too-frequently": { + previousEvents: makeEvents(defaultSpamBurst+1, duplicateEvent), + newEvent: duplicateEvent, + expectedSkip: true, + intervalSeconds: 1, + }, + "create-many-unique-events": { + previousEvents: makeUniqueEvents(30), + newEvent: uniqueEvent, + expectedEvent: setCount(uniqueEvent, 1), + intervalSeconds: 5, + }, + "similar-events-should-aggregate-event": { + previousEvents: makeSimilarEvents(defaultAggregateMaxEvents-1, similarEvent, similarEvent.Message), + newEvent: similarEvent, + expectedEvent: setCount(aggregateEvent, 1), + intervalSeconds: 5, + }, + "similar-events-many-times-should-count-the-aggregate": { + previousEvents: makeSimilarEvents(defaultAggregateMaxEvents, similarEvent, similarEvent.Message), + newEvent: similarEvent, + expectedEvent: setCount(aggregateEvent, 2), + intervalSeconds: 5, + }, + "events-from-different-containers-do-not-aggregate": { + previousEvents: makeEvents(1, similarButDifferentContainerEvent), + newEvent: similarEvent, + expectedEvent: setCount(similarEvent, 1), + intervalSeconds: 5, + }, + "similar-events-whose-interval-is-greater-than-aggregate-interval-do-not-aggregate": { + previousEvents: makeSimilarEvents(defaultAggregateMaxEvents-1, similarEvent, similarEvent.Message), + newEvent: similarEvent, + expectedEvent: setCount(similarEvent, 1), + intervalSeconds: defaultAggregateIntervalInSeconds, + }, + } + + for testScenario, testInput := range scenario { + eventInterval := time.Duration(testInput.intervalSeconds) * time.Second + clock := clock.IntervalClock{Time: time.Now(), Duration: eventInterval} + correlator := NewEventCorrelator(&clock) + for i := range testInput.previousEvents { + event := testInput.previousEvents[i] + now := metav1.NewTime(clock.Now()) + event.FirstTimestamp = now + event.LastTimestamp = now + result, err := correlator.EventCorrelate(&event) + if err != nil { + t.Errorf("scenario %v: unexpected error playing back prevEvents %v", testScenario, err) + } + // if we are skipping the event, we can avoid updating state + if !result.Skip { + correlator.UpdateState(result.Event) + } + } + + // update the input to current clock value + now := metav1.NewTime(clock.Now()) + testInput.newEvent.FirstTimestamp = now + testInput.newEvent.LastTimestamp = now + result, err := correlator.EventCorrelate(&testInput.newEvent) + if err != nil { + t.Errorf("scenario %v: unexpected error correlating input event %v", testScenario, err) + } + + // verify we did not get skip from filter function unexpectedly... + if result.Skip != testInput.expectedSkip { + t.Errorf("scenario %v: expected skip %v, but got %v", testScenario, testInput.expectedSkip, result.Skip) + continue + } + + // we wanted to actually skip, so no event is needed to validate + if testInput.expectedSkip { + continue + } + + // validate event + _, err = validateEvent(testScenario, result.Event, &testInput.expectedEvent, t) + if err != nil { + t.Errorf("scenario %v: unexpected error validating result %v", testScenario, err) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/reference/BUILD b/discovery/vendor/k8s.io/client-go/tools/reference/BUILD new file mode 100644 index 00000000..47da958a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/reference/BUILD @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["ref.go"], + importpath = "k8s.io/client-go/tools/reference", + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/remotecommand/BUILD b/discovery/vendor/k8s.io/client-go/tools/remotecommand/BUILD new file mode 100644 index 00000000..b30c122c --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/remotecommand/BUILD @@ -0,0 +1,60 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "v2_test.go", + "v4_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "errorstream.go", + "remotecommand.go", + "resize.go", + "v1.go", + "v2.go", + "v3.go", + "v4.go", + ], + importpath = "k8s.io/client-go/tools/remotecommand", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/api/core/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + "//vendor/k8s.io/client-go/transport/spdy:go_default_library", + "//vendor/k8s.io/client-go/util/exec:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/tools/remotecommand/v2_test.go b/discovery/vendor/k8s.io/client-go/tools/remotecommand/v2_test.go new file mode 100644 index 00000000..e303f57a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/remotecommand/v2_test.go @@ -0,0 +1,228 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package remotecommand + +import ( + "errors" + "io" + "net/http" + "strings" + "testing" + "time" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/httpstream" + "k8s.io/apimachinery/pkg/util/wait" +) + +type fakeReader struct { + err error +} + +func (r *fakeReader) Read([]byte) (int, error) { return 0, r.err } + +type fakeWriter struct{} + +func (*fakeWriter) Write([]byte) (int, error) { return 0, nil } + +type fakeStreamCreator struct { + created map[string]bool + errors map[string]error +} + +var _ streamCreator = &fakeStreamCreator{} + +func (f *fakeStreamCreator) CreateStream(headers http.Header) (httpstream.Stream, error) { + streamType := headers.Get(v1.StreamType) + f.created[streamType] = true + return nil, f.errors[streamType] +} + +func TestV2CreateStreams(t *testing.T) { + tests := []struct { + name string + stdin bool + stdinError error + stdout bool + stdoutError error + stderr bool + stderrError error + errorError error + tty bool + expectError bool + }{ + { + name: "stdin error", + stdin: true, + stdinError: errors.New("stdin error"), + expectError: true, + }, + { + name: "stdout error", + stdout: true, + stdoutError: errors.New("stdout error"), + expectError: true, + }, + { + name: "stderr error", + stderr: true, + stderrError: errors.New("stderr error"), + expectError: true, + }, + { + name: "error stream error", + stdin: true, + stdout: true, + stderr: true, + errorError: errors.New("error stream error"), + expectError: true, + }, + { + name: "no errors", + stdin: true, + stdout: true, + stderr: true, + expectError: false, + }, + { + name: "no errors, stderr & tty set, don't expect stderr", + stdin: true, + stdout: true, + stderr: true, + tty: true, + expectError: false, + }, + } + for _, test := range tests { + conn := &fakeStreamCreator{ + created: make(map[string]bool), + errors: map[string]error{ + v1.StreamTypeStdin: test.stdinError, + v1.StreamTypeStdout: test.stdoutError, + v1.StreamTypeStderr: test.stderrError, + v1.StreamTypeError: test.errorError, + }, + } + + opts := StreamOptions{Tty: test.tty} + if test.stdin { + opts.Stdin = &fakeReader{} + } + if test.stdout { + opts.Stdout = &fakeWriter{} + } + if test.stderr { + opts.Stderr = &fakeWriter{} + } + + h := newStreamProtocolV2(opts).(*streamProtocolV2) + err := h.createStreams(conn) + + if test.expectError { + if err == nil { + t.Errorf("%s: expected error", test.name) + continue + } + if e, a := test.stdinError, err; test.stdinError != nil && e != a { + t.Errorf("%s: expected %v, got %v", test.name, e, a) + } + if e, a := test.stdoutError, err; test.stdoutError != nil && e != a { + t.Errorf("%s: expected %v, got %v", test.name, e, a) + } + if e, a := test.stderrError, err; test.stderrError != nil && e != a { + t.Errorf("%s: expected %v, got %v", test.name, e, a) + } + if e, a := test.errorError, err; test.errorError != nil && e != a { + t.Errorf("%s: expected %v, got %v", test.name, e, a) + } + continue + } + + if !test.expectError && err != nil { + t.Errorf("%s: unexpected error: %v", test.name, err) + continue + } + + if test.stdin && !conn.created[v1.StreamTypeStdin] { + t.Errorf("%s: expected stdin stream", test.name) + } + if test.stdout && !conn.created[v1.StreamTypeStdout] { + t.Errorf("%s: expected stdout stream", test.name) + } + if test.stderr { + if test.tty && conn.created[v1.StreamTypeStderr] { + t.Errorf("%s: unexpected stderr stream because tty is set", test.name) + } else if !test.tty && !conn.created[v1.StreamTypeStderr] { + t.Errorf("%s: expected stderr stream", test.name) + } + } + if !conn.created[v1.StreamTypeError] { + t.Errorf("%s: expected error stream", test.name) + } + + } +} + +func TestV2ErrorStreamReading(t *testing.T) { + tests := []struct { + name string + stream io.Reader + expectedError error + }{ + { + name: "error reading from stream", + stream: &fakeReader{errors.New("foo")}, + expectedError: errors.New("error reading from error stream: foo"), + }, + { + name: "stream returns an error", + stream: strings.NewReader("some error"), + expectedError: errors.New("error executing remote command: some error"), + }, + } + + for _, test := range tests { + h := newStreamProtocolV2(StreamOptions{}).(*streamProtocolV2) + h.errorStream = test.stream + + ch := watchErrorStream(h.errorStream, &errorDecoderV2{}) + if ch == nil { + t.Fatalf("%s: unexpected nil channel", test.name) + } + + var err error + select { + case err = <-ch: + case <-time.After(wait.ForeverTestTimeout): + t.Fatalf("%s: timed out", test.name) + } + + if test.expectedError != nil { + if err == nil { + t.Errorf("%s: expected an error", test.name) + } else if e, a := test.expectedError, err; e.Error() != a.Error() { + t.Errorf("%s: expected %q, got %q", test.name, e, a) + } + continue + } + + if test.expectedError == nil && err != nil { + t.Errorf("%s: unexpected error: %v", test.name, err) + continue + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/tools/remotecommand/v4_test.go b/discovery/vendor/k8s.io/client-go/tools/remotecommand/v4_test.go new file mode 100644 index 00000000..b8674918 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/tools/remotecommand/v4_test.go @@ -0,0 +1,71 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package remotecommand + +import ( + "fmt" + "testing" +) + +func TestV4ErrorDecoder(t *testing.T) { + dec := errorDecoderV4{} + + type Test struct { + message string + err string + } + + for _, test := range []Test{ + { + message: "{}", + err: "error stream protocol error: unknown error", + }, + { + message: "{", + err: "error stream protocol error: unexpected end of JSON input in \"{\"", + }, + { + message: `{"status": "Success" }`, + err: "", + }, + { + message: `{"status": "Failure", "message": "foobar" }`, + err: "foobar", + }, + { + message: `{"status": "Failure", "message": "foobar", "reason": "NonZeroExitCode", "details": {"causes": [{"reason": "foo"}] } }`, + err: "error stream protocol error: no ExitCode cause given", + }, + { + message: `{"status": "Failure", "message": "foobar", "reason": "NonZeroExitCode", "details": {"causes": [{"reason": "ExitCode"}] } }`, + err: "error stream protocol error: invalid exit code value \"\"", + }, + { + message: `{"status": "Failure", "message": "foobar", "reason": "NonZeroExitCode", "details": {"causes": [{"reason": "ExitCode", "message": "42"}] } }`, + err: "command terminated with exit code 42", + }, + } { + err := dec.decode([]byte(test.message)) + want := test.err + if want == "" { + want = "" + } + if got := fmt.Sprintf("%v", err); got != want { + t.Errorf("wrong error for message %q: want=%q, got=%q", test.message, want, got) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/transport/BUILD b/discovery/vendor/k8s.io/client-go/transport/BUILD new file mode 100644 index 00000000..71494544 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/transport/BUILD @@ -0,0 +1,48 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "cache_test.go", + "round_trippers_test.go", + "transport_test.go", + ], + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "cache.go", + "config.go", + "round_trippers.go", + "transport.go", + ], + importpath = "k8s.io/client-go/transport", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/transport/spdy:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/transport/cache.go b/discovery/vendor/k8s.io/client-go/transport/cache.go index da22cdee..7c40848c 100644 --- a/discovery/vendor/k8s.io/client-go/transport/cache.go +++ b/discovery/vendor/k8s.io/client-go/transport/cache.go @@ -31,12 +31,28 @@ import ( // the config has no custom TLS options, http.DefaultTransport is returned. type tlsTransportCache struct { mu sync.Mutex - transports map[string]*http.Transport + transports map[tlsCacheKey]*http.Transport } const idleConnsPerHost = 25 -var tlsCache = &tlsTransportCache{transports: make(map[string]*http.Transport)} +var tlsCache = &tlsTransportCache{transports: make(map[tlsCacheKey]*http.Transport)} + +type tlsCacheKey struct { + insecure bool + caData string + certData string + keyData string + serverName string +} + +func (t tlsCacheKey) String() string { + keyText := "" + if len(t.keyData) > 0 { + keyText = "" + } + return fmt.Sprintf("insecure:%v, caData:%#v, certData:%#v, keyData:%s, serverName:%s", t.insecure, t.caData, t.certData, keyText, t.serverName) +} func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) { key, err := tlsConfigKey(config) @@ -82,11 +98,16 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) { } // tlsConfigKey returns a unique key for tls.Config objects returned from TLSConfigFor -func tlsConfigKey(c *Config) (string, error) { +func tlsConfigKey(c *Config) (tlsCacheKey, error) { // Make sure ca/key/cert content is loaded if err := loadTLSFiles(c); err != nil { - return "", err + return tlsCacheKey{}, err } - // Only include the things that actually affect the tls.Config - return fmt.Sprintf("%v/%x/%x/%x/%v", c.TLS.Insecure, c.TLS.CAData, c.TLS.CertData, c.TLS.KeyData, c.TLS.ServerName), nil + return tlsCacheKey{ + insecure: c.TLS.Insecure, + caData: string(c.TLS.CAData), + certData: string(c.TLS.CertData), + keyData: string(c.TLS.KeyData), + serverName: c.TLS.ServerName, + }, nil } diff --git a/discovery/vendor/k8s.io/client-go/transport/cache_test.go b/discovery/vendor/k8s.io/client-go/transport/cache_test.go new file mode 100644 index 00000000..81f428de --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/transport/cache_test.go @@ -0,0 +1,128 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package transport + +import ( + "net/http" + "testing" +) + +func TestTLSConfigKey(t *testing.T) { + // Make sure config fields that don't affect the tls config don't affect the cache key + identicalConfigurations := map[string]*Config{ + "empty": {}, + "basic": {Username: "bob", Password: "password"}, + "bearer": {BearerToken: "token"}, + "user agent": {UserAgent: "useragent"}, + "transport": {Transport: http.DefaultTransport}, + "wrap transport": {WrapTransport: func(http.RoundTripper) http.RoundTripper { return nil }}, + } + for nameA, valueA := range identicalConfigurations { + for nameB, valueB := range identicalConfigurations { + keyA, err := tlsConfigKey(valueA) + if err != nil { + t.Errorf("Unexpected error for %q: %v", nameA, err) + continue + } + keyB, err := tlsConfigKey(valueB) + if err != nil { + t.Errorf("Unexpected error for %q: %v", nameB, err) + continue + } + if keyA != keyB { + t.Errorf("Expected identical cache keys for %q and %q, got:\n\t%s\n\t%s", nameA, nameB, keyA, keyB) + continue + } + } + } + + // Make sure config fields that affect the tls config affect the cache key + uniqueConfigurations := map[string]*Config{ + "no tls": {}, + "insecure": {TLS: TLSConfig{Insecure: true}}, + "cadata 1": {TLS: TLSConfig{CAData: []byte{1}}}, + "cadata 2": {TLS: TLSConfig{CAData: []byte{2}}}, + "cert 1, key 1": { + TLS: TLSConfig{ + CertData: []byte{1}, + KeyData: []byte{1}, + }, + }, + "cert 1, key 1, servername 1": { + TLS: TLSConfig{ + CertData: []byte{1}, + KeyData: []byte{1}, + ServerName: "1", + }, + }, + "cert 1, key 1, servername 2": { + TLS: TLSConfig{ + CertData: []byte{1}, + KeyData: []byte{1}, + ServerName: "2", + }, + }, + "cert 1, key 2": { + TLS: TLSConfig{ + CertData: []byte{1}, + KeyData: []byte{2}, + }, + }, + "cert 2, key 1": { + TLS: TLSConfig{ + CertData: []byte{2}, + KeyData: []byte{1}, + }, + }, + "cert 2, key 2": { + TLS: TLSConfig{ + CertData: []byte{2}, + KeyData: []byte{2}, + }, + }, + "cadata 1, cert 1, key 1": { + TLS: TLSConfig{ + CAData: []byte{1}, + CertData: []byte{1}, + KeyData: []byte{1}, + }, + }, + } + for nameA, valueA := range uniqueConfigurations { + for nameB, valueB := range uniqueConfigurations { + // Don't compare to ourselves + if nameA == nameB { + continue + } + + keyA, err := tlsConfigKey(valueA) + if err != nil { + t.Errorf("Unexpected error for %q: %v", nameA, err) + continue + } + keyB, err := tlsConfigKey(valueB) + if err != nil { + t.Errorf("Unexpected error for %q: %v", nameB, err) + continue + } + if keyA == keyB { + t.Errorf("Expected unique cache keys for %q and %q, got:\n\t%s\n\t%s", nameA, nameB, keyA, keyB) + continue + } + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/transport/config.go b/discovery/vendor/k8s.io/client-go/transport/config.go index 425f8f87..af347daf 100644 --- a/discovery/vendor/k8s.io/client-go/transport/config.go +++ b/discovery/vendor/k8s.io/client-go/transport/config.go @@ -37,10 +37,6 @@ type Config struct { // Bearer token for authentication BearerToken string - // CacheDir is the directory where we'll store HTTP cached responses. - // If set to empty string, no caching mechanism will be used. - CacheDir string - // Impersonate is the config that this Config will impersonate using Impersonate ImpersonationConfig diff --git a/discovery/vendor/k8s.io/client-go/transport/round_trippers.go b/discovery/vendor/k8s.io/client-go/transport/round_trippers.go index 2ee605d7..c728b187 100644 --- a/discovery/vendor/k8s.io/client-go/transport/round_trippers.go +++ b/discovery/vendor/k8s.io/client-go/transport/round_trippers.go @@ -19,14 +19,10 @@ package transport import ( "fmt" "net/http" - "path/filepath" "strings" "time" "github.com/golang/glog" - "github.com/gregjones/httpcache" - "github.com/gregjones/httpcache/diskcache" - "github.com/peterbourgon/diskv" utilnet "k8s.io/apimachinery/pkg/util/net" ) @@ -60,9 +56,6 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip len(config.Impersonate.Extra) > 0 { rt = NewImpersonatingRoundTripper(config.Impersonate, rt) } - if len(config.CacheDir) > 0 { - rt = NewCacheRoundTripper(config.CacheDir, rt) - } return rt, nil } @@ -86,30 +79,6 @@ type requestCanceler interface { CancelRequest(*http.Request) } -type cacheRoundTripper struct { - rt *httpcache.Transport -} - -// NewCacheRoundTripper creates a roundtripper that reads the ETag on -// response headers and send the If-None-Match header on subsequent -// corresponding requests. -func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper { - d := diskv.New(diskv.Options{ - BasePath: cacheDir, - TempDir: filepath.Join(cacheDir, ".diskv-temp"), - }) - t := httpcache.NewTransport(diskcache.NewWithDiskv(d)) - t.Transport = rt - - return &cacheRoundTripper{rt: t} -} - -func (rt *cacheRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - return rt.rt.RoundTrip(req) -} - -func (rt *cacheRoundTripper) WrappedRoundTripper() http.RoundTripper { return rt.rt.Transport } - type authProxyRoundTripper struct { username string groups []string diff --git a/discovery/vendor/k8s.io/client-go/transport/round_trippers_test.go b/discovery/vendor/k8s.io/client-go/transport/round_trippers_test.go new file mode 100644 index 00000000..d5ffc6bd --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/transport/round_trippers_test.go @@ -0,0 +1,218 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package transport + +import ( + "net/http" + "reflect" + "strings" + "testing" +) + +type testRoundTripper struct { + Request *http.Request + Response *http.Response + Err error +} + +func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { + rt.Request = req + return rt.Response, rt.Err +} + +func TestBearerAuthRoundTripper(t *testing.T) { + rt := &testRoundTripper{} + req := &http.Request{} + NewBearerAuthRoundTripper("test", rt).RoundTrip(req) + if rt.Request == nil { + t.Fatalf("unexpected nil request: %v", rt) + } + if rt.Request == req { + t.Fatalf("round tripper should have copied request object: %#v", rt.Request) + } + if rt.Request.Header.Get("Authorization") != "Bearer test" { + t.Errorf("unexpected authorization header: %#v", rt.Request) + } +} + +func TestBasicAuthRoundTripper(t *testing.T) { + for n, tc := range map[string]struct { + user string + pass string + }{ + "basic": {user: "user", pass: "pass"}, + "no pass": {user: "user"}, + } { + rt := &testRoundTripper{} + req := &http.Request{} + NewBasicAuthRoundTripper(tc.user, tc.pass, rt).RoundTrip(req) + if rt.Request == nil { + t.Fatalf("%s: unexpected nil request: %v", n, rt) + } + if rt.Request == req { + t.Fatalf("%s: round tripper should have copied request object: %#v", n, rt.Request) + } + if user, pass, found := rt.Request.BasicAuth(); !found || user != tc.user || pass != tc.pass { + t.Errorf("%s: unexpected authorization header: %#v", n, rt.Request) + } + } +} + +func TestUserAgentRoundTripper(t *testing.T) { + rt := &testRoundTripper{} + req := &http.Request{ + Header: make(http.Header), + } + req.Header.Set("User-Agent", "other") + NewUserAgentRoundTripper("test", rt).RoundTrip(req) + if rt.Request == nil { + t.Fatalf("unexpected nil request: %v", rt) + } + if rt.Request != req { + t.Fatalf("round tripper should not have copied request object: %#v", rt.Request) + } + if rt.Request.Header.Get("User-Agent") != "other" { + t.Errorf("unexpected user agent header: %#v", rt.Request) + } + + req = &http.Request{} + NewUserAgentRoundTripper("test", rt).RoundTrip(req) + if rt.Request == nil { + t.Fatalf("unexpected nil request: %v", rt) + } + if rt.Request == req { + t.Fatalf("round tripper should have copied request object: %#v", rt.Request) + } + if rt.Request.Header.Get("User-Agent") != "test" { + t.Errorf("unexpected user agent header: %#v", rt.Request) + } +} + +func TestImpersonationRoundTripper(t *testing.T) { + tcs := []struct { + name string + impersonationConfig ImpersonationConfig + expected map[string][]string + }{ + { + name: "all", + impersonationConfig: ImpersonationConfig{ + UserName: "user", + Groups: []string{"one", "two"}, + Extra: map[string][]string{ + "first": {"A", "a"}, + "second": {"B", "b"}, + }, + }, + expected: map[string][]string{ + ImpersonateUserHeader: {"user"}, + ImpersonateGroupHeader: {"one", "two"}, + ImpersonateUserExtraHeaderPrefix + "First": {"A", "a"}, + ImpersonateUserExtraHeaderPrefix + "Second": {"B", "b"}, + }, + }, + } + + for _, tc := range tcs { + rt := &testRoundTripper{} + req := &http.Request{ + Header: make(http.Header), + } + NewImpersonatingRoundTripper(tc.impersonationConfig, rt).RoundTrip(req) + + for k, v := range rt.Request.Header { + expected, ok := tc.expected[k] + if !ok { + t.Errorf("%v missing %v=%v", tc.name, k, v) + continue + } + if !reflect.DeepEqual(expected, v) { + t.Errorf("%v expected %v: %v, got %v", tc.name, k, expected, v) + } + } + for k, v := range tc.expected { + expected, ok := rt.Request.Header[k] + if !ok { + t.Errorf("%v missing %v=%v", tc.name, k, v) + continue + } + if !reflect.DeepEqual(expected, v) { + t.Errorf("%v expected %v: %v, got %v", tc.name, k, expected, v) + } + } + } +} + +func TestAuthProxyRoundTripper(t *testing.T) { + for n, tc := range map[string]struct { + username string + groups []string + extra map[string][]string + }{ + "allfields": { + username: "user", + groups: []string{"groupA", "groupB"}, + extra: map[string][]string{ + "one": {"alpha", "bravo"}, + "two": {"charlie", "delta"}, + }, + }, + } { + rt := &testRoundTripper{} + req := &http.Request{} + NewAuthProxyRoundTripper(tc.username, tc.groups, tc.extra, rt).RoundTrip(req) + if rt.Request == nil { + t.Errorf("%s: unexpected nil request: %v", n, rt) + continue + } + if rt.Request == req { + t.Errorf("%s: round tripper should have copied request object: %#v", n, rt.Request) + continue + } + + actualUsernames, ok := rt.Request.Header["X-Remote-User"] + if !ok { + t.Errorf("%s missing value", n) + continue + } + if e, a := []string{tc.username}, actualUsernames; !reflect.DeepEqual(e, a) { + t.Errorf("%s expected %v, got %v", n, e, a) + continue + } + actualGroups, ok := rt.Request.Header["X-Remote-Group"] + if !ok { + t.Errorf("%s missing value", n) + continue + } + if e, a := tc.groups, actualGroups; !reflect.DeepEqual(e, a) { + t.Errorf("%s expected %v, got %v", n, e, a) + continue + } + + actualExtra := map[string][]string{} + for key, values := range rt.Request.Header { + if strings.HasPrefix(strings.ToLower(key), strings.ToLower("X-Remote-Extra-")) { + extraKey := strings.ToLower(key[len("X-Remote-Extra-"):]) + actualExtra[extraKey] = append(actualExtra[key], values...) + } + } + if e, a := tc.extra, actualExtra; !reflect.DeepEqual(e, a) { + t.Errorf("%s expected %v, got %v", n, e, a) + continue + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/transport/spdy/BUILD b/discovery/vendor/k8s.io/client-go/transport/spdy/BUILD new file mode 100644 index 00000000..bf90084b --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/transport/spdy/BUILD @@ -0,0 +1,30 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["spdy.go"], + importpath = "k8s.io/client-go/transport/spdy", + deps = [ + "//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy:go_default_library", + "//vendor/k8s.io/client-go/rest:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/transport/transport_test.go b/discovery/vendor/k8s.io/client-go/transport/transport_test.go new file mode 100644 index 00000000..4d2d78f8 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/transport/transport_test.go @@ -0,0 +1,204 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package transport + +import ( + "net/http" + "testing" +) + +const ( + rootCACert = `-----BEGIN CERTIFICATE----- +MIIC4DCCAcqgAwIBAgIBATALBgkqhkiG9w0BAQswIzEhMB8GA1UEAwwYMTAuMTMu +MTI5LjEwNkAxNDIxMzU5MDU4MB4XDTE1MDExNTIxNTczN1oXDTE2MDExNTIxNTcz +OFowIzEhMB8GA1UEAwwYMTAuMTMuMTI5LjEwNkAxNDIxMzU5MDU4MIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunDRXGwsiYWGFDlWH6kjGun+PshDGeZX +xtx9lUnL8pIRWH3wX6f13PO9sktaOWW0T0mlo6k2bMlSLlSZgG9H6og0W6gLS3vq +s4VavZ6DbXIwemZG2vbRwsvR+t4G6Nbwelm6F8RFnA1Fwt428pavmNQ/wgYzo+T1 +1eS+HiN4ACnSoDSx3QRWcgBkB1g6VReofVjx63i0J+w8Q/41L9GUuLqquFxu6ZnH +60vTB55lHgFiDLjA1FkEz2dGvGh/wtnFlRvjaPC54JH2K1mPYAUXTreoeJtLJKX0 +ycoiyB24+zGCniUmgIsmQWRPaOPircexCp1BOeze82BT1LCZNTVaxQIDAQABoyMw +ITAOBgNVHQ8BAf8EBAMCAKQwDwYDVR0TAQH/BAUwAwEB/zALBgkqhkiG9w0BAQsD +ggEBADMxsUuAFlsYDpF4fRCzXXwrhbtj4oQwcHpbu+rnOPHCZupiafzZpDu+rw4x +YGPnCb594bRTQn4pAu3Ac18NbLD5pV3uioAkv8oPkgr8aUhXqiv7KdDiaWm6sbAL +EHiXVBBAFvQws10HMqMoKtO8f1XDNAUkWduakR/U6yMgvOPwS7xl0eUTqyRB6zGb +K55q2dejiFWaFqB/y78txzvz6UlOZKE44g2JAVoJVM6kGaxh33q8/FmrL4kuN3ut +W+MmJCVDvd4eEqPwbp7146ZWTqpIJ8lvA6wuChtqV8lhAPka2hD/LMqY8iXNmfXD +uml0obOEy+ON91k+SWTJ3ggmF/U= +-----END CERTIFICATE-----` + + certData = `-----BEGIN CERTIFICATE----- +MIIC6jCCAdSgAwIBAgIBCzALBgkqhkiG9w0BAQswIzEhMB8GA1UEAwwYMTAuMTMu +MTI5LjEwNkAxNDIxMzU5MDU4MB4XDTE1MDExNTIyMDEzMVoXDTE2MDExNTIyMDEz +MlowGzEZMBcGA1UEAxMQb3BlbnNoaWZ0LWNsaWVudDCCASIwDQYJKoZIhvcNAQEB +BQADggEPADCCAQoCggEBAKtdhz0+uCLXw5cSYns9rU/XifFSpb/x24WDdrm72S/v +b9BPYsAStiP148buylr1SOuNi8sTAZmlVDDIpIVwMLff+o2rKYDicn9fjbrTxTOj +lI4pHJBH+JU3AJ0tbajupioh70jwFS0oYpwtneg2zcnE2Z4l6mhrj2okrc5Q1/X2 +I2HChtIU4JYTisObtin10QKJX01CLfYXJLa8upWzKZ4/GOcHG+eAV3jXWoXidtjb +1Usw70amoTZ6mIVCkiu1QwCoa8+ycojGfZhvqMsAp1536ZcCul+Na+AbCv4zKS7F +kQQaImVrXdUiFansIoofGlw/JNuoKK6ssVpS5Ic3pgcCAwEAAaM1MDMwDgYDVR0P +AQH/BAQDAgCgMBMGA1UdJQQMMAoGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwCwYJ +KoZIhvcNAQELA4IBAQCKLREH7bXtXtZ+8vI6cjD7W3QikiArGqbl36bAhhWsJLp/ +p/ndKz39iFNaiZ3GlwIURWOOKx3y3GA0x9m8FR+Llthf0EQ8sUjnwaknWs0Y6DQ3 +jjPFZOpV3KPCFrdMJ3++E3MgwFC/Ih/N2ebFX9EcV9Vcc6oVWMdwT0fsrhu683rq +6GSR/3iVX1G/pmOiuaR0fNUaCyCfYrnI4zHBDgSfnlm3vIvN2lrsR/DQBakNL8DJ +HBgKxMGeUPoneBv+c8DMXIL0EhaFXRlBv9QW45/GiAIOuyFJ0i6hCtGZpJjq4OpQ +BRjCI+izPzFTjsxD4aORE+WOkyWFCGPWKfNejfw0 +-----END CERTIFICATE-----` + + keyData = `-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAq12HPT64ItfDlxJiez2tT9eJ8VKlv/HbhYN2ubvZL+9v0E9i +wBK2I/Xjxu7KWvVI642LyxMBmaVUMMikhXAwt9/6jaspgOJyf1+NutPFM6OUjikc +kEf4lTcAnS1tqO6mKiHvSPAVLShinC2d6DbNycTZniXqaGuPaiStzlDX9fYjYcKG +0hTglhOKw5u2KfXRAolfTUIt9hcktry6lbMpnj8Y5wcb54BXeNdaheJ22NvVSzDv +RqahNnqYhUKSK7VDAKhrz7JyiMZ9mG+oywCnXnfplwK6X41r4BsK/jMpLsWRBBoi +ZWtd1SIVqewiih8aXD8k26gorqyxWlLkhzemBwIDAQABAoIBAD2XYRs3JrGHQUpU +FkdbVKZkvrSY0vAZOqBTLuH0zUv4UATb8487anGkWBjRDLQCgxH+jucPTrztekQK +aW94clo0S3aNtV4YhbSYIHWs1a0It0UdK6ID7CmdWkAj6s0T8W8lQT7C46mWYVLm +5mFnCTHi6aB42jZrqmEpC7sivWwuU0xqj3Ml8kkxQCGmyc9JjmCB4OrFFC8NNt6M +ObvQkUI6Z3nO4phTbpxkE1/9dT0MmPIF7GhHVzJMS+EyyRYUDllZ0wvVSOM3qZT0 +JMUaBerkNwm9foKJ1+dv2nMKZZbJajv7suUDCfU44mVeaEO+4kmTKSGCGjjTBGkr +7L1ySDECgYEA5ElIMhpdBzIivCuBIH8LlUeuzd93pqssO1G2Xg0jHtfM4tz7fyeI +cr90dc8gpli24dkSxzLeg3Tn3wIj/Bu64m2TpZPZEIlukYvgdgArmRIPQVxerYey +OkrfTNkxU1HXsYjLCdGcGXs5lmb+K/kuTcFxaMOs7jZi7La+jEONwf8CgYEAwCs/ +rUOOA0klDsWWisbivOiNPII79c9McZCNBqncCBfMUoiGe8uWDEO4TFHN60vFuVk9 +8PkwpCfvaBUX+ajvbafIfHxsnfk1M04WLGCeqQ/ym5Q4sQoQOcC1b1y9qc/xEWfg +nIUuia0ukYRpl7qQa3tNg+BNFyjypW8zukUAC/kCgYB1/Kojuxx5q5/oQVPrx73k +2bevD+B3c+DYh9MJqSCNwFtUpYIWpggPxoQan4LwdsmO0PKzocb/ilyNFj4i/vII +NToqSc/WjDFpaDIKyuu9oWfhECye45NqLWhb/6VOuu4QA/Nsj7luMhIBehnEAHW+ +GkzTKM8oD1PxpEG3nPKXYQKBgQC6AuMPRt3XBl1NkCrpSBy/uObFlFaP2Enpf39S +3OZ0Gv0XQrnSaL1kP8TMcz68rMrGX8DaWYsgytstR4W+jyy7WvZwsUu+GjTJ5aMG +77uEcEBpIi9CBzivfn7hPccE8ZgqPf+n4i6q66yxBJflW5xhvafJqDtW2LcPNbW/ +bvzdmQKBgExALRUXpq+5dbmkdXBHtvXdRDZ6rVmrnjy4nI5bPw+1GqQqk6uAR6B/ +F6NmLCQOO4PDG/cuatNHIr2FrwTmGdEL6ObLUGWn9Oer9gJhHVqqsY5I4sEPo4XX +stR0Yiw0buV6DL/moUO0HIM9Bjh96HJp+LxiIS6UCdIhMPp5HoQa +-----END RSA PRIVATE KEY-----` +) + +func TestNew(t *testing.T) { + testCases := map[string]struct { + Config *Config + Err bool + TLS bool + Default bool + }{ + "default transport": { + Default: true, + Config: &Config{}, + }, + + "ca transport": { + TLS: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + }, + }, + }, + "bad ca file transport": { + Err: true, + Config: &Config{ + TLS: TLSConfig{ + CAFile: "invalid file", + }, + }, + }, + "ca data overriding bad ca file transport": { + TLS: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + CAFile: "invalid file", + }, + }, + }, + + "cert transport": { + TLS: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + CertData: []byte(certData), + KeyData: []byte(keyData), + }, + }, + }, + "bad cert data transport": { + Err: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + CertData: []byte(certData), + KeyData: []byte("bad key data"), + }, + }, + }, + "bad file cert transport": { + Err: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + CertData: []byte(certData), + KeyFile: "invalid file", + }, + }, + }, + "key data overriding bad file cert transport": { + TLS: true, + Config: &Config{ + TLS: TLSConfig{ + CAData: []byte(rootCACert), + CertData: []byte(certData), + KeyData: []byte(keyData), + KeyFile: "invalid file", + }, + }, + }, + } + for k, testCase := range testCases { + transport, err := New(testCase.Config) + switch { + case testCase.Err && err == nil: + t.Errorf("%s: unexpected non-error", k) + continue + case !testCase.Err && err != nil: + t.Errorf("%s: unexpected error: %v", k, err) + continue + } + + switch { + case testCase.Default && transport != http.DefaultTransport: + t.Errorf("%s: expected the default transport, got %#v", k, transport) + continue + case !testCase.Default && transport == http.DefaultTransport: + t.Errorf("%s: expected non-default transport, got %#v", k, transport) + continue + } + + // We only know how to check TLSConfig on http.Transports + if transport, ok := transport.(*http.Transport); ok { + switch { + case testCase.TLS && transport.TLSClientConfig == nil: + t.Errorf("%s: expected TLSClientConfig, got %#v", k, transport) + continue + case !testCase.TLS && transport.TLSClientConfig != nil: + t.Errorf("%s: expected no TLSClientConfig, got %#v", k, transport) + continue + } + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/buffer/BUILD b/discovery/vendor/k8s.io/client-go/util/buffer/BUILD new file mode 100644 index 00000000..d3b2652c --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/buffer/BUILD @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = ["ring_growing.go"], + importpath = "k8s.io/client-go/util/buffer", + visibility = ["//visibility:public"], +) + +go_test( + name = "go_default_test", + srcs = ["ring_growing_test.go"], + embed = [":go_default_library"], + deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/buffer/ring_growing_test.go b/discovery/vendor/k8s.io/client-go/util/buffer/ring_growing_test.go new file mode 100644 index 00000000..231b836c --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/buffer/ring_growing_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package buffer + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGrowth(t *testing.T) { + t.Parallel() + x := 10 + g := NewRingGrowing(1) + for i := 0; i < x; i++ { + assert.Equal(t, i, g.readable) + g.WriteOne(i) + } + read := 0 + for g.readable > 0 { + v, ok := g.ReadOne() + assert.True(t, ok) + assert.Equal(t, read, v) + read++ + } + assert.Equalf(t, x, read, "expected to have read %d items: %d", x, read) + assert.Zerof(t, g.readable, "expected readable to be zero: %d", g.readable) + assert.Equalf(t, g.n, 16, "expected N to be 16: %d", g.n) +} + +func TestEmpty(t *testing.T) { + t.Parallel() + g := NewRingGrowing(1) + _, ok := g.ReadOne() + assert.False(t, ok) +} diff --git a/discovery/vendor/k8s.io/client-go/util/cert/BUILD b/discovery/vendor/k8s.io/client-go/util/cert/BUILD new file mode 100644 index 00000000..799979d4 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/cert/BUILD @@ -0,0 +1,47 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "csr_test.go", + "pem_test.go", + ], + data = glob(["testdata/**"]), + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "cert.go", + "csr.go", + "io.go", + "pem.go", + ], + data = [ + "testdata/dontUseThisKey.pem", + ], + importpath = "k8s.io/client-go/util/cert", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/util/cert/triple:all-srcs", + ], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/cert/cert.go b/discovery/vendor/k8s.io/client-go/util/cert/cert.go index 6854d415..fb7f5fac 100644 --- a/discovery/vendor/k8s.io/client-go/util/cert/cert.go +++ b/discovery/vendor/k8s.io/client-go/util/cert/cert.go @@ -38,7 +38,7 @@ const ( duration365d = time.Hour * 24 * 365 ) -// Config containes the basic fields required for creating a certificate +// Config contains the basic fields required for creating a certificate type Config struct { CommonName string Organization []string @@ -138,23 +138,50 @@ func MakeEllipticPrivateKeyPEM() ([]byte, error) { // Host may be an IP or a DNS name // You may also specify additional subject alt names (either ip or dns names) for the certificate func GenerateSelfSignedCertKey(host string, alternateIPs []net.IP, alternateDNS []string) ([]byte, []byte, error) { + caKey, err := rsa.GenerateKey(cryptorand.Reader, 2048) + if err != nil { + return nil, nil, err + } + + caTemplate := x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{ + CommonName: fmt.Sprintf("%s-ca@%d", host, time.Now().Unix()), + }, + NotBefore: time.Now(), + NotAfter: time.Now().Add(time.Hour * 24 * 365), + + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, + BasicConstraintsValid: true, + IsCA: true, + } + + caDERBytes, err := x509.CreateCertificate(cryptorand.Reader, &caTemplate, &caTemplate, &caKey.PublicKey, caKey) + if err != nil { + return nil, nil, err + } + + caCertificate, err := x509.ParseCertificate(caDERBytes) + if err != nil { + return nil, nil, err + } + priv, err := rsa.GenerateKey(cryptorand.Reader, 2048) if err != nil { return nil, nil, err } template := x509.Certificate{ - SerialNumber: big.NewInt(1), + SerialNumber: big.NewInt(2), Subject: pkix.Name{ CommonName: fmt.Sprintf("%s@%d", host, time.Now().Unix()), }, NotBefore: time.Now(), NotAfter: time.Now().Add(time.Hour * 24 * 365), - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, BasicConstraintsValid: true, - IsCA: true, } if ip := net.ParseIP(host); ip != nil { @@ -166,16 +193,19 @@ func GenerateSelfSignedCertKey(host string, alternateIPs []net.IP, alternateDNS template.IPAddresses = append(template.IPAddresses, alternateIPs...) template.DNSNames = append(template.DNSNames, alternateDNS...) - derBytes, err := x509.CreateCertificate(cryptorand.Reader, &template, &template, &priv.PublicKey, priv) + derBytes, err := x509.CreateCertificate(cryptorand.Reader, &template, caCertificate, &priv.PublicKey, caKey) if err != nil { return nil, nil, err } - // Generate cert + // Generate cert, followed by ca certBuffer := bytes.Buffer{} if err := pem.Encode(&certBuffer, &pem.Block{Type: CertificateBlockType, Bytes: derBytes}); err != nil { return nil, nil, err } + if err := pem.Encode(&certBuffer, &pem.Block{Type: CertificateBlockType, Bytes: caDERBytes}); err != nil { + return nil, nil, err + } // Generate key keyBuffer := bytes.Buffer{} diff --git a/discovery/vendor/k8s.io/client-go/util/cert/csr_test.go b/discovery/vendor/k8s.io/client-go/util/cert/csr_test.go new file mode 100644 index 00000000..ed28f021 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/cert/csr_test.go @@ -0,0 +1,75 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cert + +import ( + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "io/ioutil" + "net" + "testing" +) + +func TestMakeCSR(t *testing.T) { + keyFile := "testdata/dontUseThisKey.pem" + subject := &pkix.Name{ + CommonName: "kube-worker", + } + dnsSANs := []string{"localhost"} + ipSANs := []net.IP{net.ParseIP("127.0.0.1")} + + keyData, err := ioutil.ReadFile(keyFile) + if err != nil { + t.Fatal(err) + } + key, err := ParsePrivateKeyPEM(keyData) + if err != nil { + t.Fatal(err) + } + csrPEM, err := MakeCSR(key, subject, dnsSANs, ipSANs) + if err != nil { + t.Error(err) + } + csrBlock, rest := pem.Decode(csrPEM) + if csrBlock == nil { + t.Error("Unable to decode MakeCSR result.") + } + if len(rest) != 0 { + t.Error("Found more than one PEM encoded block in the result.") + } + if csrBlock.Type != CertificateRequestBlockType { + t.Errorf("Found block type %q, wanted 'CERTIFICATE REQUEST'", csrBlock.Type) + } + csr, err := x509.ParseCertificateRequest(csrBlock.Bytes) + if err != nil { + t.Errorf("Found %v parsing MakeCSR result as a CertificateRequest.", err) + } + if csr.Subject.CommonName != subject.CommonName { + t.Errorf("Wanted %v, got %v", subject, csr.Subject) + } + if len(csr.DNSNames) != 1 { + t.Errorf("Wanted 1 DNS name in the result, got %d", len(csr.DNSNames)) + } else if csr.DNSNames[0] != dnsSANs[0] { + t.Errorf("Wanted %v, got %v", dnsSANs[0], csr.DNSNames[0]) + } + if len(csr.IPAddresses) != 1 { + t.Errorf("Wanted 1 IP address in the result, got %d", len(csr.IPAddresses)) + } else if csr.IPAddresses[0].String() != ipSANs[0].String() { + t.Errorf("Wanted %v, got %v", ipSANs[0], csr.IPAddresses[0]) + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/cert/pem_test.go b/discovery/vendor/k8s.io/client-go/util/cert/pem_test.go new file mode 100644 index 00000000..de3ce525 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/cert/pem_test.go @@ -0,0 +1,197 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cert + +import ( + "io/ioutil" + "os" + "testing" +) + +const ( + // rsaPrivateKey is a RSA Private Key in PKCS#1 format + // openssl genrsa -out rsa2048.pem 2048 + rsaPrivateKey = `-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA92mVjhBKOFsdxFzb/Pjq+7b5TJlODAdY5hK+WxLZTIrfhDPq +FWrGKdjSNiHbXrdEtwJh9V+RqPZVSN3aWy1224RgkyNdMJsXhJKuCC24ZKY8SXtW +xuTYmMRaMnCsv6QBGRTIbZ2EFbAObVM7lDyv1VqY3amZIWFQMlZ9CNpxDSPa5yi4 +3gopbXkne0oGNmey9X0qtpk7NMZIgAL6Zz4rZ30bcfC2ag6RLOFI2E/c4n8c38R8 +9MfXfLkj8/Cxo4JfI9NvRCpPOpFO8d/ZtWVUuIrBQN+Y7tkN2T60Qq/TkKXUrhDe +fwlTlktZVJ/GztLYU41b2GcWsh/XO+PH831rmwIDAQABAoIBAQCC9c6GDjVbM0/E +WurPMusfJjE7zII1d8YkspM0HfwLug6qKdikUYpnKC/NG4rEzfl/bbFwco/lgc6O +7W/hh2U8uQttlvCDA/Uk5YddKOZL0Hpk4vaB/SxxYK3luSKXpjY2knutGg2KdVCN +qdsFkkH4iyYTXuyBcMNEgedZQldI/kEujIH/L7FE+DF5TMzT4lHhozDoG+fy564q +qVGUZXJn0ubc3GaPn2QOLNNM44sfYA4UJCpKBXPu85bvNObjxVQO4WqwwxU1vRnL +UUsaGaelhSVJCo0dVPRvrfPPKZ09HTwpy40EkgQo6VriFc1EBoQDjENLbAJv9OfQ +aCc9wiZhAoGBAP/8oEy48Zbb0P8Vdy4djf5tfBW8yXFLWzXewJ4l3itKS1r42nbX +9q3cJsgRTQm8uRcMIpWxsc3n6zG+lREvTkoTB3ViI7+uQPiqA+BtWyNy7jzufFke +ONKZfg7QxxmYRWZBRnoNGNbMpNeERuLmhvQuom9D1WbhzAYJbfs/O4WTAoGBAPds +2FNDU0gaesFDdkIUGq1nIJqRQDW485LXZm4pFqBFxdOpbdWRuYT2XZjd3fD0XY98 +Nhkpb7NTMCuK3BdKcqIptt+cK+quQgYid0hhhgZbpCQ5AL6c6KgyjgpYlh2enzU9 +Zo3yg8ej1zbbA11sBlhX+5iO2P1u5DG+JHLwUUbZAoGAUwaU102EzfEtsA4+QW7E +hyjrfgFlNKHES4yb3K9bh57pIfBkqvcQwwMMcQdrfSUAw0DkVrjzel0mI1Q09QXq +1ould6UFAz55RC2gZEITtUOpkYmoOx9aPrQZ9qQwb1S77ZZuTVfCHqjxLhVxCFbM +npYhiQTvShciHTMhwMOZgpECgYAVV5EtVXBYltgh1YTc3EkUzgF087R7LdHsx6Gx +POATwRD4WfP8aQ58lpeqOPEM+LcdSlSMRRO6fyF3kAm+BJDwxfJdRWZQXumZB94M +I0VhRQRaj4Qt7PDwmTPBVrTUJzuKZxpyggm17b8Bn1Ch/VBqzGQKW8AB1E/grosM +UwhfuQKBgQC2JO/iqTQScHClf0qlItCJsBuVukFmSAVCkpOD8YdbdlPdOOwSk1wQ +C0eAlsC3BCMvkpidKQmra6IqIrvTGI6EFgkrb3aknWdup2w8j2udYCNqyE3W+fVe +p8FdYQ1FkACQ+daO5VlClL/9l0sGjKXlNKbpmJ2H4ngZmXj5uGmxuQ== +-----END RSA PRIVATE KEY-----` + + // rsaPublicKey is a RSA Public Key in PEM encoded format + // openssl rsa -in rsa2048.pem -pubout -out rsa2048pub.pem + rsaPublicKey = `-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA92mVjhBKOFsdxFzb/Pjq ++7b5TJlODAdY5hK+WxLZTIrfhDPqFWrGKdjSNiHbXrdEtwJh9V+RqPZVSN3aWy12 +24RgkyNdMJsXhJKuCC24ZKY8SXtWxuTYmMRaMnCsv6QBGRTIbZ2EFbAObVM7lDyv +1VqY3amZIWFQMlZ9CNpxDSPa5yi43gopbXkne0oGNmey9X0qtpk7NMZIgAL6Zz4r +Z30bcfC2ag6RLOFI2E/c4n8c38R89MfXfLkj8/Cxo4JfI9NvRCpPOpFO8d/ZtWVU +uIrBQN+Y7tkN2T60Qq/TkKXUrhDefwlTlktZVJ/GztLYU41b2GcWsh/XO+PH831r +mwIDAQAB +-----END PUBLIC KEY-----` + + // certificate is an x509 certificate in PEM encoded format + // openssl req -new -key rsa2048.pem -sha256 -nodes -x509 -days 1826 -out x509certificate.pem -subj "/C=US/CN=not-valid" + certificate = `-----BEGIN CERTIFICATE----- +MIIDFTCCAf2gAwIBAgIJAN8B8NOwtiUCMA0GCSqGSIb3DQEBCwUAMCExCzAJBgNV +BAYTAlVTMRIwEAYDVQQDDAlub3QtdmFsaWQwHhcNMTcwMzIyMDI1NjM2WhcNMjIw +MzIyMDI1NjM2WjAhMQswCQYDVQQGEwJVUzESMBAGA1UEAwwJbm90LXZhbGlkMIIB +IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA92mVjhBKOFsdxFzb/Pjq+7b5 +TJlODAdY5hK+WxLZTIrfhDPqFWrGKdjSNiHbXrdEtwJh9V+RqPZVSN3aWy1224Rg +kyNdMJsXhJKuCC24ZKY8SXtWxuTYmMRaMnCsv6QBGRTIbZ2EFbAObVM7lDyv1VqY +3amZIWFQMlZ9CNpxDSPa5yi43gopbXkne0oGNmey9X0qtpk7NMZIgAL6Zz4rZ30b +cfC2ag6RLOFI2E/c4n8c38R89MfXfLkj8/Cxo4JfI9NvRCpPOpFO8d/ZtWVUuIrB +QN+Y7tkN2T60Qq/TkKXUrhDefwlTlktZVJ/GztLYU41b2GcWsh/XO+PH831rmwID +AQABo1AwTjAdBgNVHQ4EFgQU1I5GfinLF7ta+dBJ6UWcrYaexLswHwYDVR0jBBgw +FoAU1I5GfinLF7ta+dBJ6UWcrYaexLswDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0B +AQsFAAOCAQEAUl0wUD4y41juHFOVMYiziPYr1ShSpQXdwp8FfaHrzI5hsr8UMe8D +dzb9QzZ4bx3yZhiG3ahrSBh956thMTHrKTEwAfJIEXI4cuSVWQAaOJ4Em5SDFxQe +d0E6Ui2nGh1SFGF7oyuEXyzqgRMWFNDFw9HLUNgXaO18Zfouw8+K0BgbfEWEcSi1 +JLQbyhCjz088gltrliQGPWDFAg9cHBKtJhuTzZkvuqK1CLEmBhtzP1zFiGBfOJc8 +v+aKjAwrPUNX11cXOCPxBv2qXMetxaovBem6AI2hvypCInXaVQfP+yOLubzlTDjS +Y708SlY38hmS1uTwDpyLOn8AKkZ8jtx75g== +-----END CERTIFICATE-----` + + // ecdsaPrivateKeyWithParams is a ECDSA Private Key with included EC Parameters block + // openssl ecparam -name prime256v1 -genkey -out ecdsa256params.pem + ecdsaPrivateKeyWithParams = `-----BEGIN EC PARAMETERS----- +BggqhkjOPQMBBw== +-----END EC PARAMETERS----- +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIAwSOWQqlMTZNqNF7tgua812Jxib1DVOgb2pHHyIEyNNoAoGCCqGSM49 +AwEHoUQDQgAEyxYNrs6a6tsNCFNYn+l+JDUZ0PnUZbcsDgJn2O62D1se8M5iQ5rY +iIv6RpxE3VHvlHEIvYgCZkG0jHszTUopBg== +-----END EC PRIVATE KEY-----` + + // ecdsaPrivateKey is a ECDSA Private Key in ASN.1 format + // openssl ecparam -name prime256v1 -genkey -noout -out ecdsa256.pem + ecdsaPrivateKey = `-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIP6Qw6dHDiLsSnLXUhQVTPE0fTQQrj3XSbiQAZPXnk5+oAoGCCqGSM49 +AwEHoUQDQgAEZZzi1u5f2/AEGFI/HYUhU+u6cTK1q2bbtE7r1JMK+/sQA5sNAp+7 +Vdc3psr1OaNzyTyuhTECyRdFKXm63cMnGg== +-----END EC PRIVATE KEY-----` + + // ecdsaPublicKey is a ECDSA Public Key in PEM encoded format + // openssl ec -in ecdsa256.pem -pubout -out ecdsa256pub.pem + ecdsaPublicKey = `-----BEGIN PUBLIC KEY----- +MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZZzi1u5f2/AEGFI/HYUhU+u6cTK1 +q2bbtE7r1JMK+/sQA5sNAp+7Vdc3psr1OaNzyTyuhTECyRdFKXm63cMnGg== +-----END PUBLIC KEY-----` +) + +func TestReadPrivateKey(t *testing.T) { + f, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("error creating tmpfile: %v", err) + } + defer os.Remove(f.Name()) + + if _, err := PrivateKeyFromFile(f.Name()); err == nil { + t.Fatalf("Expected error reading key from empty file, got none") + } + + if err := ioutil.WriteFile(f.Name(), []byte(rsaPrivateKey), os.FileMode(0600)); err != nil { + t.Fatalf("error writing private key to tmpfile: %v", err) + } + if _, err := PrivateKeyFromFile(f.Name()); err != nil { + t.Fatalf("error reading private RSA key: %v", err) + } + + if err := ioutil.WriteFile(f.Name(), []byte(ecdsaPrivateKey), os.FileMode(0600)); err != nil { + t.Fatalf("error writing private key to tmpfile: %v", err) + } + if _, err := PrivateKeyFromFile(f.Name()); err != nil { + t.Fatalf("error reading private ECDSA key: %v", err) + } + + if err := ioutil.WriteFile(f.Name(), []byte(ecdsaPrivateKeyWithParams), os.FileMode(0600)); err != nil { + t.Fatalf("error writing private key to tmpfile: %v", err) + } + if _, err := PrivateKeyFromFile(f.Name()); err != nil { + t.Fatalf("error reading private ECDSA key with params: %v", err) + } +} + +func TestReadPublicKeys(t *testing.T) { + f, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("error creating tmpfile: %v", err) + } + defer os.Remove(f.Name()) + + if _, err := PublicKeysFromFile(f.Name()); err == nil { + t.Fatalf("Expected error reading keys from empty file, got none") + } + + if err := ioutil.WriteFile(f.Name(), []byte(rsaPublicKey), os.FileMode(0600)); err != nil { + t.Fatalf("error writing public key to tmpfile: %v", err) + } + if keys, err := PublicKeysFromFile(f.Name()); err != nil { + t.Fatalf("error reading RSA public key: %v", err) + } else if len(keys) != 1 { + t.Fatalf("expected 1 key, got %d", len(keys)) + } + + if err := ioutil.WriteFile(f.Name(), []byte(ecdsaPublicKey), os.FileMode(0600)); err != nil { + t.Fatalf("error writing public key to tmpfile: %v", err) + } + if keys, err := PublicKeysFromFile(f.Name()); err != nil { + t.Fatalf("error reading ECDSA public key: %v", err) + } else if len(keys) != 1 { + t.Fatalf("expected 1 key, got %d", len(keys)) + } + + if err := ioutil.WriteFile(f.Name(), []byte(rsaPublicKey+"\n"+ecdsaPublicKey), os.FileMode(0600)); err != nil { + t.Fatalf("error writing public key to tmpfile: %v", err) + } + if keys, err := PublicKeysFromFile(f.Name()); err != nil { + t.Fatalf("error reading combined RSA/ECDSA public key file: %v", err) + } else if len(keys) != 2 { + t.Fatalf("expected 2 keys, got %d", len(keys)) + } + + if err := ioutil.WriteFile(f.Name(), []byte(certificate), os.FileMode(0600)); err != nil { + t.Fatalf("error writing certificate to tmpfile: %v", err) + } + if keys, err := PublicKeysFromFile(f.Name()); err != nil { + t.Fatalf("error reading public key from certificate file: %v", err) + } else if len(keys) != 1 { + t.Fatalf("expected 1 keys, got %d", len(keys)) + } + +} diff --git a/discovery/vendor/k8s.io/client-go/util/cert/triple/BUILD b/discovery/vendor/k8s.io/client-go/util/cert/triple/BUILD new file mode 100644 index 00000000..6399d0e9 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/cert/triple/BUILD @@ -0,0 +1,26 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["triple.go"], + importpath = "k8s.io/client-go/util/cert/triple", + deps = ["//vendor/k8s.io/client-go/util/cert:go_default_library"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/BUILD b/discovery/vendor/k8s.io/client-go/util/certificate/BUILD new file mode 100644 index 00000000..dfc5c393 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/certificate/BUILD @@ -0,0 +1,66 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "certificate_manager_test.go", + "certificate_store_test.go", + ], + embed = [":go_default_library"], + tags = ["automanaged"], + deps = [ + "//vendor/k8s.io/api/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/client-go/util/cert:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "certificate_manager.go", + "certificate_store.go", + ], + importpath = "k8s.io/client-go/util/certificate", + tags = ["automanaged"], + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/api/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/client-go/util/cert:go_default_library", + "//vendor/k8s.io/client-go/util/certificate/csr:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//staging/src/k8s.io/client-go/util/certificate/csr:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager.go b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager.go index 7ea05ba7..e189c847 100644 --- a/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager.go +++ b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager.go @@ -141,7 +141,6 @@ type manager struct { certStore Store certAccessLock sync.RWMutex cert *tls.Certificate - rotationDeadline time.Time forceRotation bool certificateExpiration Gauge serverHealth bool @@ -208,8 +207,7 @@ func (m *manager) SetCertificateSigningRequestClient(certSigningRequestClient ce func (m *manager) Start() { // Certificate rotation depends on access to the API server certificate // signing API, so don't start the certificate manager if we don't have a - // client. This will happen on the cluster master, where the kubelet is - // responsible for bootstrapping the pods of the master components. + // client. if m.certSigningRequestClient == nil { glog.V(2).Infof("Certificate rotation is not enabled, no connection to the apiserver.") return @@ -217,27 +215,18 @@ func (m *manager) Start() { glog.V(2).Infof("Certificate rotation is enabled.") - m.setRotationDeadline() - - // Synchronously request a certificate before entering the background - // loop to allow bootstrap scenarios, where the certificate manager - // doesn't have a certificate at all yet. - if m.shouldRotate() { - glog.V(1).Infof("shouldRotate() is true, forcing immediate rotation") - if _, err := m.rotateCerts(); err != nil { - utilruntime.HandleError(fmt.Errorf("Could not rotate certificates: %v", err)) - } - } - backoff := wait.Backoff{ - Duration: 2 * time.Second, - Factor: 2, - Jitter: 0.1, - Steps: 5, - } go wait.Forever(func() { - sleepInterval := m.rotationDeadline.Sub(time.Now()) - glog.V(2).Infof("Waiting %v for next certificate rotation", sleepInterval) - time.Sleep(sleepInterval) + deadline := m.nextRotationDeadline() + if sleepInterval := deadline.Sub(time.Now()); sleepInterval > 0 { + glog.V(2).Infof("Waiting %v for next certificate rotation", sleepInterval) + time.Sleep(sleepInterval) + } + backoff := wait.Backoff{ + Duration: 2 * time.Second, + Factor: 2, + Jitter: 0.1, + Steps: 5, + } if err := wait.ExponentialBackoff(backoff, m.rotateCerts); err != nil { utilruntime.HandleError(fmt.Errorf("Reached backoff limit, still unable to rotate certs: %v", err)) wait.PollInfinite(32*time.Second, m.rotateCerts) @@ -252,11 +241,14 @@ func getCurrentCertificateOrBootstrap( currentCert, err := store.Current() if err == nil { - return currentCert, false, nil - } - - if _, ok := err.(*NoCertKeyError); !ok { - return nil, false, err + // if the current cert is expired, fall back to the bootstrap cert + if currentCert.Leaf != nil && time.Now().Before(currentCert.Leaf.NotAfter) { + return currentCert, false, nil + } + } else { + if _, ok := err.(*NoCertKeyError); !ok { + return nil, false, err + } } if bootstrapCertificatePEM == nil || bootstrapKeyPEM == nil { @@ -276,21 +268,14 @@ func getCurrentCertificateOrBootstrap( return nil, false, fmt.Errorf("unable to parse certificate data: %v", err) } bootstrapCert.Leaf = certs[0] - return &bootstrapCert, true, nil -} -// shouldRotate looks at how close the current certificate is to expiring and -// decides if it is time to rotate or not. -func (m *manager) shouldRotate() bool { - m.certAccessLock.RLock() - defer m.certAccessLock.RUnlock() - if m.cert == nil { - return true - } - if m.forceRotation { - return true + if _, err := store.Update(bootstrapCertificatePEM, bootstrapKeyPEM); err != nil { + utilruntime.HandleError(fmt.Errorf("Unable to set the cert/key pair to the bootstrap certificate: %v", err)) + } else { + glog.V(4).Infof("Updated the store to contain the initial bootstrap certificate") } - return time.Now().After(m.rotationDeadline) + + return &bootstrapCert, true, nil } // rotateCerts attempts to request a client cert from the server, wait a reasonable @@ -315,7 +300,7 @@ func (m *manager) rotateCerts() (bool, error) { return false, m.updateServerError(err) } - // Wait for the certificate to be signed. Instead of one long watch, we retry with slighly longer + // Wait for the certificate to be signed. Instead of one long watch, we retry with slightly longer // intervals each time in order to tolerate failures from the server AND to preserve the liveliness // of the cert manager loop. This creates slightly more traffic against the API server in return // for bounding the amount of time we wait when a certificate expires. @@ -349,30 +334,34 @@ func (m *manager) rotateCerts() (bool, error) { } m.updateCached(cert) - m.setRotationDeadline() - m.forceRotation = false return true, nil } -// setRotationDeadline sets a cached value for the threshold at which the +// nextRotationDeadline returns a value for the threshold at which the // current certificate should be rotated, 80%+/-10% of the expiration of the // certificate. -func (m *manager) setRotationDeadline() { +func (m *manager) nextRotationDeadline() time.Time { + // forceRotation is not protected by locks + if m.forceRotation { + m.forceRotation = false + return time.Now() + } + m.certAccessLock.RLock() defer m.certAccessLock.RUnlock() if m.cert == nil { - m.rotationDeadline = time.Now() - return + return time.Now() } notAfter := m.cert.Leaf.NotAfter totalDuration := float64(notAfter.Sub(m.cert.Leaf.NotBefore)) + deadline := m.cert.Leaf.NotBefore.Add(jitteryDuration(totalDuration)) - m.rotationDeadline = m.cert.Leaf.NotBefore.Add(jitteryDuration(totalDuration)) - glog.V(2).Infof("Certificate expiration is %v, rotation deadline is %v", notAfter, m.rotationDeadline) + glog.V(2).Infof("Certificate expiration is %v, rotation deadline is %v", notAfter, deadline) if m.certificateExpiration != nil { m.certificateExpiration.Set(float64(notAfter.Unix())) } + return deadline } // jitteryDuration uses some jitter to set the rotation threshold so each node diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager_test.go b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager_test.go new file mode 100644 index 00000000..6a23f042 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_manager_test.go @@ -0,0 +1,910 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package certificate + +import ( + "bytes" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "fmt" + "strings" + "testing" + "time" + + certificates "k8s.io/api/certificates/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/wait" + watch "k8s.io/apimachinery/pkg/watch" + certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1" +) + +var storeCertData = newCertificateData(`-----BEGIN CERTIFICATE----- +MIICRzCCAfGgAwIBAgIJALMb7ecMIk3MMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV +BAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNVBAcMBkxvbmRvbjEYMBYGA1UE +CgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1JVCBEZXBhcnRtZW50MRswGQYD +VQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTAwIBcNMTcwNDI2MjMyNjUyWhgPMjExNzA0 +MDIyMzI2NTJaMH4xCzAJBgNVBAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNV +BAcMBkxvbmRvbjEYMBYGA1UECgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1J +VCBEZXBhcnRtZW50MRswGQYDVQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTAwXDANBgkq +hkiG9w0BAQEFAANLADBIAkEAtBMa7NWpv3BVlKTCPGO/LEsguKqWHBtKzweMY2CV +tAL1rQm913huhxF9w+ai76KQ3MHK5IVnLJjYYA5MzP2H5QIDAQABo1AwTjAdBgNV +HQ4EFgQU22iy8aWkNSxv0nBxFxerfsvnZVMwHwYDVR0jBBgwFoAU22iy8aWkNSxv +0nBxFxerfsvnZVMwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAANBAEOefGbV +NcHxklaW06w6OBYJPwpIhCVozC1qdxGX1dg8VkEKzjOzjgqVD30m59OFmSlBmHsl +nkVA6wyOSDYBf3o= +-----END CERTIFICATE-----`, `-----BEGIN RSA PRIVATE KEY----- +MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAtBMa7NWpv3BVlKTC +PGO/LEsguKqWHBtKzweMY2CVtAL1rQm913huhxF9w+ai76KQ3MHK5IVnLJjYYA5M +zP2H5QIDAQABAkAS9BfXab3OKpK3bIgNNyp+DQJKrZnTJ4Q+OjsqkpXvNltPJosf +G8GsiKu/vAt4HGqI3eU77NvRI+mL4MnHRmXBAiEA3qM4FAtKSRBbcJzPxxLEUSwg +XSCcosCktbkXvpYrS30CIQDPDxgqlwDEJQ0uKuHkZI38/SPWWqfUmkecwlbpXABK +iQIgZX08DA8VfvcA5/Xj1Zjdey9FVY6POLXen6RPiabE97UCICp6eUW7ht+2jjar +e35EltCRCjoejRHTuN9TC0uCoVipAiAXaJIx/Q47vGwiw6Y8KXsNU6y54gTbOSxX +54LzHNk/+Q== +-----END RSA PRIVATE KEY-----`) +var bootstrapCertData = newCertificateData( + `-----BEGIN CERTIFICATE----- +MIICRzCCAfGgAwIBAgIJANXr+UzRFq4TMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV +BAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNVBAcMBkxvbmRvbjEYMBYGA1UE +CgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1JVCBEZXBhcnRtZW50MRswGQYD +VQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTEwIBcNMTcwNDI2MjMyNzMyWhgPMjExNzA0 +MDIyMzI3MzJaMH4xCzAJBgNVBAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNV +BAcMBkxvbmRvbjEYMBYGA1UECgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1J +VCBEZXBhcnRtZW50MRswGQYDVQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTEwXDANBgkq +hkiG9w0BAQEFAANLADBIAkEAqvbkN4RShH1rL37JFp4fZPnn0JUhVWWsrP8NOomJ +pXdBDUMGWuEQIsZ1Gf9JrCQLu6ooRyHSKRFpAVbMQ3ABJwIDAQABo1AwTjAdBgNV +HQ4EFgQUEGBc6YYheEZ/5MhwqSUYYPYRj2MwHwYDVR0jBBgwFoAUEGBc6YYheEZ/ +5MhwqSUYYPYRj2MwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAANBAIyNmznk +5dgJY52FppEEcfQRdS5k4XFPc22SHPcz77AHf5oWZ1WG9VezOZZPp8NCiFDDlDL8 +yma33a5eMyTjLD8= +-----END CERTIFICATE-----`, `-----BEGIN RSA PRIVATE KEY----- +MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqvbkN4RShH1rL37J +Fp4fZPnn0JUhVWWsrP8NOomJpXdBDUMGWuEQIsZ1Gf9JrCQLu6ooRyHSKRFpAVbM +Q3ABJwIDAQABAkBC2OBpGLMPHN8BJijIUDFkURakBvuOoX+/8MYiYk7QxEmfLCk6 +L6r+GLNFMfXwXcBmXtMKfZKAIKutKf098JaBAiEA10azfqt3G/5owrNA00plSyT6 +ZmHPzY9Uq1p/QTR/uOcCIQDLTkfBkLHm0UKeobbO/fSm6ZflhyBRDINy4FvwmZMt +wQIgYV/tmQJeIh91q3wBepFQOClFykG8CTMoDUol/YyNqUkCIHfp6Rr7fGL3JIMq +QQgf9DCK8SPZqq8DYXjdan0kKBJBAiEAyDb+07o2gpggo8BYUKSaiRCiyXfaq87f +eVqgpBq/QN4= +-----END RSA PRIVATE KEY-----`) +var apiServerCertData = newCertificateData( + `-----BEGIN CERTIFICATE----- +MIICRzCCAfGgAwIBAgIJAIydTIADd+yqMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV +BAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNVBAcMBkxvbmRvbjEYMBYGA1UE +CgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1JVCBEZXBhcnRtZW50MRswGQYD +VQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTIwIBcNMTcwNDI2MjMyNDU4WhgPMjExNzA0 +MDIyMzI0NThaMH4xCzAJBgNVBAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xDzANBgNV +BAcMBkxvbmRvbjEYMBYGA1UECgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1J +VCBEZXBhcnRtZW50MRswGQYDVQQDDBJ0ZXN0LWNlcnRpZmljYXRlLTIwXDANBgkq +hkiG9w0BAQEFAANLADBIAkEAuiRet28DV68Dk4A8eqCaqgXmymamUEjW/DxvIQqH +3lbhtm8BwSnS9wUAajSLSWiq3fci2RbRgaSPjUrnbOHCLQIDAQABo1AwTjAdBgNV +HQ4EFgQU0vhI4OPGEOqT+VAWwxdhVvcmgdIwHwYDVR0jBBgwFoAU0vhI4OPGEOqT ++VAWwxdhVvcmgdIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAANBALNeJGDe +nV5cXbp9W1bC12Tc8nnNXn4ypLE2JTQAvyp51zoZ8hQoSnRVx/VCY55Yu+br8gQZ ++tW+O/PoE7B3tuY= +-----END CERTIFICATE-----`, `-----BEGIN RSA PRIVATE KEY----- +MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEAuiRet28DV68Dk4A8 +eqCaqgXmymamUEjW/DxvIQqH3lbhtm8BwSnS9wUAajSLSWiq3fci2RbRgaSPjUrn +bOHCLQIDAQABAkEArDR1g9IqD3aUImNikDgAngbzqpAokOGyMoxeavzpEaFOgCzi +gi7HF7yHRmZkUt8CzdEvnHSqRjFuaaB0gGA+AQIhAOc8Z1h8ElLRSqaZGgI3jCTp +Izx9HNY//U5NGrXD2+ttAiEAzhOqkqI4+nDab7FpiD7MXI6fO549mEXeVBPvPtsS +OcECIQCIfkpOm+ZBBpO3JXaJynoqK4gGI6ALA/ik6LSUiIlfPQIhAISjd9hlfZME +bDQT1r8Q3Gx+h9LRqQeHgPBQ3F5ylqqBAiBaJ0hkYvrIdWxNlcLqD3065bJpHQ4S +WQkuZUQN1M/Xvg== +-----END RSA PRIVATE KEY-----`) + +type certificateData struct { + keyPEM []byte + certificatePEM []byte + certificate *tls.Certificate +} + +func newCertificateData(certificatePEM string, keyPEM string) *certificateData { + certificate, err := tls.X509KeyPair([]byte(certificatePEM), []byte(keyPEM)) + if err != nil { + panic(fmt.Sprintf("Unable to initialize certificate: %v", err)) + } + certs, err := x509.ParseCertificates(certificate.Certificate[0]) + if err != nil { + panic(fmt.Sprintf("Unable to initialize certificate leaf: %v", err)) + } + certificate.Leaf = certs[0] + return &certificateData{ + keyPEM: []byte(keyPEM), + certificatePEM: []byte(certificatePEM), + certificate: &certificate, + } +} + +func TestNewManagerNoRotation(t *testing.T) { + store := &fakeStore{ + cert: storeCertData.certificate, + } + if _, err := NewManager(&Config{ + Template: &x509.CertificateRequest{}, + Usages: []certificates.KeyUsage{}, + CertificateStore: store, + }); err != nil { + t.Fatalf("Failed to initialize the certificate manager: %v", err) + } +} + +type gaugeMock struct { + calls int + lastValue float64 +} + +func (g *gaugeMock) Set(v float64) { + g.calls++ + g.lastValue = v +} + +func TestSetRotationDeadline(t *testing.T) { + defer func(original func(float64) time.Duration) { jitteryDuration = original }(jitteryDuration) + + now := time.Now() + testCases := []struct { + name string + notBefore time.Time + notAfter time.Time + shouldRotate bool + }{ + {"just issued, still good", now.Add(-1 * time.Hour), now.Add(99 * time.Hour), false}, + {"half way expired, still good", now.Add(-24 * time.Hour), now.Add(24 * time.Hour), false}, + {"mostly expired, still good", now.Add(-69 * time.Hour), now.Add(31 * time.Hour), false}, + {"just about expired, should rotate", now.Add(-91 * time.Hour), now.Add(9 * time.Hour), true}, + {"nearly expired, should rotate", now.Add(-99 * time.Hour), now.Add(1 * time.Hour), true}, + {"already expired, should rotate", now.Add(-10 * time.Hour), now.Add(-1 * time.Hour), true}, + {"long duration", now.Add(-6 * 30 * 24 * time.Hour), now.Add(6 * 30 * 24 * time.Hour), true}, + {"short duration", now.Add(-30 * time.Second), now.Add(30 * time.Second), true}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := gaugeMock{} + m := manager{ + cert: &tls.Certificate{ + Leaf: &x509.Certificate{ + NotBefore: tc.notBefore, + NotAfter: tc.notAfter, + }, + }, + template: &x509.CertificateRequest{}, + usages: []certificates.KeyUsage{}, + certificateExpiration: &g, + } + jitteryDuration = func(float64) time.Duration { return time.Duration(float64(tc.notAfter.Sub(tc.notBefore)) * 0.7) } + lowerBound := tc.notBefore.Add(time.Duration(float64(tc.notAfter.Sub(tc.notBefore)) * 0.7)) + + deadline := m.nextRotationDeadline() + + if !deadline.Equal(lowerBound) { + t.Errorf("For notBefore %v, notAfter %v, the rotationDeadline %v should be %v.", + tc.notBefore, + tc.notAfter, + deadline, + lowerBound) + } + if g.calls != 1 { + t.Errorf("%d metrics were recorded, wanted %d", g.calls, 1) + } + if g.lastValue != float64(tc.notAfter.Unix()) { + t.Errorf("%f value for metric was recorded, wanted %d", g.lastValue, tc.notAfter.Unix()) + } + }) + } +} + +func TestRotateCertCreateCSRError(t *testing.T) { + now := time.Now() + m := manager{ + cert: &tls.Certificate{ + Leaf: &x509.Certificate{ + NotBefore: now.Add(-2 * time.Hour), + NotAfter: now.Add(-1 * time.Hour), + }, + }, + template: &x509.CertificateRequest{}, + usages: []certificates.KeyUsage{}, + certSigningRequestClient: fakeClient{ + failureType: createError, + }, + } + + if success, err := m.rotateCerts(); success { + t.Errorf("Got success from 'rotateCerts', wanted failure") + } else if err != nil { + t.Errorf("Got error %v from 'rotateCerts', wanted no error.", err) + } +} + +func TestRotateCertWaitingForResultError(t *testing.T) { + now := time.Now() + m := manager{ + cert: &tls.Certificate{ + Leaf: &x509.Certificate{ + NotBefore: now.Add(-2 * time.Hour), + NotAfter: now.Add(-1 * time.Hour), + }, + }, + template: &x509.CertificateRequest{}, + usages: []certificates.KeyUsage{}, + certSigningRequestClient: fakeClient{ + failureType: watchError, + }, + } + + certificateWaitBackoff = wait.Backoff{Steps: 1} + if success, err := m.rotateCerts(); success { + t.Errorf("Got success from 'rotateCerts', wanted failure.") + } else if err != nil { + t.Errorf("Got error %v from 'rotateCerts', wanted no error.", err) + } +} + +func TestNewManagerBootstrap(t *testing.T) { + store := &fakeStore{} + + var cm Manager + cm, err := NewManager(&Config{ + Template: &x509.CertificateRequest{}, + Usages: []certificates.KeyUsage{}, + CertificateStore: store, + BootstrapCertificatePEM: bootstrapCertData.certificatePEM, + BootstrapKeyPEM: bootstrapCertData.keyPEM, + }) + if err != nil { + t.Fatalf("Failed to initialize the certificate manager: %v", err) + } + + cert := cm.Current() + + if cert == nil { + t.Errorf("Certificate was nil, expected something.") + } + if m, ok := cm.(*manager); !ok { + t.Errorf("Expected a '*manager' from 'NewManager'") + } else if !m.forceRotation { + t.Errorf("Expected rotation should happen during bootstrap, but it won't.") + } +} + +func TestNewManagerNoBootstrap(t *testing.T) { + now := time.Now() + cert, err := tls.X509KeyPair(storeCertData.certificatePEM, storeCertData.keyPEM) + if err != nil { + t.Fatalf("Unable to initialize a certificate: %v", err) + } + cert.Leaf = &x509.Certificate{ + NotBefore: now.Add(-24 * time.Hour), + NotAfter: now.Add(24 * time.Hour), + } + store := &fakeStore{ + cert: &cert, + } + + cm, err := NewManager(&Config{ + Template: &x509.CertificateRequest{}, + Usages: []certificates.KeyUsage{}, + CertificateStore: store, + BootstrapCertificatePEM: bootstrapCertData.certificatePEM, + BootstrapKeyPEM: bootstrapCertData.keyPEM, + }) + + if err != nil { + t.Fatalf("Failed to initialize the certificate manager: %v", err) + } + + currentCert := cm.Current() + + if currentCert == nil { + t.Errorf("Certificate was nil, expected something.") + } + if m, ok := cm.(*manager); !ok { + t.Errorf("Expected a '*manager' from 'NewManager'") + } else { + if m.forceRotation { + t.Errorf("Expected rotation should not happen during bootstrap, but it won't.") + } + } +} + +func TestGetCurrentCertificateOrBootstrap(t *testing.T) { + testCases := []struct { + description string + storeCert *tls.Certificate + bootstrapCertData []byte + bootstrapKeyData []byte + expectedCert *tls.Certificate + expectedShouldRotate bool + expectedErrMsg string + }{ + { + "return cert from store", + storeCertData.certificate, + nil, + nil, + storeCertData.certificate, + false, + "", + }, + { + "no cert in store and no bootstrap cert", + nil, + nil, + nil, + nil, + true, + "", + }, + } + + for _, tc := range testCases { + t.Run(tc.description, func(t *testing.T) { + store := &fakeStore{ + cert: tc.storeCert, + } + + certResult, shouldRotate, err := getCurrentCertificateOrBootstrap( + store, + tc.bootstrapCertData, + tc.bootstrapKeyData) + if certResult == nil || certResult.Certificate == nil || tc.expectedCert == nil { + if certResult != nil && tc.expectedCert != nil { + t.Errorf("Got certificate %v, wanted %v", certResult, tc.expectedCert) + } + } else { + if !certificatesEqual(certResult, tc.expectedCert) { + t.Errorf("Got certificate %v, wanted %v", certResult, tc.expectedCert) + } + } + if shouldRotate != tc.expectedShouldRotate { + t.Errorf("Got shouldRotate %t, wanted %t", shouldRotate, tc.expectedShouldRotate) + } + if err == nil { + if tc.expectedErrMsg != "" { + t.Errorf("Got err %v, wanted %q", err, tc.expectedErrMsg) + } + } else { + if tc.expectedErrMsg == "" || !strings.Contains(err.Error(), tc.expectedErrMsg) { + t.Errorf("Got err %v, wanted %q", err, tc.expectedErrMsg) + } + } + }) + } +} + +func TestInitializeCertificateSigningRequestClient(t *testing.T) { + var nilCertificate = &certificateData{} + testCases := []struct { + description string + storeCert *certificateData + bootstrapCert *certificateData + apiCert *certificateData + expectedCertBeforeStart *certificateData + expectedCertAfterStart *certificateData + }{ + { + description: "No current certificate, no bootstrap certificate", + storeCert: nilCertificate, + bootstrapCert: nilCertificate, + apiCert: apiServerCertData, + expectedCertBeforeStart: nilCertificate, + expectedCertAfterStart: apiServerCertData, + }, + { + description: "No current certificate, bootstrap certificate", + storeCert: nilCertificate, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: bootstrapCertData, + expectedCertAfterStart: apiServerCertData, + }, + { + description: "Current certificate, no bootstrap certificate", + storeCert: storeCertData, + bootstrapCert: nilCertificate, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: storeCertData, + }, + { + description: "Current certificate, bootstrap certificate", + storeCert: storeCertData, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: storeCertData, + }, + } + + for _, tc := range testCases { + t.Run(tc.description, func(t *testing.T) { + certificateStore := &fakeStore{ + cert: tc.storeCert.certificate, + } + + certificateManager, err := NewManager(&Config{ + Template: &x509.CertificateRequest{ + Subject: pkix.Name{ + Organization: []string{"system:nodes"}, + CommonName: "system:node:fake-node-name", + }, + }, + Usages: []certificates.KeyUsage{ + certificates.UsageDigitalSignature, + certificates.UsageKeyEncipherment, + certificates.UsageClientAuth, + }, + CertificateStore: certificateStore, + BootstrapCertificatePEM: tc.bootstrapCert.certificatePEM, + BootstrapKeyPEM: tc.bootstrapCert.keyPEM, + }) + if err != nil { + t.Errorf("Got %v, wanted no error.", err) + } + + certificate := certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertBeforeStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertBeforeStart.certificate)) + } + if err := certificateManager.SetCertificateSigningRequestClient(&fakeClient{ + certificatePEM: tc.apiCert.certificatePEM, + }); err != nil { + t.Errorf("Got error %v, expected none.", err) + } + + if m, ok := certificateManager.(*manager); !ok { + t.Errorf("Expected a '*manager' from 'NewManager'") + } else { + if m.forceRotation { + if success, err := m.rotateCerts(); !success { + t.Errorf("Got failure from 'rotateCerts', wanted success.") + } else if err != nil { + t.Errorf("Got error %v, expected none.", err) + } + } + } + + certificate = certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertAfterStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertAfterStart.certificate)) + } + }) + } +} + +func TestInitializeOtherRESTClients(t *testing.T) { + var nilCertificate = &certificateData{} + testCases := []struct { + description string + storeCert *certificateData + bootstrapCert *certificateData + apiCert *certificateData + expectedCertBeforeStart *certificateData + expectedCertAfterStart *certificateData + }{ + { + description: "No current certificate, no bootstrap certificate", + storeCert: nilCertificate, + bootstrapCert: nilCertificate, + apiCert: apiServerCertData, + expectedCertBeforeStart: nilCertificate, + expectedCertAfterStart: apiServerCertData, + }, + { + description: "No current certificate, bootstrap certificate", + storeCert: nilCertificate, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: bootstrapCertData, + expectedCertAfterStart: apiServerCertData, + }, + { + description: "Current certificate, no bootstrap certificate", + storeCert: storeCertData, + bootstrapCert: nilCertificate, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: storeCertData, + }, + { + description: "Current certificate, bootstrap certificate", + storeCert: storeCertData, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: storeCertData, + }, + } + + for _, tc := range testCases { + t.Run(tc.description, func(t *testing.T) { + certificateStore := &fakeStore{ + cert: tc.storeCert.certificate, + } + + certificateManager, err := NewManager(&Config{ + Template: &x509.CertificateRequest{ + Subject: pkix.Name{ + Organization: []string{"system:nodes"}, + CommonName: "system:node:fake-node-name", + }, + }, + Usages: []certificates.KeyUsage{ + certificates.UsageDigitalSignature, + certificates.UsageKeyEncipherment, + certificates.UsageClientAuth, + }, + CertificateStore: certificateStore, + BootstrapCertificatePEM: tc.bootstrapCert.certificatePEM, + BootstrapKeyPEM: tc.bootstrapCert.keyPEM, + CertificateSigningRequestClient: &fakeClient{ + certificatePEM: tc.apiCert.certificatePEM, + }, + }) + if err != nil { + t.Errorf("Got %v, wanted no error.", err) + } + + certificate := certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertBeforeStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertBeforeStart.certificate)) + } + + if m, ok := certificateManager.(*manager); !ok { + t.Errorf("Expected a '*manager' from 'NewManager'") + } else { + if m.forceRotation { + success, err := certificateManager.(*manager).rotateCerts() + if err != nil { + t.Errorf("Got error %v, expected none.", err) + return + } + if !success { + t.Errorf("Unexpected response 'rotateCerts': %t", success) + return + } + } + } + + certificate = certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertAfterStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertAfterStart.certificate)) + } + }) + } +} + +func TestServerHealth(t *testing.T) { + type certs struct { + storeCert *certificateData + bootstrapCert *certificateData + apiCert *certificateData + expectedCertBeforeStart *certificateData + expectedCertAfterStart *certificateData + } + + updatedCerts := certs{ + storeCert: storeCertData, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: apiServerCertData, + } + + currentCerts := certs{ + storeCert: storeCertData, + bootstrapCert: bootstrapCertData, + apiCert: apiServerCertData, + expectedCertBeforeStart: storeCertData, + expectedCertAfterStart: storeCertData, + } + + testCases := []struct { + description string + certs + + failureType fakeClientFailureType + clientErr error + + expectRotateFail bool + expectHealthy bool + }{ + { + description: "Current certificate, bootstrap certificate", + certs: updatedCerts, + expectHealthy: true, + }, + { + description: "Generic error on create", + certs: currentCerts, + + failureType: createError, + expectRotateFail: true, + }, + { + description: "Unauthorized error on create", + certs: currentCerts, + + failureType: createError, + clientErr: errors.NewUnauthorized("unauthorized"), + expectRotateFail: true, + expectHealthy: true, + }, + { + description: "Generic unauthorized error on create", + certs: currentCerts, + + failureType: createError, + clientErr: errors.NewGenericServerResponse(401, "POST", schema.GroupResource{}, "", "", 0, true), + expectRotateFail: true, + expectHealthy: true, + }, + { + description: "Generic not found error on create", + certs: currentCerts, + + failureType: createError, + clientErr: errors.NewGenericServerResponse(404, "POST", schema.GroupResource{}, "", "", 0, true), + expectRotateFail: true, + expectHealthy: false, + }, + { + description: "Not found error on create", + certs: currentCerts, + + failureType: createError, + clientErr: errors.NewGenericServerResponse(404, "POST", schema.GroupResource{}, "", "", 0, false), + expectRotateFail: true, + expectHealthy: true, + }, + { + description: "Conflict error on watch", + certs: currentCerts, + + failureType: watchError, + clientErr: errors.NewGenericServerResponse(409, "POST", schema.GroupResource{}, "", "", 0, false), + expectRotateFail: true, + expectHealthy: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.description, func(t *testing.T) { + certificateStore := &fakeStore{ + cert: tc.storeCert.certificate, + } + + certificateManager, err := NewManager(&Config{ + Template: &x509.CertificateRequest{ + Subject: pkix.Name{ + Organization: []string{"system:nodes"}, + CommonName: "system:node:fake-node-name", + }, + }, + Usages: []certificates.KeyUsage{ + certificates.UsageDigitalSignature, + certificates.UsageKeyEncipherment, + certificates.UsageClientAuth, + }, + CertificateStore: certificateStore, + BootstrapCertificatePEM: tc.bootstrapCert.certificatePEM, + BootstrapKeyPEM: tc.bootstrapCert.keyPEM, + CertificateSigningRequestClient: &fakeClient{ + certificatePEM: tc.apiCert.certificatePEM, + failureType: tc.failureType, + err: tc.clientErr, + }, + }) + if err != nil { + t.Errorf("Got %v, wanted no error.", err) + } + + certificate := certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertBeforeStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertBeforeStart.certificate)) + } + + if _, ok := certificateManager.(*manager); !ok { + t.Errorf("Expected a '*manager' from 'NewManager'") + } else { + success, err := certificateManager.(*manager).rotateCerts() + if err != nil { + t.Errorf("Got error %v, expected none.", err) + return + } + if !success != tc.expectRotateFail { + t.Errorf("Unexpected response 'rotateCerts': %t", success) + return + } + if actual := certificateManager.(*manager).ServerHealthy(); actual != tc.expectHealthy { + t.Errorf("Unexpected manager server health: %t", actual) + } + } + + certificate = certificateManager.Current() + if !certificatesEqual(certificate, tc.expectedCertAfterStart.certificate) { + t.Errorf("Got %v, wanted %v", certificateString(certificate), certificateString(tc.expectedCertAfterStart.certificate)) + } + }) + } +} + +type fakeClientFailureType int + +const ( + none fakeClientFailureType = iota + createError + watchError + certificateSigningRequestDenied +) + +type fakeClient struct { + certificatesclient.CertificateSigningRequestInterface + failureType fakeClientFailureType + certificatePEM []byte + err error +} + +func (c fakeClient) List(opts v1.ListOptions) (*certificates.CertificateSigningRequestList, error) { + if c.failureType == watchError { + if c.err != nil { + return nil, c.err + } + return nil, fmt.Errorf("Watch error") + } + csrReply := certificates.CertificateSigningRequestList{ + Items: []certificates.CertificateSigningRequest{ + {ObjectMeta: v1.ObjectMeta{UID: "fake-uid"}}, + }, + } + return &csrReply, nil +} + +func (c fakeClient) Create(*certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, error) { + if c.failureType == createError { + if c.err != nil { + return nil, c.err + } + return nil, fmt.Errorf("Create error") + } + csrReply := certificates.CertificateSigningRequest{} + csrReply.UID = "fake-uid" + return &csrReply, nil +} + +func (c fakeClient) Watch(opts v1.ListOptions) (watch.Interface, error) { + if c.failureType == watchError { + if c.err != nil { + return nil, c.err + } + return nil, fmt.Errorf("Watch error") + } + return &fakeWatch{ + failureType: c.failureType, + certificatePEM: c.certificatePEM, + }, nil +} + +type fakeWatch struct { + failureType fakeClientFailureType + certificatePEM []byte +} + +func (w *fakeWatch) Stop() { +} + +func (w *fakeWatch) ResultChan() <-chan watch.Event { + var condition certificates.CertificateSigningRequestCondition + if w.failureType == certificateSigningRequestDenied { + condition = certificates.CertificateSigningRequestCondition{ + Type: certificates.CertificateDenied, + } + } else { + condition = certificates.CertificateSigningRequestCondition{ + Type: certificates.CertificateApproved, + } + } + + csr := certificates.CertificateSigningRequest{ + Status: certificates.CertificateSigningRequestStatus{ + Conditions: []certificates.CertificateSigningRequestCondition{ + condition, + }, + Certificate: []byte(w.certificatePEM), + }, + } + csr.UID = "fake-uid" + + c := make(chan watch.Event, 1) + c <- watch.Event{ + Type: watch.Added, + Object: &csr, + } + return c +} + +type fakeStore struct { + cert *tls.Certificate +} + +func (s *fakeStore) Current() (*tls.Certificate, error) { + if s.cert == nil { + noKeyErr := NoCertKeyError("") + return nil, &noKeyErr + } + return s.cert, nil +} + +// Accepts the PEM data for the cert/key pair and makes the new cert/key +// pair the 'current' pair, that will be returned by future calls to +// Current(). +func (s *fakeStore) Update(certPEM, keyPEM []byte) (*tls.Certificate, error) { + // In order to make the mocking work, whenever a cert/key pair is passed in + // to be updated in the mock store, assume that the certificate manager + // generated the key, and then asked the mock CertificateSigningRequest API + // to sign it, then the faked API returned a canned response. The canned + // signing response will not match the generated key. In order to make + // things work out, search here for the correct matching key and use that + // instead of the passed in key. That way this file of test code doesn't + // have to implement an actual certificate signing process. + for _, tc := range []*certificateData{storeCertData, bootstrapCertData, apiServerCertData} { + if bytes.Equal(tc.certificatePEM, certPEM) { + keyPEM = tc.keyPEM + } + } + cert, err := tls.X509KeyPair(certPEM, keyPEM) + if err != nil { + return nil, err + } + now := time.Now() + s.cert = &cert + s.cert.Leaf = &x509.Certificate{ + NotBefore: now.Add(-24 * time.Hour), + NotAfter: now.Add(24 * time.Hour), + } + return s.cert, nil +} + +func certificatesEqual(c1 *tls.Certificate, c2 *tls.Certificate) bool { + if c1 == nil || c2 == nil { + return c1 == c2 + } + if len(c1.Certificate) != len(c2.Certificate) { + return false + } + for i := 0; i < len(c1.Certificate); i++ { + if !bytes.Equal(c1.Certificate[i], c2.Certificate[i]) { + return false + } + } + return true +} + +func certificateString(c *tls.Certificate) string { + if c == nil { + return "certificate == nil" + } + if c.Leaf == nil { + return "certificate.Leaf == nil" + } + return c.Leaf.Subject.CommonName +} diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/certificate_store_test.go b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_store_test.go new file mode 100644 index 00000000..5d4d860d --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/certificate/certificate_store_test.go @@ -0,0 +1,505 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package certificate + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "k8s.io/client-go/util/cert" +) + +func TestUpdateSymlinkExistingFileError(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-update-symlink") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + pairFile := filepath.Join(dir, "kubelet-current.pem") + if err := ioutil.WriteFile(pairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + s := fileStore{ + certDirectory: dir, + pairNamePrefix: "kubelet", + } + if err := s.updateSymlink(pairFile); err == nil { + t.Errorf("Got no error, wanted to fail updating the symlink because there is a file there.") + } +} + +func TestUpdateSymlinkNewFileNotExist(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-update-symlink") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + oldPairFile := filepath.Join(dir, "kubelet-oldpair.pem") + if err := ioutil.WriteFile(oldPairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", oldPairFile, err) + } + + s := fileStore{ + certDirectory: dir, + pairNamePrefix: "kubelet", + } + if err := s.updateSymlink(oldPairFile); err != nil { + t.Errorf("Got %v, wanted successful update of the symlink to point to %q", err, oldPairFile) + } + + if _, err := os.Stat(oldPairFile); err != nil { + t.Errorf("Got %v, wanted file %q to be there.", oldPairFile, err) + } + + currentPairFile := filepath.Join(dir, "kubelet-current.pem") + if fi, err := os.Lstat(currentPairFile); err != nil { + t.Errorf("Got %v, wanted file %q to be there", currentPairFile, err) + } else if fi.Mode()&os.ModeSymlink != os.ModeSymlink { + t.Errorf("Got %q not a symlink.", currentPairFile) + } + + newPairFile := filepath.Join(dir, "kubelet-newpair.pem") + if err := s.updateSymlink(newPairFile); err == nil { + t.Errorf("Got no error, wanted to fail updating the symlink the file %q does not exist.", newPairFile) + } +} + +func TestUpdateSymlinkNoSymlink(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-update-symlink") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + pairFile := filepath.Join(dir, "kubelet-newfile.pem") + if err := ioutil.WriteFile(pairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + s := fileStore{ + certDirectory: dir, + pairNamePrefix: "kubelet", + } + if err := s.updateSymlink(pairFile); err != nil { + t.Errorf("Got error %v, wanted a new symlink to be created", err) + } + + if _, err := os.Stat(pairFile); err != nil { + t.Errorf("Got error %v, wanted file %q to be there", pairFile, err) + } + currentPairFile := filepath.Join(dir, "kubelet-current.pem") + if fi, err := os.Lstat(currentPairFile); err != nil { + t.Errorf("Got %v, wanted %q to be there", currentPairFile, err) + } else if fi.Mode()&os.ModeSymlink != os.ModeSymlink { + t.Errorf("%q not a symlink, wanted a symlink.", currentPairFile) + } +} + +func TestUpdateSymlinkReplaceExistingSymlink(t *testing.T) { + prefix := "kubelet" + dir, err := ioutil.TempDir("", "k8s-test-update-symlink") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + oldPairFile := filepath.Join(dir, prefix+"-oldfile.pem") + if err := ioutil.WriteFile(oldPairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", oldPairFile, err) + } + newPairFile := filepath.Join(dir, prefix+"-newfile.pem") + if err := ioutil.WriteFile(newPairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", newPairFile, err) + } + currentPairFile := filepath.Join(dir, prefix+"-current.pem") + if err := os.Symlink(oldPairFile, currentPairFile); err != nil { + t.Fatalf("unable to create a symlink from %q to %q: %v", currentPairFile, oldPairFile, err) + } + if resolved, err := os.Readlink(currentPairFile); err != nil { + t.Fatalf("Got %v when attempting to resolve symlink %q", err, currentPairFile) + } else if resolved != oldPairFile { + t.Fatalf("Got %q as resolution of symlink %q, wanted %q", resolved, currentPairFile, oldPairFile) + } + + s := fileStore{ + certDirectory: dir, + pairNamePrefix: prefix, + } + if err := s.updateSymlink(newPairFile); err != nil { + t.Errorf("Got error %v, wanted a new symlink to be created", err) + } + + if _, err := os.Stat(oldPairFile); err != nil { + t.Errorf("Got error %v, wanted file %q to be there", oldPairFile, err) + } + if _, err := os.Stat(newPairFile); err != nil { + t.Errorf("Got error %v, wanted file %q to be there", newPairFile, err) + } + if fi, err := os.Lstat(currentPairFile); err != nil { + t.Errorf("Got %v, wanted %q to be there", currentPairFile, err) + } else if fi.Mode()&os.ModeSymlink != os.ModeSymlink { + t.Errorf("%q not a symlink, wanted a symlink.", currentPairFile) + } + if resolved, err := os.Readlink(currentPairFile); err != nil { + t.Fatalf("Got %v when attempting to resolve symlink %q", err, currentPairFile) + } else if resolved != newPairFile { + t.Fatalf("Got %q as resolution of symlink %q, wanted %q", resolved, currentPairFile, newPairFile) + } +} + +func TestLoadCertKeyBlocksNoFile(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-load-cert-key-blocks") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + pairFile := filepath.Join(dir, "kubelet-pair.pem") + + if _, _, err := loadCertKeyBlocks(pairFile); err == nil { + t.Errorf("Got no error, but expected %q not found.", pairFile) + } +} + +func TestLoadCertKeyBlocksEmptyFile(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-load-cert-key-blocks") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + pairFile := filepath.Join(dir, "kubelet-pair.pem") + if err := ioutil.WriteFile(pairFile, nil, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + if _, _, err := loadCertKeyBlocks(pairFile); err == nil { + t.Errorf("Got no error, but expected %q not found.", pairFile) + } +} + +func TestLoadCertKeyBlocksPartialFile(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-load-cert-key-blocks") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + pairFile := filepath.Join(dir, "kubelet-pair.pem") + if err := ioutil.WriteFile(pairFile, storeCertData.certificatePEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + if _, _, err := loadCertKeyBlocks(pairFile); err == nil { + t.Errorf("Got no error, but expected %q invalid.", pairFile) + } +} + +func TestLoadCertKeyBlocks(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-load-cert-key-blocks") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + pairFile := filepath.Join(dir, "kubelet-pair.pem") + data := append(storeCertData.certificatePEM, []byte("\n")...) + data = append(data, storeCertData.keyPEM...) + if err := ioutil.WriteFile(pairFile, data, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + certBlock, keyBlock, err := loadCertKeyBlocks(pairFile) + if err != nil { + t.Errorf("Got %v, but expected no error.", pairFile) + } + if certBlock.Type != cert.CertificateBlockType { + t.Errorf("Got %q loaded from the pair file, expected a %q.", certBlock.Type, cert.CertificateBlockType) + } + if keyBlock.Type != cert.RSAPrivateKeyBlockType { + t.Errorf("Got %q loaded from the pair file, expected a %q.", keyBlock.Type, cert.RSAPrivateKeyBlockType) + } +} + +func TestLoadFile(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-load-cert-key-blocks") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + pairFile := filepath.Join(dir, "kubelet-pair.pem") + data := append(storeCertData.certificatePEM, []byte("\n")...) + data = append(data, storeCertData.keyPEM...) + if err := ioutil.WriteFile(pairFile, data, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + + cert, err := loadFile(pairFile) + if err != nil { + t.Fatalf("Could not load certificate from disk: %v", err) + } + if cert == nil { + t.Fatalf("There was no error, but no certificate data was returned.") + } + if cert.Leaf == nil { + t.Fatalf("Got an empty leaf, expected private data.") + } +} + +func TestUpdateNoRotation(t *testing.T) { + prefix := "kubelet-server" + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + keyFile := filepath.Join(dir, "kubelet.key") + if err := ioutil.WriteFile(keyFile, storeCertData.keyPEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", keyFile, err) + } + certFile := filepath.Join(dir, "kubelet.crt") + if err := ioutil.WriteFile(certFile, storeCertData.certificatePEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", certFile, err) + } + + s, err := NewFileStore(prefix, dir, dir, certFile, keyFile) + if err != nil { + t.Fatalf("Got %v while creating a new store.", err) + } + + cert, err := s.Update(storeCertData.certificatePEM, storeCertData.keyPEM) + if err != nil { + t.Errorf("Got %v while updating certificate store.", err) + } + if cert == nil { + t.Errorf("Got nil certificate, expected something real.") + } +} + +func TestUpdateRotation(t *testing.T) { + prefix := "kubelet-server" + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + keyFile := filepath.Join(dir, "kubelet.key") + if err := ioutil.WriteFile(keyFile, storeCertData.keyPEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", keyFile, err) + } + certFile := filepath.Join(dir, "kubelet.crt") + if err := ioutil.WriteFile(certFile, storeCertData.certificatePEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", certFile, err) + } + + s, err := NewFileStore(prefix, dir, dir, certFile, keyFile) + if err != nil { + t.Fatalf("Got %v while creating a new store.", err) + } + + cert, err := s.Update(storeCertData.certificatePEM, storeCertData.keyPEM) + if err != nil { + t.Fatalf("Got %v while updating certificate store.", err) + } + if cert == nil { + t.Fatalf("Got nil certificate, expected something real.") + } +} + +func TestUpdateWithBadCertKeyData(t *testing.T) { + prefix := "kubelet-server" + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + keyFile := filepath.Join(dir, "kubelet.key") + if err := ioutil.WriteFile(keyFile, storeCertData.keyPEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", keyFile, err) + } + certFile := filepath.Join(dir, "kubelet.crt") + if err := ioutil.WriteFile(certFile, storeCertData.certificatePEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", certFile, err) + } + + s, err := NewFileStore(prefix, dir, dir, certFile, keyFile) + if err != nil { + t.Fatalf("Got %v while creating a new store.", err) + } + + cert, err := s.Update([]byte{0, 0}, storeCertData.keyPEM) + if err == nil { + t.Fatalf("Got no error while updating certificate store with invalid data.") + } + if cert != nil { + t.Fatalf("Got %v certificate returned from the update, expected nil.", cert) + } +} + +func TestCurrentPairFile(t *testing.T) { + prefix := "kubelet-server" + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + pairFile := filepath.Join(dir, prefix+"-pair.pem") + data := append(storeCertData.certificatePEM, []byte("\n")...) + data = append(data, storeCertData.keyPEM...) + if err := ioutil.WriteFile(pairFile, data, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", pairFile, err) + } + currentFile := filepath.Join(dir, prefix+"-current.pem") + if err := os.Symlink(pairFile, currentFile); err != nil { + t.Fatalf("unable to create a symlink from %q to %q: %v", currentFile, pairFile, err) + } + + store, err := NewFileStore("kubelet-server", dir, dir, "", "") + if err != nil { + t.Fatalf("Failed to initialize certificate store: %v", err) + } + + cert, err := store.Current() + if err != nil { + t.Fatalf("Could not load certificate from disk: %v", err) + } + if cert == nil { + t.Fatalf("There was no error, but no certificate data was returned.") + } + if cert.Leaf == nil { + t.Fatalf("Got an empty leaf, expected private data.") + } +} + +func TestCurrentCertKeyFiles(t *testing.T) { + prefix := "kubelet-server" + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + certFile := filepath.Join(dir, "kubelet.crt") + if err := ioutil.WriteFile(certFile, storeCertData.certificatePEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", certFile, err) + } + keyFile := filepath.Join(dir, "kubelet.key") + if err := ioutil.WriteFile(keyFile, storeCertData.keyPEM, 0600); err != nil { + t.Fatalf("Unable to create the file %q: %v", keyFile, err) + } + + store, err := NewFileStore(prefix, dir, dir, certFile, keyFile) + if err != nil { + t.Fatalf("Failed to initialize certificate store: %v", err) + } + + cert, err := store.Current() + if err != nil { + t.Fatalf("Could not load certificate from disk: %v", err) + } + if cert == nil { + t.Fatalf("There was no error, but no certificate data was returned.") + } + if cert.Leaf == nil { + t.Fatalf("Got an empty leaf, expected private data.") + } +} + +func TestCurrentNoFiles(t *testing.T) { + dir, err := ioutil.TempDir("", "k8s-test-certstore-current") + if err != nil { + t.Fatalf("Unable to create the test directory %q: %v", dir, err) + } + defer func() { + if err := os.RemoveAll(dir); err != nil { + t.Errorf("Unable to clean up test directory %q: %v", dir, err) + } + }() + + store, err := NewFileStore("kubelet-server", dir, dir, "", "") + if err != nil { + t.Fatalf("Failed to initialize certificate store: %v", err) + } + + cert, err := store.Current() + if err == nil { + t.Fatalf("Got no error, expected an error because the cert/key files don't exist.") + } + if _, ok := err.(*NoCertKeyError); !ok { + t.Fatalf("Got error %v, expected NoCertKeyError.", err) + } + if cert != nil { + t.Fatalf("Got certificate, expected no certificate because the cert/key files don't exist.") + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/csr/BUILD b/discovery/vendor/k8s.io/client-go/util/certificate/csr/BUILD new file mode 100644 index 00000000..c1bcd957 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/certificate/csr/BUILD @@ -0,0 +1,53 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_library( + name = "go_default_library", + srcs = ["csr.go"], + importpath = "k8s.io/client-go/util/certificate/csr", + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/api/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/types:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/client-go/tools/cache:go_default_library", + "//vendor/k8s.io/client-go/util/cert:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) + +go_test( + name = "go_default_test", + srcs = ["csr_test.go"], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/api/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library", + "//vendor/k8s.io/client-go/util/cert:go_default_library", + ], +) diff --git a/discovery/vendor/k8s.io/client-go/util/certificate/csr/csr_test.go b/discovery/vendor/k8s.io/client-go/util/certificate/csr/csr_test.go new file mode 100644 index 00000000..d0182abe --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/certificate/csr/csr_test.go @@ -0,0 +1,135 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package csr + +import ( + "fmt" + "testing" + + certificates "k8s.io/api/certificates/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1" + certutil "k8s.io/client-go/util/cert" +) + +func TestRequestNodeCertificateNoKeyData(t *testing.T) { + certData, err := RequestNodeCertificate(&fakeClient{}, []byte{}, "fake-node-name") + if err == nil { + t.Errorf("Got no error, wanted error an error because there was an empty private key passed in.") + } + if certData != nil { + t.Errorf("Got cert data, wanted nothing as there should have been an error.") + } +} + +func TestRequestNodeCertificateErrorCreatingCSR(t *testing.T) { + client := &fakeClient{ + failureType: createError, + } + privateKeyData, err := certutil.MakeEllipticPrivateKeyPEM() + if err != nil { + t.Fatalf("Unable to generate a new private key: %v", err) + } + + certData, err := RequestNodeCertificate(client, privateKeyData, "fake-node-name") + if err == nil { + t.Errorf("Got no error, wanted error an error because client.Create failed.") + } + if certData != nil { + t.Errorf("Got cert data, wanted nothing as there should have been an error.") + } +} + +func TestRequestNodeCertificate(t *testing.T) { + privateKeyData, err := certutil.MakeEllipticPrivateKeyPEM() + if err != nil { + t.Fatalf("Unable to generate a new private key: %v", err) + } + + certData, err := RequestNodeCertificate(&fakeClient{}, privateKeyData, "fake-node-name") + if err != nil { + t.Errorf("Got %v, wanted no error.", err) + } + if certData == nil { + t.Errorf("Got nothing, expected a CSR.") + } +} + +type FailureType int + +const ( + noError FailureType = iota + createError + certificateSigningRequestDenied +) + +type fakeClient struct { + certificatesclient.CertificateSigningRequestInterface + watch *watch.FakeWatcher + failureType FailureType +} + +func (c *fakeClient) Create(*certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, error) { + if c.failureType == createError { + return nil, fmt.Errorf("fakeClient failed creating request") + } + csr := certificates.CertificateSigningRequest{ + ObjectMeta: metav1.ObjectMeta{ + UID: "fake-uid", + Name: "fake-certificate-signing-request-name", + }, + } + return &csr, nil +} + +func (c *fakeClient) List(opts metav1.ListOptions) (*certificates.CertificateSigningRequestList, error) { + return &certificates.CertificateSigningRequestList{}, nil +} + +func (c *fakeClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + c.watch = watch.NewFakeWithChanSize(1, false) + c.watch.Add(c.generateCSR()) + c.watch.Stop() + return c.watch, nil +} + +func (c *fakeClient) generateCSR() *certificates.CertificateSigningRequest { + var condition certificates.CertificateSigningRequestCondition + if c.failureType == certificateSigningRequestDenied { + condition = certificates.CertificateSigningRequestCondition{ + Type: certificates.CertificateDenied, + } + } else { + condition = certificates.CertificateSigningRequestCondition{ + Type: certificates.CertificateApproved, + } + } + + csr := certificates.CertificateSigningRequest{ + ObjectMeta: metav1.ObjectMeta{ + UID: "fake-uid", + }, + Status: certificates.CertificateSigningRequestStatus{ + Conditions: []certificates.CertificateSigningRequestCondition{ + condition, + }, + Certificate: []byte{}, + }, + } + return &csr +} diff --git a/discovery/vendor/k8s.io/client-go/util/exec/BUILD b/discovery/vendor/k8s.io/client-go/util/exec/BUILD new file mode 100644 index 00000000..57b58e5c --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/exec/BUILD @@ -0,0 +1,25 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["exec.go"], + importpath = "k8s.io/client-go/util/exec", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/flowcontrol/BUILD b/discovery/vendor/k8s.io/client-go/util/flowcontrol/BUILD new file mode 100644 index 00000000..819bb7ef --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/flowcontrol/BUILD @@ -0,0 +1,44 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "backoff_test.go", + "throttle_test.go", + ], + embed = [":go_default_library"], + deps = ["//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "backoff.go", + "throttle.go", + ], + importpath = "k8s.io/client-go/util/flowcontrol", + deps = [ + "//vendor/golang.org/x/time/rate:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/client-go/util/integer:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/flowcontrol/backoff_test.go b/discovery/vendor/k8s.io/client-go/util/flowcontrol/backoff_test.go new file mode 100644 index 00000000..23a6cbfa --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/flowcontrol/backoff_test.go @@ -0,0 +1,195 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flowcontrol + +import ( + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/clock" +) + +func TestSlowBackoff(t *testing.T) { + id := "_idSlow" + tc := clock.NewFakeClock(time.Now()) + step := time.Second + maxDuration := 50 * step + + b := NewFakeBackOff(step, maxDuration, tc) + cases := []time.Duration{0, 1, 2, 4, 8, 16, 32, 50, 50, 50} + for ix, c := range cases { + tc.Step(step) + w := b.Get(id) + if w != c*step { + t.Errorf("input: '%d': expected %s, got %s", ix, c*step, w) + } + b.Next(id, tc.Now()) + } + + //Now confirm that the Reset cancels backoff. + b.Next(id, tc.Now()) + b.Reset(id) + if b.Get(id) != 0 { + t.Errorf("Reset didn't clear the backoff.") + } + +} + +func TestBackoffReset(t *testing.T) { + id := "_idReset" + tc := clock.NewFakeClock(time.Now()) + step := time.Second + maxDuration := step * 5 + b := NewFakeBackOff(step, maxDuration, tc) + startTime := tc.Now() + + // get to backoff = maxDuration + for i := 0; i <= int(maxDuration/step); i++ { + tc.Step(step) + b.Next(id, tc.Now()) + } + + // backoff should be capped at maxDuration + if !b.IsInBackOffSince(id, tc.Now()) { + t.Errorf("expected to be in Backoff got %s", b.Get(id)) + } + + lastUpdate := tc.Now() + tc.Step(2*maxDuration + step) // time += 11s, 11 > 2*maxDuration + if b.IsInBackOffSince(id, lastUpdate) { + t.Errorf("expected to not be in Backoff after reset (start=%s, now=%s, lastUpdate=%s), got %s", startTime, tc.Now(), lastUpdate, b.Get(id)) + } +} + +func TestBackoffHightWaterMark(t *testing.T) { + id := "_idHiWaterMark" + tc := clock.NewFakeClock(time.Now()) + step := time.Second + maxDuration := 5 * step + b := NewFakeBackOff(step, maxDuration, tc) + + // get to backoff = maxDuration + for i := 0; i <= int(maxDuration/step); i++ { + tc.Step(step) + b.Next(id, tc.Now()) + } + + // backoff high watermark expires after 2*maxDuration + tc.Step(maxDuration + step) + b.Next(id, tc.Now()) + + if b.Get(id) != maxDuration { + t.Errorf("expected Backoff to stay at high watermark %s got %s", maxDuration, b.Get(id)) + } +} + +func TestBackoffGC(t *testing.T) { + id := "_idGC" + tc := clock.NewFakeClock(time.Now()) + step := time.Second + maxDuration := 5 * step + + b := NewFakeBackOff(step, maxDuration, tc) + + for i := 0; i <= int(maxDuration/step); i++ { + tc.Step(step) + b.Next(id, tc.Now()) + } + lastUpdate := tc.Now() + tc.Step(maxDuration + step) + b.GC() + _, found := b.perItemBackoff[id] + if !found { + t.Errorf("expected GC to skip entry, elapsed time=%s maxDuration=%s", tc.Now().Sub(lastUpdate), maxDuration) + } + + tc.Step(maxDuration + step) + b.GC() + r, found := b.perItemBackoff[id] + if found { + t.Errorf("expected GC of entry after %s got entry %v", tc.Now().Sub(lastUpdate), r) + } +} + +func TestIsInBackOffSinceUpdate(t *testing.T) { + id := "_idIsInBackOffSinceUpdate" + tc := clock.NewFakeClock(time.Now()) + step := time.Second + maxDuration := 10 * step + b := NewFakeBackOff(step, maxDuration, tc) + startTime := tc.Now() + + cases := []struct { + tick time.Duration + inBackOff bool + value int + }{ + {tick: 0, inBackOff: false, value: 0}, + {tick: 1, inBackOff: false, value: 1}, + {tick: 2, inBackOff: true, value: 2}, + {tick: 3, inBackOff: false, value: 2}, + {tick: 4, inBackOff: true, value: 4}, + {tick: 5, inBackOff: true, value: 4}, + {tick: 6, inBackOff: true, value: 4}, + {tick: 7, inBackOff: false, value: 4}, + {tick: 8, inBackOff: true, value: 8}, + {tick: 9, inBackOff: true, value: 8}, + {tick: 10, inBackOff: true, value: 8}, + {tick: 11, inBackOff: true, value: 8}, + {tick: 12, inBackOff: true, value: 8}, + {tick: 13, inBackOff: true, value: 8}, + {tick: 14, inBackOff: true, value: 8}, + {tick: 15, inBackOff: false, value: 8}, + {tick: 16, inBackOff: true, value: 10}, + {tick: 17, inBackOff: true, value: 10}, + {tick: 18, inBackOff: true, value: 10}, + {tick: 19, inBackOff: true, value: 10}, + {tick: 20, inBackOff: true, value: 10}, + {tick: 21, inBackOff: true, value: 10}, + {tick: 22, inBackOff: true, value: 10}, + {tick: 23, inBackOff: true, value: 10}, + {tick: 24, inBackOff: true, value: 10}, + {tick: 25, inBackOff: false, value: 10}, + {tick: 26, inBackOff: true, value: 10}, + {tick: 27, inBackOff: true, value: 10}, + {tick: 28, inBackOff: true, value: 10}, + {tick: 29, inBackOff: true, value: 10}, + {tick: 30, inBackOff: true, value: 10}, + {tick: 31, inBackOff: true, value: 10}, + {tick: 32, inBackOff: true, value: 10}, + {tick: 33, inBackOff: true, value: 10}, + {tick: 34, inBackOff: true, value: 10}, + {tick: 35, inBackOff: false, value: 10}, + {tick: 56, inBackOff: false, value: 0}, + {tick: 57, inBackOff: false, value: 1}, + } + + for _, c := range cases { + tc.SetTime(startTime.Add(c.tick * step)) + if c.inBackOff != b.IsInBackOffSinceUpdate(id, tc.Now()) { + t.Errorf("expected IsInBackOffSinceUpdate %v got %v at tick %s", c.inBackOff, b.IsInBackOffSinceUpdate(id, tc.Now()), c.tick*step) + } + + if c.inBackOff && (time.Duration(c.value)*step != b.Get(id)) { + t.Errorf("expected backoff value=%s got %s at tick %s", time.Duration(c.value)*step, b.Get(id), c.tick*step) + } + + if !c.inBackOff { + b.Next(id, tc.Now()) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle.go b/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle.go index c45169c4..e671c044 100644 --- a/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle.go +++ b/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle.go @@ -18,8 +18,9 @@ package flowcontrol import ( "sync" + "time" - "github.com/juju/ratelimit" + "golang.org/x/time/rate" ) type RateLimiter interface { @@ -30,17 +31,13 @@ type RateLimiter interface { Accept() // Stop stops the rate limiter, subsequent calls to CanAccept will return false Stop() - // Saturation returns a percentage number which describes how saturated - // this rate limiter is. - // Usually we use token bucket rate limiter. In that case, - // 1.0 means no tokens are available; 0.0 means we have a full bucket of tokens to use. - Saturation() float64 // QPS returns QPS of this rate limiter QPS() float32 } type tokenBucketRateLimiter struct { - limiter *ratelimit.Bucket + limiter *rate.Limiter + clock Clock qps float32 } @@ -50,42 +47,48 @@ type tokenBucketRateLimiter struct { // The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. // The maximum number of tokens in the bucket is capped at 'burst'. func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter { - limiter := ratelimit.NewBucketWithRate(float64(qps), int64(burst)) - return newTokenBucketRateLimiter(limiter, qps) + limiter := rate.NewLimiter(rate.Limit(qps), burst) + return newTokenBucketRateLimiter(limiter, realClock{}, qps) } // An injectable, mockable clock interface. type Clock interface { - ratelimit.Clock + Now() time.Time + Sleep(time.Duration) +} + +type realClock struct{} + +func (realClock) Now() time.Time { + return time.Now() +} +func (realClock) Sleep(d time.Duration) { + time.Sleep(d) } // NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter // but allows an injectable clock, for testing. -func NewTokenBucketRateLimiterWithClock(qps float32, burst int, clock Clock) RateLimiter { - limiter := ratelimit.NewBucketWithRateAndClock(float64(qps), int64(burst), clock) - return newTokenBucketRateLimiter(limiter, qps) +func NewTokenBucketRateLimiterWithClock(qps float32, burst int, c Clock) RateLimiter { + limiter := rate.NewLimiter(rate.Limit(qps), burst) + return newTokenBucketRateLimiter(limiter, c, qps) } -func newTokenBucketRateLimiter(limiter *ratelimit.Bucket, qps float32) RateLimiter { +func newTokenBucketRateLimiter(limiter *rate.Limiter, c Clock, qps float32) RateLimiter { return &tokenBucketRateLimiter{ limiter: limiter, + clock: c, qps: qps, } } func (t *tokenBucketRateLimiter) TryAccept() bool { - return t.limiter.TakeAvailable(1) == 1 -} - -func (t *tokenBucketRateLimiter) Saturation() float64 { - capacity := t.limiter.Capacity() - avail := t.limiter.Available() - return float64(capacity-avail) / float64(capacity) + return t.limiter.AllowN(t.clock.Now(), 1) } // Accept will block until a token becomes available func (t *tokenBucketRateLimiter) Accept() { - t.limiter.Wait(1) + now := t.clock.Now() + t.clock.Sleep(t.limiter.ReserveN(now, 1).DelayFrom(now)) } func (t *tokenBucketRateLimiter) Stop() { @@ -105,10 +108,6 @@ func (t *fakeAlwaysRateLimiter) TryAccept() bool { return true } -func (t *fakeAlwaysRateLimiter) Saturation() float64 { - return 0 -} - func (t *fakeAlwaysRateLimiter) Stop() {} func (t *fakeAlwaysRateLimiter) Accept() {} @@ -131,10 +130,6 @@ func (t *fakeNeverRateLimiter) TryAccept() bool { return false } -func (t *fakeNeverRateLimiter) Saturation() float64 { - return 1 -} - func (t *fakeNeverRateLimiter) Stop() { t.wg.Done() } diff --git a/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle_test.go b/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle_test.go new file mode 100644 index 00000000..99cf64d6 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/flowcontrol/throttle_test.go @@ -0,0 +1,153 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flowcontrol + +import ( + "sync" + "testing" + "time" +) + +func TestMultithreadedThrottling(t *testing.T) { + // Bucket with 100QPS and no burst + r := NewTokenBucketRateLimiter(100, 1) + + // channel to collect 100 tokens + taken := make(chan bool, 100) + + // Set up goroutines to hammer the throttler + startCh := make(chan bool) + endCh := make(chan bool) + for i := 0; i < 10; i++ { + go func() { + // wait for the starting signal + <-startCh + for { + // get a token + r.Accept() + select { + // try to add it to the taken channel + case taken <- true: + continue + // if taken is full, notify and return + default: + endCh <- true + return + } + } + }() + } + + // record wall time + startTime := time.Now() + // take the initial capacity so all tokens are the result of refill + r.Accept() + // start the thundering herd + close(startCh) + // wait for the first signal that we collected 100 tokens + <-endCh + // record wall time + endTime := time.Now() + + // tolerate a 1% clock change because these things happen + if duration := endTime.Sub(startTime); duration < (time.Second * 99 / 100) { + // We shouldn't be able to get 100 tokens out of the bucket in less than 1 second of wall clock time, no matter what + t.Errorf("Expected it to take at least 1 second to get 100 tokens, took %v", duration) + } else { + t.Logf("Took %v to get 100 tokens", duration) + } +} + +func TestBasicThrottle(t *testing.T) { + r := NewTokenBucketRateLimiter(1, 3) + for i := 0; i < 3; i++ { + if !r.TryAccept() { + t.Error("unexpected false accept") + } + } + if r.TryAccept() { + t.Error("unexpected true accept") + } +} + +func TestIncrementThrottle(t *testing.T) { + r := NewTokenBucketRateLimiter(1, 1) + if !r.TryAccept() { + t.Error("unexpected false accept") + } + if r.TryAccept() { + t.Error("unexpected true accept") + } + + // Allow to refill + time.Sleep(2 * time.Second) + + if !r.TryAccept() { + t.Error("unexpected false accept") + } +} + +func TestThrottle(t *testing.T) { + r := NewTokenBucketRateLimiter(10, 5) + + // Should consume 5 tokens immediately, then + // the remaining 11 should take at least 1 second (0.1s each) + expectedFinish := time.Now().Add(time.Second * 1) + for i := 0; i < 16; i++ { + r.Accept() + } + if time.Now().Before(expectedFinish) { + t.Error("rate limit was not respected, finished too early") + } +} + +func TestAlwaysFake(t *testing.T) { + rl := NewFakeAlwaysRateLimiter() + if !rl.TryAccept() { + t.Error("TryAccept in AlwaysFake should return true.") + } + // If this will block the test will timeout + rl.Accept() +} + +func TestNeverFake(t *testing.T) { + rl := NewFakeNeverRateLimiter() + if rl.TryAccept() { + t.Error("TryAccept in NeverFake should return false.") + } + + finished := false + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + rl.Accept() + finished = true + wg.Done() + }() + + // Wait some time to make sure it never finished. + time.Sleep(time.Second) + if finished { + t.Error("Accept should block forever in NeverFake.") + } + + rl.Stop() + wg.Wait() + if !finished { + t.Error("Stop should make Accept unblock in NeverFake.") + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/homedir/BUILD b/discovery/vendor/k8s.io/client-go/util/homedir/BUILD new file mode 100644 index 00000000..21a1952c --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/homedir/BUILD @@ -0,0 +1,25 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = ["homedir.go"], + importpath = "k8s.io/client-go/util/homedir", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/integer/BUILD b/discovery/vendor/k8s.io/client-go/util/integer/BUILD new file mode 100644 index 00000000..8a2105e4 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/integer/BUILD @@ -0,0 +1,32 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = ["integer_test.go"], + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = ["integer.go"], + importpath = "k8s.io/client-go/util/integer", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/integer/integer_test.go b/discovery/vendor/k8s.io/client-go/util/integer/integer_test.go new file mode 100644 index 00000000..e9f58688 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/integer/integer_test.go @@ -0,0 +1,244 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integer + +import "testing" + +func TestIntMax(t *testing.T) { + tests := []struct { + nums []int + expectedMax int + }{ + { + nums: []int{-1, 0}, + expectedMax: 0, + }, + { + nums: []int{-1, -2}, + expectedMax: -1, + }, + { + nums: []int{0, 1}, + expectedMax: 1, + }, + { + nums: []int{1, 2}, + expectedMax: 2, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if max := IntMax(test.nums[0], test.nums[1]); max != test.expectedMax { + t.Errorf("expected %v, got %v", test.expectedMax, max) + } + } +} + +func TestIntMin(t *testing.T) { + tests := []struct { + nums []int + expectedMin int + }{ + { + nums: []int{-1, 0}, + expectedMin: -1, + }, + { + nums: []int{-1, -2}, + expectedMin: -2, + }, + { + nums: []int{0, 1}, + expectedMin: 0, + }, + { + nums: []int{1, 2}, + expectedMin: 1, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if min := IntMin(test.nums[0], test.nums[1]); min != test.expectedMin { + t.Errorf("expected %v, got %v", test.expectedMin, min) + } + } +} + +func TestInt32Max(t *testing.T) { + tests := []struct { + nums []int32 + expectedMax int32 + }{ + { + nums: []int32{-1, 0}, + expectedMax: 0, + }, + { + nums: []int32{-1, -2}, + expectedMax: -1, + }, + { + nums: []int32{0, 1}, + expectedMax: 1, + }, + { + nums: []int32{1, 2}, + expectedMax: 2, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if max := Int32Max(test.nums[0], test.nums[1]); max != test.expectedMax { + t.Errorf("expected %v, got %v", test.expectedMax, max) + } + } +} + +func TestInt32Min(t *testing.T) { + tests := []struct { + nums []int32 + expectedMin int32 + }{ + { + nums: []int32{-1, 0}, + expectedMin: -1, + }, + { + nums: []int32{-1, -2}, + expectedMin: -2, + }, + { + nums: []int32{0, 1}, + expectedMin: 0, + }, + { + nums: []int32{1, 2}, + expectedMin: 1, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if min := Int32Min(test.nums[0], test.nums[1]); min != test.expectedMin { + t.Errorf("expected %v, got %v", test.expectedMin, min) + } + } +} + +func TestInt64Max(t *testing.T) { + tests := []struct { + nums []int64 + expectedMax int64 + }{ + { + nums: []int64{-1, 0}, + expectedMax: 0, + }, + { + nums: []int64{-1, -2}, + expectedMax: -1, + }, + { + nums: []int64{0, 1}, + expectedMax: 1, + }, + { + nums: []int64{1, 2}, + expectedMax: 2, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if max := Int64Max(test.nums[0], test.nums[1]); max != test.expectedMax { + t.Errorf("expected %v, got %v", test.expectedMax, max) + } + } +} + +func TestInt64Min(t *testing.T) { + tests := []struct { + nums []int64 + expectedMin int64 + }{ + { + nums: []int64{-1, 0}, + expectedMin: -1, + }, + { + nums: []int64{-1, -2}, + expectedMin: -2, + }, + { + nums: []int64{0, 1}, + expectedMin: 0, + }, + { + nums: []int64{1, 2}, + expectedMin: 1, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if min := Int64Min(test.nums[0], test.nums[1]); min != test.expectedMin { + t.Errorf("expected %v, got %v", test.expectedMin, min) + } + } +} + +func TestRoundToInt32(t *testing.T) { + tests := []struct { + num float64 + exp int32 + }{ + { + num: 5.5, + exp: 6, + }, + { + num: -3.7, + exp: -4, + }, + { + num: 3.49, + exp: 3, + }, + { + num: -7.9, + exp: -8, + }, + { + num: -4.499999, + exp: -4, + }, + { + num: 0, + exp: 0, + }, + } + + for i, test := range tests { + t.Logf("executing scenario %d", i) + if got := RoundToInt32(test.num); got != test.exp { + t.Errorf("expected %d, got %d", test.exp, got) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/jsonpath/BUILD b/discovery/vendor/k8s.io/client-go/util/jsonpath/BUILD new file mode 100644 index 00000000..ab43accd --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/jsonpath/BUILD @@ -0,0 +1,41 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "jsonpath_test.go", + "parser_test.go", + ], + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "jsonpath.go", + "node.go", + "parser.go", + ], + importpath = "k8s.io/client-go/util/jsonpath", + deps = ["//vendor/k8s.io/client-go/third_party/forked/golang/template:go_default_library"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/jsonpath/jsonpath_test.go b/discovery/vendor/k8s.io/client-go/util/jsonpath/jsonpath_test.go new file mode 100644 index 00000000..6c7277d1 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/jsonpath/jsonpath_test.go @@ -0,0 +1,371 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package jsonpath + +import ( + "bytes" + "encoding/json" + "fmt" + "reflect" + "sort" + "strings" + "testing" +) + +type jsonpathTest struct { + name string + template string + input interface{} + expect string + expectError bool +} + +func testJSONPath(tests []jsonpathTest, allowMissingKeys bool, t *testing.T) { + for _, test := range tests { + j := New(test.name) + j.AllowMissingKeys(allowMissingKeys) + err := j.Parse(test.template) + if err != nil { + t.Errorf("in %s, parse %s error %v", test.name, test.template, err) + } + buf := new(bytes.Buffer) + err = j.Execute(buf, test.input) + if test.expectError { + if test.expectError && err == nil { + t.Errorf("in %s, expected execute error", test.name) + } + continue + } else if err != nil { + t.Errorf("in %s, execute error %v", test.name, err) + } + out := buf.String() + if out != test.expect { + t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out) + } + } +} + +// testJSONPathSortOutput test cases related to map, the results may print in random order +func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) { + for _, test := range tests { + j := New(test.name) + err := j.Parse(test.template) + if err != nil { + t.Errorf("in %s, parse %s error %v", test.name, test.template, err) + } + buf := new(bytes.Buffer) + err = j.Execute(buf, test.input) + if err != nil { + t.Errorf("in %s, execute error %v", test.name, err) + } + out := buf.String() + //since map is visited in random order, we need to sort the results. + sortedOut := strings.Fields(out) + sort.Strings(sortedOut) + sortedExpect := strings.Fields(test.expect) + sort.Strings(sortedExpect) + if !reflect.DeepEqual(sortedOut, sortedExpect) { + t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out) + } + } +} + +func testFailJSONPath(tests []jsonpathTest, t *testing.T) { + for _, test := range tests { + j := New(test.name) + err := j.Parse(test.template) + if err != nil { + t.Errorf("in %s, parse %s error %v", test.name, test.template, err) + } + buf := new(bytes.Buffer) + err = j.Execute(buf, test.input) + var out string + if err == nil { + out = "nil" + } else { + out = err.Error() + } + if out != test.expect { + t.Errorf("in %s, expect to get error %q, got %q", test.name, test.expect, out) + } + } +} + +type book struct { + Category string + Author string + Title string + Price float32 +} + +func (b book) String() string { + return fmt.Sprintf("{Category: %s, Author: %s, Title: %s, Price: %v}", b.Category, b.Author, b.Title, b.Price) +} + +type bicycle struct { + Color string + Price float32 + IsNew bool +} + +type empName string +type job string +type store struct { + Book []book + Bicycle []bicycle + Name string + Labels map[string]int + Employees map[empName]job +} + +func TestStructInput(t *testing.T) { + + storeData := store{ + Name: "jsonpath", + Book: []book{ + {"reference", "Nigel Rees", "Sayings of the Centurey", 8.95}, + {"fiction", "Evelyn Waugh", "Sword of Honour", 12.99}, + {"fiction", "Herman Melville", "Moby Dick", 8.99}, + }, + Bicycle: []bicycle{ + {"red", 19.95, true}, + {"green", 20.01, false}, + }, + Labels: map[string]int{ + "engieer": 10, + "web/html": 15, + "k8s-app": 20, + }, + Employees: map[empName]job{ + "jason": "manager", + "dan": "clerk", + }, + } + + storeTests := []jsonpathTest{ + {"plain", "hello jsonpath", nil, "hello jsonpath", false}, + {"recursive", "{..}", []int{1, 2, 3}, "[1 2 3]", false}, + {"filter", "{[?(@<5)]}", []int{2, 6, 3, 7}, "2 3", false}, + {"quote", `{"{"}`, nil, "{", false}, + {"union", "{[1,3,4]}", []int{0, 1, 2, 3, 4}, "1 3 4", false}, + {"array", "{[0:2]}", []string{"Monday", "Tudesday"}, "Monday Tudesday", false}, + {"variable", "hello {.Name}", storeData, "hello jsonpath", false}, + {"dict/", "{$.Labels.web/html}", storeData, "15", false}, + {"dict/", "{$.Employees.jason}", storeData, "manager", false}, + {"dict/", "{$.Employees.dan}", storeData, "clerk", false}, + {"dict-", "{.Labels.k8s-app}", storeData, "20", false}, + {"nest", "{.Bicycle[*].Color}", storeData, "red green", false}, + {"allarray", "{.Book[*].Author}", storeData, "Nigel Rees Evelyn Waugh Herman Melville", false}, + {"allfileds", "{.Bicycle.*}", storeData, "{red 19.95 true} {green 20.01 false}", false}, + {"recurfileds", "{..Price}", storeData, "8.95 12.99 8.99 19.95 20.01", false}, + {"lastarray", "{.Book[-1:]}", storeData, + "{Category: fiction, Author: Herman Melville, Title: Moby Dick, Price: 8.99}", false}, + {"recurarray", "{..Book[2]}", storeData, + "{Category: fiction, Author: Herman Melville, Title: Moby Dick, Price: 8.99}", false}, + {"bool", "{.Bicycle[?(@.IsNew==true)]}", storeData, "{red 19.95 true}", false}, + } + testJSONPath(storeTests, false, t) + + missingKeyTests := []jsonpathTest{ + {"nonexistent field", "{.hello}", storeData, "", false}, + } + testJSONPath(missingKeyTests, true, t) + + failStoreTests := []jsonpathTest{ + {"invalid identifier", "{hello}", storeData, "unrecognized identifier hello", false}, + {"nonexistent field", "{.hello}", storeData, "hello is not found", false}, + {"invalid array", "{.Labels[0]}", storeData, "map[string]int is not array or slice", false}, + {"invalid filter operator", "{.Book[?(@.Price<>10)]}", storeData, "unrecognized filter operator <>", false}, + {"redundant end", "{range .Labels.*}{@}{end}{end}", storeData, "not in range, nothing to end", false}, + } + testFailJSONPath(failStoreTests, t) +} + +func TestJSONInput(t *testing.T) { + var pointsJSON = []byte(`[ + {"id": "i1", "x":4, "y":-5}, + {"id": "i2", "x":-2, "y":-5, "z":1}, + {"id": "i3", "x": 8, "y": 3 }, + {"id": "i4", "x": -6, "y": -1 }, + {"id": "i5", "x": 0, "y": 2, "z": 1 }, + {"id": "i6", "x": 1, "y": 4 } + ]`) + var pointsData interface{} + err := json.Unmarshal(pointsJSON, &pointsData) + if err != nil { + t.Error(err) + } + pointsTests := []jsonpathTest{ + {"exists filter", "{[?(@.z)].id}", pointsData, "i2 i5", false}, + {"bracket key", "{[0]['id']}", pointsData, "i1", false}, + } + testJSONPath(pointsTests, false, t) +} + +// TestKubernetes tests some use cases from kubernetes +func TestKubernetes(t *testing.T) { + var input = []byte(`{ + "kind": "List", + "items":[ + { + "kind":"None", + "metadata":{ + "name":"127.0.0.1", + "labels":{ + "kubernetes.io/hostname":"127.0.0.1" + } + }, + "status":{ + "capacity":{"cpu":"4"}, + "ready": true, + "addresses":[{"type": "LegacyHostIP", "address":"127.0.0.1"}] + } + }, + { + "kind":"None", + "metadata":{ + "name":"127.0.0.2", + "labels":{ + "kubernetes.io/hostname":"127.0.0.2" + } + }, + "status":{ + "capacity":{"cpu":"8"}, + "ready": false, + "addresses":[ + {"type": "LegacyHostIP", "address":"127.0.0.2"}, + {"type": "another", "address":"127.0.0.3"} + ] + } + } + ], + "users":[ + { + "name": "myself", + "user": {} + }, + { + "name": "e2e", + "user": {"username": "admin", "password": "secret"} + } + ] + }`) + var nodesData interface{} + err := json.Unmarshal(input, &nodesData) + if err != nil { + t.Error(err) + } + + nodesTests := []jsonpathTest{ + {"range item", `{range .items[*]}{.metadata.name}, {end}{.kind}`, nodesData, "127.0.0.1, 127.0.0.2, List", false}, + {"range item with quote", `{range .items[*]}{.metadata.name}{"\t"}{end}`, nodesData, "127.0.0.1\t127.0.0.2\t", false}, + {"range addresss", `{.items[*].status.addresses[*].address}`, nodesData, + "127.0.0.1 127.0.0.2 127.0.0.3", false}, + {"double range", `{range .items[*]}{range .status.addresses[*]}{.address}, {end}{end}`, nodesData, + "127.0.0.1, 127.0.0.2, 127.0.0.3, ", false}, + {"item name", `{.items[*].metadata.name}`, nodesData, "127.0.0.1 127.0.0.2", false}, + {"union nodes capacity", `{.items[*]['metadata.name', 'status.capacity']}`, nodesData, + "127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]", false}, + {"range nodes capacity", `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}`, nodesData, + "[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]] ", false}, + {"user password", `{.users[?(@.name=="e2e")].user.password}`, &nodesData, "secret", false}, + {"hostname", `{.items[0].metadata.labels.kubernetes\.io/hostname}`, &nodesData, "127.0.0.1", false}, + {"hostname filter", `{.items[?(@.metadata.labels.kubernetes\.io/hostname=="127.0.0.1")].kind}`, &nodesData, "None", false}, + {"bool item", `{.items[?(@..ready==true)].metadata.name}`, &nodesData, "127.0.0.1", false}, + } + testJSONPath(nodesTests, false, t) + + randomPrintOrderTests := []jsonpathTest{ + {"recursive name", "{..name}", nodesData, `127.0.0.1 127.0.0.2 myself e2e`, false}, + } + testJSONPathSortOutput(randomPrintOrderTests, t) +} + +func TestFilterPartialMatchesSometimesMissingAnnotations(t *testing.T) { + // for https://issues.k8s.io/45546 + var input = []byte(`{ + "kind": "List", + "items": [ + { + "kind": "Pod", + "metadata": { + "name": "pod1", + "annotations": { + "color": "blue" + } + } + }, + { + "kind": "Pod", + "metadata": { + "name": "pod2" + } + }, + { + "kind": "Pod", + "metadata": { + "name": "pod3", + "annotations": { + "color": "green" + } + } + }, + { + "kind": "Pod", + "metadata": { + "name": "pod4", + "annotations": { + "color": "blue" + } + } + } + ] + }`) + var data interface{} + err := json.Unmarshal(input, &data) + if err != nil { + t.Fatal(err) + } + + testJSONPath( + []jsonpathTest{ + { + "filter, should only match a subset, some items don't have annotations, tolerate missing items", + `{.items[?(@.metadata.annotations.color=="blue")].metadata.name}`, + data, + "pod1 pod4", + false, // expect no error + }, + }, + true, // allow missing keys + t, + ) + + testJSONPath( + []jsonpathTest{ + { + "filter, should only match a subset, some items don't have annotations, error on missing items", + `{.items[?(@.metadata.annotations.color=="blue")].metadata.name}`, + data, + "", + true, // expect an error + }, + }, + false, // don't allow missing keys + t, + ) +} diff --git a/discovery/vendor/k8s.io/client-go/util/jsonpath/parser_test.go b/discovery/vendor/k8s.io/client-go/util/jsonpath/parser_test.go new file mode 100644 index 00000000..4f71a60a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/jsonpath/parser_test.go @@ -0,0 +1,152 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package jsonpath + +import ( + "testing" +) + +type parserTest struct { + name string + text string + nodes []Node + shouldError bool +} + +var parserTests = []parserTest{ + {"plain", `hello jsonpath`, []Node{newText("hello jsonpath")}, false}, + {"variable", `hello {.jsonpath}`, + []Node{newText("hello "), newList(), newField("jsonpath")}, false}, + {"arrayfiled", `hello {['jsonpath']}`, + []Node{newText("hello "), newList(), newField("jsonpath")}, false}, + {"quote", `{"{"}`, []Node{newList(), newText("{")}, false}, + {"array", `{[1:3]}`, []Node{newList(), + newArray([3]ParamsEntry{{1, true}, {3, true}, {0, false}})}, false}, + {"allarray", `{.book[*].author}`, + []Node{newList(), newField("book"), + newArray([3]ParamsEntry{{0, false}, {0, false}, {0, false}}), newField("author")}, false}, + {"wildcard", `{.bicycle.*}`, + []Node{newList(), newField("bicycle"), newWildcard()}, false}, + {"filter", `{[?(@.price<3)]}`, + []Node{newList(), newFilter(newList(), newList(), "<"), + newList(), newField("price"), newList(), newInt(3)}, false}, + {"recursive", `{..}`, []Node{newList(), newRecursive()}, false}, + {"recurField", `{..price}`, + []Node{newList(), newRecursive(), newField("price")}, false}, + {"arraydict", `{['book.price']}`, []Node{newList(), + newField("book"), newField("price"), + }, false}, + {"union", `{['bicycle.price', 3, 'book.price']}`, []Node{newList(), newUnion([]*ListNode{}), + newList(), newField("bicycle"), newField("price"), + newList(), newArray([3]ParamsEntry{{3, true}, {4, true}, {0, false}}), + newList(), newField("book"), newField("price"), + }, false}, + {"range", `{range .items}{.name},{end}`, []Node{ + newList(), newIdentifier("range"), newField("items"), + newList(), newField("name"), newText(","), + newList(), newIdentifier("end"), + }, false}, + {"malformat input", `{\\\}`, []Node{}, true}, + {"paired parentheses in quotes", `{[?(@.status.nodeInfo.osImage == "()")]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("()")}, false}, + {"paired parentheses in double quotes and with double quotes escape", `{[?(@.status.nodeInfo.osImage == "(\"\")")]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("(\"\")")}, false}, + {"unregular parentheses in double quotes", `{[?(@.test == "())(")]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("test"), newList(), newText("())(")}, false}, + {"plain text in single quotes", `{[?(@.status.nodeInfo.osImage == 'Linux')]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("Linux")}, false}, + {"test filter suffix", `{[?(@.status.nodeInfo.osImage == "{[()]}")]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("{[()]}")}, false}, + {"double inside single", `{[?(@.status.nodeInfo.osImage == "''")]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("''")}, false}, + {"single inside double", `{[?(@.status.nodeInfo.osImage == '""')]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("\"\"")}, false}, + {"single containing escaped single", `{[?(@.status.nodeInfo.osImage == '\\\'')]}`, + []Node{newList(), newFilter(newList(), newList(), "=="), newList(), newField("status"), newField("nodeInfo"), newField("osImage"), newList(), newText("\\'")}, false}, +} + +func collectNode(nodes []Node, cur Node) []Node { + nodes = append(nodes, cur) + switch cur.Type() { + case NodeList: + for _, node := range cur.(*ListNode).Nodes { + nodes = collectNode(nodes, node) + } + case NodeFilter: + nodes = collectNode(nodes, cur.(*FilterNode).Left) + nodes = collectNode(nodes, cur.(*FilterNode).Right) + case NodeUnion: + for _, node := range cur.(*UnionNode).Nodes { + nodes = collectNode(nodes, node) + } + } + return nodes +} + +func TestParser(t *testing.T) { + for _, test := range parserTests { + parser, err := Parse(test.name, test.text) + if test.shouldError { + if err == nil { + t.Errorf("unexpected non-error when parsing %s", test.name) + } + continue + } + if err != nil { + t.Errorf("parse %s error %v", test.name, err) + } + result := collectNode([]Node{}, parser.Root)[1:] + if len(result) != len(test.nodes) { + t.Errorf("in %s, expect to get %d nodes, got %d nodes", test.name, len(test.nodes), len(result)) + t.Error(result) + } + for i, expect := range test.nodes { + if result[i].String() != expect.String() { + t.Errorf("in %s, %dth node, expect %v, got %v", test.name, i, expect, result[i]) + } + } + } +} + +type failParserTest struct { + name string + text string + err string +} + +func TestFailParser(t *testing.T) { + failParserTests := []failParserTest{ + {"unclosed action", "{.hello", "unclosed action"}, + {"unrecognized character", "{*}", "unrecognized character in action: U+002A '*'"}, + {"invalid number", "{+12.3.0}", "cannot parse number +12.3.0"}, + {"unterminated array", "{[1}", "unterminated array"}, + {"invalid index", "{[::-1]}", "invalid array index ::-1"}, + {"unterminated filter", "{[?(.price]}", "unterminated filter"}, + } + for _, test := range failParserTests { + _, err := Parse(test.name, test.text) + var out string + if err == nil { + out = "nil" + } else { + out = err.Error() + } + if out != test.err { + t.Errorf("in %s, expect to get error %v, got %v", test.name, test.err, out) + } + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/retry/BUILD b/discovery/vendor/k8s.io/client-go/util/retry/BUILD new file mode 100644 index 00000000..d7458131 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/retry/BUILD @@ -0,0 +1,41 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_library( + name = "go_default_library", + srcs = ["util.go"], + importpath = "k8s.io/client-go/util/retry", + deps = [ + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + ], +) + +go_test( + name = "go_default_test", + srcs = ["util_test.go"], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/retry/util_test.go b/discovery/vendor/k8s.io/client-go/util/retry/util_test.go new file mode 100644 index 00000000..dbb4374f --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/retry/util_test.go @@ -0,0 +1,71 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package retry + +import ( + "fmt" + "testing" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/wait" +) + +func TestRetryOnConflict(t *testing.T) { + opts := wait.Backoff{Factor: 1.0, Steps: 3} + conflictErr := errors.NewConflict(schema.GroupResource{Resource: "test"}, "other", nil) + + // never returns + err := RetryOnConflict(opts, func() error { + return conflictErr + }) + if err != conflictErr { + t.Errorf("unexpected error: %v", err) + } + + // returns immediately + i := 0 + err = RetryOnConflict(opts, func() error { + i++ + return nil + }) + if err != nil || i != 1 { + t.Errorf("unexpected error: %v", err) + } + + // returns immediately on error + testErr := fmt.Errorf("some other error") + err = RetryOnConflict(opts, func() error { + return testErr + }) + if err != testErr { + t.Errorf("unexpected error: %v", err) + } + + // keeps retrying + i = 0 + err = RetryOnConflict(opts, func() error { + if i < 2 { + i++ + return errors.NewConflict(schema.GroupResource{Resource: "test"}, "other", nil) + } + return nil + }) + if err != nil || i != 2 { + t.Errorf("unexpected error: %v", err) + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/testing/BUILD b/discovery/vendor/k8s.io/client-go/util/testing/BUILD new file mode 100644 index 00000000..726a30f9 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/testing/BUILD @@ -0,0 +1,35 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = ["fake_handler_test.go"], + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "fake_handler.go", + "tmpdir.go", + ], + importpath = "k8s.io/client-go/util/testing", +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/testing/fake_handler_test.go b/discovery/vendor/k8s.io/client-go/util/testing/fake_handler_test.go new file mode 100644 index 00000000..0d2c3e42 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/testing/fake_handler_test.go @@ -0,0 +1,180 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "bytes" + "net/http" + "net/http/httptest" + "testing" +) + +func TestFakeHandlerPath(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + body := "somebody" + + req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body)) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + handler.ValidateRequest(t, path, method, &body) +} + +func TestFakeHandlerPathNoBody(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + + req, err := http.NewRequest(method, server.URL+path, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + handler.ValidateRequest(t, path, method, nil) +} + +type fakeError struct { + errors []string +} + +func (f *fakeError) Errorf(format string, args ...interface{}) { + f.errors = append(f.errors, format) +} + +func (f *fakeError) Logf(format string, args ...interface{}) {} + +func TestFakeHandlerWrongPath(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + fakeT := fakeError{} + + req, err := http.NewRequest(method, server.URL+"/foo/baz", nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + handler.ValidateRequest(&fakeT, path, method, nil) + if len(fakeT.errors) != 1 { + t.Errorf("Unexpected error set: %#v", fakeT.errors) + } +} + +func TestFakeHandlerWrongMethod(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + fakeT := fakeError{} + + req, err := http.NewRequest("PUT", server.URL+path, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + handler.ValidateRequest(&fakeT, path, method, nil) + if len(fakeT.errors) != 1 { + t.Errorf("Unexpected error set: %#v", fakeT.errors) + } +} + +func TestFakeHandlerWrongBody(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + body := "somebody" + fakeT := fakeError{} + + req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body)) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + otherbody := "otherbody" + handler.ValidateRequest(&fakeT, path, method, &otherbody) + if len(fakeT.errors) != 1 { + t.Errorf("Unexpected error set: %#v", fakeT.errors) + } +} + +func TestFakeHandlerNilBody(t *testing.T) { + handler := FakeHandler{StatusCode: http.StatusOK} + server := httptest.NewServer(&handler) + defer server.Close() + method := "GET" + path := "/foo/bar" + body := "somebody" + fakeT := fakeError{} + + req, err := http.NewRequest(method, server.URL+path, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + client := http.Client{} + _, err = client.Do(req) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + handler.ValidateRequest(&fakeT, path, method, &body) + if len(fakeT.errors) != 1 { + t.Errorf("Unexpected error set: %#v", fakeT.errors) + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/BUILD b/discovery/vendor/k8s.io/client-go/util/workqueue/BUILD new file mode 100644 index 00000000..7fb9fba4 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/BUILD @@ -0,0 +1,59 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", + "go_test", +) + +go_test( + name = "go_default_test", + srcs = [ + "default_rate_limiters_test.go", + "delaying_queue_test.go", + "rate_limitting_queue_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", + ], +) + +go_library( + name = "go_default_library", + srcs = [ + "default_rate_limiters.go", + "delaying_queue.go", + "doc.go", + "metrics.go", + "parallelizer.go", + "queue.go", + "rate_limitting_queue.go", + ], + importpath = "k8s.io/client-go/util/workqueue", + deps = [ + "//vendor/golang.org/x/time/rate:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + ], +) + +go_test( + name = "go_default_xtest", + srcs = ["queue_test.go"], + deps = ["//vendor/k8s.io/client-go/util/workqueue:go_default_library"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters.go b/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters.go index 35caed4f..a5bed29e 100644 --- a/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters.go +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters.go @@ -21,7 +21,7 @@ import ( "sync" "time" - "github.com/juju/ratelimit" + "golang.org/x/time/rate" ) type RateLimiter interface { @@ -40,19 +40,19 @@ func DefaultControllerRateLimiter() RateLimiter { return NewMaxOfRateLimiter( NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second), // 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item) - &BucketRateLimiter{Bucket: ratelimit.NewBucketWithRate(float64(10), int64(100))}, + &BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, ) } // BucketRateLimiter adapts a standard bucket to the workqueue ratelimiter API type BucketRateLimiter struct { - *ratelimit.Bucket + *rate.Limiter } var _ RateLimiter = &BucketRateLimiter{} func (r *BucketRateLimiter) When(item interface{}) time.Duration { - return r.Bucket.Take(1) + return r.Limiter.Reserve().Delay() } func (r *BucketRateLimiter) NumRequeues(item interface{}) int { diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters_test.go b/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters_test.go new file mode 100644 index 00000000..91d34a31 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/default_rate_limiters_test.go @@ -0,0 +1,184 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package workqueue + +import ( + "testing" + "time" +) + +func TestItemExponentialFailureRateLimiter(t *testing.T) { + limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second) + + if e, a := 1*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 4*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 8*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 16*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + if e, a := 1*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2, limiter.NumRequeues("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + limiter.Forget("one") + if e, a := 0, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 1*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + +} + +func TestItemExponentialFailureRateLimiterOverFlow(t *testing.T) { + limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1000*time.Second) + for i := 0; i < 5; i++ { + limiter.When("one") + } + if e, a := 32*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + for i := 0; i < 1000; i++ { + limiter.When("overflow1") + } + if e, a := 1000*time.Second, limiter.When("overflow1"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + limiter = NewItemExponentialFailureRateLimiter(1*time.Minute, 1000*time.Hour) + for i := 0; i < 2; i++ { + limiter.When("two") + } + if e, a := 4*time.Minute, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + for i := 0; i < 1000; i++ { + limiter.When("overflow2") + } + if e, a := 1000*time.Hour, limiter.When("overflow2"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + +} + +func TestItemFastSlowRateLimiter(t *testing.T) { + limiter := NewItemFastSlowRateLimiter(5*time.Millisecond, 10*time.Second, 3) + + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 10*time.Second, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 10*time.Second, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + if e, a := 5*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2, limiter.NumRequeues("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + limiter.Forget("one") + if e, a := 0, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + +} + +func TestMaxOfRateLimiter(t *testing.T) { + limiter := NewMaxOfRateLimiter( + NewItemFastSlowRateLimiter(5*time.Millisecond, 3*time.Second, 3), + NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second), + ) + + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 3*time.Second, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 3*time.Second, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + if e, a := 5*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2, limiter.NumRequeues("two"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + limiter.Forget("one") + if e, a := 0, limiter.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 5*time.Millisecond, limiter.When("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + +} diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue.go b/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue.go index 74fefd38..c62ed32e 100644 --- a/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue.go +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue.go @@ -89,7 +89,7 @@ type waitFor struct { // waitForPriorityQueue implements a priority queue for waitFor items. // -// waitForPriorityQueue implements heap.Interface. The item occuring next in +// waitForPriorityQueue implements heap.Interface. The item occurring next in // time (i.e., the item with the smallest readyAt) is at the root (index 0). // Peek returns this minimum item at index 0. Pop returns the minimum item after // it has been removed from the queue and placed at index Len()-1 by diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue_test.go b/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue_test.go new file mode 100644 index 00000000..3c8ebf13 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/delaying_queue_test.go @@ -0,0 +1,255 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package workqueue + +import ( + "fmt" + "math/rand" + "reflect" + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/apimachinery/pkg/util/wait" +) + +func TestSimpleQueue(t *testing.T) { + fakeClock := clock.NewFakeClock(time.Now()) + q := newDelayingQueue(fakeClock, "") + + first := "foo" + + q.AddAfter(first, 50*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + + if q.Len() != 0 { + t.Errorf("should not have added") + } + + fakeClock.Step(60 * time.Millisecond) + + if err := waitForAdded(q, 1); err != nil { + t.Errorf("should have added") + } + item, _ := q.Get() + q.Done(item) + + // step past the next heartbeat + fakeClock.Step(10 * time.Second) + + err := wait.Poll(1*time.Millisecond, 30*time.Millisecond, func() (done bool, err error) { + if q.Len() > 0 { + return false, fmt.Errorf("added to queue") + } + + return false, nil + }) + if err != wait.ErrWaitTimeout { + t.Errorf("expected timeout, got: %v", err) + } + + if q.Len() != 0 { + t.Errorf("should not have added") + } +} + +func TestDeduping(t *testing.T) { + fakeClock := clock.NewFakeClock(time.Now()) + q := newDelayingQueue(fakeClock, "") + + first := "foo" + + q.AddAfter(first, 50*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + q.AddAfter(first, 70*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + if q.Len() != 0 { + t.Errorf("should not have added") + } + + // step past the first block, we should receive now + fakeClock.Step(60 * time.Millisecond) + if err := waitForAdded(q, 1); err != nil { + t.Errorf("should have added") + } + item, _ := q.Get() + q.Done(item) + + // step past the second add + fakeClock.Step(20 * time.Millisecond) + if q.Len() != 0 { + t.Errorf("should not have added") + } + + // test again, but this time the earlier should override + q.AddAfter(first, 50*time.Millisecond) + q.AddAfter(first, 30*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + if q.Len() != 0 { + t.Errorf("should not have added") + } + + fakeClock.Step(40 * time.Millisecond) + if err := waitForAdded(q, 1); err != nil { + t.Errorf("should have added") + } + item, _ = q.Get() + q.Done(item) + + // step past the second add + fakeClock.Step(20 * time.Millisecond) + if q.Len() != 0 { + t.Errorf("should not have added") + } + if q.Len() != 0 { + t.Errorf("should not have added") + } +} + +func TestAddTwoFireEarly(t *testing.T) { + fakeClock := clock.NewFakeClock(time.Now()) + q := newDelayingQueue(fakeClock, "") + + first := "foo" + second := "bar" + third := "baz" + + q.AddAfter(first, 1*time.Second) + q.AddAfter(second, 50*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + + if q.Len() != 0 { + t.Errorf("should not have added") + } + + fakeClock.Step(60 * time.Millisecond) + + if err := waitForAdded(q, 1); err != nil { + t.Fatalf("unexpected err: %v", err) + } + item, _ := q.Get() + if !reflect.DeepEqual(item, second) { + t.Errorf("expected %v, got %v", second, item) + } + + q.AddAfter(third, 2*time.Second) + + fakeClock.Step(1 * time.Second) + if err := waitForAdded(q, 1); err != nil { + t.Fatalf("unexpected err: %v", err) + } + item, _ = q.Get() + if !reflect.DeepEqual(item, first) { + t.Errorf("expected %v, got %v", first, item) + } + + fakeClock.Step(2 * time.Second) + if err := waitForAdded(q, 1); err != nil { + t.Fatalf("unexpected err: %v", err) + } + item, _ = q.Get() + if !reflect.DeepEqual(item, third) { + t.Errorf("expected %v, got %v", third, item) + } +} + +func TestCopyShifting(t *testing.T) { + fakeClock := clock.NewFakeClock(time.Now()) + q := newDelayingQueue(fakeClock, "") + + first := "foo" + second := "bar" + third := "baz" + + q.AddAfter(first, 1*time.Second) + q.AddAfter(second, 500*time.Millisecond) + q.AddAfter(third, 250*time.Millisecond) + if err := waitForWaitingQueueToFill(q); err != nil { + t.Fatalf("unexpected err: %v", err) + } + + if q.Len() != 0 { + t.Errorf("should not have added") + } + + fakeClock.Step(2 * time.Second) + + if err := waitForAdded(q, 3); err != nil { + t.Fatalf("unexpected err: %v", err) + } + actualFirst, _ := q.Get() + if !reflect.DeepEqual(actualFirst, third) { + t.Errorf("expected %v, got %v", third, actualFirst) + } + actualSecond, _ := q.Get() + if !reflect.DeepEqual(actualSecond, second) { + t.Errorf("expected %v, got %v", second, actualSecond) + } + actualThird, _ := q.Get() + if !reflect.DeepEqual(actualThird, first) { + t.Errorf("expected %v, got %v", first, actualThird) + } +} + +func BenchmarkDelayingQueue_AddAfter(b *testing.B) { + r := rand.New(rand.NewSource(time.Now().Unix())) + + fakeClock := clock.NewFakeClock(time.Now()) + q := newDelayingQueue(fakeClock, "") + + // Add items + for n := 0; n < b.N; n++ { + data := fmt.Sprintf("%d", n) + q.AddAfter(data, time.Duration(r.Int63n(int64(10*time.Minute)))) + } + + // Exercise item removal as well + fakeClock.Step(11 * time.Minute) + for n := 0; n < b.N; n++ { + _, _ = q.Get() + } +} + +func waitForAdded(q DelayingInterface, depth int) error { + return wait.Poll(1*time.Millisecond, 10*time.Second, func() (done bool, err error) { + if q.Len() == depth { + return true, nil + } + + return false, nil + }) +} + +func waitForWaitingQueueToFill(q DelayingInterface) error { + return wait.Poll(1*time.Millisecond, 10*time.Second, func() (done bool, err error) { + if len(q.(*delayingType).waitingForAddCh) == 0 { + return true, nil + } + + return false, nil + }) +} diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/queue_test.go b/discovery/vendor/k8s.io/client-go/util/workqueue/queue_test.go new file mode 100644 index 00000000..131f4a2a --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/queue_test.go @@ -0,0 +1,161 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package workqueue_test + +import ( + "sync" + "testing" + "time" + + "k8s.io/client-go/util/workqueue" +) + +func TestBasic(t *testing.T) { + // If something is seriously wrong this test will never complete. + q := workqueue.New() + + // Start producers + const producers = 50 + producerWG := sync.WaitGroup{} + producerWG.Add(producers) + for i := 0; i < producers; i++ { + go func(i int) { + defer producerWG.Done() + for j := 0; j < 50; j++ { + q.Add(i) + time.Sleep(time.Millisecond) + } + }(i) + } + + // Start consumers + const consumers = 10 + consumerWG := sync.WaitGroup{} + consumerWG.Add(consumers) + for i := 0; i < consumers; i++ { + go func(i int) { + defer consumerWG.Done() + for { + item, quit := q.Get() + if item == "added after shutdown!" { + t.Errorf("Got an item added after shutdown.") + } + if quit { + return + } + t.Logf("Worker %v: begin processing %v", i, item) + time.Sleep(3 * time.Millisecond) + t.Logf("Worker %v: done processing %v", i, item) + q.Done(item) + } + }(i) + } + + producerWG.Wait() + q.ShutDown() + q.Add("added after shutdown!") + consumerWG.Wait() +} + +func TestAddWhileProcessing(t *testing.T) { + q := workqueue.New() + + // Start producers + const producers = 50 + producerWG := sync.WaitGroup{} + producerWG.Add(producers) + for i := 0; i < producers; i++ { + go func(i int) { + defer producerWG.Done() + q.Add(i) + }(i) + } + + // Start consumers + const consumers = 10 + consumerWG := sync.WaitGroup{} + consumerWG.Add(consumers) + for i := 0; i < consumers; i++ { + go func(i int) { + defer consumerWG.Done() + // Every worker will re-add every item up to two times. + // This tests the dirty-while-processing case. + counters := map[interface{}]int{} + for { + item, quit := q.Get() + if quit { + return + } + counters[item]++ + if counters[item] < 2 { + q.Add(item) + } + q.Done(item) + } + }(i) + } + + producerWG.Wait() + q.ShutDown() + consumerWG.Wait() +} + +func TestLen(t *testing.T) { + q := workqueue.New() + q.Add("foo") + if e, a := 1, q.Len(); e != a { + t.Errorf("Expected %v, got %v", e, a) + } + q.Add("bar") + if e, a := 2, q.Len(); e != a { + t.Errorf("Expected %v, got %v", e, a) + } + q.Add("foo") // should not increase the queue length. + if e, a := 2, q.Len(); e != a { + t.Errorf("Expected %v, got %v", e, a) + } +} + +func TestReinsert(t *testing.T) { + q := workqueue.New() + q.Add("foo") + + // Start processing + i, _ := q.Get() + if i != "foo" { + t.Errorf("Expected %v, got %v", "foo", i) + } + + // Add it back while processing + q.Add(i) + + // Finish it up + q.Done(i) + + // It should be back on the queue + i, _ = q.Get() + if i != "foo" { + t.Errorf("Expected %v, got %v", "foo", i) + } + + // Finish that one up + q.Done(i) + + if a := q.Len(); a != 0 { + t.Errorf("Expected queue to be empty. Has %v items", a) + } +} diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue.go b/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue.go index 9acc5810..417ac001 100644 --- a/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue.go +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue.go @@ -55,7 +55,7 @@ type rateLimitingType struct { rateLimiter RateLimiter } -// Limited AddAfter's the item based on the time when the rate limiter says its ok +// AddRateLimited AddAfter's the item based on the time when the rate limiter says its ok func (q *rateLimitingType) AddRateLimited(item interface{}) { q.DelayingInterface.AddAfter(item, q.rateLimiter.When(item)) } diff --git a/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue_test.go b/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue_test.go new file mode 100644 index 00000000..32d7fc90 --- /dev/null +++ b/discovery/vendor/k8s.io/client-go/util/workqueue/rate_limitting_queue_test.go @@ -0,0 +1,75 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package workqueue + +import ( + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/clock" +) + +func TestRateLimitingQueue(t *testing.T) { + limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second) + queue := NewRateLimitingQueue(limiter).(*rateLimitingType) + fakeClock := clock.NewFakeClock(time.Now()) + delayingQueue := &delayingType{ + Interface: New(), + clock: fakeClock, + heartbeat: fakeClock.Tick(maxWait), + stopCh: make(chan struct{}), + waitingForAddCh: make(chan *waitFor, 1000), + metrics: newRetryMetrics(""), + } + queue.DelayingInterface = delayingQueue + + queue.AddRateLimited("one") + waitEntry := <-delayingQueue.waitingForAddCh + if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a { + t.Errorf("expected %v, got %v", e, a) + } + queue.AddRateLimited("one") + waitEntry = <-delayingQueue.waitingForAddCh + if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := 2, queue.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + queue.AddRateLimited("two") + waitEntry = <-delayingQueue.waitingForAddCh + if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a { + t.Errorf("expected %v, got %v", e, a) + } + queue.AddRateLimited("two") + waitEntry = <-delayingQueue.waitingForAddCh + if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + queue.Forget("one") + if e, a := 0, queue.NumRequeues("one"); e != a { + t.Errorf("expected %v, got %v", e, a) + } + queue.AddRateLimited("one") + waitEntry = <-delayingQueue.waitingForAddCh + if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a { + t.Errorf("expected %v, got %v", e, a) + } + +} diff --git a/discovery/vendor/k8s.io/code-generator/.github/PULL_REQUEST_TEMPLATE.md b/discovery/vendor/k8s.io/code-generator/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..e559c074 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,2 @@ +Sorry, we do not accept changes directly against this repository. Please see +CONTRIBUTING.md for information on where and how to contribute instead. diff --git a/discovery/vendor/k8s.io/code-generator/CONTRIBUTING.md b/discovery/vendor/k8s.io/code-generator/CONTRIBUTING.md new file mode 100644 index 00000000..bc4e7697 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contributing guidelines + +Do not open pull requests directly against this repository, they will be ignored. Instead, please open pull requests against [kubernetes/kubernetes](https://git.k8s.io/kubernetes/). Please follow the same [contributing guide](https://git.k8s.io/kubernetes/CONTRIBUTING.md) you would follow for any other pull request made to kubernetes/kubernetes. + +This repository is published from [kubernetes/kubernetes/staging/src/k8s.io/code-generator](https://git.k8s.io/kubernetes/staging/src/k8s.io/code-generator) by the [kubernetes publishing-bot](https://git.k8s.io/publishing-bot). + +Please see [Staging Directory and Publishing](https://git.k8s.io/community/contributors/devel/staging.md) for more information diff --git a/discovery/vendor/k8s.io/code-generator/Godeps/Godeps.json b/discovery/vendor/k8s.io/code-generator/Godeps/Godeps.json index 239636cb..30ee4a3b 100644 --- a/discovery/vendor/k8s.io/code-generator/Godeps/Godeps.json +++ b/discovery/vendor/k8s.io/code-generator/Godeps/Godeps.json @@ -1,7 +1,7 @@ { "ImportPath": "k8s.io/code-generator", "GoVersion": "go1.9", - "GodepVersion": "v79", + "GodepVersion": "v80", "Packages": [ "./..." ], @@ -32,7 +32,7 @@ }, { "ImportPath": "github.com/go-openapi/spec", - "Rev": "7abd5745472fff5eb3685386d5fb8bf38683154d" + "Rev": "1de3e0542de65ad8d75452a595886fdd0befb363" }, { "ImportPath": "github.com/go-openapi/swag", @@ -156,7 +156,7 @@ }, { "ImportPath": "github.com/spf13/pflag", - "Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7" + "Rev": "583c0c0531f06d5278b7d917446061adc344b5cd" }, { "ImportPath": "golang.org/x/net/idna", @@ -206,57 +206,65 @@ "ImportPath": "golang.org/x/text/width", "Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01" }, + { + "ImportPath": "golang.org/x/tools/go/ast/astutil", + "Rev": "2382e3994d48b1d22acc2c86bcad0a2aff028e32" + }, + { + "ImportPath": "golang.org/x/tools/imports", + "Rev": "2382e3994d48b1d22acc2c86bcad0a2aff028e32" + }, { "ImportPath": "gopkg.in/yaml.v2", - "Rev": "53feefa2559fb8dfa8d81baad31be332c97d6c77" + "Rev": "670d4cfef0544295bc27a114dbac37980d83185a" }, { "ImportPath": "k8s.io/gengo/args", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/examples/import-boss/generators", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/generators", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/sets", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/generator", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/namer", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/parser", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/gengo/types", - "Rev": "b58fc7edb82e0c6ffc9b8aef61813c7261b785d4" + "Rev": "01a732e01d00cb9a81bb0ca050d3e6d2b947927b" }, { "ImportPath": "k8s.io/kube-openapi/pkg/common", - "Rev": "39a7bf85c140f972372c2a0d1ee40adbf0c8bfe1" + "Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4" }, { "ImportPath": "k8s.io/kube-openapi/pkg/generators", - "Rev": "39a7bf85c140f972372c2a0d1ee40adbf0c8bfe1" + "Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4" } ] } diff --git a/discovery/vendor/k8s.io/code-generator/Godeps/OWNERS b/discovery/vendor/k8s.io/code-generator/Godeps/OWNERS new file mode 100644 index 00000000..3d49f306 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/Godeps/OWNERS @@ -0,0 +1,2 @@ +approvers: +- dep-approvers diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversion.go index 85dd5b95..66667f1b 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversion.go @@ -16,15 +16,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by conversion-gen. Do not edit it manually! +// Code generated by conversion-gen. DO NOT EDIT. package v1 import ( + unsafe "unsafe" + conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" example "k8s.io/code-generator/_examples/apiserver/apis/example" - unsafe "unsafe" ) func init() { diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversions.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversions.go deleted file mode 100644 index 183921e9..00000000 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.conversions.go +++ /dev/null @@ -1,113 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// This file was autogenerated by conversion-gen. Do not edit it manually! - -package v1 - -import ( - conversion "k8s.io/apimachinery/pkg/conversion" - runtime "k8s.io/apimachinery/pkg/runtime" - example "k8s.io/code-generator/_examples/apiserver/apis/example" - unsafe "unsafe" -) - -func init() { - localSchemeBuilder.Register(RegisterConversions) -} - -// RegisterConversions adds conversion functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterConversions(scheme *runtime.Scheme) error { - return scheme.AddGeneratedConversionFuncs( - Convert_v1_TestType_To_example_TestType, - Convert_example_TestType_To_v1_TestType, - Convert_v1_TestTypeList_To_example_TestTypeList, - Convert_example_TestTypeList_To_v1_TestTypeList, - Convert_v1_TestTypeStatus_To_example_TestTypeStatus, - Convert_example_TestTypeStatus_To_v1_TestTypeStatus, - ) -} - -func autoConvert_v1_TestType_To_example_TestType(in *TestType, out *example.TestType, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1_TestTypeStatus_To_example_TestTypeStatus(&in.Status, &out.Status, s); err != nil { - return err - } - return nil -} - -// Convert_v1_TestType_To_example_TestType is an autogenerated conversion function. -func Convert_v1_TestType_To_example_TestType(in *TestType, out *example.TestType, s conversion.Scope) error { - return autoConvert_v1_TestType_To_example_TestType(in, out, s) -} - -func autoConvert_example_TestType_To_v1_TestType(in *example.TestType, out *TestType, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_example_TestTypeStatus_To_v1_TestTypeStatus(&in.Status, &out.Status, s); err != nil { - return err - } - return nil -} - -// Convert_example_TestType_To_v1_TestType is an autogenerated conversion function. -func Convert_example_TestType_To_v1_TestType(in *example.TestType, out *TestType, s conversion.Scope) error { - return autoConvert_example_TestType_To_v1_TestType(in, out, s) -} - -func autoConvert_v1_TestTypeList_To_example_TestTypeList(in *TestTypeList, out *example.TestTypeList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - out.Items = *(*[]example.TestType)(unsafe.Pointer(&in.Items)) - return nil -} - -// Convert_v1_TestTypeList_To_example_TestTypeList is an autogenerated conversion function. -func Convert_v1_TestTypeList_To_example_TestTypeList(in *TestTypeList, out *example.TestTypeList, s conversion.Scope) error { - return autoConvert_v1_TestTypeList_To_example_TestTypeList(in, out, s) -} - -func autoConvert_example_TestTypeList_To_v1_TestTypeList(in *example.TestTypeList, out *TestTypeList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - out.Items = *(*[]TestType)(unsafe.Pointer(&in.Items)) - return nil -} - -// Convert_example_TestTypeList_To_v1_TestTypeList is an autogenerated conversion function. -func Convert_example_TestTypeList_To_v1_TestTypeList(in *example.TestTypeList, out *TestTypeList, s conversion.Scope) error { - return autoConvert_example_TestTypeList_To_v1_TestTypeList(in, out, s) -} - -func autoConvert_v1_TestTypeStatus_To_example_TestTypeStatus(in *TestTypeStatus, out *example.TestTypeStatus, s conversion.Scope) error { - out.Blah = in.Blah - return nil -} - -// Convert_v1_TestTypeStatus_To_example_TestTypeStatus is an autogenerated conversion function. -func Convert_v1_TestTypeStatus_To_example_TestTypeStatus(in *TestTypeStatus, out *example.TestTypeStatus, s conversion.Scope) error { - return autoConvert_v1_TestTypeStatus_To_example_TestTypeStatus(in, out, s) -} - -func autoConvert_example_TestTypeStatus_To_v1_TestTypeStatus(in *example.TestTypeStatus, out *TestTypeStatus, s conversion.Scope) error { - out.Blah = in.Blah - return nil -} - -// Convert_example_TestTypeStatus_To_v1_TestTypeStatus is an autogenerated conversion function. -func Convert_example_TestTypeStatus_To_v1_TestTypeStatus(in *example.TestTypeStatus, out *TestTypeStatus, s conversion.Scope) error { - return autoConvert_example_TestTypeStatus_To_v1_TestTypeStatus(in, out, s) -} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.deepcopy.go index 96771586..1e4402a8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.defaults.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.defaults.go index 88d7af08..40d9ab00 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.defaults.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/v1/zz_generated.defaults.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by defaulter-gen. Do not edit it manually! +// Code generated by defaulter-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/zz_generated.deepcopy.go index 7f46d2bb..291de95f 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package example @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.conversion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.conversion.go index 738d2d9b..e73a0f63 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.conversion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.conversion.go @@ -16,15 +16,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by conversion-gen. Do not edit it manually! +// Code generated by conversion-gen. DO NOT EDIT. package v1 import ( + unsafe "unsafe" + conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" example2 "k8s.io/code-generator/_examples/apiserver/apis/example2" - unsafe "unsafe" ) func init() { diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.deepcopy.go index 96771586..1e4402a8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.defaults.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.defaults.go index 88d7af08..40d9ab00 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.defaults.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/v1/zz_generated.defaults.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by defaulter-gen. Do not edit it manually! +// Code generated by defaulter-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/zz_generated.deepcopy.go index 55746bfe..284ecd2d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/apis/example2/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package example2 @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go index cf71a677..0cb86bf5 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/doc.go index 6a6cae17..50398f9e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated clientset. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/clientset_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/clientset_generated.go index 62ab5446..efc0095b 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/clientset_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/clientset_generated.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -43,7 +45,15 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { fakePtr := testing.Fake{} fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + fakePtr.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/doc.go index 8a3101e3..0bc260bc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated fake clientset. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/register.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/register.go index 910e117d..ef0ba8fc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/fake/register.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -39,7 +41,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -51,5 +53,4 @@ func init() { func AddToScheme(scheme *runtime.Scheme) { exampleinternalversion.AddToScheme(scheme) secondexampleinternalversion.AddToScheme(scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/doc.go index 3d3ab5f4..5c5c8deb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package contains the scheme of the automatically generated clientset. package scheme diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/register.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/register.go index 5ee4dddb..e3b2cf66 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/scheme/register.go @@ -14,9 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package scheme import ( + os "os" + announced "k8s.io/apimachinery/pkg/apimachinery/announced" registered "k8s.io/apimachinery/pkg/apimachinery/registered" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -25,7 +29,6 @@ import ( serializer "k8s.io/apimachinery/pkg/runtime/serializer" example "k8s.io/code-generator/_examples/apiserver/apis/example/install" secondexample "k8s.io/code-generator/_examples/apiserver/apis/example2/install" - os "os" ) var Scheme = runtime.NewScheme() @@ -44,5 +47,4 @@ func init() { func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) { example.Install(groupFactoryRegistry, registry, scheme) secondexample.Install(groupFactoryRegistry, registry, scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/doc.go index 86150197..b057e520 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/example_client.go index 906aa3f4..e99d41f9 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_example_client.go index b8c081d9..71e9e11c 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_testtype.go index bee016ec..4f268fb8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/generated_expansion.go index 189d4e23..0cdfc312 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/testtype.go index 5077c0ca..6cfbcb36 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example/internalversion/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/doc.go index 86150197..b057e520 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/example2_client.go index 4939e1ec..b0e673a8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_example2_client.go index ea617dc8..91751c24 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_testtype.go index 0691a495..3e9e6c7a 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/generated_expansion.go index 189d4e23..0cdfc312 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/testtype.go index 10725f49..77ab9a34 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/typed/example2/internalversion/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package internalversion import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go index 86cca3b1..c0d337d2 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package versioned import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/doc.go index 9c6dfafa..006b7921 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated clientset. package versioned diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/clientset_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/clientset_generated.go index 2a692a5c..fe657f08 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/clientset_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/clientset_generated.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -43,7 +45,15 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { fakePtr := testing.Fake{} fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + fakePtr.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/doc.go index 8a3101e3..0bc260bc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated fake clientset. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/register.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/register.go index b4a0ec52..37c3ae6f 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/fake/register.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -39,7 +41,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -51,5 +53,4 @@ func init() { func AddToScheme(scheme *runtime.Scheme) { examplev1.AddToScheme(scheme) secondexamplev1.AddToScheme(scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/doc.go index 3d3ab5f4..5c5c8deb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package contains the scheme of the automatically generated clientset. package scheme diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/register.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/register.go index cad0ee75..7c7daa6a 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/scheme/register.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package scheme import ( @@ -39,7 +41,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -51,5 +53,4 @@ func init() { func AddToScheme(scheme *runtime.Scheme) { examplev1.AddToScheme(scheme) secondexamplev1.AddToScheme(scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/doc.go index 95b44dfa..d007a290 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/example_client.go index 407fa9e2..4cead71e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go index 1a863637..c8bbfe7c 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 063d8cc7..a0779aae 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/generated_expansion.go index 4e2775e3..3f19f4e3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/testtype.go index 70fded42..0e51af49 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example/v1/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/doc.go index 95b44dfa..d007a290 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/example2_client.go index 552a87f8..c245b071 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go index 43ad4e98..2c52a144 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go index 12bbdcbe..9b005136 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/generated_expansion.go index 4e2775e3..3f19f4e3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/testtype.go index fa39745a..21e7e080 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/clientset/versioned/typed/example2/v1/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/interface.go index 21d8874a..e014cde1 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/interface.go index 21e19c62..ae5abf35 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/testtype.go index 0beb10fa..d8cdead8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example/v1/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( + time "time" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( versioned "k8s.io/code-generator/_examples/apiserver/clientset/versioned" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces" v1 "k8s.io/code-generator/_examples/apiserver/listers/example/v1" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/interface.go index c6a04446..7aef7a4e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/interface.go index 21e19c62..ae5abf35 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/testtype.go index c07397c9..48d09823 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2/v1/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( + time "time" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( versioned "k8s.io/code-generator/_examples/apiserver/clientset/versioned" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces" v1 "k8s.io/code-generator/_examples/apiserver/listers/example2/v1" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/factory.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/factory.go index 6b77479e..767191e1 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/factory.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/factory.go @@ -14,11 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package externalversions import ( + reflect "reflect" + sync "sync" + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -27,9 +31,6 @@ import ( example "k8s.io/code-generator/_examples/apiserver/informers/externalversions/example" example2 "k8s.io/code-generator/_examples/apiserver/informers/externalversions/example2" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces" - reflect "reflect" - sync "sync" - time "time" ) type sharedInformerFactory struct { diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/generic.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/generic.go index 6fd29b0b..e1273ab3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/generic.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/generic.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package externalversions import ( "fmt" + schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" v1 "k8s.io/code-generator/_examples/apiserver/apis/example/v1" diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces/factory_interfaces.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces/factory_interfaces.go index 31df120f..988e57b5 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -14,16 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalinterfaces import ( + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" versioned "k8s.io/code-generator/_examples/apiserver/clientset/versioned" - time "time" ) type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/interface.go index 836e7e01..4f0aae2f 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/interface.go index 5abe3852..1ac865c7 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/testtype.go index 5c1c1fe8..f6991dfd 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example/internalversion/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion import ( + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( clientset_internalversion "k8s.io/code-generator/_examples/apiserver/clientset/internalversion" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces" internalversion "k8s.io/code-generator/_examples/apiserver/listers/example/internalversion" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/interface.go index 0656ffbd..843463dd 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/interface.go index 5abe3852..1ac865c7 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/testtype.go index 2c00c3d8..613fd693 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2/internalversion/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion import ( + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( clientset_internalversion "k8s.io/code-generator/_examples/apiserver/clientset/internalversion" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces" internalversion "k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/factory.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/factory.go index fee4e791..737d5227 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/factory.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/factory.go @@ -14,11 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion import ( + reflect "reflect" + sync "sync" + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -27,9 +31,6 @@ import ( example "k8s.io/code-generator/_examples/apiserver/informers/internalversion/example" example2 "k8s.io/code-generator/_examples/apiserver/informers/internalversion/example2" internalinterfaces "k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces" - reflect "reflect" - sync "sync" - time "time" ) type sharedInformerFactory struct { diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/generic.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/generic.go index bddd60f7..d0822bbb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/generic.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/generic.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalversion import ( "fmt" + schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" example "k8s.io/code-generator/_examples/apiserver/apis/example" diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces/factory_interfaces.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces/factory_interfaces.go index 973d73d1..80e3603a 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces/factory_interfaces.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/informers/internalversion/internalinterfaces/factory_interfaces.go @@ -14,16 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalinterfaces import ( + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" internalversion "k8s.io/code-generator/_examples/apiserver/clientset/internalversion" - time "time" ) type NewInformerFunc func(internalversion.Interface, time.Duration) cache.SharedIndexInformer diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/expansion_generated.go index f308c167..6d32d975 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/testtype.go index ccfe8f80..184c1649 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/internalversion/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/expansion_generated.go index d258c22f..c5f4333d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/testtype.go index 5e420f12..9eee6a69 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example/v1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/expansion_generated.go index f308c167..6d32d975 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/testtype.go index 35abf866..24659a2d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/internalversion/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package internalversion diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/expansion_generated.go index d258c22f..c5f4333d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/testtype.go index 65f5a58b..64c5bb88 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/apiserver/listers/example2/v1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example/v1/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example/v1/zz_generated.deepcopy.go index 96771586..1e4402a8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example/v1/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example/v1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example2/v1/zz_generated.deepcopy.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example2/v1/zz_generated.deepcopy.go index 96771586..1e4402a8 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example2/v1/zz_generated.deepcopy.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/apis/example2/v1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was autogenerated by deepcopy-gen. Do not edit it manually! +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 @@ -47,9 +47,8 @@ func (in *TestType) DeepCopy() *TestType { func (in *TestType) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -81,9 +80,8 @@ func (in *TestTypeList) DeepCopy() *TestTypeList { func (in *TestTypeList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c - } else { - return nil } + return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go index c0c581df..fe1447d5 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package versioned import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/doc.go index 9c6dfafa..006b7921 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated clientset. package versioned diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/clientset_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/clientset_generated.go index 7fd60de7..ab158f77 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/clientset_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/clientset_generated.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -43,7 +45,15 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { fakePtr := testing.Fake{} fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + fakePtr.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/doc.go index 8a3101e3..0bc260bc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated fake clientset. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/register.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/register.go index 79d92504..08ebf3b3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/fake/register.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( @@ -39,7 +41,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -51,5 +53,4 @@ func init() { func AddToScheme(scheme *runtime.Scheme) { examplev1.AddToScheme(scheme) secondexamplev1.AddToScheme(scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/doc.go index 3d3ab5f4..5c5c8deb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package contains the scheme of the automatically generated clientset. package scheme diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/register.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/register.go index 1b55c1cf..1a2abe6a 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/register.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/scheme/register.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package scheme import ( @@ -39,7 +41,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -51,5 +53,4 @@ func init() { func AddToScheme(scheme *runtime.Scheme) { examplev1.AddToScheme(scheme) secondexamplev1.AddToScheme(scheme) - } diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/doc.go index 95b44dfa..d007a290 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/example_client.go index 1e282aa1..7dcb34bb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go index c7bf2dfc..4e99c7cb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 124396f2..848b529a 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/generated_expansion.go index 4e2775e3..3f19f4e3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/testtype.go index 460b68ab..d1175fe7 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example/v1/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/doc.go index 95b44dfa..d007a290 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // This package has the automatically generated typed clients. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/example2_client.go index a753b968..71e7cd31 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/doc.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/doc.go index 63e2c8a0..87a1873e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/doc.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/doc.go @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + // Package fake has the automatically generated clients. package fake diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go index 89e64d64..d63405ff 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go index ccba168a..07d26a27 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package fake import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/generated_expansion.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/generated_expansion.go index 4e2775e3..3f19f4e3 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/generated_expansion.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/generated_expansion.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 type TestTypeExpansion interface{} diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/testtype.go index bf6b4de4..056415cb 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/clientset/versioned/typed/example2/v1/testtype.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by client-gen. DO NOT EDIT. + package v1 import ( diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/interface.go index d74e15f5..51440cbc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/interface.go index d0a447bd..9378a06b 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/testtype.go index 7fe59ce3..d1e600c9 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example/v1/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( + time "time" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( versioned "k8s.io/code-generator/_examples/crd/clientset/versioned" internalinterfaces "k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces" v1 "k8s.io/code-generator/_examples/crd/listers/example/v1" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/interface.go index d58b0edb..cf0d52cc 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/interface.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/interface.go index d0a447bd..9378a06b 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/interface.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/testtype.go index 303b3473..855dd1d7 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/example2/v1/testtype.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( + time "time" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -27,7 +29,6 @@ import ( versioned "k8s.io/code-generator/_examples/crd/clientset/versioned" internalinterfaces "k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces" v1 "k8s.io/code-generator/_examples/crd/listers/example2/v1" - time "time" ) // TestTypeInformer provides access to a shared informer and lister for diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/factory.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/factory.go index 2d0b35f9..a843ddb9 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/factory.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/factory.go @@ -14,11 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package externalversions import ( + reflect "reflect" + sync "sync" + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -27,9 +31,6 @@ import ( example "k8s.io/code-generator/_examples/crd/informers/externalversions/example" example2 "k8s.io/code-generator/_examples/crd/informers/externalversions/example2" internalinterfaces "k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces" - reflect "reflect" - sync "sync" - time "time" ) type sharedInformerFactory struct { diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/generic.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/generic.go index 25acc507..2e88773e 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/generic.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/generic.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package externalversions import ( "fmt" + schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" v1 "k8s.io/code-generator/_examples/crd/apis/example/v1" diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces/factory_interfaces.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces/factory_interfaces.go index b8da4f9f..e87f5803 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -14,16 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by informer-gen +// Code generated by informer-gen. DO NOT EDIT. package internalinterfaces import ( + time "time" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" versioned "k8s.io/code-generator/_examples/crd/clientset/versioned" - time "time" ) type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/expansion_generated.go index d258c22f..c5f4333d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/testtype.go index ce132fd2..c39f5a39 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example/v1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/expansion_generated.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/expansion_generated.go index d258c22f..c5f4333d 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/expansion_generated.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/testtype.go b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/testtype.go index a7ad6062..cd239c2f 100644 --- a/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/testtype.go +++ b/discovery/vendor/k8s.io/code-generator/_examples/crd/listers/example2/v1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This file was automatically generated by lister-gen +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/args.go index fee31d90..f45be1bb 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/args.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/args.go @@ -17,22 +17,23 @@ limitations under the License. package args import ( + "fmt" + "path" + "github.com/spf13/pflag" + "k8s.io/gengo/args" "k8s.io/code-generator/cmd/client-gen/types" + codegenutil "k8s.io/code-generator/pkg/util" ) +var DefaultInputDirs = []string{} + // ClientGenArgs is a wrapper for arguments to client-gen. type CustomArgs struct { // A sorted list of group versions to generate. For each of them the package path is found // in GroupVersionToInputPath. Groups []types.GroupVersions - // GroupVersionToInputPath is a map between GroupVersion and the path to the respective - // types.go, relative to InputBasePath. We still need GroupVersions in the - // struct because we need an order. - GroupVersionToInputPath map[types.GroupVersion]string - // The base for the path of GroupVersionToInputPath. - InputBasePath string // Overrides for which types should be included in the client. IncludedTypesOverrides map[types.GroupVersion][]string @@ -40,10 +41,7 @@ type CustomArgs struct { // ClientsetName is the name of the clientset to be generated. It's // populated from command-line arguments. ClientsetName string - // ClientsetOutputPath is the path the clientset will be generated at. It's - // populated from command-line arguments. - ClientsetOutputPath string - // ClientsetAPIPath is the default API path for generated clients. + // ClientsetAPIPath is the default API HTTP path for generated clients. ClientsetAPIPath string // ClientsetOnly determines if we should generate the clients for groups and // types along with the clientset. It's populated from command-line @@ -53,13 +51,70 @@ type CustomArgs struct { FakeClient bool } -func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { - pflag.Var(NewGVPackagesValue(&ca.GroupVersionToInputPath, &ca.Groups, nil), "input", "group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format \"group1/version1,group2/version2...\".") +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{ + ClientsetName: "internalclientset", + ClientsetAPIPath: "/apis", + ClientsetOnly: false, + FakeClient: true, + } + genericArgs.CustomArgs = customArgs + genericArgs.InputDirs = DefaultInputDirs + + if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 { + genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/clientset") + } + + return genericArgs, customArgs +} + +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet, inputBase string) { + gvsBuilder := NewGroupVersionsBuilder(&ca.Groups) + pflag.Var(NewGVPackagesValue(gvsBuilder, nil), "input", "group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format \"group1/version1,group2/version2...\".") pflag.Var(NewGVTypesValue(&ca.IncludedTypesOverrides, []string{}), "included-types-overrides", "list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient in types.go. This overrides that. For each groupVersion in this list, only the types mentioned here will be included. The default check of genclient will be used for other group versions.") - pflag.StringVar(&ca.InputBasePath, "input-base", "k8s.io/kubernetes/pkg/apis", "base path to look for the api group.") - pflag.StringVarP(&ca.ClientsetName, "clientset-name", "n", "internalclientset", "the name of the generated clientset package.") - pflag.StringVarP(&ca.ClientsetAPIPath, "clientset-api-path", "", "", "the value of default API path.") - pflag.StringVar(&ca.ClientsetOutputPath, "clientset-path", "k8s.io/kubernetes/pkg/client/clientset_generated/", "the generated clientset will be output to /.") - pflag.BoolVar(&ca.ClientsetOnly, "clientset-only", false, "when set, client-gen only generates the clientset shell, without generating the individual typed clients") - pflag.BoolVar(&ca.FakeClient, "fake-clientset", true, "when set, client-gen will generate the fake clientset that can be used in tests") + pflag.Var(NewInputBasePathValue(gvsBuilder, inputBase), "input-base", "base path to look for the api group.") + pflag.StringVarP(&ca.ClientsetName, "clientset-name", "n", ca.ClientsetName, "the name of the generated clientset package.") + pflag.StringVarP(&ca.ClientsetAPIPath, "clientset-api-path", "", ca.ClientsetAPIPath, "the value of default API HTTP path, starting with / and without trailing /.") + pflag.BoolVar(&ca.ClientsetOnly, "clientset-only", ca.ClientsetOnly, "when set, client-gen only generates the clientset shell, without generating the individual typed clients") + pflag.BoolVar(&ca.FakeClient, "fake-clientset", ca.FakeClient, "when set, client-gen will generate the fake clientset that can be used in tests") + + // support old flags + fs.SetNormalizeFunc(mapFlagName("clientset-path", "output-package", fs.GetNormalizeFunc())) +} + +func Validate(genericArgs *args.GeneratorArgs) error { + customArgs := genericArgs.CustomArgs.(*CustomArgs) + + if len(genericArgs.OutputPackagePath) == 0 { + return fmt.Errorf("output package cannot be empty") + } + if len(customArgs.ClientsetName) == 0 { + return fmt.Errorf("clientset name cannot be empty") + } + if len(customArgs.ClientsetAPIPath) == 0 { + return fmt.Errorf("clientset API path cannot be empty") + } + + return nil +} + +// GroupVersionPackages returns a map from GroupVersion to the package with the types.go. +func (ca *CustomArgs) GroupVersionPackages() map[types.GroupVersion]string { + res := map[types.GroupVersion]string{} + for _, pkg := range ca.Groups { + for _, v := range pkg.Versions { + res[types.GroupVersion{Group: pkg.Group, Version: v.Version}] = v.Package + } + } + return res +} + +func mapFlagName(from, to string, old func(fs *pflag.FlagSet, name string) pflag.NormalizedName) func(fs *pflag.FlagSet, name string) pflag.NormalizedName { + return func(fs *pflag.FlagSet, name string) pflag.NormalizedName { + if name == from { + name = to + } + return old(fs, name) + } } diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go index 4ffdd32e..8da71d6f 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go @@ -21,24 +21,48 @@ import ( "encoding/csv" "flag" "path" - "strings" - - "path/filepath" "sort" + "strings" "k8s.io/code-generator/cmd/client-gen/types" ) +type inputBasePathValue struct { + builder *groupVersionsBuilder +} + +var _ flag.Value = &inputBasePathValue{} + +func NewInputBasePathValue(builder *groupVersionsBuilder, def string) *inputBasePathValue { + v := &inputBasePathValue{ + builder: builder, + } + v.Set(def) + return v +} + +func (s *inputBasePathValue) Set(val string) error { + s.builder.importBasePath = val + return s.builder.update() +} + +func (s *inputBasePathValue) Type() string { + return "string" +} + +func (s *inputBasePathValue) String() string { + return s.builder.importBasePath +} + type gvPackagesValue struct { - gvToPath *map[types.GroupVersion]string - groups *[]types.GroupVersions - changed bool + builder *groupVersionsBuilder + groups []string + changed bool } -func NewGVPackagesValue(gvToPath *map[types.GroupVersion]string, groups *[]types.GroupVersions, def []string) *gvPackagesValue { +func NewGVPackagesValue(builder *groupVersionsBuilder, def []string) *gvPackagesValue { gvp := new(gvPackagesValue) - gvp.gvToPath = gvToPath - gvp.groups = groups + gvp.builder = builder if def != nil { if err := gvp.set(def); err != nil { panic(err) @@ -49,55 +73,69 @@ func NewGVPackagesValue(gvToPath *map[types.GroupVersion]string, groups *[]types var _ flag.Value = &gvPackagesValue{} -func readAsCSV(val string) ([]string, error) { - if val == "" { - return []string{}, nil +func (s *gvPackagesValue) set(vs []string) error { + if s.changed { + s.groups = append(s.groups, vs...) + } else { + s.groups = append([]string(nil), vs...) } - stringReader := strings.NewReader(val) - csvReader := csv.NewReader(stringReader) - return csvReader.Read() + + s.builder.groups = s.groups + return s.builder.update() } -func writeAsCSV(vals []string) (string, error) { - b := &bytes.Buffer{} - w := csv.NewWriter(b) - err := w.Write(vals) +func (s *gvPackagesValue) Set(val string) error { + vs, err := readAsCSV(val) if err != nil { - return "", err + return err } - w.Flush() - return strings.TrimSuffix(b.String(), "\n"), nil + if err := s.set(vs); err != nil { + return err + } + s.changed = true + return nil } -func (s *gvPackagesValue) set(vs []string) error { - if !s.changed { - *s.gvToPath = map[types.GroupVersion]string{} - *s.groups = []types.GroupVersions{} - } +func (s *gvPackagesValue) Type() string { + return "stringSlice" +} - var seenGroups = make(map[types.Group]*types.GroupVersions) - for _, g := range *s.groups { - seenGroups[g.Group] = &g +func (s *gvPackagesValue) String() string { + str, _ := writeAsCSV(s.groups) + return "[" + str + "]" +} + +type groupVersionsBuilder struct { + value *[]types.GroupVersions + groups []string + importBasePath string +} + +func NewGroupVersionsBuilder(groups *[]types.GroupVersions) *groupVersionsBuilder { + return &groupVersionsBuilder{ + value: groups, } +} - for _, v := range vs { +func (p *groupVersionsBuilder) update() error { + var seenGroups = make(map[types.Group]*types.GroupVersions) + for _, v := range p.groups { pth, gvString := parsePathGroupVersion(v) gv, err := types.ToGroupVersion(gvString) if err != nil { return err } + versionPkg := types.PackageVersion{Package: path.Join(p.importBasePath, pth, gv.Group.NonEmpty(), gv.Version.String()), Version: gv.Version} if group, ok := seenGroups[gv.Group]; ok { - seenGroups[gv.Group].Versions = append(group.Versions, gv.Version) + seenGroups[gv.Group].Versions = append(group.Versions, versionPkg) } else { seenGroups[gv.Group] = &types.GroupVersions{ PackageName: gv.Group.NonEmpty(), Group: gv.Group, - Versions: []types.Version{gv.Version}, + Versions: []types.PackageVersion{versionPkg}, } } - - (*s.gvToPath)[gv] = groupVersionPath(pth, gv.Group.String(), gv.Version.String()) } var groupNames []string @@ -105,39 +143,14 @@ func (s *gvPackagesValue) set(vs []string) error { groupNames = append(groupNames, groupName.String()) } sort.Strings(groupNames) - *s.groups = []types.GroupVersions{} + *p.value = []types.GroupVersions{} for _, groupName := range groupNames { - *s.groups = append(*s.groups, *seenGroups[types.Group(groupName)]) + *p.value = append(*p.value, *seenGroups[types.Group(groupName)]) } return nil } -func (s *gvPackagesValue) Set(val string) error { - vs, err := readAsCSV(val) - if err != nil { - return err - } - if err := s.set(vs); err != nil { - return err - } - s.changed = true - return nil -} - -func (s *gvPackagesValue) Type() string { - return "stringSlice" -} - -func (s *gvPackagesValue) String() string { - strs := make([]string, 0, len(*s.gvToPath)) - for gv, pth := range *s.gvToPath { - strs = append(strs, path.Join(pth, gv.Group.String(), gv.Version.String())) - } - str, _ := writeAsCSV(strs) - return "[" + str + "]" -} - func parsePathGroupVersion(pgvString string) (gvPath string, gvString string) { subs := strings.Split(pgvString, "/") length := len(subs) @@ -149,12 +162,22 @@ func parsePathGroupVersion(pgvString string) (gvPath string, gvString string) { } } -func groupVersionPath(gvPath string, group string, version string) (path string) { - // special case for the core group - if group == "api" { - path = filepath.Join("core", version) - } else { - path = filepath.Join(gvPath, group, version) +func readAsCSV(val string) ([]string, error) { + if val == "" { + return []string{}, nil } - return + stringReader := strings.NewReader(val) + csvReader := csv.NewReader(stringReader) + return csvReader.Read() +} + +func writeAsCSV(vals []string) (string, error) { + b := &bytes.Buffer{} + w := csv.NewWriter(b) + err := w.Write(vals) + if err != nil { + return "", err + } + w.Flush() + return strings.TrimSuffix(b.String(), "\n"), nil } diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go new file mode 100644 index 00000000..8154c2ee --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go @@ -0,0 +1,116 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + "reflect" + "strings" + "testing" + + "github.com/spf13/pflag" + + "k8s.io/code-generator/cmd/client-gen/types" +) + +func TestGVPackageFlag(t *testing.T) { + tests := []struct { + args []string + def []string + importBasePath string + expected map[types.GroupVersion]string + expectedGroups []types.GroupVersions + parseError string + }{ + { + args: []string{}, + expected: map[types.GroupVersion]string{}, + expectedGroups: []types.GroupVersions{}, + }, + { + args: []string{"foo/bar/v1", "foo/bar/v2", "foo/bar/", "foo/v1"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "bar", Group: types.Group("bar"), Versions: []types.PackageVersion{ + {"v1", "foo/bar/v1"}, + {"v2", "foo/bar/v2"}, + {"", "foo/bar"}, + }}, + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {"v1", "foo/v1"}, + }}, + }, + }, + { + args: []string{"foo/bar/v1", "foo/bar/v2", "foo/bar/", "foo/v1"}, + def: []string{"foo/bar/v1alpha1", "foo/v1"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "bar", Group: types.Group("bar"), Versions: []types.PackageVersion{ + {"v1", "foo/bar/v1"}, + {"v2", "foo/bar/v2"}, + {"", "foo/bar"}, + }}, + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {"v1", "foo/v1"}, + }}, + }, + }, + { + args: []string{"api/v1", "api"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "core", Group: types.Group("api"), Versions: []types.PackageVersion{ + {"v1", "core/v1"}, + {"", "core"}, + }}, + }, + }, + { + args: []string{"foo/v1"}, + importBasePath: "k8s.io/api", + expectedGroups: []types.GroupVersions{ + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {"v1", "k8s.io/api/foo/v1"}, + }}, + }, + }, + } + for i, test := range tests { + fs := pflag.NewFlagSet("testGVPackage", pflag.ContinueOnError) + groups := []types.GroupVersions{} + builder := NewGroupVersionsBuilder(&groups) + fs.Var(NewGVPackagesValue(builder, test.def), "input", "usage") + fs.Var(NewInputBasePathValue(builder, test.importBasePath), "input-base-path", "usage") + + args := []string{} + for _, a := range test.args { + args = append(args, fmt.Sprintf("--input=%s", a)) + } + + err := fs.Parse(args) + if test.parseError != "" { + if err == nil { + t.Errorf("%d: expected error %q, got nil", i, test.parseError) + } else if !strings.Contains(err.Error(), test.parseError) { + t.Errorf("%d: expected error %q, got %q", i, test.parseError, err) + } + } else if err != nil { + t.Errorf("%d: expected nil error, got %v", i, err) + } + if !reflect.DeepEqual(groups, test.expectedGroups) { + t.Errorf("%d: expected groups %+v, got groups %+v", i, test.expectedGroups, groups) + } + } +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go index 5d314848..74af0b31 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go @@ -233,7 +233,7 @@ func packageForScheme(customArgs *clientgenargs.CustomArgs, clientsetPackage str NextGroup: for _, group := range customArgs.Groups { for _, v := range group.Versions { - if v == "" { + if v.String() == "" { internalClient = true break NextGroup } @@ -258,7 +258,7 @@ NextGroup: DefaultGen: generator.DefaultGen{ OptionalName: "register", }, - InputPackages: customArgs.GroupVersionToInputPath, + InputPackages: customArgs.GroupVersionPackages(), OutputPackage: schemePackage, OutputPath: filepath.Join(srcTreePath, schemePackage), Groups: customArgs.Groups, @@ -274,13 +274,13 @@ NextGroup: // applyGroupOverrides applies group name overrides to each package, if applicable. If there is a // comment of the form "// +groupName=somegroup" or "// +groupName=somegroup.foo.bar.io", use the -// first field (somegroup) as the name of the group when generating. +// first field (somegroup) as the name of the group in Go code, e.g. as the func name in a clientset. // // If the first field of the groupName is not unique within the clientset, use "// +groupName=unique func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.CustomArgs) { // Create a map from "old GV" to "new GV" so we know what changes we need to make. changes := make(map[clientgentypes.GroupVersion]clientgentypes.GroupVersion) - for gv, inputDir := range customArgs.GroupVersionToInputPath { + for gv, inputDir := range customArgs.GroupVersionPackages() { p := universe.Package(inputDir) if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil { newGV := clientgentypes.GroupVersion{ @@ -296,7 +296,7 @@ func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.Cust for _, gvs := range customArgs.Groups { gv := clientgentypes.GroupVersion{ Group: gvs.Group, - Version: gvs.Versions[0], // we only need a version, and the first will do + Version: gvs.Versions[0].Version, // we only need a version, and the first will do } if newGV, ok := changes[gv]; ok { // There's an override, so use it. @@ -312,19 +312,6 @@ func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.Cust } } customArgs.Groups = newGroups - - // Modify customArgs.GroupVersionToInputPath based on the groupName overrides. - newGVToInputPath := make(map[clientgentypes.GroupVersion]string) - for gv, inputDir := range customArgs.GroupVersionToInputPath { - if newGV, ok := changes[gv]; ok { - // There's an override, so use it. - newGVToInputPath[newGV] = inputDir - } else { - // No override. - newGVToInputPath[gv] = inputDir - } - } - customArgs.GroupVersionToInputPath = newGVToInputPath } // Packages makes the client package definition. @@ -344,7 +331,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat gvToTypes := map[clientgentypes.GroupVersion][]*types.Type{} groupGoNames := make(map[clientgentypes.GroupVersion]string) - for gv, inputDir := range customArgs.GroupVersionToInputPath { + for gv, inputDir := range customArgs.GroupVersionPackages() { p := context.Universe.Package(path.Vendorless(inputDir)) // If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as @@ -384,7 +371,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat } var packageList []generator.Package - clientsetPackage := filepath.Join(customArgs.ClientsetOutputPath, customArgs.ClientsetName) + clientsetPackage := filepath.Join(arguments.OutputPackagePath, customArgs.ClientsetName) packageList = append(packageList, packageForClientset(customArgs, clientsetPackage, groupGoNames, boilerplate)) packageList = append(packageList, packageForScheme(customArgs, clientsetPackage, arguments.OutputBase, groupGoNames, boilerplate)) @@ -398,11 +385,12 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat } orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} + gvPackages := customArgs.GroupVersionPackages() for _, group := range customArgs.Groups { for _, version := range group.Versions { - gv := clientgentypes.GroupVersion{Group: group.Group, Version: version} + gv := clientgentypes.GroupVersion{Group: group.Group, Version: version.Version} types := gvToTypes[gv] - inputPath := customArgs.GroupVersionToInputPath[gv] + inputPath := gvPackages[gv] packageList = append(packageList, packageForGroup(gv, orderer.OrderTypes(types), clientsetPackage, group.PackageName, groupGoNames[gv], customArgs.ClientsetAPIPath, arguments.OutputBase, inputPath, boilerplate)) if customArgs.FakeClient { packageList = append(packageList, fake.PackageForGroup(gv, orderer.OrderTypes(types), clientsetPackage, group.PackageName, groupGoNames[gv], inputPath, boilerplate)) diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go index 941cc35b..ec439c2f 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go @@ -84,12 +84,12 @@ func PackageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli } } -func PackageForClientset(customArgs *clientgenargs.CustomArgs, fakeClientsetPackage string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Package { +func PackageForClientset(customArgs *clientgenargs.CustomArgs, clientsetPackage string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Package { return &generator.DefaultPackage{ // TODO: we'll generate fake clientset for different release in the future. // Package name and path are hard coded for now. PackageName: "fake", - PackagePath: filepath.Join(fakeClientsetPackage, "fake"), + PackagePath: filepath.Join(clientsetPackage, "fake"), HeaderText: boilerplate, PackageDocumentation: []byte( `// This package has the automatically generated fake clientset. @@ -107,17 +107,17 @@ func PackageForClientset(customArgs *clientgenargs.CustomArgs, fakeClientsetPack }, groups: customArgs.Groups, groupGoNames: groupGoNames, - fakeClientsetPackage: fakeClientsetPackage, + fakeClientsetPackage: clientsetPackage, outputPackage: "fake", imports: generator.NewImportTracker(), - realClientsetPackage: filepath.Join(customArgs.ClientsetOutputPath, customArgs.ClientsetName), + realClientsetPackage: clientsetPackage, }, &scheme.GenScheme{ DefaultGen: generator.DefaultGen{ OptionalName: "register", }, - InputPackages: customArgs.GroupVersionToInputPath, - OutputPackage: fakeClientsetPackage, + InputPackages: customArgs.GroupVersionPackages(), + OutputPackage: clientsetPackage, Groups: customArgs.Groups, GroupGoNames: groupGoNames, ImportTracker: generator.NewImportTracker(), diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go index b6a8de3f..f77ab057 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go @@ -63,7 +63,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) { groupClientPackage := filepath.Join(g.fakeClientsetPackage, "typed", group.PackageName, version.NonEmpty()) fakeGroupClientPackage := filepath.Join(groupClientPackage, "fake") - groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{group.Group, version}]) + groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{group.Group, version.Version}]) imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", groupAlias, version.NonEmpty(), groupClientPackage))) imports = append(imports, strings.ToLower(fmt.Sprintf("fake%s%s \"%s\"", groupAlias, version.NonEmpty(), fakeGroupClientPackage))) } @@ -87,7 +87,7 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr // perhaps we can adapt the go2ild framework to this kind of usage. sw := generator.NewSnippetWriter(w, c, "$", "$") - allGroups := clientgentypes.ToGroupVersionPackages(g.groups, g.groupGoNames) + allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames) sw.Do(common, nil) sw.Do(checkImpl, nil) @@ -127,7 +127,15 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { fakePtr := testing.Fake{} fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + fakePtr.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} } diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go index a7fdf85d..de526466 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go @@ -59,7 +59,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) { for _, group := range g.groups { for _, version := range group.Versions { typedClientPath := filepath.Join(g.clientsetPackage, "typed", group.PackageName, version.NonEmpty()) - groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{group.Group, version}]) + groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{group.Group, version.Version}]) imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", groupAlias, version.NonEmpty(), typedClientPath))) } } @@ -71,7 +71,7 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr // perhaps we can adapt the go2ild framework to this kind of usage. sw := generator.NewSnippetWriter(w, c, "$", "$") - allGroups := clientgentypes.ToGroupVersionPackages(g.groups, g.groupGoNames) + allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames) m := map[string]interface{}{ "allGroups": allGroups, "Config": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}), diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go index 3646794e..8e569a84 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go @@ -72,13 +72,10 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer sw := generator.NewSnippetWriter(w, c, "$", "$") apiPath := func(group string) string { - if len(g.apiPath) > 0 { - return `"` + g.apiPath + `"` - } if group == "core" { return `"/api"` } - return `"/apis"` + return `"` + g.apiPath + `"` } groupName := g.group diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go index 416877c4..6000e40d 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go @@ -61,18 +61,18 @@ func (g *GenScheme) Imports(c *generator.Context) (imports []string) { imports = append(imports, g.ImportTracker.ImportLines()...) for _, group := range g.Groups { for _, version := range group.Versions { - packagePath := g.InputPackages[clientgentypes.GroupVersion{Group: group.Group, Version: version}] - groupAlias := strings.ToLower(g.GroupGoNames[clientgentypes.GroupVersion{group.Group, version}]) + packagePath := g.InputPackages[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}] + groupAlias := strings.ToLower(g.GroupGoNames[clientgentypes.GroupVersion{group.Group, version.Version}]) if g.CreateRegistry { // import the install package for internal clientsets instead of the type package with register.go - if version != "" { + if version.Version != "" { packagePath = filepath.Dir(packagePath) } packagePath = filepath.Join(packagePath, "install") imports = append(imports, strings.ToLower(fmt.Sprintf("%s \"%s\"", groupAlias, path.Vendorless(packagePath)))) break } else { - imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", groupAlias, version.NonEmpty(), path.Vendorless(packagePath)))) + imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", groupAlias, version.Version.NonEmpty(), path.Vendorless(packagePath)))) } } } @@ -82,7 +82,7 @@ func (g *GenScheme) Imports(c *generator.Context) (imports []string) { func (g *GenScheme) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { sw := generator.NewSnippetWriter(w, c, "$", "$") - allGroupVersions := clientgentypes.ToGroupVersionPackages(g.Groups, g.GroupGoNames) + allGroupVersions := clientgentypes.ToGroupVersionInfo(g.Groups, g.GroupGoNames) allInstallGroups := clientgentypes.ToGroupInstallPackages(g.Groups, g.GroupGoNames) m := map[string]interface{}{ @@ -149,9 +149,12 @@ func init() { // Install registers the API group and adds types to a scheme func Install(groupFactoryRegistry $.announcedAPIGroupFactoryRegistry|raw$, registry *$.registeredAPIRegistrationManager|raw$, scheme *$.runtimeScheme|raw$) { - $range .allInstallGroups$ $.InstallPackageAlias$.Install(groupFactoryRegistry, registry, scheme) - $end$ - $if .customRegister$ExtraInstall(groupFactoryRegistry, registry, scheme)$end$ + $- range .allInstallGroups$ + $.InstallPackageAlias$.Install(groupFactoryRegistry, registry, scheme) + $- end$ + $if .customRegister$ + ExtraInstall(groupFactoryRegistry, registry, scheme) + $end -$ } ` @@ -168,7 +171,7 @@ func init() { // // import ( // "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" // ) // @@ -178,8 +181,11 @@ func init() { // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. func AddToScheme(scheme *$.runtimeScheme|raw$) { - $range .allGroupVersions$ $.PackageAlias$.AddToScheme(scheme) - $end$ - $if .customRegister$ExtraAddToScheme(scheme)$end$ + $- range .allGroupVersions$ + $.PackageAlias$.AddToScheme(scheme) + $- end$ + $if .customRegister$ + ExtraAddToScheme(scheme) + $end -$ } ` diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags_test.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags_test.go new file mode 100644 index 00000000..a5c93875 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags_test.go @@ -0,0 +1,148 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "reflect" + "testing" +) + +func TestParseTags(t *testing.T) { + testCases := map[string]struct { + lines []string + expectTags Tags + expectError bool + }{ + "genclient": { + lines: []string{`+genclient`}, + expectTags: Tags{GenerateClient: true}, + }, + "genclient=true": { + lines: []string{`+genclient=true`}, + expectError: true, + }, + "nonNamespaced=true": { + lines: []string{`+genclient=true`, `+nonNamespaced=true`}, + expectError: true, + }, + "readonly=true": { + lines: []string{`+genclient=true`, `+readonly=true`}, + expectError: true, + }, + "genclient:nonNamespaced": { + lines: []string{`+genclient`, `+genclient:nonNamespaced`}, + expectTags: Tags{GenerateClient: true, NonNamespaced: true}, + }, + "genclient:noVerbs": { + lines: []string{`+genclient`, `+genclient:noVerbs`}, + expectTags: Tags{GenerateClient: true, NoVerbs: true}, + }, + "genclient:noStatus": { + lines: []string{`+genclient`, `+genclient:noStatus`}, + expectTags: Tags{GenerateClient: true, NoStatus: true}, + }, + "genclient:onlyVerbs": { + lines: []string{`+genclient`, `+genclient:onlyVerbs=create,delete`}, + expectTags: Tags{GenerateClient: true, SkipVerbs: []string{"update", "updateStatus", "deleteCollection", "get", "list", "watch", "patch"}}, + }, + "genclient:readonly": { + lines: []string{`+genclient`, `+genclient:readonly`}, + expectTags: Tags{GenerateClient: true, SkipVerbs: []string{"create", "update", "updateStatus", "delete", "deleteCollection", "patch"}}, + }, + "genclient:conflict": { + lines: []string{`+genclient`, `+genclient:onlyVerbs=create`, `+genclient:skipVerbs=create`}, + expectError: true, + }, + "genclient:invalid": { + lines: []string{`+genclient`, `+genclient:invalid`}, + expectError: true, + }, + } + for key, c := range testCases { + result, err := ParseClientGenTags(c.lines) + if err != nil && !c.expectError { + t.Fatalf("unexpected error: %v", err) + } + if !c.expectError && !reflect.DeepEqual(result, c.expectTags) { + t.Errorf("[%s] expected %#v to be %#v", key, result, c.expectTags) + } + } +} + +func TestParseTagsExtension(t *testing.T) { + testCases := map[string]struct { + lines []string + expectedExtensions []extension + expectError bool + }{ + "simplest extension": { + lines: []string{`+genclient:method=Foo,verb=create`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create"}}, + }, + "multiple extensions": { + lines: []string{`+genclient:method=Foo,verb=create`, `+genclient:method=Bar,verb=get`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create"}, {VerbName: "Bar", VerbType: "get"}}, + }, + "extension without verb": { + lines: []string{`+genclient:method`}, + expectError: true, + }, + "extension without verb type": { + lines: []string{`+genclient:method=Foo`}, + expectError: true, + }, + "sub-resource extension": { + lines: []string{`+genclient:method=Foo,verb=create,subresource=bar`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create", SubResourcePath: "bar"}}, + }, + "output type extension": { + lines: []string{`+genclient:method=Foos,verb=list,result=Bars`}, + expectedExtensions: []extension{{VerbName: "Foos", VerbType: "list", ResultTypeOverride: "Bars"}}, + }, + "input type extension": { + lines: []string{`+genclient:method=Foo,verb=update,input=Bar`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "update", InputTypeOverride: "Bar"}}, + }, + "unknown verb type extension": { + lines: []string{`+genclient:method=Foo,verb=explode`}, + expectedExtensions: nil, + expectError: true, + }, + "invalid verb extension": { + lines: []string{`+genclient:method=Foo,unknown=bar`}, + expectedExtensions: nil, + expectError: true, + }, + "empty verb extension subresource": { + lines: []string{`+genclient:method=Foo,verb=get,subresource=`}, + expectedExtensions: nil, + expectError: true, + }, + } + for key, c := range testCases { + result, err := ParseClientGenTags(c.lines) + if err != nil && !c.expectError { + t.Fatalf("[%s] unexpected error: %v", key, err) + } + if err != nil && c.expectError { + t.Logf("[%s] got expected error: %+v", key, err) + } + if !c.expectError && !reflect.DeepEqual(result.Extensions, c.expectedExtensions) { + t.Errorf("[%s] expected %#+v to be %#+v", key, result.Extensions, c.expectedExtensions) + } + } +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/main.go index 72404808..22c28e35 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/main.go @@ -19,49 +19,43 @@ package main import ( "flag" - "path" "path/filepath" "github.com/golang/glog" "github.com/spf13/pflag" + "k8s.io/gengo/args" - clientgenargs "k8s.io/code-generator/cmd/client-gen/args" + generatorargs "k8s.io/code-generator/cmd/client-gen/args" "k8s.io/code-generator/cmd/client-gen/generators" - "k8s.io/gengo/args" + "k8s.io/code-generator/pkg/util" ) func main() { - arguments := args.Default().WithoutDefaultFlagParsing() - - // Custom args. - customArgs := &clientgenargs.CustomArgs{} - customArgs.AddFlags(pflag.CommandLine) + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.CustomArgs = customArgs - arguments.InputDirs = []string{ - "k8s.io/apimachinery/pkg/fields", - "k8s.io/apimachinery/pkg/labels", - "k8s.io/apimachinery/pkg/watch", - "k8s.io/apimachinery/pkg/apimachinery/registered", - } + // TODO: move this out of client-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/clientset_generated/" - // Register default flags. We do this manually here because we have to override InputDirs below after additional - // input dirs are parse fromt he command-line. - arguments.AddFlags(pflag.CommandLine) + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine, "k8s.io/kubernetes/pkg/apis") // TODO: move this input path out of client-gen + flag.Set("logtostderr", "true") pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() - // Prefix with InputBaseDir and add client dirs as input dirs. - for gv, pth := range customArgs.GroupVersionToInputPath { - customArgs.GroupVersionToInputPath[gv] = path.Join(customArgs.InputBasePath, pth) + // add group version package as input dirs for gengo + for _, pkg := range customArgs.Groups { + for _, v := range pkg.Versions { + genericArgs.InputDirs = append(genericArgs.InputDirs, v.Package) + } } - for _, pkg := range customArgs.GroupVersionToInputPath { - arguments.InputDirs = append(arguments.InputDirs, pkg) + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) } - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go index bc4d9dea..33e6ac45 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go @@ -75,27 +75,27 @@ func (a sortableSliceOfVersions) Less(i, j int) bool { // Determine the default version among versions. If a user calls a group client // without specifying the version (e.g., c.Core(), instead of c.CoreV1()), the // default version will be returned. -func defaultVersion(versions []Version) Version { +func defaultVersion(versions []PackageVersion) Version { var versionStrings []string for _, version := range versions { - versionStrings = append(versionStrings, string(version)) + versionStrings = append(versionStrings, version.Version.String()) } sort.Sort(sortableSliceOfVersions(versionStrings)) return Version(versionStrings[len(versionStrings)-1]) } -// ToGroupVersionPackages is a helper function used by generators for groups. -func ToGroupVersionPackages(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupVersionPackage { - var groupVersionPackages []GroupVersionPackage +// ToGroupVersionInfo is a helper function used by generators for groups. +func ToGroupVersionInfo(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupVersionInfo { + var groupVersionPackages []GroupVersionInfo for _, group := range groups { defaultVersion := defaultVersion(group.Versions) for _, version := range group.Versions { - groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: version}] - groupVersionPackages = append(groupVersionPackages, GroupVersionPackage{ + groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: version.Version}] + groupVersionPackages = append(groupVersionPackages, GroupVersionInfo{ Group: Group(namer.IC(group.Group.NonEmpty())), - Version: Version(namer.IC(version.String())), - PackageAlias: strings.ToLower(groupGoName + version.NonEmpty()), - IsDefaultVersion: version == defaultVersion && version != "", + Version: Version(namer.IC(version.Version.String())), + PackageAlias: strings.ToLower(groupGoName + version.Version.NonEmpty()), + IsDefaultVersion: version.Version == defaultVersion && version.Version != "", GroupGoName: groupGoName, LowerCaseGroupGoName: namer.IL(groupGoName), }) diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers_test.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers_test.go new file mode 100644 index 00000000..dec62dff --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/helpers_test.go @@ -0,0 +1,32 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "reflect" + "sort" + "testing" +) + +func TestVersionSort(t *testing.T) { + unsortedVersions := []string{"v4beta1", "v2beta1", "v2alpha1", "v3", "v1"} + expected := []string{"v2alpha1", "v2beta1", "v4beta1", "v1", "v3"} + sort.Sort(sortableSliceOfVersions(unsortedVersions)) + if !reflect.DeepEqual(unsortedVersions, expected) { + t.Errorf("expected %#v\ngot %#v", expected, unsortedVersions) + } +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/types.go b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/types.go index a2a87b1e..17fd6e92 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/types.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/client-gen/types/types.go @@ -42,20 +42,26 @@ func (g Group) NonEmpty() string { return string(g) } +type PackageVersion struct { + Version + // The fully qualified package, e.g. k8s.io/kubernetes/pkg/apis/apps, where the types.go is found. + Package string +} + type GroupVersion struct { Group Group Version Version } type GroupVersions struct { - // The package name of the group, e.g. extensions or networking + // The name of the package for this group, e.g. apps. PackageName string Group Group - Versions []Version + Versions []PackageVersion } -// GroupVersionPackage contains group name, version name, and the package name client-gen will generate for this group version. -type GroupVersionPackage struct { +// GroupVersionInfo contains all the info around a group version. +type GroupVersionInfo struct { Group Group Version Version // If a user calls a group client without specifying the version (e.g., diff --git a/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/args/args.go new file mode 100644 index 00000000..3b7b0123 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/args/args.go @@ -0,0 +1,83 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" + "k8s.io/gengo/args" +) + +// DefaultBasePeerDirs are the peer-dirs nearly everybody will use, i.e. those coming from +// apimachinery. +var DefaultBasePeerDirs = []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1", + "k8s.io/apimachinery/pkg/conversion", + "k8s.io/apimachinery/pkg/runtime", +} + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs struct { + // Base peer dirs which nearly everybody will use, i.e. outside of Kubernetes core. Peer dirs + // are declared to make the generator pick up manually written conversion funcs from external + // packages. + BasePeerDirs []string + + // Custom peer dirs which are application specific. Peer dirs are declared to make the + // generator pick up manually written conversion funcs from external packages. + ExtraPeerDirs []string + + // Skipunsafe indicates whether to generate unsafe conversions to improve the efficiency + // of these operations. The unsafe operation is a direct pointer assignment via unsafe + // (within the allowed uses of unsafe) and is equivalent to a proposed Golang change to + // allow structs that are identical to be assigned to each other. + SkipUnsafe bool +} + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{ + BasePeerDirs: DefaultBasePeerDirs, + SkipUnsafe: false, + } + genericArgs.CustomArgs = customArgs + genericArgs.OutputFileBaseName = "conversion_generated" + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { + pflag.CommandLine.StringSliceVar(&ca.BasePeerDirs, "base-peer-dirs", ca.BasePeerDirs, + "Comma-separated list of apimachinery import paths which are considered, after tag-specified peers, for conversions. Only change these if you have very good reasons.") + pflag.CommandLine.StringSliceVar(&ca.ExtraPeerDirs, "extra-peer-dirs", ca.ExtraPeerDirs, + "Application specific comma-separated list of import paths which are considered, after tag-specified peers and base-peer-dirs, for conversions.") + pflag.CommandLine.BoolVar(&ca.SkipUnsafe, "skip-unsafe", ca.SkipUnsafe, + "If true, will not generate code using unsafe pointer conversions; resulting code may be slower.") +} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + _ = genericArgs.CustomArgs.(*CustomArgs) + + if len(genericArgs.OutputFileBaseName) == 0 { + return fmt.Errorf("output file base name cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go index ed7ab27e..3c16a85b 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go @@ -30,31 +30,9 @@ import ( "k8s.io/gengo/types" "github.com/golang/glog" -) - -// DefaultBasePeerDirs are the peer-dirs nearly everybody will use, i.e. those coming from -// apimachinery. -var DefaultBasePeerDirs = []string{ - "k8s.io/apimachinery/pkg/apis/meta/v1", - "k8s.io/apimachinery/pkg/conversion", - "k8s.io/apimachinery/pkg/runtime", -} -// CustomArgs is used by the gengo framework to pass args specific to this generator. -type CustomArgs struct { - // Base peer dirs which nearly everybody will use, i.e. outside of Kubernetes core. - BasePeerDirs []string - - // Custom peer dirs which are application specific. Always consider these as - // last-ditch possibilities for conversions. - ExtraPeerDirs []string // - - // Skipunsafe indicates whether to generate unsafe conversions to improve the efficiency - // of these operations. The unsafe operation is a direct pointer assignment via unsafe - // (within the allowed uses of unsafe) and is equivalent to a proposed Golang change to - // allow structs that are identical to be assigned to each other. - SkipUnsafe bool -} + conversionargs "k8s.io/code-generator/cmd/conversion-gen/args" +) // These are the comment tags that carry parameters for conversion generation. const ( @@ -215,7 +193,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat packages := generator.Packages{} header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...) - header = append(header, []byte("\n// This file was autogenerated by conversion-gen. Do not edit it manually!\n\n")...) // Accumulate pre-existing conversion functions. // TODO: This is too ad-hoc. We need a better way. @@ -264,7 +241,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat continue } skipUnsafe := false - if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { + if customArgs, ok := arguments.CustomArgs.(*conversionargs.CustomArgs); ok { peerPkgs = append(peerPkgs, customArgs.BasePeerDirs...) peerPkgs = append(peerPkgs, customArgs.ExtraPeerDirs...) skipUnsafe = customArgs.SkipUnsafe @@ -593,12 +570,6 @@ func argsFromType(inType, outType *types.Type) generator.Args { } } -func defaultingArgsFromType(inType *types.Type) generator.Args { - return generator.Args{ - "inType": inType, - } -} - const nameTmpl = "Convert_$.inType|publicIT$_To_$.outType|publicIT$" func (g *genConversion) preexists(inType, outType *types.Type) (*types.Type, bool) { diff --git a/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/main.go index aab38ad1..f2b91cc2 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/conversion-gen/main.go @@ -35,37 +35,37 @@ limitations under the License. package main import ( + "flag" "path/filepath" - "k8s.io/code-generator/cmd/conversion-gen/generators" - "k8s.io/gengo/args" - "github.com/golang/glog" "github.com/spf13/pflag" + "k8s.io/gengo/args" + + generatorargs "k8s.io/code-generator/cmd/conversion-gen/args" + "k8s.io/code-generator/cmd/conversion-gen/generators" + "k8s.io/code-generator/pkg/util" ) func main() { - arguments := args.Default() - - // Custom args. - customArgs := &generators.CustomArgs{ - BasePeerDirs: generators.DefaultBasePeerDirs, - SkipUnsafe: false, - } - pflag.CommandLine.StringSliceVar(&customArgs.BasePeerDirs, "base-peer-dirs", customArgs.BasePeerDirs, - "Comma-separated list of apimachinery import paths which are considered, after tag-specified peers, for conversions. Only change these if you have very good reasons.") - pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs, - "Application specific comma-separated list of import paths which are considered, after tag-specified peers and base-peer-dirs, for conversions.") - pflag.CommandLine.BoolVar(&customArgs.SkipUnsafe, "skip-unsafe", customArgs.SkipUnsafe, - "If true, will not generate code using unsafe pointer conversions; resulting code may be slower.") + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputFileBaseName = "conversion_generated" - arguments.CustomArgs = customArgs + // TODO: move this out of conversion-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/args/args.go new file mode 100644 index 00000000..78971301 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/args/args.go @@ -0,0 +1,54 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" + "k8s.io/gengo/args" + "k8s.io/gengo/examples/deepcopy-gen/generators" +) + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs generators.CustomArgs + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{} + genericArgs.CustomArgs = (*generators.CustomArgs)(customArgs) // convert to upstream type to make type-casts work there + genericArgs.OutputFileBaseName = "deepcopy_generated" + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { + pflag.CommandLine.StringSliceVar(&ca.BoundingDirs, "bounding-dirs", ca.BoundingDirs, + "Comma-separated list of import paths which bound the types for which deep-copies will be generated.") +} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + _ = genericArgs.CustomArgs.(*generators.CustomArgs) + + if len(genericArgs.OutputFileBaseName) == 0 { + return fmt.Errorf("output file base name cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go index 75cd29b2..cce65b77 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go @@ -43,30 +43,37 @@ limitations under the License. package main import ( + "flag" "path/filepath" + "github.com/golang/glog" + "github.com/spf13/pflag" "k8s.io/gengo/args" "k8s.io/gengo/examples/deepcopy-gen/generators" - "github.com/golang/glog" - "github.com/spf13/pflag" + generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args" + "k8s.io/code-generator/pkg/util" ) func main() { - arguments := args.Default() - - // Custom args. - customArgs := &generators.CustomArgs{} - pflag.CommandLine.StringSliceVar(&customArgs.BoundingDirs, "bounding-dirs", customArgs.BoundingDirs, - "Comma-separated list of import paths which bound the types for which deep-copies will be generated.") + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputFileBaseName = "deepcopy_generated" - arguments.CustomArgs = customArgs + // TODO: move this out of deepcopy-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/args/args.go new file mode 100644 index 00000000..3c5a042c --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/args/args.go @@ -0,0 +1,54 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" + "k8s.io/gengo/args" + "k8s.io/gengo/examples/defaulter-gen/generators" +) + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs generators.CustomArgs + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{} + genericArgs.CustomArgs = (*generators.CustomArgs)(customArgs) // convert to upstream type to make type-casts work there + genericArgs.OutputFileBaseName = "zz_generated.defaults" + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { + pflag.CommandLine.StringSliceVar(&ca.ExtraPeerDirs, "extra-peer-dirs", ca.ExtraPeerDirs, + "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.") +} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + _ = genericArgs.CustomArgs.(*generators.CustomArgs) + + if len(genericArgs.OutputFileBaseName) == 0 { + return fmt.Errorf("output file base name cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/main.go index 119ca119..9d33f700 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/defaulter-gen/main.go @@ -42,32 +42,37 @@ limitations under the License. package main import ( + "flag" "path/filepath" + "github.com/golang/glog" + "github.com/spf13/pflag" "k8s.io/gengo/args" "k8s.io/gengo/examples/defaulter-gen/generators" - "github.com/golang/glog" - "github.com/spf13/pflag" + generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args" + "k8s.io/code-generator/pkg/util" ) func main() { - arguments := args.Default() - - // Custom args. - customArgs := &generators.CustomArgs{ - ExtraPeerDirs: []string{}, - } - pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs, - "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.") + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputFileBaseName = "zz_generated.defaults" - arguments.CustomArgs = customArgs + // TODO: move this out of defaulter-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/main.go b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/main.go index ce1756c1..847a6a5a 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/main.go @@ -29,6 +29,7 @@ var g = protobuf.New() func init() { g.BindFlags(flag.CommandLine) + goflag.Set("logtostderr", "true") flag.CommandLine.AddGoFlagSet(goflag.CommandLine) } diff --git a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go index 0c2573bf..55507322 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go @@ -27,6 +27,7 @@ import ( "path/filepath" "strings" + "k8s.io/code-generator/pkg/util" "k8s.io/gengo/args" "k8s.io/gengo/generator" "k8s.io/gengo/namer" @@ -55,7 +56,7 @@ func New() *Generator { sourceTree := args.DefaultSourceTree() common := args.GeneratorArgs{ OutputBase: sourceTree, - GoHeaderFilePath: filepath.Join(sourceTree, "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt"), + GoHeaderFilePath: filepath.Join(sourceTree, util.BoilerplatePath()), } defaultProtoImport := filepath.Join(sourceTree, "k8s.io", "kubernetes", "vendor", "github.com", "gogo", "protobuf", "protobuf") cwd, err := os.Getwd() @@ -73,7 +74,8 @@ func New() *Generator { `+k8s.io/apimachinery/pkg/runtime/schema`, `+k8s.io/apimachinery/pkg/runtime`, `k8s.io/apimachinery/pkg/apis/meta/v1`, - `k8s.io/apimachinery/pkg/apis/meta/v1alpha1`, + `k8s.io/apimachinery/pkg/apis/meta/v1beta1`, + `k8s.io/apimachinery/pkg/apis/testapigroup/v1`, }, ","), Packages: "", DropEmbeddedFields: "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta", diff --git a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go index 94ea7ff6..0e7a7d8e 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go @@ -128,7 +128,7 @@ func isProtoable(seen map[*types.Type]bool, t *types.Type) bool { case types.Interface: return false default: - log.Printf("WARNING: type %q is not protable: %s", t.Kind, t.Name) + log.Printf("WARNING: type %q is not portable: %s", t.Kind, t.Name) return false } } @@ -516,10 +516,13 @@ func memberTypeToProtobufField(locator ProtobufLocator, field *protoField, t *ty log.Printf("failed to alias: %s %s: err %v", t.Name, t.Underlying.Name, err) return err } - if field.Extras == nil { - field.Extras = make(map[string]string) + // If this is not an alias to a slice, cast to the alias + if !field.Repeated { + if field.Extras == nil { + field.Extras = make(map[string]string) + } + field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name)) } - field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name)) } case types.Slice: if t.Elem.Name.Name == "byte" && len(t.Elem.Name.Package) == 0 { diff --git a/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/namer_test.go b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/namer_test.go new file mode 100644 index 00000000..0ee71f80 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/namer_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package protobuf + +import "testing" + +func TestProtoSafePackage(t *testing.T) { + tests := []struct { + pkg string + expected string + }{ + { + pkg: "foo", + expected: "foo", + }, + { + pkg: "foo/bar", + expected: "foo.bar", + }, + { + pkg: "foo/bar/baz", + expected: "foo.bar.baz", + }, + { + pkg: "foo/bar-baz/x/y-z/q", + expected: "foo.bar_baz.x.y_z.q", + }, + } + + for _, test := range tests { + actual := protoSafePackage(test.pkg) + if e, a := test.expected, actual; e != a { + t.Errorf("%s: expected %s, got %s", test.pkg, e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/import-boss/main.go b/discovery/vendor/k8s.io/code-generator/cmd/import-boss/main.go index a6fad8ef..d9989944 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/import-boss/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/import-boss/main.go @@ -59,6 +59,7 @@ import ( "os" "path/filepath" + "k8s.io/code-generator/pkg/util" "k8s.io/gengo/args" "k8s.io/gengo/examples/import-boss/generators" @@ -69,7 +70,7 @@ func main() { arguments := args.Default() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") + arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) arguments.InputDirs = []string{ "k8s.io/kubernetes/pkg/...", "k8s.io/kubernetes/cmd/...", diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go new file mode 100644 index 00000000..ba7f7209 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go @@ -0,0 +1,77 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + "path" + + "github.com/spf13/pflag" + codegenutil "k8s.io/code-generator/pkg/util" + "k8s.io/gengo/args" +) + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs struct { + VersionedClientSetPackage string + InternalClientSetPackage string + ListersPackage string + SingleDirectory bool +} + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{ + SingleDirectory: false, + } + genericArgs.CustomArgs = customArgs + + if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 { + genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/informers") + customArgs.VersionedClientSetPackage = path.Join(pkg, "pkg/client/clientset/versioned") + customArgs.InternalClientSetPackage = path.Join(pkg, "pkg/client/clientset/internalversion") + customArgs.ListersPackage = path.Join(pkg, "pkg/client/listers") + } + + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&ca.InternalClientSetPackage, "internal-clientset-package", ca.InternalClientSetPackage, "the full package name for the internal clientset to use") + fs.StringVar(&ca.VersionedClientSetPackage, "versioned-clientset-package", ca.VersionedClientSetPackage, "the full package name for the versioned clientset to use") + fs.StringVar(&ca.ListersPackage, "listers-package", ca.ListersPackage, "the full package name for the listers to use") + fs.BoolVar(&ca.SingleDirectory, "single-directory", ca.SingleDirectory, "if true, omit the intermediate \"internalversion\" and \"externalversions\" subdirectories") +} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + customArgs := genericArgs.CustomArgs.(*CustomArgs) + + if len(genericArgs.OutputPackagePath) == 0 { + return fmt.Errorf("output package cannot be empty") + } + if len(customArgs.VersionedClientSetPackage) == 0 { + return fmt.Errorf("versioned clientset package cannot be empty") + } + if len(customArgs.ListersPackage) == 0 { + return fmt.Errorf("listers package cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/customargs.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/customargs.go deleted file mode 100644 index 168309a9..00000000 --- a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/customargs.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package generators - -import "github.com/spf13/pflag" - -type CustomArgs struct { - VersionedClientSetPackage string - InternalClientSetPackage string - ListersPackage string - SingleDirectory bool -} - -func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { - fs.StringVar(&ca.InternalClientSetPackage, "internal-clientset-package", ca.InternalClientSetPackage, "the full package name for the internal clientset to use") - fs.StringVar(&ca.VersionedClientSetPackage, "versioned-clientset-package", ca.VersionedClientSetPackage, "the full package name for the versioned clientset to use") - fs.StringVar(&ca.ListersPackage, "listers-package", ca.ListersPackage, "the full package name for the listers to use") - fs.BoolVar(&ca.SingleDirectory, "single-directory", ca.SingleDirectory, "if true, omit the intermediate \"internalversion\" and \"externalversions\" subdirectories") -} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go index 891cac31..54632de0 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go @@ -105,10 +105,10 @@ func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w i Versions: []*version{}, } for _, v := range groupVersions.Versions { - gv := clientgentypes.GroupVersion{Group: groupVersions.Group, Version: v} + gv := clientgentypes.GroupVersion{Group: groupVersions.Group, Version: v.Version} version := &version{ - Name: v.NonEmpty(), - GoName: namer.IC(v.NonEmpty()), + Name: v.Version.NonEmpty(), + GoName: namer.IC(v.Version.NonEmpty()), Resources: orderer.OrderTypes(g.typesForGroupVersion[gv]), } schemeGVs[version] = c.Universe.Variable(types.Name{Package: g.typesForGroupVersion[gv][0].Name.Package, Name: "SchemeGroupVersion"}) diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go index 253b79f3..0bba93c4 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go @@ -69,11 +69,11 @@ func (g *groupInterfaceGenerator) GenerateType(c *generator.Context, t *types.Ty versions := make([]versionData, 0, len(g.groupVersions.Versions)) for _, version := range g.groupVersions.Versions { - gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version} + gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version.Version} versionPackage := filepath.Join(g.outputPackage, strings.ToLower(gv.Version.NonEmpty())) iface := c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"}) versions = append(versions, versionData{ - Name: namer.IC(version.NonEmpty()), + Name: namer.IC(version.Version.NonEmpty()), Interface: iface, New: c.Universe.Function(types.Name{Package: versionPackage, Name: "New"}), }) diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go index faa01218..2cc0372f 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go @@ -18,9 +18,11 @@ package generators import ( "fmt" + "path" "path/filepath" "strings" + "github.com/golang/glog" "k8s.io/gengo/args" "k8s.io/gengo/generator" "k8s.io/gengo/namer" @@ -28,8 +30,7 @@ import ( "k8s.io/code-generator/cmd/client-gen/generators/util" clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/golang/glog" + informergenargs "k8s.io/code-generator/cmd/informer-gen/args" ) // NameSystems returns the name system used by the generators in this package. @@ -61,12 +62,6 @@ func DefaultNameSystem() string { return "public" } -// generatedBy returns information about the arguments used to invoke -// lister-gen. -func generatedBy() string { - return fmt.Sprintf("\n// This file was automatically generated by informer-gen\n\n") -} - // objectMetaForPackage returns the type of ObjectMeta used by package p. func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) { generatingForPackage := false @@ -110,9 +105,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat glog.Fatalf("Failed loading boilerplate: %v", err) } - boilerplate = append(boilerplate, []byte(generatedBy())...) - - customArgs, ok := arguments.CustomArgs.(*CustomArgs) + customArgs, ok := arguments.CustomArgs.(*informergenargs.CustomArgs) if !ok { glog.Fatalf("Wrong CustomArgs type: %T", arguments.CustomArgs) } @@ -158,7 +151,8 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat gv.Version = clientgentypes.Version(parts[len(parts)-1]) targetGroupVersions = externalGroupVersions } - groupPkgName := strings.ToLower(gv.Group.NonEmpty()) + groupPackageName := gv.Group.NonEmpty() + gvPackage := path.Clean(p.Path) // If there's a comment of the form "// +groupName=somegroup" or // "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the @@ -169,9 +163,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat // If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as // the Go group identifier in CamelCase. It defaults - groupGoNames[groupPkgName] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0]) + groupGoNames[groupPackageName] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0]) if override := types.ExtractCommentTags("+", p.Comments)["groupGoName"]; override != nil { - groupGoNames[groupPkgName] = namer.IC(override[0]) + groupGoNames[groupPackageName] = namer.IC(override[0]) } var typesToGenerate []*types.Type @@ -192,23 +186,23 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat continue } - groupVersionsEntry, ok := targetGroupVersions[groupPkgName] + groupVersionsEntry, ok := targetGroupVersions[groupPackageName] if !ok { groupVersionsEntry = clientgentypes.GroupVersions{ - PackageName: groupPkgName, + PackageName: groupPackageName, Group: gv.Group, } } - groupVersionsEntry.Versions = append(groupVersionsEntry.Versions, gv.Version) - targetGroupVersions[groupPkgName] = groupVersionsEntry + groupVersionsEntry.Versions = append(groupVersionsEntry.Versions, clientgentypes.PackageVersion{Version: gv.Version, Package: gvPackage}) + targetGroupVersions[groupPackageName] = groupVersionsEntry orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} typesToGenerate = orderer.OrderTypes(typesToGenerate) if internal { - packageList = append(packageList, versionPackage(internalVersionPackagePath, groupPkgName, gv, groupGoNames[groupPkgName], boilerplate, typesToGenerate, customArgs.InternalClientSetPackage, customArgs.ListersPackage)) + packageList = append(packageList, versionPackage(internalVersionPackagePath, groupPackageName, gv, groupGoNames[groupPackageName], boilerplate, typesToGenerate, customArgs.InternalClientSetPackage, customArgs.ListersPackage)) } else { - packageList = append(packageList, versionPackage(externalVersionPackagePath, groupPkgName, gv, groupGoNames[groupPkgName], boilerplate, typesToGenerate, customArgs.VersionedClientSetPackage, customArgs.ListersPackage)) + packageList = append(packageList, versionPackage(externalVersionPackagePath, groupPackageName, gv, groupGoNames[groupPackageName], boilerplate, typesToGenerate, customArgs.VersionedClientSetPackage, customArgs.ListersPackage)) } } diff --git a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/main.go index 78c0b382..bfe82608 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/informer-gen/main.go @@ -17,34 +17,41 @@ limitations under the License. package main import ( + "flag" "path/filepath" + "github.com/golang/glog" + "github.com/spf13/pflag" "k8s.io/code-generator/cmd/informer-gen/generators" + "k8s.io/code-generator/pkg/util" "k8s.io/gengo/args" - "github.com/golang/glog" - "github.com/spf13/pflag" + generatorargs "k8s.io/code-generator/cmd/informer-gen/args" ) func main() { - arguments := args.Default() - - // Custom arguments. - customArgs := &generators.CustomArgs{ - VersionedClientSetPackage: "k8s.io/kubernetes/pkg/client/clientset_generated/clientset", - InternalClientSetPackage: "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset", - ListersPackage: "k8s.io/kubernetes/pkg/client/listers", - SingleDirectory: false, - } - customArgs.AddFlags(pflag.CommandLine) + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputPackagePath = "k8s.io/kubernetes/pkg/client/informers/informers_generated" - arguments.CustomArgs = customArgs + // TODO: move out of informer-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/informers/informers_generated" + customArgs.VersionedClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" + customArgs.InternalClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + customArgs.ListersPackage = "k8s.io/kubernetes/pkg/client/listers" + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go new file mode 100644 index 00000000..34914ea8 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go @@ -0,0 +1,56 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + "path" + + "github.com/spf13/pflag" + codegenutil "k8s.io/code-generator/pkg/util" + "k8s.io/gengo/args" +) + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs struct{} + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{} + genericArgs.CustomArgs = customArgs + + if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 { + genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/listers") + } + + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + _ = genericArgs.CustomArgs.(*CustomArgs) + + if len(genericArgs.OutputPackagePath) == 0 { + return fmt.Errorf("output package cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go index 3da8d2dd..cde6e2f7 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go @@ -62,12 +62,6 @@ func DefaultNameSystem() string { return "public" } -// generatedBy returns information about the arguments used to invoke -// lister-gen. -func generatedBy() string { - return fmt.Sprintf("\n// This file was automatically generated by lister-gen\n\n") -} - // Packages makes the client package definition. func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages { boilerplate, err := arguments.LoadGoBoilerplate() @@ -75,8 +69,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat glog.Fatalf("Failed loading boilerplate: %v", err) } - boilerplate = append(boilerplate, []byte(generatedBy())...) - var packageList generator.Packages for _, inputDir := range arguments.InputDirs { p := context.Universe.Package(inputDir) diff --git a/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/main.go index 3b305f82..d5ff8e46 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/lister-gen/main.go @@ -17,23 +17,38 @@ limitations under the License. package main import ( + "flag" "path/filepath" + "github.com/golang/glog" + "github.com/spf13/pflag" "k8s.io/code-generator/cmd/lister-gen/generators" + "k8s.io/code-generator/pkg/util" "k8s.io/gengo/args" - "github.com/golang/glog" + generatorargs "k8s.io/code-generator/cmd/lister-gen/args" ) func main() { - arguments := args.Default() + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputPackagePath = "k8s.io/kubernetes/pkg/client/listers" + // TODO: move this out of lister-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/listers" + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/args/args.go b/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/args/args.go new file mode 100644 index 00000000..f9bb17e1 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/args/args.go @@ -0,0 +1,53 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" + "k8s.io/gengo/args" +) + +// CustomArgs is used by the gengo framework to pass args specific to this generator. +type CustomArgs struct{} + +// NewDefaults returns default arguments for the generator. +func NewDefaults() (*args.GeneratorArgs, *CustomArgs) { + genericArgs := args.Default().WithoutDefaultFlagParsing() + customArgs := &CustomArgs{} + genericArgs.CustomArgs = customArgs + genericArgs.OutputFileBaseName = "openapi_generated" + return genericArgs, customArgs +} + +// AddFlags add the generator flags to the flag set. +func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {} + +// Validate checks the given arguments. +func Validate(genericArgs *args.GeneratorArgs) error { + _ = genericArgs.CustomArgs.(*CustomArgs) + + if len(genericArgs.OutputFileBaseName) == 0 { + return fmt.Errorf("output file base name cannot be empty") + } + if len(genericArgs.OutputPackagePath) == 0 { + return fmt.Errorf("output package cannot be empty") + } + + return nil +} diff --git a/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/main.go index 67355f83..fbafc502 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/openapi-gen/main.go @@ -20,23 +20,37 @@ limitations under the License. package main import ( + "flag" "path/filepath" + "github.com/golang/glog" + "github.com/spf13/pflag" "k8s.io/gengo/args" "k8s.io/kube-openapi/pkg/generators" - "github.com/golang/glog" + generatorargs "k8s.io/code-generator/cmd/openapi-gen/args" + "k8s.io/code-generator/pkg/util" ) func main() { - arguments := args.Default() + genericArgs, customArgs := generatorargs.NewDefaults() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") - arguments.OutputFileBaseName = "openapi_generated" + // TODO: move this out of openapi-gen + genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) + + genericArgs.AddFlags(pflag.CommandLine) + customArgs.AddFlags(pflag.CommandLine) + flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := generatorargs.Validate(genericArgs); err != nil { + glog.Fatalf("Error: %v", err) + } // Run it. - if err := arguments.Execute( + if err := genericArgs.Execute( generators.NameSystems(), generators.DefaultNameSystem(), generators.Packages, diff --git a/discovery/vendor/k8s.io/code-generator/cmd/set-gen/main.go b/discovery/vendor/k8s.io/code-generator/cmd/set-gen/main.go index 24af2229..cf8f01d8 100644 --- a/discovery/vendor/k8s.io/code-generator/cmd/set-gen/main.go +++ b/discovery/vendor/k8s.io/code-generator/cmd/set-gen/main.go @@ -28,6 +28,7 @@ import ( "os" "path/filepath" + "k8s.io/code-generator/pkg/util" "k8s.io/gengo/args" "k8s.io/gengo/examples/set-gen/generators" @@ -38,7 +39,7 @@ func main() { arguments := args.Default() // Override defaults. - arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") + arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath()) arguments.InputDirs = []string{"k8s.io/kubernetes/pkg/util/sets/types"} arguments.OutputPackagePath = "k8s.io/apimachinery/pkg/util/sets" diff --git a/discovery/vendor/k8s.io/code-generator/code-of-conduct.md b/discovery/vendor/k8s.io/code-generator/code-of-conduct.md new file mode 100644 index 00000000..0d15c00c --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/code-of-conduct.md @@ -0,0 +1,3 @@ +# Kubernetes Community Code of Conduct + +Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) diff --git a/discovery/vendor/k8s.io/code-generator/generate-groups.sh b/discovery/vendor/k8s.io/code-generator/generate-groups.sh index 145b1240..b92296d9 100755 --- a/discovery/vendor/k8s.io/code-generator/generate-groups.sh +++ b/discovery/vendor/k8s.io/code-generator/generate-groups.sh @@ -67,7 +67,7 @@ fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/clientset" - ${GOPATH}/bin/client-gen --clientset-name versioned --input-base "" --input $(codegen::join , "${FQ_APIS[@]}") --clientset-path ${OUTPUT_PKG}/clientset "$@" + ${GOPATH}/bin/client-gen --clientset-name versioned --input-base "" --input $(codegen::join , "${FQ_APIS[@]}") --output-package ${OUTPUT_PKG}/clientset "$@" fi if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then diff --git a/discovery/vendor/k8s.io/code-generator/generate-internal-groups.sh b/discovery/vendor/k8s.io/code-generator/generate-internal-groups.sh index b995dd4d..0de606d3 100755 --- a/discovery/vendor/k8s.io/code-generator/generate-internal-groups.sh +++ b/discovery/vendor/k8s.io/code-generator/generate-internal-groups.sh @@ -87,9 +87,9 @@ fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/clientset" if [ -n "${INT_APIS_PKG}" ]; then - ${GOPATH}/bin/client-gen --clientset-name internalversion --input-base "" --input $(codegen::join , $(printf '%s/ ' "${INT_FQ_APIS[@]}")) --clientset-path ${OUTPUT_PKG}/clientset "$@" + ${GOPATH}/bin/client-gen --clientset-name internalversion --input-base "" --input $(codegen::join , $(printf '%s/ ' "${INT_FQ_APIS[@]}")) --output-package ${OUTPUT_PKG}/clientset "$@" fi - ${GOPATH}/bin/client-gen --clientset-name versioned --input-base "" --input $(codegen::join , "${EXT_FQ_APIS[@]}") --clientset-path ${OUTPUT_PKG}/clientset "$@" + ${GOPATH}/bin/client-gen --clientset-name versioned --input-base "" --input $(codegen::join , "${EXT_FQ_APIS[@]}") --output-package ${OUTPUT_PKG}/clientset "$@" fi if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then diff --git a/discovery/vendor/k8s.io/code-generator/hack/boilerplate.go.txt b/discovery/vendor/k8s.io/code-generator/hack/boilerplate.go.txt new file mode 100644 index 00000000..59e740c1 --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/hack/boilerplate.go.txt @@ -0,0 +1,16 @@ +/* +Copyright YEAR The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + diff --git a/discovery/vendor/k8s.io/code-generator/pkg/util/build.go b/discovery/vendor/k8s.io/code-generator/pkg/util/build.go new file mode 100644 index 00000000..6ea8f52e --- /dev/null +++ b/discovery/vendor/k8s.io/code-generator/pkg/util/build.go @@ -0,0 +1,61 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + gobuild "go/build" + "path" + "path/filepath" + "reflect" + "strings" +) + +type empty struct{} + +// CurrentPackage returns the go package of the current directory, or "" if it cannot +// be derived from the GOPATH. +func CurrentPackage() string { + for _, root := range gobuild.Default.SrcDirs() { + if pkg, ok := hasSubdir(root, "."); ok { + return pkg + } + } + return "" +} + +func hasSubdir(root, dir string) (rel string, ok bool) { + // ensure a tailing separator to properly compare on word-boundaries + const sep = string(filepath.Separator) + root = filepath.Clean(root) + if !strings.HasSuffix(root, sep) { + root += sep + } + + // check whether root dir starts with root + dir = filepath.Clean(dir) + if !strings.HasPrefix(dir, root) { + return "", false + } + + // cut off root + return filepath.ToSlash(dir[len(root):]), true +} + +// BoilerplatePath uses the boilerplate in code-generator by calculating the relative path to it. +func BoilerplatePath() string { + return path.Join(reflect.TypeOf(empty{}).PkgPath(), "/../../hack/boilerplate.go.txt") +} diff --git a/discovery/vendor/k8s.io/gengo/.travis.yml b/discovery/vendor/k8s.io/gengo/.travis.yml new file mode 100644 index 00000000..bad78f7e --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/.travis.yml @@ -0,0 +1,17 @@ +language: go +go: + - 1.8 + - tip + +go_import_path: k8s.io/gengo + +jobs: + include: + - stage: Run tests + script: + - find . -name Makefile | xargs -n1 dirname | while read DIR; do make -C $DIR test; done + - go test -v ./... + - stage: Verify examples + script: + - go run ./examples/set-gen/main.go -i k8s.io/gengo/examples/set-gen/sets/types -o ./examples/set-gen/sets --verify-only + - go run ./examples/import-boss/main.go -i k8s.io/gengo/... --verify-only diff --git a/discovery/vendor/k8s.io/gengo/args/args_test.go b/discovery/vendor/k8s.io/gengo/args/args_test.go new file mode 100644 index 00000000..3e85447f --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/args/args_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "testing" + + "k8s.io/gengo/types" +) + +func TestInputIncludes(t *testing.T) { + a := &GeneratorArgs{ + InputDirs: []string{"a/b/..."}, + } + if !a.InputIncludes(&types.Package{Path: "a/b/c"}) { + t.Errorf("Expected /... syntax to work") + } + if a.InputIncludes(&types.Package{Path: "a/c/b"}) { + t.Errorf("Expected correctness") + } +} diff --git a/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy_test.go b/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy_test.go new file mode 100644 index 00000000..71cc23c9 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy_test.go @@ -0,0 +1,398 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "reflect" + "testing" + + "k8s.io/gengo/types" +) + +func Test_isRootedUnder(t *testing.T) { + testCases := []struct { + path string + roots []string + expect bool + }{ + { + path: "/foo/bar", + roots: nil, + expect: false, + }, + { + path: "/foo/bar", + roots: []string{}, + expect: false, + }, + { + path: "/foo/bar", + roots: []string{ + "/bad", + }, + expect: false, + }, + { + path: "/foo/bar", + roots: []string{ + "/foo", + }, + expect: true, + }, + { + path: "/foo/bar", + roots: []string{ + "/bad", + "/foo", + }, + expect: true, + }, + { + path: "/foo/bar/qux/zorb", + roots: []string{ + "/foo/bar/qux", + }, + expect: true, + }, + { + path: "/foo/bar", + roots: []string{ + "/foo/bar", + }, + expect: true, + }, + { + path: "/foo/barn", + roots: []string{ + "/foo/bar", + }, + expect: false, + }, + { + path: "/foo/bar", + roots: []string{ + "/foo/barn", + }, + expect: false, + }, + { + path: "/foo/bar", + roots: []string{ + "", + }, + expect: true, + }, + } + + for i, tc := range testCases { + r := isRootedUnder(tc.path, tc.roots) + if r != tc.expect { + t.Errorf("case[%d]: expected %t, got %t for %q in %q", i, tc.expect, r, tc.path, tc.roots) + } + } +} + +func Test_hasDeepCopyMethod(t *testing.T) { + testCases := []struct { + typ types.Type + expect bool + }{ + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + // No DeepCopy method. + Methods: map[string]*types.Type{}, + }, + expect: false, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // No DeepCopy method. + "method": { + Name: types.Name{Package: "pkgname", Name: "func()"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{}, + Results: []*types.Type{}, + }, + }, + }, + }, + expect: false, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // Wrong signature (no result). + "DeepCopy": { + Name: types.Name{Package: "pkgname", Name: "func()"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{}, + Results: []*types.Type{}, + }, + }, + }, + }, + expect: false, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // Wrong signature (wrong result). + "DeepCopy": { + Name: types.Name{Package: "pkgname", Name: "func() int"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{}, + Results: []*types.Type{ + { + Name: types.Name{Name: "int"}, + Kind: types.Builtin, + }, + }, + }, + }, + }, + }, + expect: false, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // Correct signature. + "DeepCopy": { + Name: types.Name{Package: "pkgname", Name: "func() pkgname.typename"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{}, + Results: []*types.Type{ + { + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + }, + }, + }, + }, + }, + }, + expect: true, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // Wrong signature (has params). + "DeepCopy": { + Name: types.Name{Package: "pkgname", Name: "func(int) pkgname.typename"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{ + { + Name: types.Name{Name: "int"}, + Kind: types.Builtin, + }, + }, + Results: []*types.Type{ + { + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + }, + }, + }, + }, + }, + }, + expect: false, + }, + { + typ: types.Type{ + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + Methods: map[string]*types.Type{ + // Wrong signature (extra results). + "DeepCopy": { + Name: types.Name{Package: "pkgname", Name: "func() (pkgname.typename, int)"}, + Kind: types.Func, + Signature: &types.Signature{ + Parameters: []*types.Type{}, + Results: []*types.Type{ + { + Name: types.Name{Package: "pkgname", Name: "typename"}, + Kind: types.Builtin, + }, + { + Name: types.Name{Name: "int"}, + Kind: types.Builtin, + }, + }, + }, + }, + }, + }, + expect: false, + }, + } + + for i, tc := range testCases { + r := hasDeepCopyMethod(&tc.typ) + if r != tc.expect { + t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r) + } + } +} + +func Test_extractTagParams(t *testing.T) { + testCases := []struct { + comments []string + expect *tagValue + }{ + { + comments: []string{ + "Human comment", + }, + expect: nil, + }, + { + comments: []string{ + "Human comment", + "+k8s:deepcopy-gen", + }, + expect: &tagValue{ + value: "", + register: false, + }, + }, + { + comments: []string{ + "Human comment", + "+k8s:deepcopy-gen=package", + }, + expect: &tagValue{ + value: "package", + register: false, + }, + }, + { + comments: []string{ + "Human comment", + "+k8s:deepcopy-gen=package,register", + }, + expect: &tagValue{ + value: "package", + register: true, + }, + }, + { + comments: []string{ + "Human comment", + "+k8s:deepcopy-gen=package,register=true", + }, + expect: &tagValue{ + value: "package", + register: true, + }, + }, + { + comments: []string{ + "Human comment", + "+k8s:deepcopy-gen=package,register=false", + }, + expect: &tagValue{ + value: "package", + register: false, + }, + }, + } + + for i, tc := range testCases { + r := extractTag(tc.comments) + if r == nil && tc.expect != nil { + t.Errorf("case[%d]: expected non-nil", i) + } + if r != nil && tc.expect == nil { + t.Errorf("case[%d]: expected nil, got %v", i, *r) + } + if r != nil && *r != *tc.expect { + t.Errorf("case[%d]: expected %v, got %v", i, *tc.expect, *r) + } + } +} + +func Test_extractInterfacesTag(t *testing.T) { + testCases := []struct { + comments []string + expect []string + }{ + { + comments: []string{}, + expect: nil, + }, + { + comments: []string{ + "+k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.Object", + }, + expect: []string{ + "k8s.io/kubernetes/runtime.Object", + }, + }, + { + comments: []string{ + "+k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.Object", + "+k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.List", + }, + expect: []string{ + "k8s.io/kubernetes/runtime.Object", + "k8s.io/kubernetes/runtime.List", + }, + }, + { + comments: []string{ + "+k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.Object", + "+k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.Object", + }, + expect: []string{ + "k8s.io/kubernetes/runtime.Object", + "k8s.io/kubernetes/runtime.Object", + }, + }, + } + + for i, tc := range testCases { + r := extractInterfacesTag(tc.comments) + if r == nil && tc.expect != nil { + t.Errorf("case[%d]: expected non-nil", i) + } + if r != nil && tc.expect == nil { + t.Errorf("case[%d]: expected nil, got %v", i, r) + } + if r != nil && !reflect.DeepEqual(r, tc.expect) { + t.Errorf("case[%d]: expected %v, got %v", i, tc.expect, r) + } + } +} \ No newline at end of file diff --git a/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go b/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go new file mode 100644 index 00000000..27900401 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go @@ -0,0 +1,145 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package wholepkg + +import ( + "reflect" + "testing" + + fuzz "github.com/google/gofuzz" +) + +func TestDeepCopyPrimitives(t *testing.T) { + x := Struct_Primitives{} + y := Struct_Primitives{} + + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal to start, but are not") + } + + fuzzer := fuzz.New() + fuzzer.Fuzz(&x) + fuzzer.Fuzz(&y) + + if reflect.DeepEqual(&x, &y) { + t.Errorf("objects should not be equal, but are") + } + + x.DeepCopyInto(&y) + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal, but are not") + } +} + +func TestDeepCopyInterfaceFields(t *testing.T) { + x := Struct_Interfaces{} + y := Struct_Interfaces{} + + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal to start, but are not") + } + + fuzzer := fuzz.New() + + obj := Struct_ExplicitObject{} + fuzzer.Fuzz(&obj) + x.ObjectField = &obj + + sel := Struct_ExplicitSelectorExplicitObject{} + fuzzer.Fuzz(&sel) + x.SelectorField = &sel + + if reflect.DeepEqual(&x, &y) { + t.Errorf("objects should not be equal, but are") + } + + x.DeepCopyInto(&y) + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal, but are not") + } +} + +func TestNilCopy(t *testing.T) { + var x *Struct_B + y := x.DeepCopy() + if y != nil { + t.Errorf("Expected nil as deepcopy of nil, got %+v", y) + } +} + +func assertMethod(t *testing.T, typ reflect.Type, name string) { + if _, found := typ.MethodByName(name); !found { + t.Errorf("Struct_ExplicitObject must have %v method", name) + } +} + +func assertNotMethod(t *testing.T, typ reflect.Type, name string) { + if _, found := typ.MethodByName(name); found { + t.Errorf("%v must not have %v method", typ, name) + } +} + +func TestInterfaceTypes(t *testing.T) { + explicitObject := reflect.TypeOf(&Struct_ExplicitObject{}) + assertMethod(t, explicitObject, "DeepCopyObject") + + typeMeta := reflect.TypeOf(&Struct_TypeMeta{}) + assertNotMethod(t, typeMeta, "DeepCopy") + + objectAndList := reflect.TypeOf(&Struct_ObjectAndList{}) + assertMethod(t, objectAndList, "DeepCopyObject") + assertMethod(t, objectAndList, "DeepCopyList") + + objectAndObject := reflect.TypeOf(&Struct_ObjectAndObject{}) + assertMethod(t, objectAndObject, "DeepCopyObject") + + explicitSelectorExplicitObject := reflect.TypeOf(&Struct_ExplicitSelectorExplicitObject{}) + assertMethod(t, explicitSelectorExplicitObject, "DeepCopySelector") + assertMethod(t, explicitSelectorExplicitObject, "DeepCopyObject") +} + +func TestInterfaceDeepCopy(t *testing.T) { + x := Struct_ExplicitObject{} + + fuzzer := fuzz.New() + fuzzer.Fuzz(&x) + + y_obj := x.DeepCopyObject() + y, ok := y_obj.(*Struct_ExplicitObject) + if !ok { + t.Fatalf("epxected Struct_ExplicitObject from Struct_ExplicitObject.DeepCopyObject, got: %t", y_obj) + } + if !reflect.DeepEqual(y, &x) { + t.Error("objects should be equal, but are not") + } +} + +func TestInterfaceNonPointerDeepCopy(t *testing.T) { + x := Struct_NonPointerExplicitObject{} + + fuzzer := fuzz.New() + fuzzer.Fuzz(&x) + + y_obj := x.DeepCopyObject() + y, ok := y_obj.(Struct_NonPointerExplicitObject) + if !ok { + t.Fatalf("epxected Struct_NonPointerExplicitObject from Struct_NonPointerExplicitObject.DeepCopyObject, got: %t", y_obj) + } + if !reflect.DeepEqual(y, x) { + t.Error("objects should be equal, but are not") + } +} diff --git a/discovery/vendor/k8s.io/gengo/examples/go-to-protobuf/protobuf/namer_test.go b/discovery/vendor/k8s.io/gengo/examples/go-to-protobuf/protobuf/namer_test.go new file mode 100644 index 00000000..0ee71f80 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/examples/go-to-protobuf/protobuf/namer_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package protobuf + +import "testing" + +func TestProtoSafePackage(t *testing.T) { + tests := []struct { + pkg string + expected string + }{ + { + pkg: "foo", + expected: "foo", + }, + { + pkg: "foo/bar", + expected: "foo.bar", + }, + { + pkg: "foo/bar/baz", + expected: "foo.bar.baz", + }, + { + pkg: "foo/bar-baz/x/y-z/q", + expected: "foo.bar_baz.x.y_z.q", + }, + } + + for _, test := range tests { + actual := protoSafePackage(test.pkg) + if e, a := test.expected, actual; e != a { + t.Errorf("%s: expected %s, got %s", test.pkg, e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/examples/import-boss/generators/import_restrict_test.go b/discovery/vendor/k8s.io/gengo/examples/import-boss/generators/import_restrict_test.go new file mode 100644 index 00000000..0d21024e --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/examples/import-boss/generators/import_restrict_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "testing" +) + +func TestRemoveLastDir(t *testing.T) { + table := map[string]struct{ newPath, removedDir string }{ + "a/b/c": {"a/c", "b"}, + } + for input, expect := range table { + gotPath, gotRemoved := removeLastDir(input) + if e, a := expect.newPath, gotPath; e != a { + t.Errorf("%v: wanted %v, got %v", input, e, a) + } + if e, a := expect.removedDir, gotRemoved; e != a { + t.Errorf("%v: wanted %v, got %v", input, e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/examples/set-gen/sets/set_test.go b/discovery/vendor/k8s.io/gengo/examples/set-gen/sets/set_test.go new file mode 100644 index 00000000..df722ec2 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/examples/set-gen/sets/set_test.go @@ -0,0 +1,270 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sets + +import ( + "reflect" + "testing" +) + +func TestStringSet(t *testing.T) { + s := String{} + s2 := String{} + if len(s) != 0 { + t.Errorf("Expected len=0: %d", len(s)) + } + s.Insert("a", "b") + if len(s) != 2 { + t.Errorf("Expected len=2: %d", len(s)) + } + s.Insert("c") + if s.Has("d") { + t.Errorf("Unexpected contents: %#v", s) + } + if !s.Has("a") { + t.Errorf("Missing contents: %#v", s) + } + s.Delete("a") + if s.Has("a") { + t.Errorf("Unexpected contents: %#v", s) + } + s.Insert("a") + if s.HasAll("a", "b", "d") { + t.Errorf("Unexpected contents: %#v", s) + } + if !s.HasAll("a", "b") { + t.Errorf("Missing contents: %#v", s) + } + s2.Insert("a", "b", "d") + if s.IsSuperset(s2) { + t.Errorf("Unexpected contents: %#v", s) + } + s2.Delete("d") + if !s.IsSuperset(s2) { + t.Errorf("Missing contents: %#v", s) + } +} + +func TestStringSetDeleteMultiples(t *testing.T) { + s := String{} + s.Insert("a", "b", "c") + if len(s) != 3 { + t.Errorf("Expected len=3: %d", len(s)) + } + + s.Delete("a", "c") + if len(s) != 1 { + t.Errorf("Expected len=1: %d", len(s)) + } + if s.Has("a") { + t.Errorf("Unexpected contents: %#v", s) + } + if s.Has("c") { + t.Errorf("Unexpected contents: %#v", s) + } + if !s.Has("b") { + t.Errorf("Missing contents: %#v", s) + } + +} + +func TestNewStringSet(t *testing.T) { + s := NewString("a", "b", "c") + if len(s) != 3 { + t.Errorf("Expected len=3: %d", len(s)) + } + if !s.Has("a") || !s.Has("b") || !s.Has("c") { + t.Errorf("Unexpected contents: %#v", s) + } +} + +func TestStringSetList(t *testing.T) { + s := NewString("z", "y", "x", "a") + if !reflect.DeepEqual(s.List(), []string{"a", "x", "y", "z"}) { + t.Errorf("List gave unexpected result: %#v", s.List()) + } +} + +func TestStringSetDifference(t *testing.T) { + a := NewString("1", "2", "3") + b := NewString("1", "2", "4", "5") + c := a.Difference(b) + d := b.Difference(a) + if len(c) != 1 { + t.Errorf("Expected len=1: %d", len(c)) + } + if !c.Has("3") { + t.Errorf("Unexpected contents: %#v", c.List()) + } + if len(d) != 2 { + t.Errorf("Expected len=2: %d", len(d)) + } + if !d.Has("4") || !d.Has("5") { + t.Errorf("Unexpected contents: %#v", d.List()) + } +} + +func TestStringSetHasAny(t *testing.T) { + a := NewString("1", "2", "3") + + if !a.HasAny("1", "4") { + t.Errorf("expected true, got false") + } + + if a.HasAny("0", "4") { + t.Errorf("expected false, got true") + } +} + +func TestStringSetEquals(t *testing.T) { + // Simple case (order doesn't matter) + a := NewString("1", "2") + b := NewString("2", "1") + if !a.Equal(b) { + t.Errorf("Expected to be equal: %v vs %v", a, b) + } + + // It is a set; duplicates are ignored + b = NewString("2", "2", "1") + if !a.Equal(b) { + t.Errorf("Expected to be equal: %v vs %v", a, b) + } + + // Edge cases around empty sets / empty strings + a = NewString() + b = NewString() + if !a.Equal(b) { + t.Errorf("Expected to be equal: %v vs %v", a, b) + } + + b = NewString("1", "2", "3") + if a.Equal(b) { + t.Errorf("Expected to be not-equal: %v vs %v", a, b) + } + + b = NewString("1", "2", "") + if a.Equal(b) { + t.Errorf("Expected to be not-equal: %v vs %v", a, b) + } + + // Check for equality after mutation + a = NewString() + a.Insert("1") + if a.Equal(b) { + t.Errorf("Expected to be not-equal: %v vs %v", a, b) + } + + a.Insert("2") + if a.Equal(b) { + t.Errorf("Expected to be not-equal: %v vs %v", a, b) + } + + a.Insert("") + if !a.Equal(b) { + t.Errorf("Expected to be equal: %v vs %v", a, b) + } + + a.Delete("") + if a.Equal(b) { + t.Errorf("Expected to be not-equal: %v vs %v", a, b) + } +} + +func TestStringUnion(t *testing.T) { + tests := []struct { + s1 String + s2 String + expected String + }{ + { + NewString("1", "2", "3", "4"), + NewString("3", "4", "5", "6"), + NewString("1", "2", "3", "4", "5", "6"), + }, + { + NewString("1", "2", "3", "4"), + NewString(), + NewString("1", "2", "3", "4"), + }, + { + NewString(), + NewString("1", "2", "3", "4"), + NewString("1", "2", "3", "4"), + }, + { + NewString(), + NewString(), + NewString(), + }, + } + + for _, test := range tests { + union := test.s1.Union(test.s2) + if union.Len() != test.expected.Len() { + t.Errorf("Expected union.Len()=%d but got %d", test.expected.Len(), union.Len()) + } + + if !union.Equal(test.expected) { + t.Errorf("Expected union.Equal(expected) but not true. union:%v expected:%v", union.List(), test.expected.List()) + } + } +} + +func TestStringIntersection(t *testing.T) { + tests := []struct { + s1 String + s2 String + expected String + }{ + { + NewString("1", "2", "3", "4"), + NewString("3", "4", "5", "6"), + NewString("3", "4"), + }, + { + NewString("1", "2", "3", "4"), + NewString("1", "2", "3", "4"), + NewString("1", "2", "3", "4"), + }, + { + NewString("1", "2", "3", "4"), + NewString(), + NewString(), + }, + { + NewString(), + NewString("1", "2", "3", "4"), + NewString(), + }, + { + NewString(), + NewString(), + NewString(), + }, + } + + for _, test := range tests { + intersection := test.s1.Intersection(test.s2) + if intersection.Len() != test.expected.Len() { + t.Errorf("Expected intersection.Len()=%d but got %d", test.expected.Len(), intersection.Len()) + } + + if !intersection.Equal(test.expected) { + t.Errorf("Expected intersection.Equal(expected) but not true. intersection:%v expected:%v", intersection.List(), test.expected.List()) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/generator/snippet_writer_test.go b/discovery/vendor/k8s.io/gengo/generator/snippet_writer_test.go new file mode 100644 index 00000000..04649414 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/generator/snippet_writer_test.go @@ -0,0 +1,88 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generator_test + +import ( + "bytes" + "strings" + "testing" + + "k8s.io/gengo/generator" + "k8s.io/gengo/namer" + "k8s.io/gengo/parser" +) + +func construct(t *testing.T, files map[string]string) *generator.Context { + b := parser.New() + for name, src := range files { + if err := b.AddFileForTest("/tmp/"+name, name, []byte(src)); err != nil { + t.Fatal(err) + } + } + c, err := generator.NewContext(b, namer.NameSystems{ + "public": namer.NewPublicNamer(0), + "private": namer.NewPrivateNamer(0), + }, "public") + if err != nil { + t.Fatal(err) + } + return c +} + +func TestSnippetWriter(t *testing.T) { + var structTest = map[string]string{ + "base/foo/proto/foo.go": ` +package foo + +// Blah is a test. +// A test, I tell you. +type Blah struct { + // A is the first field. + A int64 ` + "`" + `json:"a"` + "`" + ` + + // B is the second field. + // Multiline comments work. + B string ` + "`" + `json:"b"` + "`" + ` +} +`, + } + + c := construct(t, structTest) + b := &bytes.Buffer{} + err := generator.NewSnippetWriter(b, c, "$", "$"). + Do("$.|public$$.|private$", c.Order[0]). + Error() + if err != nil { + t.Errorf("Unexpected error %v", err) + } + if e, a := "Blahblah", b.String(); e != a { + t.Errorf("Expected %q, got %q", e, a) + } + + err = generator.NewSnippetWriter(b, c, "$", "$"). + Do("$.|public", c.Order[0]). + Error() + if err == nil { + t.Errorf("expected error on invalid template") + } else { + // Dear reader, I apologize for making the worst change + // detection test in the history of ever. + if e, a := "snippet_writer_test.go", err.Error(); !strings.Contains(a, e) { + t.Errorf("Expected %q but didn't find it in %q", e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/namer/namer_test.go b/discovery/vendor/k8s.io/gengo/namer/namer_test.go new file mode 100644 index 00000000..fd5ca636 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/namer/namer_test.go @@ -0,0 +1,100 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package namer + +import ( + "reflect" + "testing" + + "k8s.io/gengo/types" +) + +func TestNameStrategy(t *testing.T) { + u := types.Universe{} + + // Add some types. + base := u.Type(types.Name{Package: "foo/bar", Name: "Baz"}) + base.Kind = types.Struct + + tmp := u.Type(types.Name{Package: "", Name: "[]bar.Baz"}) + tmp.Kind = types.Slice + tmp.Elem = base + + tmp = u.Type(types.Name{Package: "", Name: "map[string]bar.Baz"}) + tmp.Kind = types.Map + tmp.Key = types.String + tmp.Elem = base + + tmp = u.Type(types.Name{Package: "foo/other", Name: "Baz"}) + tmp.Kind = types.Struct + tmp.Members = []types.Member{{ + Embedded: true, + Type: base, + }} + + tmp = u.Type(types.Name{Package: "", Name: "chan Baz"}) + tmp.Kind = types.Chan + tmp.Elem = base + + u.Type(types.Name{Package: "", Name: "string"}) + + o := Orderer{NewPublicNamer(0)} + order := o.OrderUniverse(u) + orderedNames := make([]string, len(order)) + for i, t := range order { + orderedNames[i] = o.Name(t) + } + expect := []string{"Baz", "Baz", "ChanBaz", "MapStringToBaz", "SliceBaz", "String"} + if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) { + t.Errorf("Wanted %#v, got %#v", e, a) + } + + o = Orderer{NewRawNamer("my/package", nil)} + order = o.OrderUniverse(u) + orderedNames = make([]string, len(order)) + for i, t := range order { + orderedNames[i] = o.Name(t) + } + + expect = []string{"[]bar.Baz", "bar.Baz", "chan bar.Baz", "map[string]bar.Baz", "other.Baz", "string"} + if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) { + t.Errorf("Wanted %#v, got %#v", e, a) + } + + o = Orderer{NewRawNamer("foo/bar", nil)} + order = o.OrderUniverse(u) + orderedNames = make([]string, len(order)) + for i, t := range order { + orderedNames[i] = o.Name(t) + } + + expect = []string{"Baz", "[]Baz", "chan Baz", "map[string]Baz", "other.Baz", "string"} + if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) { + t.Errorf("Wanted %#v, got %#v", e, a) + } + + o = Orderer{NewPublicNamer(1)} + order = o.OrderUniverse(u) + orderedNames = make([]string, len(order)) + for i, t := range order { + orderedNames[i] = o.Name(t) + } + expect = []string{"BarBaz", "ChanBarBaz", "MapStringToBarBaz", "OtherBaz", "SliceBarBaz", "String"} + if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) { + t.Errorf("Wanted %#v, got %#v", e, a) + } +} diff --git a/discovery/vendor/k8s.io/gengo/namer/plural_namer_test.go b/discovery/vendor/k8s.io/gengo/namer/plural_namer_test.go new file mode 100644 index 00000000..418cd7f7 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/namer/plural_namer_test.go @@ -0,0 +1,68 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package namer + +import ( + "testing" + + "k8s.io/gengo/types" +) + +func TestPluralNamer(t *testing.T) { + exceptions := map[string]string{ + // The type name is already in the plural form + "Endpoints": "endpoints", + } + public := NewPublicPluralNamer(exceptions) + private := NewPrivatePluralNamer(exceptions) + + cases := []struct { + typeName string + expectedPrivate string + expectedPublic string + }{ + { + "Pod", + "pods", + "Pods", + }, + { + "Entry", + "entries", + "Entries", + }, + { + "Endpoints", + "endpoints", + "Endpoints", + }, + { + "Bus", + "buses", + "Buses", + }, + } + for _, c := range cases { + testType := &types.Type{Name: types.Name{Name: c.typeName}} + if e, a := c.expectedPrivate, private.Name(testType); e != a { + t.Errorf("Unexpected result from private plural namer. Expected: %s, Got: %s", e, a) + } + if e, a := c.expectedPublic, public.Name(testType); e != a { + t.Errorf("Unexpected result from public plural namer. Expected: %s, Got: %s", e, a) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/parser/local_parse_test.go b/discovery/vendor/k8s.io/gengo/parser/local_parse_test.go new file mode 100644 index 00000000..851fc7da --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/parser/local_parse_test.go @@ -0,0 +1,68 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parser + +import ( + "testing" +) + +func TestImportBuildPackage(t *testing.T) { + b := New() + if _, err := b.importBuildPackage("fake/dep"); err != nil { + t.Fatal(err) + } + if _, ok := b.buildPackages["fake/dep"]; !ok { + t.Errorf("missing expected, but got %v", b.buildPackages) + } + + if len(b.buildPackages) > 1 { + // this would happen if the canonicalization failed to normalize the path + // you'd get a k8s.io/gengo/vendor/fake/dep key too + t.Errorf("missing one, but got %v", b.buildPackages) + } +} + +func TestCanonicalizeImportPath(t *testing.T) { + tcs := []struct { + name string + input string + output string + }{ + { + name: "passthrough", + input: "github.com/foo/bar", + output: "github.com/foo/bar", + }, + { + name: "simple", + input: "github.com/foo/vendor/k8s.io/kubernetes/pkg/api", + output: "k8s.io/kubernetes/pkg/api", + }, + { + name: "deeper", + input: "github.com/foo/bar/vendor/k8s.io/kubernetes/pkg/api", + output: "k8s.io/kubernetes/pkg/api", + }, + } + + for _, tc := range tcs { + actual := canonicalizeImportPath(tc.input) + if string(actual) != tc.output { + t.Errorf("%v: expected %q got %q", tc.name, tc.output, actual) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/parser/parse_test.go b/discovery/vendor/k8s.io/gengo/parser/parse_test.go new file mode 100644 index 00000000..6212682c --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/parser/parse_test.go @@ -0,0 +1,458 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parser_test + +import ( + "bytes" + "path/filepath" + "reflect" + "testing" + "text/template" + + "k8s.io/gengo/args" + "k8s.io/gengo/namer" + "k8s.io/gengo/parser" + "k8s.io/gengo/types" +) + +func TestRecursive(t *testing.T) { + d := args.Default() + d.InputDirs = []string{"k8s.io/gengo/testdata/a/..."} + b, err := d.NewBuilder() + if err != nil { + t.Fatalf("Fail making builder: %v", err) + } + _, err = b.FindTypes() + if err != nil { + t.Fatalf("Fail finding types: %v", err) + } + foundB := false + for _, p := range b.FindPackages() { + t.Logf("Package: %v", p) + if p == "k8s.io/gengo/testdata/a/b" { + foundB = true + } + } + if !foundB { + t.Errorf("Expected to find packages a and b") + } +} + +type file struct { + path string + contents string +} + +// Pass files in topological order - deps first! +func construct(t *testing.T, files []file, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) { + b := parser.New() + for _, f := range files { + if err := b.AddFileForTest(filepath.Dir(f.path), f.path, []byte(f.contents)); err != nil { + t.Fatal(err) + } + } + u, err := b.FindTypes() + if err != nil { + t.Fatal(err) + } + orderer := namer.Orderer{Namer: testNamer} + o := orderer.OrderUniverse(u) + return b, u, o +} + +func TestBuilder(t *testing.T) { + var testFiles = []file{ + { + path: "base/common/proto/common.go", contents: ` + package common + + type Object struct { + ID int64 + } + `, + }, { + path: "base/foo/proto/foo.go", contents: ` + package foo + + import ( + "base/common/proto" + ) + + type Blah struct { + common.Object + Count int64 + Frobbers map[string]*Frobber + Baz []Object + Nickname *string + NumberIsAFavorite map[int]bool + } + + type Frobber struct { + Name string + Amount int64 + } + + type Object struct { + common.Object + } + + func AFunc(obj1 common.Object, obj2 Object) Frobber { + } + + var AVar Frobber + + var ( + AnotherVar = Frobber{} + ) + `, + }, + } + + var tmplText = ` +package o +{{define "Struct"}}type {{Name .}} interface { {{range $m := .Members}}{{$n := Name $m.Type}} + {{if $m.Embedded}}{{$n}}{{else}}{{$m.Name}}() {{$n}}{{if $m.Type.Elem}}{{else}} + Set{{$m.Name}}({{$n}}){{end}}{{end}}{{end}} +} + +{{end}} +{{define "Func"}}{{$s := .Underlying.Signature}}var {{Name .}} func({{range $index,$elem := $s.Parameters}}{{if $index}}, {{end}}{{Raw $elem}}{{end}}) {{if $s.Results|len |gt 1}}({{end}}{{range $index,$elem := $s.Results}}{{if $index}}, {{end}}{{Raw .}}{{end}}{{if $s.Results|len |gt 1}}){{end}} = {{Raw .}} + +{{end}} +{{define "Var"}}{{$t := .Underlying}}var {{Name .}} {{Raw $t}} = {{Raw .}} + +{{end}} +{{range $t := .}}{{if eq $t.Kind "Struct"}}{{template "Struct" $t}}{{end}}{{end}} +{{range $t := .}}{{if eq $t.Kind "DeclarationOf"}}{{if eq $t.Underlying.Kind "Func"}}{{template "Func" $t}}{{end}}{{end}}{{end}} +{{range $t := .}}{{if eq $t.Kind "DeclarationOf"}}{{if ne $t.Underlying.Kind "Func"}}{{template "Var" $t}}{{end}}{{end}}{{end}}` + + var expect = ` +package o + + + +type CommonObject interface { + ID() Int64 + SetID(Int64) +} + +type FooBlah interface { + CommonObject + Count() Int64 + SetCount(Int64) + Frobbers() MapStringToPointerFooFrobber + Baz() SliceFooObject + Nickname() PointerString + NumberIsAFavorite() MapIntToBool +} + +type FooFrobber interface { + Name() String + SetName(String) + Amount() Int64 + SetAmount(Int64) +} + +type FooObject interface { + CommonObject +} + + +var FooAFunc func(proto.Object, proto.Object) proto.Frobber = proto.AFunc + + +var FooAVar proto.Frobber = proto.AVar + +var FooAnotherVar proto.Frobber = proto.AnotherVar + +` + testNamer := namer.NewPublicNamer(1, "proto") + rawNamer := namer.NewRawNamer("o", nil) + _, u, o := construct(t, testFiles, testNamer) + t.Logf("\n%v\n\n", o) + args := map[string]interface{}{ + "Name": testNamer.Name, + "Raw": rawNamer.Name, + } + tmpl := template.Must( + template.New(""). + Funcs(args). + Parse(tmplText), + ) + buf := &bytes.Buffer{} + tmpl.Execute(buf, o) + if e, a := expect, buf.String(); e != a { + t.Errorf("Wanted, got:\n%v\n-----\n%v\n", e, a) + } + if p := u.Package("base/foo/proto"); !p.HasImport("base/common/proto") { + t.Errorf("Unexpected lack of import line: %s", p.Imports) + } +} + +func TestStructParse(t *testing.T) { + var structTest = file{ + path: "base/foo/proto/foo.go", + contents: ` + package foo + + // Blah is a test. + // A test, I tell you. + type Blah struct { + // A is the first field. + A int64 ` + "`" + `json:"a"` + "`" + ` + + // B is the second field. + // Multiline comments work. + B string ` + "`" + `json:"b"` + "`" + ` + } + `, + } + + _, u, o := construct(t, []file{structTest}, namer.NewPublicNamer(0)) + t.Logf("%#v", o) + blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"}) + if blahT == nil { + t.Fatal("type not found") + } + if e, a := types.Struct, blahT.Kind; e != a { + t.Errorf("struct kind wrong, wanted %v, got %v", e, a) + } + if e, a := []string{"Blah is a test.", "A test, I tell you."}, blahT.CommentLines; !reflect.DeepEqual(e, a) { + t.Errorf("struct comment wrong, wanted %q, got %q", e, a) + } + m := types.Member{ + Name: "B", + Embedded: false, + CommentLines: []string{"B is the second field.", "Multiline comments work."}, + Tags: `json:"b"`, + Type: types.String, + } + if e, a := m, blahT.Members[1]; !reflect.DeepEqual(e, a) { + t.Errorf("wanted, got:\n%#v\n%#v", e, a) + } +} + +func TestParseSecondClosestCommentLines(t *testing.T) { + const fileName = "base/foo/proto/foo.go" + testCases := []struct { + testFile file + expected []string + }{ + { + testFile: file{ + path: fileName, contents: ` + package foo + // Blah's SecondClosestCommentLines. + // Another line. + + // Blah is a test. + // A test, I tell you. + type Blah struct { + a int + } + `}, + expected: []string{"Blah's SecondClosestCommentLines.", "Another line."}, + }, + { + testFile: file{ + path: fileName, contents: ` + package foo + // Blah's SecondClosestCommentLines. + // Another line. + + type Blah struct { + a int + } + `}, + expected: []string{"Blah's SecondClosestCommentLines.", "Another line."}, + }, + } + for _, test := range testCases { + _, u, o := construct(t, []file{test.testFile}, namer.NewPublicNamer(0)) + t.Logf("%#v", o) + blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"}) + if e, a := test.expected, blahT.SecondClosestCommentLines; !reflect.DeepEqual(e, a) { + t.Errorf("struct second closest comment wrong, wanted %q, got %q", e, a) + } + } +} + +func TestTypeKindParse(t *testing.T) { + var testFiles = []file{ + {path: "a/foo.go", contents: "package a\ntype Test string\n"}, + {path: "b/foo.go", contents: "package b\ntype Test map[int]string\n"}, + {path: "c/foo.go", contents: "package c\ntype Test []string\n"}, + {path: "d/foo.go", contents: "package d\ntype Test struct{a int; b struct{a int}; c map[int]string; d *string}\n"}, + {path: "e/foo.go", contents: "package e\ntype Test *string\n"}, + {path: "f/foo.go", contents: ` + package f + import ( + "a" + "b" + ) + type Test []a.Test + type Test2 *a.Test + type Test3 map[a.Test]b.Test + type Test4 struct { + a struct {a a.Test; b b.Test} + b map[a.Test]b.Test + c *a.Test + d []a.Test + e []string + } + `}, + {path: "g/foo.go", contents: ` + package g + type Test func(a, b string) (c, d string) + func (t Test) Method(a, b string) (c, d string) { return t(a, b) } + type Interface interface{Method(a, b string) (c, d string)} + `}, + } + + // Check that the right types are found, and the namers give the expected names. + + assertions := []struct { + Package, Name string + k types.Kind + names []string + }{ + { + Package: "a", Name: "Test", k: types.Alias, + names: []string{"Test", "ATest", "test", "aTest", "a.Test"}, + }, + { + Package: "b", Name: "Test", k: types.Map, + names: []string{"Test", "BTest", "test", "bTest", "b.Test"}, + }, + { + Package: "c", Name: "Test", k: types.Slice, + names: []string{"Test", "CTest", "test", "cTest", "c.Test"}, + }, + { + Package: "d", Name: "Test", k: types.Struct, + names: []string{"Test", "DTest", "test", "dTest", "d.Test"}, + }, + { + Package: "e", Name: "Test", k: types.Pointer, + names: []string{"Test", "ETest", "test", "eTest", "e.Test"}, + }, + { + Package: "f", Name: "Test", k: types.Slice, + names: []string{"Test", "FTest", "test", "fTest", "f.Test"}, + }, + { + Package: "g", Name: "Test", k: types.Func, + names: []string{"Test", "GTest", "test", "gTest", "g.Test"}, + }, + { + Package: "g", Name: "Interface", k: types.Interface, + names: []string{"Interface", "GInterface", "interface", "gInterface", "g.Interface"}, + }, + { + Package: "", Name: "string", k: types.Builtin, + names: []string{"String", "String", "string", "string", "string"}, + }, + { + Package: "", Name: "int", k: types.Builtin, + names: []string{"Int", "Int", "int", "int", "int"}, + }, + { + Package: "", Name: "struct{a int}", k: types.Struct, + names: []string{"StructInt", "StructInt", "structInt", "structInt", "struct{a int}"}, + }, + { + Package: "", Name: "struct{a a.Test; b b.Test}", k: types.Struct, + names: []string{"StructTestTest", "StructATestBTest", "structTestTest", "structATestBTest", "struct{a a.Test; b b.Test}"}, + }, + { + Package: "", Name: "map[int]string", k: types.Map, + names: []string{"MapIntToString", "MapIntToString", "mapIntToString", "mapIntToString", "map[int]string"}, + }, + { + Package: "", Name: "map[a.Test]b.Test", k: types.Map, + names: []string{"MapTestToTest", "MapATestToBTest", "mapTestToTest", "mapATestToBTest", "map[a.Test]b.Test"}, + }, + { + Package: "", Name: "[]string", k: types.Slice, + names: []string{"SliceString", "SliceString", "sliceString", "sliceString", "[]string"}, + }, + { + Package: "", Name: "[]a.Test", k: types.Slice, + names: []string{"SliceTest", "SliceATest", "sliceTest", "sliceATest", "[]a.Test"}, + }, + { + Package: "", Name: "*string", k: types.Pointer, + names: []string{"PointerString", "PointerString", "pointerString", "pointerString", "*string"}, + }, + { + Package: "", Name: "*a.Test", k: types.Pointer, + names: []string{"PointerTest", "PointerATest", "pointerTest", "pointerATest", "*a.Test"}, + }, + } + + namers := []namer.Namer{ + namer.NewPublicNamer(0), + namer.NewPublicNamer(1), + namer.NewPrivateNamer(0), + namer.NewPrivateNamer(1), + namer.NewRawNamer("", nil), + } + + for nameIndex, namer := range namers { + _, u, _ := construct(t, testFiles, namer) + t.Logf("Found types:\n") + for pkgName, pkg := range u { + for typeName, cur := range pkg.Types { + t.Logf("%q-%q: %s %s", pkgName, typeName, cur.Name, cur.Kind) + } + } + t.Logf("\n\n") + + for _, item := range assertions { + n := types.Name{Package: item.Package, Name: item.Name} + thisType := u.Type(n) + if thisType == nil { + t.Errorf("type %s not found", n) + continue + } + underlyingType := thisType + if item.k != types.Alias && thisType.Kind == types.Alias { + underlyingType = thisType.Underlying + if underlyingType == nil { + t.Errorf("underlying type %s not found", n) + continue + } + } + if e, a := item.k, underlyingType.Kind; e != a { + t.Errorf("%v-%s: type kind wrong, wanted %v, got %v (%#v)", nameIndex, n, e, a, underlyingType) + } + if e, a := item.names[nameIndex], namer.Name(thisType); e != a { + t.Errorf("%v-%s: Expected %q, got %q", nameIndex, n, e, a) + } + } + + // Also do some one-off checks + gtest := u.Type(types.Name{Package: "g", Name: "Test"}) + if e, a := 1, len(gtest.Methods); e != a { + t.Errorf("expected %v but found %v methods: %#v", e, a, gtest) + } + iface := u.Type(types.Name{Package: "g", Name: "Interface"}) + if e, a := 1, len(iface.Methods); e != a { + t.Errorf("expected %v but found %v methods: %#v", e, a, iface) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/types/comments_test.go b/discovery/vendor/k8s.io/gengo/types/comments_test.go new file mode 100644 index 00000000..161f4a6e --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/types/comments_test.go @@ -0,0 +1,86 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "reflect" + "strings" + "testing" +) + +func TestExtractCommentTags(t *testing.T) { + commentLines := []string{ + "Human comment that is ignored.", + "+foo=value1", + "+bar", + "+foo=value2", + "+baz=qux,zrb=true", + } + + a := ExtractCommentTags("+", commentLines) + e := map[string][]string{ + "foo": {"value1", "value2"}, + "bar": {""}, + "baz": {"qux,zrb=true"}, + } + if !reflect.DeepEqual(e, a) { + t.Errorf("Wanted %q, got %q", e, a) + } +} + +func TestExtractSingleBoolCommentTag(t *testing.T) { + commentLines := []string{ + "Human comment that is ignored.", + "+TRUE=true", + "+FALSE=false", + "+MULTI=true", + "+MULTI=false", + "+MULTI=multi", + "+NOTBOOL=blue", + "+EMPTY", + } + + testCases := []struct { + key string + def bool + exp bool + err string // if set, ignore exp. + }{ + {"TRUE", false, true, ""}, + {"FALSE", true, false, ""}, + {"MULTI", false, true, ""}, + {"NOTBOOL", false, true, "is not boolean"}, + {"EMPTY", false, true, "is not boolean"}, + {"ABSENT", true, true, ""}, + {"ABSENT", false, false, ""}, + } + + for i, tc := range testCases { + v, err := ExtractSingleBoolCommentTag("+", tc.key, tc.def, commentLines) + if err != nil && tc.err == "" { + t.Errorf("[%d]: unexpected failure: %v", i, err) + } else if err == nil && tc.err != "" { + t.Errorf("[%d]: expected failure: %v", i, tc.err) + } else if err != nil { + if !strings.Contains(err.Error(), tc.err) { + t.Errorf("[%d]: unexpected error: expected %q, got %q", i, tc.err, err) + } + } else if v != tc.exp { + t.Errorf("[%d]: unexpected value: expected %t, got %t", i, tc.exp, v) + } + } +} diff --git a/discovery/vendor/k8s.io/gengo/types/flatten_test.go b/discovery/vendor/k8s.io/gengo/types/flatten_test.go new file mode 100644 index 00000000..9da34e56 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/types/flatten_test.go @@ -0,0 +1,68 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "reflect" + "testing" +) + +func TestFlatten(t *testing.T) { + mapType := &Type{ + Name: Name{Package: "", Name: "map[string]string"}, + Kind: Map, + Key: String, + Elem: String, + } + m := []Member{ + { + Name: "Baz", + Embedded: true, + Type: &Type{ + Name: Name{Package: "pkg", Name: "Baz"}, + Kind: Struct, + Members: []Member{ + {Name: "Foo", Type: String}, + { + Name: "Qux", + Embedded: true, + Type: &Type{ + Name: Name{Package: "pkg", Name: "Qux"}, + Kind: Struct, + Members: []Member{{Name: "Zot", Type: String}}, + }, + }, + }, + }, + }, + {Name: "Bar", Type: String}, + { + Name: "NotSureIfLegal", + Embedded: true, + Type: mapType, + }, + } + e := []Member{ + {Name: "Bar", Type: String}, + {Name: "NotSureIfLegal", Type: mapType, Embedded: true}, + {Name: "Foo", Type: String}, + {Name: "Zot", Type: String}, + } + if a := FlattenMembers(m); !reflect.DeepEqual(e, a) { + t.Errorf("Expected \n%#v\n, got \n%#v\n", e, a) + } +} diff --git a/discovery/vendor/k8s.io/gengo/types/types_test.go b/discovery/vendor/k8s.io/gengo/types/types_test.go new file mode 100644 index 00000000..35cc4d61 --- /dev/null +++ b/discovery/vendor/k8s.io/gengo/types/types_test.go @@ -0,0 +1,210 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "testing" +) + +func TestGetBuiltin(t *testing.T) { + u := Universe{} + if builtinPkg := u.Package(""); builtinPkg.Has("string") { + t.Errorf("Expected builtin package to not have builtins until they're asked for explicitly. %#v", builtinPkg) + } + s := u.Type(Name{Package: "", Name: "string"}) + if s != String { + t.Errorf("Expected canonical string type.") + } + if builtinPkg := u.Package(""); !builtinPkg.Has("string") { + t.Errorf("Expected builtin package to exist and have builtins by default. %#v", builtinPkg) + } + if builtinPkg := u.Package(""); len(builtinPkg.Types) != 1 { + t.Errorf("Expected builtin package to not have builtins until they're asked for explicitly. %#v", builtinPkg) + } +} + +func TestGetMarker(t *testing.T) { + u := Universe{} + n := Name{Package: "path/to/package", Name: "Foo"} + f := u.Type(n) + if f == nil || f.Name != n { + t.Errorf("Expected marker type.") + } +} + +func Test_Type_IsPrimitive(t *testing.T) { + testCases := []struct { + typ Type + expect bool + }{ + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Builtin, + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Alias, + Underlying: &Type{ + Name: Name{Package: "pkgname", Name: "underlying"}, + Kind: Builtin, + }, + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Pointer, + Elem: &Type{ + Name: Name{Package: "pkgname", Name: "pointee"}, + Kind: Builtin, + }, + }, + expect: false, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Struct, + }, + expect: false, + }, + } + + for i, tc := range testCases { + r := tc.typ.IsPrimitive() + if r != tc.expect { + t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r) + } + } +} + +func Test_Type_IsAssignable(t *testing.T) { + testCases := []struct { + typ Type + expect bool + }{ + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Builtin, + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Alias, + Underlying: &Type{ + Name: Name{Package: "pkgname", Name: "underlying"}, + Kind: Builtin, + }, + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Pointer, + Elem: &Type{ + Name: Name{Package: "pkgname", Name: "pointee"}, + Kind: Builtin, + }, + }, + expect: false, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Struct, // Empty struct + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Struct, + Members: []Member{ + { + Name: "m1", + Type: &Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Builtin, + }, + }, + { + Name: "m2", + Type: &Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Alias, + Underlying: &Type{ + Name: Name{Package: "pkgname", Name: "underlying"}, + Kind: Builtin, + }, + }, + }, + { + Name: "m3", + Type: &Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Struct, // Empty struct + }, + }, + }, + }, + expect: true, + }, + { + typ: Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Struct, + Members: []Member{ + { + Name: "m1", + Type: &Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Builtin, + }, + }, + { + Name: "m2", + Type: &Type{ + Name: Name{Package: "pkgname", Name: "typename"}, + Kind: Pointer, + Elem: &Type{ + Name: Name{Package: "pkgname", Name: "pointee"}, + Kind: Builtin, + }, + }, + }, + }, + }, + expect: false, + }, + } + + for i, tc := range testCases { + r := tc.typ.IsAssignable() + if r != tc.expect { + t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r) + } + } +} diff --git a/discovery/vendor/k8s.io/kube-openapi/.travis.yml b/discovery/vendor/k8s.io/kube-openapi/.travis.yml new file mode 100644 index 00000000..996a4df0 --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/.travis.yml @@ -0,0 +1,4 @@ +language: go +go_import_path: k8s.io/kube-openapi +script: go test ./pkg/... + diff --git a/discovery/vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator_test.go b/discovery/vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator_test.go new file mode 100644 index 00000000..51bbb1d9 --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator_test.go @@ -0,0 +1,1099 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package aggregator + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/ghodss/yaml" + "github.com/go-openapi/spec" + "github.com/stretchr/testify/assert" +) + +type DebugSpec struct { + *spec.Swagger +} + +func (d DebugSpec) String() string { + bytes, err := json.MarshalIndent(d.Swagger, "", " ") + if err != nil { + return fmt.Sprintf("DebugSpec.String failed: %s", err) + } + return string(bytes) +} +func TestFilterSpecs(t *testing.T) { + var spec1, spec1_filtered *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test2" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" + Test2: + type: "object" + properties: + other: + $ref: "#/definitions/Other" + Other: + type: "string" +`), &spec1) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &spec1_filtered) + assert := assert.New(t) + FilterSpecByPaths(spec1, []string{"/test"}) + assert.Equal(DebugSpec{spec1_filtered}, DebugSpec{spec1}) +} + +func TestFilterSpecsWithUnusedDefinitions(t *testing.T) { + var spec1, spec1Filtered *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test2" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" + Test2: + type: "object" + properties: + other: + $ref: "#/definitions/Other" + Other: + type: "string" + Unused: + type: "object" +`), &spec1) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" + Unused: + type: "object" +`), &spec1Filtered) + assert := assert.New(t) + FilterSpecByPaths(spec1, []string{"/test"}) + assert.Equal(DebugSpec{spec1Filtered}, DebugSpec{spec1}) +} + +func TestMergeSpecsSimple(t *testing.T) { + var spec1, spec2, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &spec1) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test2" +definitions: + Test2: + type: "object" + properties: + other: + $ref: "#/definitions/Other" + Other: + type: "string" +`), &spec2) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test2" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" + Test2: + type: "object" + properties: + other: + $ref: "#/definitions/Other" + Other: + type: "string" +`), &expected) + assert := assert.New(t) + if !assert.NoError(MergeSpecs(spec1, spec2)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{spec1}) +} + +func TestMergeSpecsReuseModel(t *testing.T) { + var spec1, spec2, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &spec1) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &spec2) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &expected) + assert := assert.New(t) + if !assert.NoError(MergeSpecs(spec1, spec2)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{spec1}) +} + +func TestMergeSpecsRenameModel(t *testing.T) { + var spec1, spec2, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + InvalidInput: + type: "string" + format: "string" +`), &spec1) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test" +definitions: + Test: + description: "This Test has a description" + type: "object" + properties: + id: + type: "integer" + format: "int64" + InvalidInput: + type: "string" + format: "string" +`), &spec2) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /test: + post: + tags: + - "test" + summary: "Test API" + operationId: "addTest" + parameters: + - in: "body" + name: "body" + description: "test object" + required: true + schema: + $ref: "#/definitions/Test" + responses: + 405: + description: "Invalid input" + $ref: "#/definitions/InvalidInput" + /othertest: + post: + tags: + - "test2" + summary: "Test2 API" + operationId: "addTest2" + consumes: + - "application/json" + produces: + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "test2 object" + required: true + schema: + $ref: "#/definitions/Test_v2" +definitions: + Test: + type: "object" + properties: + id: + type: "integer" + format: "int64" + status: + type: "string" + description: "Status" + Test_v2: + description: "This Test has a description" + type: "object" + properties: + id: + type: "integer" + format: "int64" + InvalidInput: + type: "string" + format: "string" +`), &expected) + assert := assert.New(t) + if !assert.NoError(MergeSpecs(spec1, spec2)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{spec1}) +} + +func TestSafeMergeSpecsSimple(t *testing.T) { + var fooSpec, barSpec, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &fooSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /bar: + post: + summary: "Bar API" + operationId: "barTest" + parameters: + - in: "body" + name: "body" + description: "bar object" + required: true + schema: + $ref: "#/definitions/Bar" + responses: + 200: + description: "OK" +definitions: + Bar: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &barSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" + /bar: + post: + summary: "Bar API" + operationId: "barTest" + parameters: + - in: "body" + name: "body" + description: "bar object" + required: true + schema: + $ref: "#/definitions/Bar" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" + Bar: + type: "object" + properties: + id: + type: "integer" + format: "int64" + `), &expected) + assert := assert.New(t) + actual, err := CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + if !assert.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{actual}) +} + +func TestSafeMergeSpecsReuseModel(t *testing.T) { + var fooSpec, barSpec, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &fooSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /refoo: + post: + summary: "Refoo API" + operationId: "refooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &barSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" + /refoo: + post: + summary: "Refoo API" + operationId: "refooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" + `), &expected) + assert := assert.New(t) + actual, err := CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + if !assert.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{actual}) +} + +func TestSafeMergeSpecsReuseModelFails(t *testing.T) { + var fooSpec, barSpec, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &fooSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /refoo: + post: + summary: "Refoo API" + operationId: "refooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" + new_field: + type: "string" +`), &barSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" + /refoo: + post: + summary: "Refoo API" + operationId: "refooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" + `), &expected) + assert := assert.New(t) + actual, err := CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + assert.Error(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) +} + +func TestMergeSpecsIgnorePathConflicts(t *testing.T) { + var fooSpec, barSpec, expected *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &fooSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Should be ignored" + /bar: + post: + summary: "Bar API" + operationId: "barTest" + parameters: + - in: "body" + name: "body" + description: "bar object" + required: true + schema: + $ref: "#/definitions/Bar" + responses: + 200: + description: "OK" +definitions: + Bar: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &barSpec) + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" + /bar: + post: + summary: "Bar API" + operationId: "barTest" + parameters: + - in: "body" + name: "body" + description: "bar object" + required: true + schema: + $ref: "#/definitions/Bar" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" + Bar: + type: "object" + properties: + id: + type: "integer" + format: "int64" + `), &expected) + assert := assert.New(t) + actual, err := CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + if !assert.Error(MergeSpecs(actual, barSpec)) { + return + } + actual, err = CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + if !assert.NoError(MergeSpecsIgnorePathConflict(actual, barSpec)) { + return + } + assert.Equal(DebugSpec{expected}, DebugSpec{actual}) +} + +func TestMergeSpecsIgnorePathConflictsAllConflicting(t *testing.T) { + var fooSpec *spec.Swagger + yaml.Unmarshal([]byte(` +swagger: "2.0" +paths: + /foo: + post: + summary: "Foo API" + operationId: "fooTest" + parameters: + - in: "body" + name: "body" + description: "foo object" + required: true + schema: + $ref: "#/definitions/Foo" + responses: + 200: + description: "OK" +definitions: + Foo: + type: "object" + properties: + id: + type: "integer" + format: "int64" +`), &fooSpec) + assert := assert.New(t) + foo2Spec, err := CloneSpec(fooSpec) + actual, err := CloneSpec(fooSpec) + if !assert.NoError(err) { + return + } + if !assert.NoError(MergeSpecsIgnorePathConflict(actual, foo2Spec)) { + return + } + assert.Equal(DebugSpec{fooSpec}, DebugSpec{actual}) +} diff --git a/discovery/vendor/k8s.io/kube-openapi/pkg/builder/openapi_test.go b/discovery/vendor/k8s.io/kube-openapi/pkg/builder/openapi_test.go new file mode 100644 index 00000000..9045e06d --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/pkg/builder/openapi_test.go @@ -0,0 +1,465 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package builder + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" + "testing" + + "github.com/emicklei/go-restful" + "github.com/go-openapi/spec" + "github.com/stretchr/testify/assert" + openapi "k8s.io/kube-openapi/pkg/common" +) + +// setUp is a convenience function for setting up for (most) tests. +func setUp(t *testing.T, fullMethods bool) (openAPI, *restful.Container, *assert.Assertions) { + assert := assert.New(t) + config, container := getConfig(fullMethods) + return openAPI{ + config: config, + swagger: &spec.Swagger{ + SwaggerProps: spec.SwaggerProps{ + Swagger: OpenAPIVersion, + Definitions: spec.Definitions{}, + Paths: &spec.Paths{Paths: map[string]spec.PathItem{}}, + Info: config.Info, + }, + }, + }, container, assert +} + +func noOp(request *restful.Request, response *restful.Response) {} + +// Test input +type TestInput struct { + // Name of the input + Name string `json:"name,omitempty"` + // ID of the input + ID int `json:"id,omitempty"` + Tags []string `json:"tags,omitempty"` +} + +// Test output +type TestOutput struct { + // Name of the output + Name string `json:"name,omitempty"` + // Number of outputs + Count int `json:"count,omitempty"` +} + +func (_ TestInput) OpenAPIDefinition() *openapi.OpenAPIDefinition { + schema := spec.Schema{} + schema.Description = "Test input" + schema.Properties = map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name of the input", + Type: []string{"string"}, + Format: "", + }, + }, + "id": { + SchemaProps: spec.SchemaProps{ + Description: "ID of the input", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "tags": { + SchemaProps: spec.SchemaProps{ + Description: "", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } + schema.Extensions = spec.Extensions{"x-test": "test"} + return &openapi.OpenAPIDefinition{ + Schema: schema, + Dependencies: []string{}, + } +} + +func (_ TestOutput) OpenAPIDefinition() *openapi.OpenAPIDefinition { + schema := spec.Schema{} + schema.Description = "Test output" + schema.Properties = map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name of the output", + Type: []string{"string"}, + Format: "", + }, + }, + "count": { + SchemaProps: spec.SchemaProps{ + Description: "Number of outputs", + Type: []string{"integer"}, + Format: "int32", + }, + }, + } + return &openapi.OpenAPIDefinition{ + Schema: schema, + Dependencies: []string{}, + } +} + +var _ openapi.OpenAPIDefinitionGetter = TestInput{} +var _ openapi.OpenAPIDefinitionGetter = TestOutput{} + +func getTestRoute(ws *restful.WebService, method string, additionalParams bool, opPrefix string) *restful.RouteBuilder { + ret := ws.Method(method). + Path("/test/{path:*}"). + Doc(fmt.Sprintf("%s test input", method)). + Operation(fmt.Sprintf("%s%sTestInput", method, opPrefix)). + Produces(restful.MIME_JSON). + Consumes(restful.MIME_JSON). + Param(ws.PathParameter("path", "path to the resource").DataType("string")). + Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")). + Reads(TestInput{}). + Returns(200, "OK", TestOutput{}). + Writes(TestOutput{}). + To(noOp) + if additionalParams { + ret.Param(ws.HeaderParameter("hparam", "a test head parameter").DataType("integer")) + ret.Param(ws.FormParameter("fparam", "a test form parameter").DataType("number")) + } + return ret +} + +func getConfig(fullMethods bool) (*openapi.Config, *restful.Container) { + mux := http.NewServeMux() + container := restful.NewContainer() + container.ServeMux = mux + ws := new(restful.WebService) + ws.Path("/foo") + ws.Route(getTestRoute(ws, "get", true, "foo")) + if fullMethods { + ws.Route(getTestRoute(ws, "post", false, "foo")). + Route(getTestRoute(ws, "put", false, "foo")). + Route(getTestRoute(ws, "head", false, "foo")). + Route(getTestRoute(ws, "patch", false, "foo")). + Route(getTestRoute(ws, "options", false, "foo")). + Route(getTestRoute(ws, "delete", false, "foo")) + + } + ws.Path("/bar") + ws.Route(getTestRoute(ws, "get", true, "bar")) + if fullMethods { + ws.Route(getTestRoute(ws, "post", false, "bar")). + Route(getTestRoute(ws, "put", false, "bar")). + Route(getTestRoute(ws, "head", false, "bar")). + Route(getTestRoute(ws, "patch", false, "bar")). + Route(getTestRoute(ws, "options", false, "bar")). + Route(getTestRoute(ws, "delete", false, "bar")) + + } + container.Add(ws) + return &openapi.Config{ + ProtocolList: []string{"https"}, + Info: &spec.Info{ + InfoProps: spec.InfoProps{ + Title: "TestAPI", + Description: "Test API", + Version: "unversioned", + }, + }, + GetDefinitions: func(_ openapi.ReferenceCallback) map[string]openapi.OpenAPIDefinition { + return map[string]openapi.OpenAPIDefinition{ + "k8s.io/kube-openapi/pkg/builder.TestInput": *TestInput{}.OpenAPIDefinition(), + "k8s.io/kube-openapi/pkg/builder.TestOutput": *TestOutput{}.OpenAPIDefinition(), + // Bazel changes the package name, this is ok for testing, but we need to fix it if it happened + // in the main code. + "k8s.io/kube-openapi/pkg/builder/go_default_test.TestInput": *TestInput{}.OpenAPIDefinition(), + "k8s.io/kube-openapi/pkg/builder/go_default_test.TestOutput": *TestOutput{}.OpenAPIDefinition(), + } + }, + GetDefinitionName: func(name string) (string, spec.Extensions) { + friendlyName := name[strings.LastIndex(name, "/")+1:] + if strings.HasPrefix(friendlyName, "go_default_test") { + friendlyName = "builder" + friendlyName[len("go_default_test"):] + } + return friendlyName, spec.Extensions{"x-test2": "test2"} + }, + }, container +} + +func getTestOperation(method string, opPrefix string) *spec.Operation { + return &spec.Operation{ + OperationProps: spec.OperationProps{ + Description: fmt.Sprintf("%s test input", method), + Consumes: []string{"application/json"}, + Produces: []string{"application/json"}, + Schemes: []string{"https"}, + Parameters: []spec.Parameter{}, + Responses: getTestResponses(), + ID: fmt.Sprintf("%s%sTestInput", method, opPrefix), + }, + } +} + +func getTestPathItem(allMethods bool, opPrefix string) spec.PathItem { + ret := spec.PathItem{ + PathItemProps: spec.PathItemProps{ + Get: getTestOperation("get", opPrefix), + Parameters: getTestCommonParameters(), + }, + } + ret.Get.Parameters = getAdditionalTestParameters() + if allMethods { + ret.Put = getTestOperation("put", opPrefix) + ret.Put.Parameters = getTestParameters() + ret.Post = getTestOperation("post", opPrefix) + ret.Post.Parameters = getTestParameters() + ret.Head = getTestOperation("head", opPrefix) + ret.Head.Parameters = getTestParameters() + ret.Patch = getTestOperation("patch", opPrefix) + ret.Patch.Parameters = getTestParameters() + ret.Delete = getTestOperation("delete", opPrefix) + ret.Delete.Parameters = getTestParameters() + ret.Options = getTestOperation("options", opPrefix) + ret.Options.Parameters = getTestParameters() + } + return ret +} + +func getRefSchema(ref string) *spec.Schema { + return &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: spec.MustCreateRef(ref), + }, + } +} + +func getTestResponses() *spec.Responses { + ret := spec.Responses{ + ResponsesProps: spec.ResponsesProps{ + StatusCodeResponses: map[int]spec.Response{}, + }, + } + ret.StatusCodeResponses[200] = spec.Response{ + ResponseProps: spec.ResponseProps{ + Description: "OK", + Schema: getRefSchema("#/definitions/builder.TestOutput"), + }, + } + return &ret +} + +func getTestCommonParameters() []spec.Parameter { + ret := make([]spec.Parameter, 2) + ret[0] = spec.Parameter{ + SimpleSchema: spec.SimpleSchema{ + Type: "string", + }, + ParamProps: spec.ParamProps{ + Description: "path to the resource", + Name: "path", + In: "path", + Required: true, + }, + CommonValidations: spec.CommonValidations{ + UniqueItems: true, + }, + } + ret[1] = spec.Parameter{ + SimpleSchema: spec.SimpleSchema{ + Type: "string", + }, + ParamProps: spec.ParamProps{ + Description: "If 'true', then the output is pretty printed.", + Name: "pretty", + In: "query", + }, + CommonValidations: spec.CommonValidations{ + UniqueItems: true, + }, + } + return ret +} + +func getTestParameters() []spec.Parameter { + ret := make([]spec.Parameter, 1) + ret[0] = spec.Parameter{ + ParamProps: spec.ParamProps{ + Name: "body", + In: "body", + Required: true, + Schema: getRefSchema("#/definitions/builder.TestInput"), + }, + } + return ret +} + +func getAdditionalTestParameters() []spec.Parameter { + ret := make([]spec.Parameter, 3) + ret[0] = spec.Parameter{ + ParamProps: spec.ParamProps{ + Name: "body", + In: "body", + Required: true, + Schema: getRefSchema("#/definitions/builder.TestInput"), + }, + } + ret[1] = spec.Parameter{ + ParamProps: spec.ParamProps{ + Name: "fparam", + Description: "a test form parameter", + In: "formData", + }, + SimpleSchema: spec.SimpleSchema{ + Type: "number", + }, + CommonValidations: spec.CommonValidations{ + UniqueItems: true, + }, + } + ret[2] = spec.Parameter{ + SimpleSchema: spec.SimpleSchema{ + Type: "integer", + }, + ParamProps: spec.ParamProps{ + Description: "a test head parameter", + Name: "hparam", + In: "header", + }, + CommonValidations: spec.CommonValidations{ + UniqueItems: true, + }, + } + return ret +} + +func getTestInputDefinition() spec.Schema { + return spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Test input", + Properties: map[string]spec.Schema{ + "id": { + SchemaProps: spec.SchemaProps{ + Description: "ID of the input", + Type: spec.StringOrArray{"integer"}, + Format: "int32", + }, + }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name of the input", + Type: spec.StringOrArray{"string"}, + }, + }, + "tags": { + SchemaProps: spec.SchemaProps{ + Type: spec.StringOrArray{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: spec.StringOrArray{"string"}, + }, + }, + }, + }, + }, + }, + }, + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-test": "test", + "x-test2": "test2", + }, + }, + } +} + +func getTestOutputDefinition() spec.Schema { + return spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Test output", + Properties: map[string]spec.Schema{ + "count": { + SchemaProps: spec.SchemaProps{ + Description: "Number of outputs", + Type: spec.StringOrArray{"integer"}, + Format: "int32", + }, + }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name of the output", + Type: spec.StringOrArray{"string"}, + }, + }, + }, + }, + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-test2": "test2", + }, + }, + } +} + +func TestBuildSwaggerSpec(t *testing.T) { + o, container, assert := setUp(t, true) + expected := &spec.Swagger{ + SwaggerProps: spec.SwaggerProps{ + Info: &spec.Info{ + InfoProps: spec.InfoProps{ + Title: "TestAPI", + Description: "Test API", + Version: "unversioned", + }, + }, + Swagger: "2.0", + Paths: &spec.Paths{ + Paths: map[string]spec.PathItem{ + "/foo/test/{path}": getTestPathItem(true, "foo"), + "/bar/test/{path}": getTestPathItem(true, "bar"), + }, + }, + Definitions: spec.Definitions{ + "builder.TestInput": getTestInputDefinition(), + "builder.TestOutput": getTestOutputDefinition(), + }, + }, + } + err := o.init(container.RegisteredWebServices()) + if !assert.NoError(err) { + return + } + expected_json, err := json.Marshal(expected) + if !assert.NoError(err) { + return + } + actual_json, err := json.Marshal(o.swagger) + if !assert.NoError(err) { + return + } + assert.Equal(string(expected_json), string(actual_json)) +} diff --git a/discovery/vendor/k8s.io/kube-openapi/pkg/generators/openapi_test.go b/discovery/vendor/k8s.io/kube-openapi/pkg/generators/openapi_test.go new file mode 100644 index 00000000..70e52ea1 --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/pkg/generators/openapi_test.go @@ -0,0 +1,375 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "bytes" + "fmt" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + + "k8s.io/gengo/generator" + "k8s.io/gengo/namer" + "k8s.io/gengo/parser" + "k8s.io/gengo/types" +) + +func construct(t *testing.T, files map[string]string, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) { + b := parser.New() + for name, src := range files { + if err := b.AddFileForTest(filepath.Dir(name), name, []byte(src)); err != nil { + t.Fatal(err) + } + } + u, err := b.FindTypes() + if err != nil { + t.Fatal(err) + } + orderer := namer.Orderer{Namer: testNamer} + o := orderer.OrderUniverse(u) + return b, u, o +} + +func testOpenAPITypeWritter(t *testing.T, code string) (error, *assert.Assertions, *bytes.Buffer) { + assert := assert.New(t) + var testFiles = map[string]string{ + "base/foo/bar.go": code, + } + rawNamer := namer.NewRawNamer("o", nil) + namers := namer.NameSystems{ + "raw": namer.NewRawNamer("", nil), + } + builder, universe, _ := construct(t, testFiles, rawNamer) + context, err := generator.NewContext(builder, namers, "raw") + if err != nil { + t.Fatal(err) + } + buffer := &bytes.Buffer{} + sw := generator.NewSnippetWriter(buffer, context, "$", "$") + blahT := universe.Type(types.Name{Package: "base/foo", Name: "Blah"}) + return newOpenAPITypeWriter(sw).generate(blahT), assert, buffer +} + +func TestSimple(t *testing.T) { + err, assert, buffer := testOpenAPITypeWritter(t, ` +package foo + +// Blah is a test. +// +k8s:openapi-gen=true +// +k8s:openapi-gen=x-kubernetes-type-tag:type_test +type Blah struct { + // A simple string + String string + // A simple int + Int int `+"`"+`json:",omitempty"`+"`"+` + // An int considered string simple int + IntString int `+"`"+`json:",string"`+"`"+` + // A simple int64 + Int64 int64 + // A simple int32 + Int32 int32 + // A simple int16 + Int16 int16 + // A simple int8 + Int8 int8 + // A simple int + Uint uint + // A simple int64 + Uint64 uint64 + // A simple int32 + Uint32 uint32 + // A simple int16 + Uint16 uint16 + // A simple int8 + Uint8 uint8 + // A simple byte + Byte byte + // A simple boolean + Bool bool + // A simple float64 + Float64 float64 + // A simple float32 + Float32 float32 + // a base64 encoded characters + ByteArray []byte + // a member with an extension + // +k8s:openapi-gen=x-kubernetes-member-tag:member_test + WithExtension string + // a member with struct tag as extension + // +patchStrategy=ps + // +patchMergeKey=pmk + WithStructTagExtension string `+"`"+`patchStrategy:"ps" patchMergeKey:"pmk"`+"`"+` +} + `) + if err != nil { + t.Fatal(err) + } + assert.Equal(`"base/foo.Blah": { +Schema: spec.Schema{ +SchemaProps: spec.SchemaProps{ +Description: "Blah is a test.", +Properties: map[string]spec.Schema{ +"String": { +SchemaProps: spec.SchemaProps{ +Description: "A simple string", +Type: []string{"string"}, +Format: "", +}, +}, +"Int64": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int64", +Type: []string{"integer"}, +Format: "int64", +}, +}, +"Int32": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int32", +Type: []string{"integer"}, +Format: "int32", +}, +}, +"Int16": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int16", +Type: []string{"integer"}, +Format: "int32", +}, +}, +"Int8": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int8", +Type: []string{"integer"}, +Format: "byte", +}, +}, +"Uint": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int", +Type: []string{"integer"}, +Format: "int32", +}, +}, +"Uint64": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int64", +Type: []string{"integer"}, +Format: "int64", +}, +}, +"Uint32": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int32", +Type: []string{"integer"}, +Format: "int64", +}, +}, +"Uint16": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int16", +Type: []string{"integer"}, +Format: "int32", +}, +}, +"Uint8": { +SchemaProps: spec.SchemaProps{ +Description: "A simple int8", +Type: []string{"integer"}, +Format: "byte", +}, +}, +"Byte": { +SchemaProps: spec.SchemaProps{ +Description: "A simple byte", +Type: []string{"integer"}, +Format: "byte", +}, +}, +"Bool": { +SchemaProps: spec.SchemaProps{ +Description: "A simple boolean", +Type: []string{"boolean"}, +Format: "", +}, +}, +"Float64": { +SchemaProps: spec.SchemaProps{ +Description: "A simple float64", +Type: []string{"number"}, +Format: "double", +}, +}, +"Float32": { +SchemaProps: spec.SchemaProps{ +Description: "A simple float32", +Type: []string{"number"}, +Format: "float", +}, +}, +"ByteArray": { +SchemaProps: spec.SchemaProps{ +Description: "a base64 encoded characters", +Type: []string{"string"}, +Format: "byte", +}, +}, +"WithExtension": { +VendorExtensible: spec.VendorExtensible{ +Extensions: spec.Extensions{ +"x-kubernetes-member-tag": "member_test", +}, +}, +SchemaProps: spec.SchemaProps{ +Description: "a member with an extension", +Type: []string{"string"}, +Format: "", +}, +}, +"WithStructTagExtension": { +VendorExtensible: spec.VendorExtensible{ +Extensions: spec.Extensions{ +"x-kubernetes-patch-merge-key": "pmk", +"x-kubernetes-patch-strategy": "ps", +}, +}, +SchemaProps: spec.SchemaProps{ +Description: "a member with struct tag as extension", +Type: []string{"string"}, +Format: "", +}, +}, +}, +Required: []string{"String","Int64","Int32","Int16","Int8","Uint","Uint64","Uint32","Uint16","Uint8","Byte","Bool","Float64","Float32","ByteArray","WithExtension","WithStructTagExtension"}, +}, +VendorExtensible: spec.VendorExtensible{ +Extensions: spec.Extensions{ +"x-kubernetes-type-tag": "type_test", +}, +}, +}, +Dependencies: []string{ +}, +}, +`, buffer.String()) +} + +func TestFailingSample1(t *testing.T) { + err, assert, _ := testOpenAPITypeWritter(t, ` +package foo + +// Map sample tests openAPIGen.generateMapProperty method. +type Blah struct { + // A sample String to String map + StringToArray map[string]map[string]string +} + `) + if assert.Error(err, "An error was expected") { + assert.Equal(err, fmt.Errorf("map Element kind Map is not supported in map[string]map[string]string")) + } +} + +func TestFailingSample2(t *testing.T) { + err, assert, _ := testOpenAPITypeWritter(t, ` +package foo + +// Map sample tests openAPIGen.generateMapProperty method. +type Blah struct { + // A sample String to String map + StringToArray map[int]string +} `) + if assert.Error(err, "An error was expected") { + assert.Equal(err, fmt.Errorf("map with non-string keys are not supported by OpenAPI in map[int]string")) + } +} + +func TestPointer(t *testing.T) { + err, assert, buffer := testOpenAPITypeWritter(t, ` +package foo + +// PointerSample demonstrate pointer's properties +type Blah struct { + // A string pointer + StringPointer *string + // A struct pointer + StructPointer *Blah + // A slice pointer + SlicePointer *[]string + // A map pointer + MapPointer *map[string]string +} + `) + if err != nil { + t.Fatal(err) + } + assert.Equal(`"base/foo.Blah": { +Schema: spec.Schema{ +SchemaProps: spec.SchemaProps{ +Description: "PointerSample demonstrate pointer's properties", +Properties: map[string]spec.Schema{ +"StringPointer": { +SchemaProps: spec.SchemaProps{ +Description: "A string pointer", +Type: []string{"string"}, +Format: "", +}, +}, +"StructPointer": { +SchemaProps: spec.SchemaProps{ +Description: "A struct pointer", +Ref: ref("base/foo.Blah"), +}, +}, +"SlicePointer": { +SchemaProps: spec.SchemaProps{ +Description: "A slice pointer", +Type: []string{"array"}, +Items: &spec.SchemaOrArray{ +Schema: &spec.Schema{ +SchemaProps: spec.SchemaProps{ +Type: []string{"string"}, +Format: "", +}, +}, +}, +}, +}, +"MapPointer": { +SchemaProps: spec.SchemaProps{ +Description: "A map pointer", +Type: []string{"object"}, +AdditionalProperties: &spec.SchemaOrBool{ +Schema: &spec.Schema{ +SchemaProps: spec.SchemaProps{ +Type: []string{"string"}, +Format: "", +}, +}, +}, +}, +}, +}, +Required: []string{"StringPointer","StructPointer","SlicePointer","MapPointer"}, +}, +}, +Dependencies: []string{ +"base/foo.Blah",}, +}, +`, buffer.String()) +} diff --git a/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_suite_test.go b/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_suite_test.go new file mode 100644 index 00000000..24b5168e --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_suite_test.go @@ -0,0 +1,49 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package proto_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/config" + . "github.com/onsi/ginkgo/types" + . "github.com/onsi/gomega" + + "fmt" + "testing" +) + +func TestOpenapi(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecsWithDefaultAndCustomReporters(t, "Openapi Suite", []Reporter{newlineReporter{}}) +} + +// Print a newline after the default newlineReporter due to issue +// https://github.com/jstemmer/go-junit-report/issues/31 +type newlineReporter struct{} + +func (newlineReporter) SpecSuiteWillBegin(config GinkgoConfigType, summary *SuiteSummary) {} + +func (newlineReporter) BeforeSuiteDidRun(setupSummary *SetupSummary) {} + +func (newlineReporter) AfterSuiteDidRun(setupSummary *SetupSummary) {} + +func (newlineReporter) SpecWillRun(specSummary *SpecSummary) {} + +func (newlineReporter) SpecDidComplete(specSummary *SpecSummary) {} + +// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:" +func (newlineReporter) SpecSuiteDidEnd(summary *SuiteSummary) { fmt.Printf("\n") } diff --git a/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_test.go b/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_test.go new file mode 100644 index 00000000..916abe0c --- /dev/null +++ b/discovery/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi_test.go @@ -0,0 +1,207 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package proto_test + +import ( + "path/filepath" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "k8s.io/kube-openapi/pkg/util/proto" + "k8s.io/kube-openapi/pkg/util/proto/testing" +) + +var fakeSchema = testing.Fake{Path: filepath.Join("testing", "swagger.json")} + +var _ = Describe("Reading apps/v1beta1/Deployment from openAPIData", func() { + var models proto.Models + BeforeEach(func() { + s, err := fakeSchema.OpenAPISchema() + Expect(err).To(BeNil()) + models, err = proto.NewOpenAPIData(s) + Expect(err).To(BeNil()) + }) + + model := "io.k8s.api.apps.v1beta1.Deployment" + var schema proto.Schema + It("should lookup the Schema by its model name", func() { + schema = models.LookupModel(model) + Expect(schema).ToNot(BeNil()) + }) + + var deployment *proto.Kind + It("should be a Kind", func() { + deployment = schema.(*proto.Kind) + Expect(deployment).ToNot(BeNil()) + }) + + It("should have a path", func() { + Expect(deployment.GetPath().Get()).To(Equal([]string{"io.k8s.api.apps.v1beta1.Deployment"})) + }) + + It("should have a kind key of type string", func() { + Expect(deployment.Fields).To(HaveKey("kind")) + key := deployment.Fields["kind"].(*proto.Primitive) + Expect(key).ToNot(BeNil()) + Expect(key.Type).To(Equal("string")) + Expect(key.GetPath().Get()).To(Equal([]string{"io.k8s.api.apps.v1beta1.Deployment", ".kind"})) + }) + + It("should have a apiVersion key of type string", func() { + Expect(deployment.Fields).To(HaveKey("apiVersion")) + key := deployment.Fields["apiVersion"].(*proto.Primitive) + Expect(key).ToNot(BeNil()) + Expect(key.Type).To(Equal("string")) + Expect(key.GetPath().Get()).To(Equal([]string{"io.k8s.api.apps.v1beta1.Deployment", ".apiVersion"})) + }) + + It("should have a metadata key of type Reference", func() { + Expect(deployment.Fields).To(HaveKey("metadata")) + key := deployment.Fields["metadata"].(proto.Reference) + Expect(key).ToNot(BeNil()) + Expect(key.Reference()).To(Equal("io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta")) + subSchema := key.SubSchema().(*proto.Kind) + Expect(subSchema).ToNot(BeNil()) + }) + + var status *proto.Kind + It("should have a status key of type Reference", func() { + Expect(deployment.Fields).To(HaveKey("status")) + key := deployment.Fields["status"].(proto.Reference) + Expect(key).ToNot(BeNil()) + Expect(key.Reference()).To(Equal("io.k8s.api.apps.v1beta1.DeploymentStatus")) + status = key.SubSchema().(*proto.Kind) + Expect(status).ToNot(BeNil()) + }) + + It("should have a valid DeploymentStatus", func() { + By("having availableReplicas key") + Expect(status.Fields).To(HaveKey("availableReplicas")) + replicas := status.Fields["availableReplicas"].(*proto.Primitive) + Expect(replicas).ToNot(BeNil()) + Expect(replicas.Type).To(Equal("integer")) + + By("having conditions key") + Expect(status.Fields).To(HaveKey("conditions")) + conditions := status.Fields["conditions"].(*proto.Array) + Expect(conditions).ToNot(BeNil()) + Expect(conditions.GetName()).To(Equal(`Array of Reference to "io.k8s.api.apps.v1beta1.DeploymentCondition"`)) + Expect(conditions.GetExtensions()).To(Equal(map[string]interface{}{ + "x-kubernetes-patch-merge-key": "type", + "x-kubernetes-patch-strategy": "merge", + })) + condition := conditions.SubType.(proto.Reference) + Expect(condition.Reference()).To(Equal("io.k8s.api.apps.v1beta1.DeploymentCondition")) + }) + + var spec *proto.Kind + It("should have a spec key of type Reference", func() { + Expect(deployment.Fields).To(HaveKey("spec")) + key := deployment.Fields["spec"].(proto.Reference) + Expect(key).ToNot(BeNil()) + Expect(key.Reference()).To(Equal("io.k8s.api.apps.v1beta1.DeploymentSpec")) + spec = key.SubSchema().(*proto.Kind) + Expect(spec).ToNot(BeNil()) + }) + + It("should have a spec with no gvk", func() { + _, found := spec.GetExtensions()["x-kubernetes-group-version-kind"] + Expect(found).To(BeFalse()) + }) + + It("should have a spec with a PodTemplateSpec sub-field", func() { + Expect(spec.Fields).To(HaveKey("template")) + key := spec.Fields["template"].(proto.Reference) + Expect(key).ToNot(BeNil()) + Expect(key.Reference()).To(Equal("io.k8s.api.core.v1.PodTemplateSpec")) + }) +}) + +var _ = Describe("Reading authorization.k8s.io/v1/SubjectAccessReview from openAPIData", func() { + var models proto.Models + BeforeEach(func() { + s, err := fakeSchema.OpenAPISchema() + Expect(err).To(BeNil()) + models, err = proto.NewOpenAPIData(s) + Expect(err).To(BeNil()) + }) + + model := "io.k8s.api.authorization.v1.LocalSubjectAccessReview" + var schema proto.Schema + It("should lookup the Schema by its model", func() { + schema = models.LookupModel(model) + Expect(schema).ToNot(BeNil()) + }) + + var sarspec *proto.Kind + It("should be a Kind and have a spec", func() { + sar := schema.(*proto.Kind) + Expect(sar).ToNot(BeNil()) + Expect(sar.Fields).To(HaveKey("spec")) + specRef := sar.Fields["spec"].(proto.Reference) + Expect(specRef).ToNot(BeNil()) + Expect(specRef.Reference()).To(Equal("io.k8s.api.authorization.v1.SubjectAccessReviewSpec")) + sarspec = specRef.SubSchema().(*proto.Kind) + Expect(sarspec).ToNot(BeNil()) + }) + + It("should have a valid SubjectAccessReviewSpec", func() { + Expect(sarspec.Fields).To(HaveKey("extra")) + extra := sarspec.Fields["extra"].(*proto.Map) + Expect(extra).ToNot(BeNil()) + Expect(extra.GetName()).To(Equal("Map of Array of string")) + Expect(extra.GetPath().Get()).To(Equal([]string{"io.k8s.api.authorization.v1.SubjectAccessReviewSpec", ".extra"})) + array := extra.SubType.(*proto.Array) + Expect(array).ToNot(BeNil()) + Expect(array.GetName()).To(Equal("Array of string")) + Expect(array.GetPath().Get()).To(Equal([]string{"io.k8s.api.authorization.v1.SubjectAccessReviewSpec", ".extra"})) + str := array.SubType.(*proto.Primitive) + Expect(str).ToNot(BeNil()) + Expect(str.Type).To(Equal("string")) + Expect(str.GetName()).To(Equal("string")) + Expect(str.GetPath().Get()).To(Equal([]string{"io.k8s.api.authorization.v1.SubjectAccessReviewSpec", ".extra"})) + }) +}) + +var _ = Describe("Path", func() { + It("can be created by NewPath", func() { + path := proto.NewPath("key") + Expect(path.String()).To(Equal("key")) + }) + It("can create and print complex paths", func() { + key := proto.NewPath("key") + array := key.ArrayPath(12) + field := array.FieldPath("subKey") + + Expect(field.String()).To(Equal("key[12].subKey")) + }) + It("has a length", func() { + key := proto.NewPath("key") + array := key.ArrayPath(12) + field := array.FieldPath("subKey") + + Expect(field.Len()).To(Equal(3)) + }) + It("can look like an array", func() { + key := proto.NewPath("key") + array := key.ArrayPath(12) + field := array.FieldPath("subKey") + + Expect(field.Get()).To(Equal([]string{"key", "[12]", ".subKey"})) + }) +})